summaryrefslogtreecommitdiff
path: root/lib/Bitcode/Reader/BitcodeReader.h
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2008-05-10 08:32:32 +0000
committerGabor Greif <ggreif@gmail.com>2008-05-10 08:32:32 +0000
commitefe65369a74871c3140a540a6c95ce5d1f080954 (patch)
treebd2fa60ec2238187a780f4f72f8b77e892cb7e4d /lib/Bitcode/Reader/BitcodeReader.h
parent4982babf4a2ae663ab841bd7f456078a306ad450 (diff)
downloadllvm-efe65369a74871c3140a540a6c95ce5d1f080954.tar.gz
llvm-efe65369a74871c3140a540a6c95ce5d1f080954.tar.bz2
llvm-efe65369a74871c3140a540a6c95ce5d1f080954.tar.xz
merge of use-diet branch to trunk
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50943 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader/BitcodeReader.h')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h50
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 86b00a5ef1..c35846f402 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -17,7 +17,7 @@
#include "llvm/ModuleProvider.h"
#include "llvm/ParameterAttributes.h"
#include "llvm/Type.h"
-#include "llvm/User.h"
+#include "llvm/OperandTraits.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/ADT/DenseMap.h"
@@ -26,32 +26,43 @@
namespace llvm {
class MemoryBuffer;
+//===----------------------------------------------------------------------===//
+// BitcodeReaderValueList Class
+//===----------------------------------------------------------------------===//
+
class BitcodeReaderValueList : public User {
- std::vector<Use> Uses;
+ unsigned Capacity;
public:
- BitcodeReaderValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0) {}
-
+ BitcodeReaderValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0)
+ , Capacity(0) {}
+
+ /// Provide fast operand accessors
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
// vector compatibility methods
unsigned size() const { return getNumOperands(); }
+ void resize(unsigned);
void push_back(Value *V) {
- Uses.push_back(Use(V, this));
- OperandList = &Uses[0];
- ++NumOperands;
+ unsigned OldOps(NumOperands), NewOps(NumOperands + 1);
+ resize(NewOps);
+ NumOperands = NewOps;
+ OperandList[OldOps] = V;
}
void clear() {
- std::vector<Use>().swap(Uses);
+ if (OperandList) dropHungoffUses(OperandList);
+ Capacity = 0;
}
Value *operator[](unsigned i) const { return getOperand(i); }
- Value *back() const { return Uses.back(); }
- void pop_back() { Uses.pop_back(); --NumOperands; }
+ Value *back() const { return getOperand(size() - 1); }
+ void pop_back() { setOperand(size() - 1, 0); --NumOperands; }
bool empty() const { return NumOperands == 0; }
void shrinkTo(unsigned N) {
assert(N <= NumOperands && "Invalid shrinkTo request!");
- Uses.resize(N);
- NumOperands = N;
+ while (NumOperands > N)
+ pop_back();
}
virtual void print(std::ostream&) const {}
@@ -73,11 +84,20 @@ public:
private:
void initVal(unsigned Idx, Value *V) {
- assert(Uses[Idx] == 0 && "Cannot init an already init'd Use!");
- Uses[Idx].init(V, this);
+ if (Idx >= size()) {
+ // Insert a bunch of null values.
+ resize(Idx * 2 + 1);
+ }
+ assert(getOperand(Idx) == 0 && "Cannot init an already init'd Use!");
+ OperandList[Idx].init(V, this);
}
};
-
+
+template <>
+struct OperandTraits<BitcodeReaderValueList> : HungoffOperandTraits</*16 FIXME*/> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitcodeReaderValueList, Value)
class BitcodeReader : public ModuleProvider {
MemoryBuffer *Buffer;