[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-05-05 Thread Jeff Cohen


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.7 -> 1.8
BitstreamReader.h updated: 1.18 -> 1.19
BitstreamWriter.h updated: 1.13 -> 1.14
---
Log message:

Unbreak VC++.

---
Diffs of the changes:  (+10 -8)

 BitCodes.h|2 ++
 BitstreamReader.h |   12 ++--
 BitstreamWriter.h |4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.7 
llvm/include/llvm/Bitcode/BitCodes.h:1.8
--- llvm/include/llvm/Bitcode/BitCodes.h:1.7Fri May  4 20:15:42 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hSat May  5 22:12:47 2007
@@ -136,6 +136,7 @@
 if (C == '.') return 62;
 if (C == '_') return 63;
 assert(0 && "Not a value Char6 character!");
+return 0;
   }
   
   static char DecodeChar6(unsigned V) {
@@ -146,6 +147,7 @@
 if (V == 62) return '.';
 if (V == 63) return '_';
 assert(0 && "Not a value Char6 character!");
+return ' ';
   }
   
 };


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.18 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.19
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.18Sat May  5 20:43:38 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Sat May  5 22:12:47 2007
@@ -110,8 +110,8 @@
   
   /// JumpToBit - Reset the stream to the specified bit number.
   void JumpToBit(uint64_t BitNo) {
-unsigned ByteNo = (BitNo/8) & ~3;
-unsigned WordBitNo = BitNo & 31;
+unsigned ByteNo = unsigned(BitNo/8) & ~3;
+unsigned WordBitNo = unsigned(BitNo) & 31;
 assert(ByteNo < (unsigned)(LastChar-FirstChar) && "Invalid location");
 
 // Move the cursor to the right word.
@@ -327,10 +327,10 @@
   switch (Op.getEncoding()) {
   default: assert(0 && "Unknown encoding!");
   case BitCodeAbbrevOp::Fixed:
-Vals.push_back(Read(Op.getEncodingData()));
+Vals.push_back(Read((unsigned)Op.getEncodingData()));
 break;
   case BitCodeAbbrevOp::VBR:
-Vals.push_back(ReadVBR64(Op.getEncodingData()));
+Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData()));
 break;
   case BitCodeAbbrevOp::Char6:
 Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
@@ -370,7 +370,7 @@
   }
 }
 
-unsigned Code = Vals[0];
+unsigned Code = (unsigned)Vals[0];
 Vals.erase(Vals.begin());
 return Code;
   }
@@ -451,7 +451,7 @@
   default: break;  // Default behavior, ignore unknown content.
   case bitc::BLOCKINFO_CODE_SETBID:
 if (Record.size() < 1) return true;
-CurBlockInfo = &getOrCreateBlockInfo(Record[0]);
+CurBlockInfo = &getOrCreateBlockInfo((unsigned)Record[0]);
 break;
   }
 }  


Index: llvm/include/llvm/Bitcode/BitstreamWriter.h
diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.13 
llvm/include/llvm/Bitcode/BitstreamWriter.h:1.14
--- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.13Sat May  5 18:40:48 2007
+++ llvm/include/llvm/Bitcode/BitstreamWriter.h Sat May  5 22:12:47 2007
@@ -255,10 +255,10 @@
 switch (Op.getEncoding()) {
 default: assert(0 && "Unknown encoding!");
 case BitCodeAbbrevOp::Fixed:
-  Emit(V, Op.getEncodingData());
+  Emit((unsigned)V, (unsigned)Op.getEncodingData());
   break;
 case BitCodeAbbrevOp::VBR:
-  EmitVBR64(V, Op.getEncodingData());
+  EmitVBR64(V, (unsigned)Op.getEncodingData());
   break;
 case BitCodeAbbrevOp::Char6:
   Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-05-04 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.6 -> 1.7
BitstreamReader.h updated: 1.15 -> 1.16
BitstreamWriter.h updated: 1.11 -> 1.12
---
Log message:

add a 6-bit encoding type for strings.


---
Diffs of the changes:  (+38 -3)

 BitCodes.h|   35 ---
 BitstreamReader.h |3 +++
 BitstreamWriter.h |3 +++
 3 files changed, 38 insertions(+), 3 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.6 
llvm/include/llvm/Bitcode/BitCodes.h:1.7
--- llvm/include/llvm/Bitcode/BitCodes.h:1.6Fri May  4 19:16:30 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hFri May  4 20:15:42 2007
@@ -85,15 +85,15 @@
   unsigned Enc   : 3; // The encoding to use.
 public:
   enum Encoding {
-Fixed = 1,  // A fixed with field, Val specifies number of bits.
+Fixed = 1,  // A fixed width field, Val specifies number of bits.
 VBR   = 2,  // A VBR field where Val specifies the width of each chunk.
-Array = 3   // A sequence of fields, next field species elt encoding.
+Array = 3,  // A sequence of fields, next field species elt encoding.
+Char6 = 4   // A 6-bit fixed field which maps to [a-zA-Z0-9._].
   };
 
   BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
   BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
 : Val(Data), IsLiteral(false), Enc(E) {}
-
   
   bool isLiteral() const { return IsLiteral; }
   bool isEncoding() const { return !IsLiteral; }
@@ -116,9 +116,38 @@
 case VBR:
   return true;
 case Array:
+case Char6:
   return false;
 }
   }
