OLD | NEW |
---|---|
1 //===- NaClBitCodes.h - Enum values for the bitcode format ------*- C++ -*-===// | 1 //===- NaClBitCodes.h - Enum values for the bitcode format ------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This header Bitcode enum values. | 10 // This header Bitcode enum values. |
11 // | 11 // |
12 // The enum values defined in this file should be considered permanent. If | 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 | 13 // new features are added, they should have values added at the end of the |
14 // respective lists. | 14 // respective lists. |
15 // | 15 // |
16 //===----------------------------------------------------------------------===// | 16 //===----------------------------------------------------------------------===// |
17 | 17 |
18 #ifndef LLVM_BITCODE_NACL_NACLBITCODES_H | 18 #ifndef LLVM_BITCODE_NACL_NACLBITCODES_H |
19 #define LLVM_BITCODE_NACL_NACLBITCODES_H | 19 #define LLVM_BITCODE_NACL_NACLBITCODES_H |
20 | 20 |
21 #include "llvm/ADT/SmallVector.h" | 21 #include "llvm/ADT/SmallVector.h" |
22 #include "llvm/Support/DataTypes.h" | 22 #include "llvm/Support/DataTypes.h" |
23 #include "llvm/Support/ErrorHandling.h" | 23 #include "llvm/Support/ErrorHandling.h" |
24 #include "llvm/Support/MathExtras.h" | |
24 #include <cassert> | 25 #include <cassert> |
25 | 26 |
26 namespace llvm { | 27 namespace llvm { |
27 namespace naclbitc { | 28 namespace naclbitc { |
28 enum StandardWidths { | 29 enum StandardWidths { |
29 BlockIDWidth = 8, // We use VBR-8 for block IDs. | 30 BlockIDWidth = 8, // We use VBR-8 for block IDs. |
30 CodeLenWidth = 4, // Codelen are VBR-4. | 31 CodeLenWidth = 4, // Codelen are VBR-4. |
31 BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. | 32 BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. |
32 }; | 33 }; |
33 | 34 |
34 // The standard abbrev namespace always has a way to exit a block, enter a | 35 // The standard abbrev namespace always has a way to exit a block, enter a |
35 // nested block, define abbrevs, and define an unabbreviated record. | 36 // nested block, define abbrevs, and define an unabbreviated record. |
36 enum FixedAbbrevIDs { | 37 enum FixedAbbrevIDs { |
37 END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode. | 38 END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode. |
38 ENTER_SUBBLOCK = 1, | 39 ENTER_SUBBLOCK = 1, |
39 | 40 |
40 /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists | 41 /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists |
41 /// of a vbr5 for # operand infos. Each operand info is emitted with a | 42 /// of a vbr5 for # operand infos. Each operand info is emitted with a |
42 /// single bit to indicate if it is a literal encoding. If so, the value is | 43 /// single bit to indicate if it is a literal encoding. If so, the value is |
43 /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed | 44 /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed |
44 /// by the info value as a vbr5 if needed. | 45 /// by the info value as a vbr5 if needed. |
45 DEFINE_ABBREV = 2, | 46 DEFINE_ABBREV = 2, |
46 | 47 |
47 // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by | 48 // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by |
48 // a vbr6 for the # operands, followed by vbr6's for each operand. | 49 // a vbr6 for the # operands, followed by vbr6's for each operand. |
49 UNABBREV_RECORD = 3, | 50 UNABBREV_RECORD = 3, |
50 | 51 |
51 // This is not a code, this is a marker for the first abbrev assignment. | 52 // This is not a code, this is a marker for the first abbrev assignment. |
52 FIRST_APPLICATION_ABBREV = 4 | 53 // In addition, we assume up to two additional enumerated constants are |
54 // added for each extension. These constants are: | |
55 // | |
56 // PREFIX_MAX_FIXED_ABBREV | |
57 // PREFIX_MAX_ABBREV | |
58 // | |
59 // PREFIX_MAX_ABBREV defines the maximal enumeration value used for | |
60 // the code selector of a block. If Both PREFIX_MAX_FIXED_ABBREV | |
61 // and PREFIX_MAX_ABBREV is defined, then PREFIX_MAX_FIXED_ABBREV | |
62 // defines the last code selector of the block that must be read using | |
63 // a single read (i.e. a FIXED read, or the first chunk of a VBR read. | |
64 FIRST_APPLICATION_ABBREV = 4, | |
65 // Defines default values for code length, if no additional selectors | |
66 // are added. | |
67 DEFAULT_MAX_ABBREV = FIRST_APPLICATION_ABBREV-1 | |
53 }; | 68 }; |
54 | 69 |
55 /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO | 70 /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO |
56 /// block, which contains metadata about other blocks in the file. | 71 /// block, which contains metadata about other blocks in the file. |
57 enum StandardBlockIDs { | 72 enum StandardBlockIDs { |
58 /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, | 73 /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, |
59 /// standard abbrevs that should be available to all blocks of a specified | 74 /// standard abbrevs that should be available to all blocks of a specified |
60 /// ID. | 75 /// ID. |
61 BLOCKINFO_BLOCK_ID = 0, | 76 BLOCKINFO_BLOCK_ID = 0, |
62 | 77 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 return static_cast<unsigned>(OperandList.size()); | 192 return static_cast<unsigned>(OperandList.size()); |
178 } | 193 } |
179 const NaClBitCodeAbbrevOp &getOperandInfo(unsigned N) const { | 194 const NaClBitCodeAbbrevOp &getOperandInfo(unsigned N) const { |
180 return OperandList[N]; | 195 return OperandList[N]; |
181 } | 196 } |
182 | 197 |
183 void Add(const NaClBitCodeAbbrevOp &OpInfo) { | 198 void Add(const NaClBitCodeAbbrevOp &OpInfo) { |
184 OperandList.push_back(OpInfo); | 199 OperandList.push_back(OpInfo); |
185 } | 200 } |
186 }; | 201 }; |
202 | |
203 // NaClBitsNeededForValue - Returns number of bits needed to encode | |
204 // value for dense FIXED encoding. | |
205 inline unsigned NaClBitsNeededForValue(unsigned Value) { | |
206 // Note: Need to handle case where Value=0xFFFFFFFF as special case, | |
207 // since we can't add 1 to it. | |
208 if (Value >= 0x80000000) return 32; | |
209 return Log2_32_Ceil(Value+1); | |
210 } | |
211 | |
212 // NaClEncodeSignRotatedValue - Encode a signed value by moving the sign | |
213 // to the LSB for dense VBR encoding. | |
214 inline uint64_t NaClEncodeSignRotatedValue(int64_t V) { | |
215 return (V >= 0) ? (V << 1) : ((-V << 1) | 1); | |
216 } | |
217 | |
218 // decodeSignRotatedValue - Decode a signed value stored with the sign bit in | |
jvoung (off chromium)
2013/05/21 17:24:17
NaClDecodeSignRotatedValue, or just use "\brief" i
Karl
2013/05/21 23:06:52
Done.
| |
219 // the LSB for dense VBR encoding. | |
220 inline uint64_t NaClDecodeSignRotatedValue(uint64_t V) { | |
221 if ((V & 1) == 0) | |
222 return V >> 1; | |
223 if (V != 1) | |
224 return -(V >> 1); | |
225 // There is no such thing as -0 with integers. "-0" really means MININT. | |
226 return 1ULL << 63; | |
227 } | |
228 | |
229 // NaClBitcodeSelectorAbbrev - This class determines whether a FIXED or VBR | |
230 // abbreviation should be used for the selector, and the number of bits | |
231 // needed to capture such selectors. | |
232 class NaClBitcodeSelectorAbbrev { | |
233 | |
234 public: | |
235 // If true, use a FIXED abbreviation. Otherwise, use a VBR abbreviation. | |
236 bool IsFixed; | |
237 // Number of bits needed for selector. | |
238 unsigned NumBits; | |
239 | |
240 // Creates a selector range for the given values. | |
241 NaClBitcodeSelectorAbbrev(bool IF, unsigned NB) | |
242 : IsFixed(IF), NumBits(NB) {} | |
243 | |
244 // Creates a selector range when no abbreviations are defined. | |
245 NaClBitcodeSelectorAbbrev() | |
246 : IsFixed(true), | |
247 NumBits(NaClBitsNeededForValue(naclbitc::DEFAULT_MAX_ABBREV)) {} | |
248 | |
249 // Creates a selector range to handle fixed abbrevations up to | |
250 // the specified value. | |
251 explicit NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev) | |
252 : IsFixed(true), | |
253 NumBits(NaClBitsNeededForValue(MaxAbbrev)) {} | |
254 | |
255 // Creates a selector range where the first chunk can handle all | |
256 // values < FirstChunkCutoff, and all range values are less than | |
257 // MaxAbbrev. | |
258 NaClBitcodeSelectorAbbrev(unsigned FirstChunkCutoff, unsigned MaxAbbrev) | |
jvoung (off chromium)
2013/05/21 17:24:17
firstchunkcutoff version not used yet here also
Karl
2013/05/21 23:06:52
Removed.
| |
259 : IsFixed(FirstChunkCutoff == MaxAbbrev), | |
260 NumBits(NaClBitsNeededForValue(FirstChunkCutoff)) { | |
261 // Before returning, patch up values, based on behaviour of | |
262 // bitstream writer. Note that VBR requires an extra bit to | |
263 // define if further bit chunks are needed. Hence, add this information. | |
264 if (!IsFixed) { | |
265 ++NumBits; | |
266 IsFixed = ((1U << NumBits) > MaxAbbrev); | |
267 } | |
268 } | |
269 }; | |
187 } // End llvm namespace | 270 } // End llvm namespace |
188 | 271 |
189 #endif | 272 #endif |
OLD | NEW |