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

Chris Lattner sabre at nondot.org
Fri May 4 10:35:37 PDT 2007



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.2	Mon Apr 23 11:04:05 2007
+++ llvm/include/llvm/Bitcode/BitCodes.h	Fri 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<BitCodeAbbrevOp, 8> 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.11	Tue 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<BitCodeAbbrev*> &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();
     






More information about the llvm-commits mailing list