+  
+  /// isChar6 - Return true if this character is legal in the Char6 encoding.
+  static bool isChar6(char C) {
+if (C >= 'a' && C <= 'z') return true;
+if (C >= 'A' && C <= 'Z') return true;
+if (C >= '0' && C <= '9') return true;
+if (C == '.' || C == '_') return true;
+return false;
+  }
+  static unsigned EncodeChar6(char C) {
+if (C >= 'a' && C <= 'z') return C-'a';
+if (C >= 'A' && C <= 'Z') return C-'A'+26;
+if (C >= '0' && C <= '9') return C-'0'+26+26;
+if (C == '.') return 62;
+if (C == '_') return 63;
+assert(0 && "Not a value Char6 character!");
+  }
+  
+  static char DecodeChar6(unsigned V) {
+assert((V & ~63) == 0 && "Not a Char6 encoded character!");
+if (V < 26) return V+'a';
+if (V < 26+26) return V-26+'A';
+if (V < 26+26+10) return V-26-26+'0';
+if (V == 62) return '.';
+if (V == 63) return '_';
+assert(0 && "Not a value Char6 character!");
+  }
+  
 };
 
 /// BitCodeAbbrev - This class represents an abbreviation record.  An


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.15 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.16
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.15Fri May  4 19:16:30 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May  4 20:15:42 2007
@@ -332,6 +332,9 @@
   case BitCodeAbbrevOp::VBR:
 Vals.push_back(ReadVBR64(Op.getEncodingData()));
 break;
+  case BitCodeAbbrevOp::Char6:
+Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6)));
+break;
   }
 }
   }


Index: llvm/include/llvm/Bitcode/BitstreamWriter.h
diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.11 
llvm/include/llvm/Bitcode/BitstreamWriter.h:1.12
--- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.11Fri May  4 19:16:30 2007
+++ llvm/include/llvm/Bitcode/BitstreamWriter.h Fri May  4 20:15:42 2007
@@ -260,6 +260,9 @@
 case BitCodeAbbrevOp::VBR:
   EmitVBR(V, Op.getEncodingData());
   break;
+case BitCodeAbbrevOp::Char6:
+  Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
+  break;
 }
   }
 public:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-05-04 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.5 -> 1.6
BitstreamReader.h updated: 1.14 -> 1.15
BitstreamWriter.h updated: 1.10 -> 1.11
---
Log message:

Implement support for globally associating abbrevs with block IDs, which 
relieves us from having to emit the abbrevs into each instance of the block.
This shrinks kc.bit from 3368K to K, but will be a more significant win
once instructions are abbreviated.

The VST went from:

  Block ID #14 (VALUE_SYMTAB):
  Num Instances: 2345
 Total Size: 1.29508e+07b/1.61885e+06B/404713W
   Average Size: 5522.73b/690.342B/172.585W
  % of file: 48.0645
  Tot/Avg SubBlocks: 0/0
Tot/Avg Abbrevs: 7035/3
Tot/Avg Records: 120924/51.5667
  % Abbrev Recs: 100

to:

  Block ID #14 (VALUE_SYMTAB):
  Num Instances: 2345
 Total Size: 1.26713e+07b/1.58391e+06B/395978W
   Average Size: 5403.53b/675.442B/168.86W
  % of file: 47.5198
  Tot/Avg SubBlocks: 0/0
Tot/Avg Abbrevs: 0/0
Tot/Avg Records: 120924/51.5667
  % Abbrev Recs: 100

because we didn't emit the same 3 abbrevs 2345 times :)



---
Diffs of the changes:  (+213 -12)

 BitCodes.h|5 +-
 BitstreamReader.h |  102 ++
 BitstreamWriter.h |  118 +-
 3 files changed, 213 insertions(+), 12 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.5 
