summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-04 17:35:19 +0000
committerChris Lattner <sabre@nondot.org>2007-05-04 17:35:19 +0000
commit299b2d2070165eccea3fb61f7387fa016b847338 (patch)
tree65d0e434fe969115ede96fa7976c2623b3a620b9 /include
parentf0799fe155a1206e9e76c0a104bbd05914390ff8 (diff)
downloadllvm-299b2d2070165eccea3fb61f7387fa016b847338.tar.gz
llvm-299b2d2070165eccea3fb61f7387fa016b847338.tar.bz2
llvm-299b2d2070165eccea3fb61f7387fa016b847338.tar.xz
refcount BitCodeAbbrev objects
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36747 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Bitcode/BitCodes.h12
-rw-r--r--include/llvm/Bitcode/BitstreamReader.h6
-rw-r--r--include/llvm/Bitcode/BitstreamWriter.h2
3 files changed, 13 insertions, 7 deletions
diff --git a/include/llvm/Bitcode/BitCodes.h b/include/llvm/Bitcode/BitCodes.h
index 98d18b194b..15a7a4943d 100644
--- a/include/llvm/Bitcode/BitCodes.h
+++ b/include/llvm/Bitcode/BitCodes.h
@@ -58,9 +58,9 @@ namespace bitc {
/// 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 @@ public:
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];
diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h
index 8d70f1f713..bff4e537fd 100644
--- a/include/llvm/Bitcode/BitstreamReader.h
+++ b/include/llvm/Bitcode/BitstreamReader.h
@@ -75,12 +75,12 @@ public:
// 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 @@ public:
// 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();
diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h
index eaf2e4317c..808fa527e0 100644
--- a/include/llvm/Bitcode/BitstreamWriter.h
+++ b/include/llvm/Bitcode/BitstreamWriter.h
@@ -160,7 +160,7 @@ public:
// Delete all abbrevs.
for (unsigned i = 0, e = CurAbbrevs.size(); i != e; ++i)
- delete CurAbbrevs[i];
+ CurAbbrevs[i]->dropRef();
const Block &B = BlockScope.back();