Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: include/llvm/Bitcode/NaCl/NaClBitCodes.h

Issue 14813032: Make abbreviations explicit in pnacl-freeze/thaw. (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Fix typos in CL Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/llvm/Bitcode/NaCl/NaClBitCodes.h
diff --git a/include/llvm/Bitcode/NaCl/NaClBitCodes.h b/include/llvm/Bitcode/NaCl/NaClBitCodes.h
index 4c0f754f7bab3ef33369679f15bdbe5b0bc829d9..81bae1a46f7e1b113b8a88823a1e95a9e85eeabe 100644
--- a/include/llvm/Bitcode/NaCl/NaClBitCodes.h
+++ b/include/llvm/Bitcode/NaCl/NaClBitCodes.h
@@ -49,7 +49,21 @@ namespace naclbitc {
UNABBREV_RECORD = 3,
// This is not a code, this is a marker for the first abbrev assignment.
- FIRST_APPLICATION_ABBREV = 4
+ // 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.
+ // added for each extension. These constants are:
+ //
+ // PREFIX_MAX_FIXED_ABBREV
+ // PREFIX_MAX_ABBREV
+ //
+ // PREFIX_MAX_ABBREV defines the maximal enumeration value used for
+ // the code selector of a block. If Both PREFIX_MAX_FIXED_ABBREV
+ // and PREFIX_MAX_ABBREV is defined, then PREFIX_MAX_FIXED_ABBREV
+ // defines the last code selector of the block that must be read using
+ // a single read (i.e. a FIXED read, or the first chunk of a VBR read.
+ FIRST_APPLICATION_ABBREV = 4,
+ // Defines default values for code length, if no additional selectors
+ // are added.
+ DEFAULT_MAX_ABBREV = FIRST_APPLICATION_ABBREV-1
};
/// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
@@ -184,6 +198,70 @@ public:
OperandList.push_back(OpInfo);
}
};
+
+// NaClBitcodeSelectorAbbrev - This class determines whether a FIXED or VBR
+// abbreviation should be used for the selector, and the number of bits
+// needed to capture such selectors.
+class NaClBitcodeSelectorAbbrev {
+ // Number of bits needed for selector.
+ unsigned NumBits;
Karl 2013/05/17 20:52:18 Made publicly visible so that it can be set by the
+ // If true, use a FIXED abbreviation. Otherwise, use a VBR abbreviation.
+ bool UseFixedAbbrev;
Karl 2013/05/17 20:52:18 Renamed to IsFixed, and made publicly visible (so
+
+public:
+
+ // Computes the minimum number of bits needed to encode value.
+ static unsigned BitsNeededForValue(unsigned Value) {
Karl 2013/05/17 20:52:18 Moved this out (above) to be an inline. Also added
+ unsigned NumBits = 1;
Karl 2013/05/17 20:52:18 Replaced body with call to Log2_32_Ceil.
+ while (Value >= 2) {
+ ++NumBits;
+ Value >>= 1;
+ }
+ return NumBits;
+ }
+
+ // Creates a selector range when no abbreviations are defined.
+ NaClBitcodeSelectorAbbrev()
+ : NumBits(BitsNeededForValue(naclbitc::DEFAULT_MAX_ABBREV)),
+ UseFixedAbbrev(true) {}
+
+ // Creates a selector range to handle fixed abbrevations up to
+ // the specified value.
+ NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev)
+ : NumBits(BitsNeededForValue(MaxAbbrev)), UseFixedAbbrev(true) {}
+
+ // Creates a selector range where the first chunk can handle all
+ // values < FirstChunkCutoff, and all range values are less than
+ // 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".
+ NaClBitcodeSelectorAbbrev(unsigned FirstChunkCutoff, unsigned MaxAbbrev)
+ : NumBits(BitsNeededForValue(FirstChunkCutoff)),
+ UseFixedAbbrev(FirstChunkCutoff == MaxAbbrev) {
+ // Before returning, patch up values, based on behaviour of
+ // bitstream writer. Note that VBR requires an extra bit to
+ // define if further bit chunks are needed. Hence, add this
+ // information.
+ if (!UseFixedAbbrev) {
+ if ((1U << (NumBits+1)) < MaxAbbrev) {
+ // Fixed size on corresponding VBR will hold all values, so
+ // don't bother to use VBR.
+ UseFixedAbbrev = true;
+ } else {
+ // Add bit to handle multiple chunks.
+ ++NumBits;
+ }
+ }
+ }
+
+ // Returns true if FIXED should be used (instead of VBR).
+ bool UseFixed() const {
Karl 2013/05/17 20:52:18 Removed UseFixed and UseNumBits, since the fields
+ return UseFixedAbbrev;
+ }
+
+ // Returns the number of bits to use.
+ int UseNumBits() const {
+ return NumBits;
+ }
+};
} // End llvm namespace
#endif
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitstreamReader.h » ('j') | include/llvm/Bitcode/NaCl/NaClBitstreamReader.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698