llvm/include/llvm/Bitcode/BitCodes.h:1.6
--- llvm/include/llvm/Bitcode/BitCodes.h:1.5Fri May  4 15:33:47 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hFri May  4 19:16:30 2007
@@ -66,8 +66,9 @@
   /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
   /// blocks.
   enum BlockInfoCodes {
-BLOCKINFO_CODE_SETBID = 1,  // SETBID: [blockid#]
-BLOCKINFO_CODE_ABBREV = 2   // ABBREV: [standard abbrev encoding]
+BLOCKINFO_CODE_SETBID = 1  // SETBID: [blockid#]
+// DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
+// block, instead of the BlockInfo block.
 // BLOCKNAME: give string name to block, if desired.
   };
   


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.14 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.15
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.14Fri May  4 15:33:47 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May  4 19:16:30 2007
@@ -48,6 +48,14 @@
   /// BlockScope - This tracks the codesize of parent blocks.
   SmallVector BlockScope;
 
+  /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks.
+  /// These describe abbreviations that all blocks of the specified ID inherit.
+  struct BlockInfo {
+unsigned BlockID;
+std::vector Abbrevs;
+  };
+  std::vector BlockInfoRecords;
+  
   /// FirstChar - This remembers the first byte of the stream.
   const unsigned char *FirstChar;
 public:
@@ -82,6 +90,15 @@
   for (unsigned i = 0, e = Abbrevs.size(); i != e; ++i)
 Abbrevs[i]->dropRef();
 }
+
+// Free the BlockInfoRecords.
+while (!BlockInfoRecords.empty()) {
+  BlockInfo &Info = BlockInfoRecords.back();
+  // Free blockinfo abbrev info.
+  for (unsigned i = 0, e = Info.Abbrevs.size(); i != e; ++i)
+Info.Abbrevs[i]->dropRef();
+  BlockInfoRecords.pop_back();
+}
   }
   
   bool AtEndOfStream() const { return NextChar == LastChar; }
@@ -206,6 +223,22 @@
   // Block Manipulation
   
//======//
   
+private:
+  /// getBlockInfo - If there is block info for the specified ID, return it,
+  /// otherwise return null.
+  BlockInfo *getBlockInfo(unsigned BlockID) {
+// Common case, the most recent entry matches BlockID.
+if (!BlockInfoRecords.empty() && BlockInfoRecords.back().BlockID == 
BlockID)
+  return &BlockInfoRecords.back();
+
+for (unsigned i = 0, e = BlockInfoRecords.size(); i != e; ++i)
+  if (BlockInfoRecords[i].BlockID == BlockID)
+return &BlockInfoRecords[i];
+return 0;
+  }
+public:
+  
+  
   // Block header:
   //[ENTER_SUBBLOCK, blockid, newcodelen, , blocklen]
 
@@ -236,10 +269,19 @@
   
   /// EnterSubBlock - Having read the ENTER_SUBBLOCK abbrevid, read and enter
   /// the block, returning the BlockID of the block we just entered.
