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 | 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" |
|
Karl
2013/05/17 20:52:18
Added '#include "llvm/Support/MathExtras.h" so tha
| |
| 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 |
|
jvoung (off chromium)
2013/05/14 23:47:14
In addition, ...
Karl
2013/05/17 20:52:18
Done.
| |
| 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 | |
| 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 // NaClBitcodeSelectorAbbrev - This class determines whether a FIXED or VBR | |
| 203 // abbreviation should be used for the selector, and the number of bits | |
| 204 // needed to capture such selectors. | |
| 205 class NaClBitcodeSelectorAbbrev { | |
| 206 // Number of bits needed for selector. | |
| 207 unsigned NumBits; | |
|
Karl
2013/05/17 20:52:18
Made publicly visible so that it can be set by the
| |
| 208 // If true, use a FIXED abbreviation. Otherwise, use a VBR abbreviation. | |
| 209 bool UseFixedAbbrev; | |
|
Karl
2013/05/17 20:52:18
Renamed to IsFixed, and made publicly visible (so
| |
| 210 | |
| 211 public: | |
| 212 | |
| 213 // Computes the minimum number of bits needed to encode value. | |
| 214 static unsigned BitsNeededForValue(unsigned Value) { | |
|
Karl
2013/05/17 20:52:18
Moved this out (above) to be an inline. Also added
| |
| 215 unsigned NumBits = 1; | |
|
Karl
2013/05/17 20:52:18
Replaced body with call to Log2_32_Ceil.
| |
| 216 while (Value >= 2) { | |
| 217 ++NumBits; | |
| 218 Value >>= 1; | |
| 219 } | |
| 220 return NumBits; | |
| 221 } | |
| 222 | |
| 223 // Creates a selector range when no abbreviations are defined. | |
| 224 NaClBitcodeSelectorAbbrev() | |
| 225 : NumBits(BitsNeededForValue(naclbitc::DEFAULT_MAX_ABBREV)), | |
| 226 UseFixedAbbrev(true) {} | |
| 227 | |
| 228 // Creates a selector range to handle fixed abbrevations up to | |
| 229 // the specified value. | |
| 230 NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev) | |
| 231 : NumBits(BitsNeededForValue(MaxAbbrev)), UseFixedAbbrev(true) {} | |
| 232 | |
| 233 // Creates a selector range where the first chunk can handle all | |
| 234 // values < FirstChunkCutoff, and all range values are less than | |
| 235 // AllCutoff. | |
|
jvoung (off chromium)
2013/05/14 23:47:14
what is AllCutoff?
Karl
2013/05/17 20:52:18
Fixed reference to use "MaxAbbrev".
| |
| 236 NaClBitcodeSelectorAbbrev(unsigned FirstChunkCutoff, unsigned MaxAbbrev) | |
| 237 : NumBits(BitsNeededForValue(FirstChunkCutoff)), | |
| 238 UseFixedAbbrev(FirstChunkCutoff == MaxAbbrev) { | |
| 239 // Before returning, patch up values, based on behaviour of | |
| 240 // bitstream writer. Note that VBR requires an extra bit to | |
| 241 // define if further bit chunks are needed. Hence, add this | |
| 242 // information. | |
| 243 if (!UseFixedAbbrev) { | |
| 244 if ((1U << (NumBits+1)) < MaxAbbrev) { | |
| 245 // Fixed size on corresponding VBR will hold all values, so | |
| 246 // don't bother to use VBR. | |
| 247 UseFixedAbbrev = true; | |
| 248 } else { | |
| 249 // Add bit to handle multiple chunks. | |
| 250 ++NumBits; | |
| 251 } | |
| 252 } | |
| 253 } | |
| 254 | |
| 255 // Returns true if FIXED should be used (instead of VBR). | |
| 256 bool UseFixed() const { | |
|
Karl
2013/05/17 20:52:18
Removed UseFixed and UseNumBits, since the fields
| |
| 257 return UseFixedAbbrev; | |
| 258 } | |
| 259 | |
| 260 // Returns the number of bits to use. | |
| 261 int UseNumBits() const { | |
| 262 return NumBits; | |
| 263 } | |
| 264 }; | |
| 187 } // End llvm namespace | 265 } // End llvm namespace |
| 188 | 266 |
| 189 #endif | 267 #endif |
| OLD | NEW |