Coverage Report

Created: 2018-07-19 03:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Bitcode/BitCodes.h
Line
Count
Source
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
2.03M
  explicit BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
108
  explicit BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
109
3.71M
    : Val(Data), IsLiteral(false), Enc(E) {}
110
111
78.5M
  bool isLiteral() const  { return IsLiteral; }
112
11.6M
  bool isEncoding() const { return !IsLiteral; }
113
114
  // Accessors for literals.
115
19.6M
  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
116
117
  // Accessors for encoding info.
118
158M
  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
119
68.8M
  uint64_t getEncodingData() const {
120
68.8M
    assert(isEncoding() && hasEncodingData());
121
68.8M
    return Val;
122
68.8M
  }
123
124
1.27M
  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
125
3.71M
  static bool hasEncodingData(Encoding E) {
126
3.71M
    switch (E) {
127
3.71M
    case Fixed:
128
3.07M
    case VBR:
129
3.07M
      return true;
130
3.07M
    case Array:
131
638k
    case Char6:
132
638k
    case Blob:
133
638k
      return false;
134
1
    }
135
1
    report_fatal_error("Invalid encoding");
136
1
  }
137
138
  /// isChar6 - Return true if this character is legal in the Char6 encoding.
139
774k
  static bool isChar6(char C) {
140
774k
    if (C >= 'a' && 
C <= 'z'554k
)
return true554k
;
141
219k
    if (C >= 'A' && 
C <= 'Z'42.6k
)
return true23.0k
;
142
196k
    if (C >= '0' && 
C <= '9'109k
)
return true88.8k
;
143
108k
    if (C == '.' || 
C == '_'24.1k
)
return true103k
;
144
4.57k
    return false;
145
4.57k
  }
146
766k
  static unsigned EncodeChar6(char C) {
147
766k
    if (C >= 'a' && 
C <= 'z'551k
)
return C-'a'551k
;
148
215k
    if (C >= 'A' && 
C <= 'Z'42.5k
)
return C-'A'+2623.0k
;
149
192k
    if (C >= '0' && 
C <= '9'108k
)
return C-'0'+26+2688.7k
;
150
103k
    if (C == '.')             
return 6283.7k
;
151
19.5k
    
if (19.5k
C == '_'19.5k
) return 63;
152
18.4E
    llvm_unreachable("Not a value Char6 character!");
153
18.4E
  }
154
155
108M
  static char DecodeChar6(unsigned V) {
156
108M
    assert((V & ~63) == 0 && "Not a Char6 encoded character!");
157
108M
    return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._"
158
108M
        [V];
159
108M
  }
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
20.1M
  unsigned getNumOperandInfos() const {
173
20.1M
    return static_cast<unsigned>(OperandList.size());
174
20.1M
  }
175
88.4M
  const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
176
88.4M
    return OperandList[N];
177
88.4M
  }
178
179
5.74M
  void Add(const BitCodeAbbrevOp &OpInfo) {
180
5.74M
    OperandList.push_back(OpInfo);
181
5.74M
  }
182
};
183
} // End llvm namespace
184
185
#endif