-  bool EnterSubBlock(unsigned *NumWordsP = 0) {
+  bool EnterSubBlock(unsigned BlockID, unsigned *NumWordsP = 0) {
+// Save the current block's state on BlockScope.
 BlockScope.push_back(Block(CurCodeSize));
 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
 
+// Add the abbrevs specific to this block to the CurAbbrevs list.
+if (BlockInfo *Info = getBlockInfo(BlockID)) {
+  for (unsigned i = 0, e = Info->Abbrevs.size(); i != e; ++i) {
+CurAbbrevs.push_back(Info->Abbrevs[i]);
+CurAbbrevs.back()

[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-05-04 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.4 -> 1.5
BitstreamReader.h updated: 1.13 -> 1.14
BitstreamWriter.h updated: 1.8 -> 1.9
---
Log message:

add support for array abbreviations.


---
Diffs of the changes:  (+101 -59)

 BitCodes.h|   22 ++---
 BitstreamReader.h |   52 +---
 BitstreamWriter.h |   86 ++
 3 files changed, 101 insertions(+), 59 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.4 
llvm/include/llvm/Bitcode/BitCodes.h:1.5
--- llvm/include/llvm/Bitcode/BitCodes.h:1.4Fri May  4 13:25:49 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hFri May  4 15:33:47 2007
@@ -84,13 +84,15 @@
   unsigned Enc   : 3; // The encoding to use.
 public:
   enum Encoding {
-FixedWidth = 1,  // A fixed with field, Val specifies number of bits.
-VBR= 2   // A VBR field where Val specifies the width of each 
chunk.
+Fixed = 1,  // A fixed with field, Val specifies number of bits.
+VBR   = 2,  // A VBR field where Val specifies the width of each chunk.
+Array = 3   // A sequence of fields, next field species elt encoding.
   };
 
   BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
-  BitCodeAbbrevOp(Encoding E, uint64_t Data)
+  BitCodeAbbrevOp(Encoding E, uint64_t Data = 0)
 : Val(Data), IsLiteral(false), Enc(E) {}
+
   
   bool isLiteral() const { return IsLiteral; }
   bool isEncoding() const { return !IsLiteral; }
@@ -100,11 +102,21 @@
   
   // Accessors for encoding info.
   Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
-  uint64_t getEncodingData() const { assert(isEncoding()); return Val; }
+  uint64_t getEncodingData() const {
+assert(isEncoding() && hasEncodingData());
+return Val;
+  }
   
   bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
   static bool hasEncodingData(Encoding E) {
-return true; 
+switch (E) {
+default: assert(0 && "Unknown encoding");
+case Fixed:
+case VBR:
+  return true;
+case Array:
+  return false;
+}
   }
 };
 


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.13 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.14
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.13Fri May  4 13:25:49 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May  4 15:33:47 2007
@@ -274,6 +274,26 @@
   // Record Processing
   
//======//
   
+private:
+  void ReadAbbreviatedField(const BitCodeAbbrevOp &Op, 
+SmallVectorImpl &Vals) {
+if (Op.isLiteral()) {
+  // If the abbrev specifies the literal value to use, use it.
+  Vals.push_back(Op.getLiteralValue());
+} else {
+  // Decode the value as we are commanded.
+  switch (Op.getEncoding()) {
+  default: assert(0 && "Unknown encoding!");
+  case BitCodeAbbrevOp::Fixed:
+Vals.push_back(Read(Op.getEncodingData()));
+break;
+  case BitCodeAbbrevOp::VBR:
+Vals.push_back(ReadVBR64(Op.getEncodingData()));
+break;
+  }
+}
+  }
+public:
   unsigned ReadRecord(unsigned AbbrevID, SmallVectorImpl &Vals) {
 if (AbbrevID == bitc::UNABBREV_RECORD) {
   unsigned Code = ReadVBR(6);
@@ -289,20 +309,19 @@
 
 for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
   const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
-  if (Op.isLiteral()) {
-// If the abbrev specifies the literal value to use, use it.
-Vals.push_back(Op.getLiteralValue());
+  if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) {
+ReadAbbreviatedField(Op, Vals);
   } else {
-// Decode the value as we are commanded.
-switch (Op.getEncoding()) {
-default: assert(0 && "Unknown encoding!");
-case BitCodeAbbrevOp::FixedWidth:
-  Vals.push_back(Read(Op.getEncodingData()));
-  break;
-case BitCodeAbbrevOp::VBR:
-  Vals.push_back(ReadVBR64(Op.getEncodingData()));
-  break;
-}
+// Array case.  Read the number of elements as a vbr6.
+unsigned NumElts = ReadVBR(6);
+
+// Get the element encoding.
+assert(i+2 == e && "array op not second to last?");
+const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
+
+// Read all the elements.
+for (; NumElts; --NumElts)
+  ReadAbbreviatedField(EltEnc, Vals);
   }
 }
 
@@ -326,11 +345,10 @@
   }
 
   BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3);
-  if (BitCodeAbbrevOp::hasEncodingData(E)) {
+  if (BitCodeAbbrevOp::hasEncodingData(E))
 Abbv->Add(BitCodeAbbrevOp(E, ReadVBR64(5)));
-  } else {
-assert(0 && "unimp");
-  }
+

[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h LLVMBitCodes.h

2007-05-04 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.3 -> 1.4
BitstreamReader.h updated: 1.12 -> 1.13
BitstreamWriter.h updated: 1.7 -> 1.8
LLVMBitCodes.h updated: 1.14 -> 1.15
---
Log message:

minor cleanups.  Add provisions for a new standard BLOCKINFO_BLOCK
block type.


---
Diffs of the changes:  (+41 -17)

 BitCodes.h|   32 
 BitstreamReader.h |2 +-
 BitstreamWriter.h |6 +++---
 LLVMBitCodes.h|   18 +-
 4 files changed, 41 insertions(+), 17 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.3 
llvm/include/llvm/Bitcode/BitCodes.h:1.4
--- llvm/include/llvm/Bitcode/BitCodes.h:1.3Fri May  4 12:35:19 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hFri May  4 13:25:49 2007
@@ -30,9 +30,9 @@
 BlockSizeWidth = 32  // BlockSize up to 2^32 32-bit words = 32GB per block.
   };
   
-  // The standard code namespace always has a way to exit a block, enter a
+  // The standard abbrev namespace always has a way to exit a block, enter a
   // nested block, define abbrevs, and define an unabbreviated record.
-  enum FixedCodes {
+  enum FixedAbbrevIDs {
 END_BLOCK = 0,  // Must be zero to guarantee termination for broken 
bitcode.
 ENTER_SUBBLOCK = 1,
 
@@ -48,8 +48,29 @@
 UNABBREV_RECORD = 3,
 
 // This is not a code, this is a marker for the first abbrev assignment.
-FIRST_ABBREV = 4
+FIRST_APPLICATION_ABBREV = 4
   };
+  
+  /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
+  /// block, which contains metadata about other blocks in the file.
+  enum StandardBlockIDs {
+/// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
+/// standard abbrevs that should be available to all blocks of a specified
+/// ID.
+BLOCKINFO_BLOCK_ID = 0,
+
+// Block IDs 1-7 are reserved for future expansion.
+FIRST_APPLICATION_BLOCKID = 8
+  };
+  
+  /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
+  /// blocks.
+  enum BlockInfoCodes {
+BLOCKINFO_CODE_SETBID = 1,  // SETBID: [blockid#]
+BLOCKINFO_CODE_ABBREV = 2   // ABBREV: [standard abbrev encoding]
+// BLOCKNAME: give string name to block, if desired.
+  };
+  
 } // End bitc namespace
 
 /// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
@@ -63,7 +84,7 @@
   unsigned Enc   : 3; // The encoding to use.
 public:
   enum Encoding {
-FixedWidth = 1,   // A fixed with field, Val specifies number of bits.
+FixedWidth = 1,  // A fixed with field, Val specifies number of bits.
 VBR= 2   // A VBR field where Val specifies the width of each 
chunk.
   };
 
@@ -87,6 +108,9 @@
   }
 };
 
+/// BitCodeAbbrev - This class represents an abbreviation record.  An
+/// abbreviation allows a complex record that has redundancy to be stored in a
+/// specialized format instead of the fully-general, fully-vbr, format.
 class BitCodeAbbrev {
   SmallVector OperandList;
   unsigned char RefCount; // Number of things using this.


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.12 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.13
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.12Fri May  4 12:35:19 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May  4 13:25:49 2007
@@ -283,7 +283,7 @@
   return Code;
 }
 
-unsigned AbbrevNo = AbbrevID-bitc::FIRST_ABBREV;
+unsigned AbbrevNo = AbbrevID-bitc::FIRST_APPLICATION_ABBREV;
 assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
 BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo];
 


