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