Coverage Report

Created: 2018-09-19 20:53

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Bitcode/BitCodes.h
Line
Count
Source (jump to first uncovered line)
1
//===- BitCodes.h - Enum values for the bitcode format ----------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This header Bitcode enum values.
11
//
12
// The enum values defined in this file should be considered permanent.  If
13
// new features are added, they should have values added at the end of the
14
// respective lists.
15
//
16
//===----------------------------------------------------------------------===//
17
18
#ifndef LLVM_BITCODE_BITCODES_H
19
#define LLVM_BITCODE_BITCODES_H
20
21
#include "llvm/ADT/SmallVector.h"
22
#include "llvm/Support/DataTypes.h"
23
#include "llvm/Support/ErrorHandling.h"
24
#include <cassert>
25
26
namespace llvm {
27
/// Offsets of the 32-bit fields of bitcode wrapper header.
28
static const unsigned BWH_MagicField = 0 * 4;
29
static const unsigned BWH_VersionField = 1 * 4;
30
static const unsigned BWH_OffsetField = 2 * 4;
31
static const unsigned BWH_SizeField = 3 * 4;
32
static const unsigned BWH_CPUTypeField = 4 * 4;
33
static const unsigned BWH_HeaderSize = 5 * 4;
34
35
namespace bitc {
36
  enum StandardWidths {
37
    BlockIDWidth   = 8,  // We use VBR-8 for block IDs.
38
    CodeLenWidth   = 4,  // Codelen are VBR-4.
39
    BlockSizeWidth = 32  // BlockSize up to 2^32 32-bit words = 16GB per block.
40
  };
41
42
  // The standard abbrev namespace always has a way to exit a block, enter a
43
  // nested block, define abbrevs, and define an unabbreviated record.
44
  enum FixedAbbrevIDs {
45
    END_BLOCK = 0,  // Must be zero to guarantee termination for broken bitcode.
46
    ENTER_SUBBLOCK = 1,
47
48
    /// DEFINE_ABBREV - Defines an abbrev for the current block.  It consists
49
    /// of a vbr5 for # operand infos.  Each operand info is emitted with a
50
    /// single bit to indicate if it is a literal encoding.  If so, the value is
51
    /// emitted with a vbr8.  If not, the encoding is emitted as 3 bits followed
52
    /// by the info value as a vbr5 if needed.
53
    DEFINE_ABBREV = 2,
54
55
    // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by
56
    // a vbr6 for the # operands, followed by vbr6's for each operand.
57
    UNABBREV_RECORD = 3,
58
59
    // This is not a code, this is a marker for the first abbrev assignment.
60
    FIRST_APPLICATION_ABBREV = 4
61
  };
62
63
  /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
64
  /// block, which contains metadata about other blocks in the file.
65
  enum StandardBlockIDs {
66
    /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
67
    /// standard abbrevs that should be available to all blocks of a specified
68
    /// ID.
69
    BLOCKINFO_BLOCK_ID = 0,
70
71
    // Block IDs 1-7 are reserved for future expansion.
72
    FIRST_APPLICATION_BLOCKID = 8
73
  };
74
75
  /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
76
  /// blocks.
77
  enum BlockInfoCodes {
78
    // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
79
    // block, instead of the BlockInfo block.
80
81
    BLOCKINFO_CODE_SETBID        = 1, // SETBID: [blockid#]
82
    BLOCKINFO_CODE_BLOCKNAME     = 2, // BLOCKNAME: [name]
83
    BLOCKINFO_CODE_SETRECORDNAME = 3  // BLOCKINFO_CODE_SETRECORDNAME:
84
                                      //                             [id, name]
85
  };
86
87
} // End bitc namespace
88
89
/// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
90
/// This is actually a union of two different things:
91
///   1. It could be a literal integer value ("the operand is always 17").
92
///   2. It could be an encoding specification ("this operand encoded like so").
93
///
94
class BitCodeAbbrevOp {
95
  uint64_t Val;           // A literal value or data for an encoding.
96
  bool IsLiteral : 1;     // Indicate whether this is a literal value or not.
97
  unsigned Enc   : 3;     // The encoding to use.
98
public:
99
  enum Encoding {
100
    Fixed = 1,  // A fixed width field, Val specifies number of bits.
101
    VBR   = 2,  // A VBR field where Val specifies the width of each chunk.
102
    Array = 3,  // A sequence of fields, next field species elt encoding.
103
    Char6 = 4,  // A 6-bit fixed field which maps to [a-zA-Z0-9._].
104
    Blob  = 5   // 32-bit aligned array of 8-bit characters.
105
  };
106
107
192k
  explicit BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
108
  explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
109
452k
    : Val(Data), IsLiteral(false), Enc(E) {}
110
111
56.5M
  bool isLiteral() const  { return IsLiteral; }
112
11.4M
  bool isEncoding() const { return !IsLiteral; }
113
114
  // Accessors for literals.
115
17.6M
  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
116
117
  // Accessors for encoding info.
118
116M
  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
119
46.1M
  uint64_t getEncodingData() const {
120
46.1M
    assert(isEncoding() && hasEncodingData());
121
46.1M
    return Val;
122
46.1M
  }
123
124
35.9k
  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
125
452k
  static bool hasEncodingData(Encoding E) {
126
452k
    switch (E) {
127
452k
    case Fixed:
128
318k
    case VBR:
129
318k
      return true;
130
318k
    case Array:
131
134k
    case Char6:
132
134k
    case Blob:
133
134k
      return false;
134
0
    }
135
0
    report_fatal_error("Invalid encoding");
136
0
  }
137
138
  /// isChar6 - Return true if this character is legal in the Char6 encoding.
139
24.7k
  static bool isChar6(char C) {
140
24.7k
    if (C >= 'a' && 
C <= 'z'13.0k
)
return true13.0k
;
141
11.6k
    if (C >= 'A' && 
C <= 'Z'2.54k
)
return true2.35k
;
142
9.28k
    if (C >= '0' && 
C <= '9'5.90k
)
return true5.66k
;
143
3.61k
    if (C == '.' || 
C == '_'764
)
return true3.04k
;
144
568
    return false;
145
568
  }
146
23.6k
  static unsigned EncodeChar6(char C) {
147
23.6k
    if (C >= 'a' && 
C <= 'z'12.6k
)
return C-'a'12.6k
;
148
11.0k
    if (C >= 'A' && 
C <= 'Z'2.54k
)
return C-'A'+262.34k
;
149
8.71k
    if (C >= '0' && 
C <= '9'5.86k
)
return C-'0'+26+265.66k
;
150
3.04k
    if (C == '.')             
return 622.85k
;
151
197
    
if (196
C == '_'196
) return 63;
152
18.4E
    llvm_unreachable("Not a value Char6 character!");
153
18.4E
  }
154
155
107M
  static char DecodeChar6(unsigned V) {
156
107M
    assert((V & ~63) == 0 && "Not a Char6 encoded character!");
157
107M
    return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
158
107M
        [V];
159
107M
  }
160
161
};
162
163
template <> struct isPodLike<BitCodeAbbrevOp> { static const bool value=true; };
164
165
/// BitCodeAbbrev - This class represents an abbreviation record.  An
166
/// abbreviation allows a complex record that has redundancy to be stored in a
167
/// specialized format instead of the fully-general, fully-vbr, format.
168
class BitCodeAbbrev {
169
  SmallVector<BitCodeAbbrevOp, 32> OperandList;
170
171
public:
172
17.2M
  unsigned getNumOperandInfos() const {
173
17.2M
    return static_cast<unsigned>(OperandList.size());
174
17.2M
  }
175
67.9M
  const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
176
67.9M
    return OperandList[N];
177
67.9M
  }
178
179
644k
  void Add(const BitCodeAbbrevOp &OpInfo) {
180
644k
    OperandList.push_back(OpInfo);
181
644k
  }
182
};
183
} // End llvm namespace
184
185
#endif