Index: llvm/include/llvm/Bitcode/BitstreamWriter.h
diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.7 
llvm/include/llvm/Bitcode/BitstreamWriter.h:1.8
--- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.7 Fri May  4 12:35:19 2007
+++ llvm/include/llvm/Bitcode/BitstreamWriter.h Fri May  4 13:25:49 2007
@@ -194,7 +194,7 @@
   void EmitRecord(unsigned Code, SmallVectorImpl &Vals,
   unsigned Abbrev = 0) {
 if (Abbrev) {
-  unsigned AbbrevNo = Abbrev-bitc::FIRST_ABBREV;
+  unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
   assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
   BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo];
   
@@ -247,7 +247,7 @@
   void EmitRecord(unsigned Code, SmallVectorImpl &Vals,
   unsigned Abbrev = 0) {
 if (Abbrev) {
-  unsigned AbbrevNo = Abbrev-bitc::FIRST_ABBREV;
+  unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
   assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
   BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo];
   
@@ -318,7 +318,7 @@
 }
 
 CurAbbrevs.push_back(Abbv);
-return CurAbbrevs.size()-1+bitc::FIRST_ABBREV;
+return CurAbbrevs.size()-1+bitc::FIRST_APPLICATION_ABBRE

[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-05-04 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.2 -> 1.3
BitstreamReader.h updated: 1.11 -> 1.12
BitstreamWriter.h updated: 1.6 -> 1.7
---
Log message:

refcount BitCodeAbbrev objects


---
Diffs of the changes:  (+13 -7)

 BitCodes.h|   12 +---
 BitstreamReader.h |6 +++---
 BitstreamWriter.h |2 +-
 3 files changed, 13 insertions(+), 7 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.2 
llvm/include/llvm/Bitcode/BitCodes.h:1.3
--- llvm/include/llvm/Bitcode/BitCodes.h:1.2Mon Apr 23 11:04:05 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hFri May  4 12:35:19 2007
@@ -58,9 +58,9 @@
 ///   2. It could be an encoding specification ("this operand encoded like 
so").
 ///
 class BitCodeAbbrevOp {
-  uint64_t Val;// A literal value or data for an encoding.
-  bool IsLiteral : 1;  // Indicate whether this is a literal value or not.
-  unsigned Enc   : 3;  // The encoding to use.
+  uint64_t Val;   // A literal value or data for an encoding.
+  bool IsLiteral : 1; // Indicate whether this is a literal value or not.
+  unsigned Enc   : 3; // The encoding to use.
 public:
   enum Encoding {
 FixedWidth = 1,   // A fixed with field, Val specifies number of bits.
@@ -89,8 +89,14 @@
 
 class BitCodeAbbrev {
   SmallVector OperandList;
+  unsigned char RefCount; // Number of things using this.
+  ~BitCodeAbbrev() {}
 public:
+  BitCodeAbbrev() : RefCount(1) {}
   
+  void addRef() { ++RefCount; }
+  void dropRef() { if (--RefCount == 0) delete this; }
+
   unsigned getNumOperandInfos() const { return OperandList.size(); }
   const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
 return OperandList[N];


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.11 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.12
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.11Tue May  1 00:51:32 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May  4 12:35:19 2007
@@ -75,12 +75,12 @@
 // Abbrevs could still exist if the stream was broken.  If so, don't leak
 // them.
 for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
-  delete CurAbbrevs[i];
+  CurAbbrevs[i]->dropRef();
 
 for (unsigned S = 0, e = BlockScope.size(); S != e; ++S) {
   std::vector &Abbrevs = BlockScope[S].PrevAbbrevs;
   for (unsigned i = 0, e = Abbrevs.size(); i != e; ++i)
-delete Abbrevs[i];
+Abbrevs[i]->dropRef();
 }
   }
   
@@ -263,7 +263,7 @@
 
 // Delete abbrevs from popped scope.
 for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
-  delete CurAbbrevs[i];
+  CurAbbrevs[i]->dropRef();
 
 BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
 BlockScope.pop_back();


Index: llvm/include/llvm/Bitcode/BitstreamWriter.h
diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.6 
llvm/include/llvm/Bitcode/BitstreamWriter.h:1.7
--- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.6 Mon Apr 23 15:34:46 2007
+++ llvm/include/llvm/Bitcode/BitstreamWriter.h Fri May  4 12:35:19 2007
@@ -160,7 +160,7 @@
 
 // Delete all abbrevs.
 for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
-  delete CurAbbrevs[i];
+  CurAbbrevs[i]->dropRef();
 
 const Block &B = BlockScope.back();
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h

2007-04-23 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h updated: 1.1 -> 1.2
BitstreamReader.h updated: 1.3 -> 1.4
BitstreamWriter.h updated: 1.2 -> 1.3
---
Log message:

first part of implementation of abbrevs.  The writer isn't fully there yet and 
the
reader doesn't handle them at all yet.


---
Diffs of the changes:  (+109 -13)

 BitCodes.h|   65 +++---
 BitstreamReader.h |3 --
 BitstreamWriter.h |   54 +++-
 3 files changed, 109 insertions(+), 13 deletions(-)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.1 
llvm/include/llvm/Bitcode/BitCodes.h:1.2
--- llvm/include/llvm/Bitcode/BitCodes.h:1.1Sun Apr 22 01:22:05 2007
+++ llvm/include/llvm/Bitcode/BitCodes.hMon Apr 23 11:04:05 2007
@@ -18,6 +18,10 @@
 #ifndef LLVM_BITCODE_BITCODES_H
 #define LLVM_BITCODE_BITCODES_H
 
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/DataTypes.h"
+#include 
+
 namespace llvm {
 namespace bitc {
   enum StandardWidths {
@@ -31,16 +35,71 @@
   enum FixedCodes {
 END_BLOCK = 0,  // Must be zero to guarantee termination for broken 
bitcode.
 ENTER_SUBBLOCK = 1,
+
+/// DEFINE_ABBREV - Defines an abbrev for the current block.  It consists
+/// of a vbr5 for # operand infos.  Each operand info is emitted with a
+/// single bit to indicate if it is a literal encoding.  If so, the value 
is
+/// emitted with a vbr8.  If not, the encoding is emitted as 3 bits 
followed
+/// by the info value as a vbr5 if needed.
+DEFINE_ABBREV = 2, 
 
-// Two codes are reserved for defining abbrevs and for emitting an
-// unabbreviated record.
-DEFINE_ABBREVS = 2,
+// UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed 
by
+// a vbr6 for the # operands, followed by vbr6's for each operand.
 UNABBREV_RECORD = 3,
 
 // This is not a code, this is a marker for the first abbrev assignment.
 FIRST_ABBREV = 4
   };
 } // End bitc namespace
+
+/// BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
+/// This is actually a union of two different things:
+///   1. It could be a literal integer value ("the operand is always 17").
+///   2. It could be an encoding specification ("this operand encoded like 
so").
+///
+class BitCodeAbbrevOp {
+  uint64_t Val;// A literal value or data for an encoding.
+  bool IsLiteral : 1;  // Indicate whether this is a literal value or not.
+  unsigned Enc   : 3;  // The encoding to use.
+public:
+  enum Encoding {
+FixedWidth = 1,   // A fixed with field, Val specifies number of bits.
+VBR= 2   // A VBR field where Val specifies the width of each 
chunk.
+  };
+
+  BitCodeAbbrevOp(uint64_t V) :  Val(V), IsLiteral(true) {}
+  BitCodeAbbrevOp(Encoding E, uint64_t Data)
+: Val(Data), IsLiteral(false), Enc(E) {}
+  
+  bool isLiteral() const { return IsLiteral; }
+  bool isEncoding() const { return !IsLiteral; }
+
+  // Accessors for literals.
+  uint64_t getLiteralValue() const { assert(isLiteral()); return Val; }
+  
+  // Accessors for encoding info.
+  Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; }
+  uint64_t getEncodingData() const { assert(isEncoding()); return Val; }
+  
+  bool hasEncodingData() const { return hasEncodingData(getEncoding()); }
+  static bool hasEncodingData(Encoding E) {
+return true; 
+  }
+};
+
+class BitCodeAbbrev {
+  SmallVector OperandList;
+public:
+  
+  unsigned getNumOperandInfos() const { return OperandList.size(); }
+  const BitCodeAbbrevOp &getOperandInfo(unsigned N) const {
+return OperandList[N];
+  }
+  
+  void Add(const BitCodeAbbrevOp &OpInfo) {
+OperandList.push_back(OpInfo);
+  }
+};
 } // End llvm namespace
 
 #endif


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.3 
llvm/include/llvm/Bitcode/BitstreamReader.h:1.4
--- llvm/include/llvm/Bitcode/BitstreamReader.h:1.3 Sun Apr 22 11:31:22 2007
+++ llvm/include/llvm/Bitcode/BitstreamReader.h Mon Apr 23 11:04:05 2007
@@ -16,9 +16,6 @@
 #define BITSTREAM_READER_H
 
 #include "llvm/Bitcode/BitCodes.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
-#include 
 
 namespace llvm {
   


Index: llvm/include/llvm/Bitcode/BitstreamWriter.h
diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.2 
llvm/include/llvm/Bitcode/BitstreamWriter.h:1.3
--- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.2 Sun Apr 22 10:00:52 2007
+++ llvm/include/llvm/Bitcode/BitstreamWriter.h Mon Apr 23 11:04:05 2007
@@ -16,9 +16,6 @@
 #define BITSTREAM_WRITER_H
 
 #include "llvm/Bitcode/BitCodes.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
-#include 
 #include 
 
 namespace llvm {
@@ -39,11 +36,14 @@
   struct Block {
 unsigned PrevCodeSize;
 unsigned StartSizeWord;
+std::vector PrevAbb

[llvm-commits] CVS: llvm/include/llvm/Bitcode/BitCodes.h BitstreamReader.h BitstreamWriter.h ReaderWriter.h

2007-04-21 Thread Chris Lattner


Changes in directory llvm/include/llvm/Bitcode:

BitCodes.h added (r1.1)
BitstreamReader.h added (r1.1)
BitstreamWriter.h added (r1.1)
ReaderWriter.h added (r1.1)
---
Log message:

Define the content-independent interfaces to read/write bitcode files and
the high-level interface to read/write LLVM IR bitcode files.

This is a work in progress.



---
Diffs of the changes:  (+523 -0)

 BitCodes.h|   46 +++
 BitstreamReader.h |  220 ++
 BitstreamWriter.h |  219 +
 ReaderWriter.h|   38 +
 4 files changed, 523 insertions(+)


Index: llvm/include/llvm/Bitcode/BitCodes.h
diff -c /dev/null llvm/include/llvm/Bitcode/BitCodes.h:1.1
*** /dev/null   Sun Apr 22 01:22:15 2007
--- llvm/include/llvm/Bitcode/BitCodes.hSun Apr 22 01:22:05 2007
***
*** 0 
--- 1,46 
+ //===- BitCodes.h - Enum values for the bitcode format --*- C++ 
-*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for 
details.
+ //
+ 
//===--===//
+ //
+ // This header Bitcode enum values.
+ //
+ // The enum values defined in this file should be considered permanent.  If
+ // new features are added, they should have values added at the end of the
+ // respective lists.
+ //
+ 
//===--===//
+ 
+ #ifndef LLVM_BITCODE_BITCODES_H
+ #define LLVM_BITCODE_BITCODES_H
+ 
+ namespace llvm {
+ namespace bitc {
+   enum StandardWidths {
+ BlockIDWidth = 8,  // We use VBR-8 for block IDs.
+ CodeLenWidth = 4,  // Codelen are VBR-4.
+ BlockSizeWidth = 32  // BlockSize up to 2^32 32-bit words = 32GB per 
block.
+   };
+   
+   // The standard code namespace always has a way to exit a block, enter a
+   // nested block, define abbrevs, and define an unabbreviated record.
+   enum FixedCodes {
+ END_BLOCK = 0,  // Must be zero to guarantee termination for broken 
bitcode.
+ ENTER_SUBBLOCK = 1,
+ 
+ // Two codes are reserved for defining abbrevs and for emitting an
+ // unabbreviated record.
+ DEFINE_ABBREVS = 2,
+ UNABBREV_RECORD = 3,
+ 
+ // This is not a code, this is a marker for the first abbrev assignment.
+ FIRST_ABBREV = 4
+   };
+ } // End bitc namespace
+ } // End llvm namespace
+ 
+ #endif


Index: llvm/include/llvm/Bitcode/BitstreamReader.h
diff -c /dev/null llvm/include/llvm/Bitcode/BitstreamReader.h:1.1
*** /dev/null   Sun Apr 22 01:22:23 2007
--- llvm/include/llvm/Bitcode/BitstreamReader.h Sun Apr 22 01:22:05 2007
***
*** 0 
--- 1,220 
+ //===- BitstreamReader.h - Low-level bitstream reader interface -*- C++ 
-*-===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by Chris Lattner and is distributed under
+ // the University of Illinois Open Source License.  See LICENSE.TXT for 
details.
+ //
+ 
//===--===//
+ //
+ // This header defines the BitstreamReader class.  This class can be used to
+ // read an arbitrary bitstream, regardless of its contents.
+ //
+ 
//===--===//
+ 
+ #ifndef BITSTREAM_READER_H
+ #define BITSTREAM_READER_H
+ 
+ #include "llvm/Bitcode/BitCodes.h"
+ #include "llvm/ADT/SmallVector.h"
+ #include 
+ 
+ namespace llvm {
+   
+ class BitstreamReader {
+   const unsigned char *NextChar;
+   const unsigned char *LastChar;
+   
+   /// CurWord - This is the current data we have pulled from the stream but 
have
+   /// not returned to the client.
+   uint32_t CurWord;
+   
+   /// BitsInCurWord - This is the number of bits in CurWord that are valid. 
This
+   /// is always from [0...31] inclusive.
+   unsigned BitsInCurWord;
+   
+   // CurCodeSize - This is the declared size of code values used for the 
current
+   // block, in bits.
+   unsigned CurCodeSize;
+   
+   /// BlockScope - This tracks the codesize of parent blocks.
+   SmallVector BlockScope;
+   
+ public:
+   BitstreamReader(const unsigned char *Start, const unsigned char *End)
+ : NextChar(Start), LastChar(End) {
+ assert(((End-Start) & 3) == 0 &&"Bitcode stream not a multiple of 4 
bytes");
+ CurWord = 0;
+ BitsInCurWord = 0;
+ CurCodeSize = 2;
+   }
+   
+   bool AtEndOfStream() const { return NextChar == LastChar; }
+   
+   uint32_t Read(unsigned NumBits) {
+ // If the field is fully contained by CurWord, return it quickly.
+ if (BitsInCurWord >= NumBits) {
+   uint32_t R = CurWord & ((1U << NumBits)-1);
+   CurWord >>= NumBits;
+   BitsInCurWord -= NumBits;
+   return R;
+ }
+ 
+ // If we run out of data, st