summaryrefslogtreecommitdiff
path: root/lib/Bitcode/Reader/BitcodeReader.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-31 22:55:09 +0000
committerChris Lattner <sabre@nondot.org>2009-03-31 22:55:09 +0000
commit46e7740a4433383e6e5561f089a091c22125bd07 (patch)
tree14e6e14ecffcfbe71c99cf3fdbda3e86ed1408ca /lib/Bitcode/Reader/BitcodeReader.h
parentd3c7b7359d4992b9ab9f8e12ccd0a9b7d2446566 (diff)
downloadllvm-46e7740a4433383e6e5561f089a091c22125bd07.tar.gz
llvm-46e7740a4433383e6e5561f089a091c22125bd07.tar.bz2
llvm-46e7740a4433383e6e5561f089a091c22125bd07.tar.xz
reimplement BitcodeReaderValueList in terms of WeakVH instead of making
it be an LLVM IR User object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68156 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader/BitcodeReader.h')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h77
1 files changed, 18 insertions, 59 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 0b72b34015..1fbf219fb8 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -20,6 +20,7 @@
#include "llvm/OperandTraits.h"
#include "llvm/Bitcode/BitstreamReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
+#include "llvm/Support/ValueHandle.h"
#include "llvm/ADT/DenseMap.h"
#include <vector>
@@ -30,8 +31,8 @@ namespace llvm {
// BitcodeReaderValueList Class
//===----------------------------------------------------------------------===//
-class BitcodeReaderValueList : public User {
- unsigned Capacity;
+class BitcodeReaderValueList {
+ std::vector<WeakVH> ValuePtrs;
/// ResolveConstants - As we resolve forward-referenced constants, we add
/// information about them to this vector. This allows us to resolve them in
@@ -43,88 +44,46 @@ class BitcodeReaderValueList : public User {
typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
ResolveConstantsTy ResolveConstants;
public:
- BitcodeReaderValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0)
- , Capacity(0) {}
+ BitcodeReaderValueList() {}
~BitcodeReaderValueList() {
assert(ResolveConstants.empty() && "Constants not resolved?");
}
- /// Provide fast operand accessors
- DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
-
// vector compatibility methods
- unsigned size() const { return getNumOperands(); }
- void resize(unsigned);
+ unsigned size() const { return ValuePtrs.size(); }
+ void resize(unsigned N) { ValuePtrs.resize(N); }
void push_back(Value *V) {
- unsigned OldOps(NumOperands), NewOps(NumOperands + 1);
- resize(NewOps);
- NumOperands = NewOps;
- OperandList[OldOps] = V;
+ ValuePtrs.push_back(V);
}
void clear() {
assert(ResolveConstants.empty() && "Constants not resolved?");
- if (OperandList) dropHungoffUses(OperandList);
- Capacity = 0;
+ ValuePtrs.clear();
}
- Value *operator[](unsigned i) const { return getOperand(i); }
+ Value *operator[](unsigned i) const {
+ assert(i < ValuePtrs.size());
+ return ValuePtrs[i];
+ }
- Value *back() const { return getOperand(size() - 1); }
- void pop_back() { setOperand(size() - 1, 0); --NumOperands; }
- bool empty() const { return NumOperands == 0; }
+ Value *back() const { return ValuePtrs.back(); }
+ void pop_back() { ValuePtrs.pop_back(); }
+ bool empty() const { return ValuePtrs.empty(); }
void shrinkTo(unsigned N) {
- assert(N <= NumOperands && "Invalid shrinkTo request!");
- while (NumOperands > N)
- pop_back();
+ assert(N <= size() && "Invalid shrinkTo request!");
+ ValuePtrs.resize(N);
}
- virtual void print(std::ostream&) const {}
Constant *getConstantFwdRef(unsigned Idx, const Type *Ty);
Value *getValueFwdRef(unsigned Idx, const Type *Ty);
- void AssignValue(Value *V, unsigned Idx) {
- if (Idx == size()) {
- push_back(V);
- } else if (Value *OldV = getOperand(Idx)) {
- // Handle constants and non-constants (e.g. instrs) differently for
- // efficiency.
- if (Constant *PHC = dyn_cast<Constant>(OldV)) {
- ResolveConstants.push_back(std::make_pair(PHC, Idx));
- setOperand(Idx, V);
- } else {
- // If there was a forward reference to this value, replace it.
- setOperand(Idx, V);
- OldV->replaceAllUsesWith(V);
- delete OldV;
- }
- } else {
- initVal(Idx, V);
- }
- }
+ void AssignValue(Value *V, unsigned Idx);
/// ResolveConstantForwardRefs - Once all constants are read, this method bulk
/// resolves any forward references.
void ResolveConstantForwardRefs();
-
-private:
- void initVal(unsigned Idx, Value *V) {
- 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] = V;
- }
};
-template <>
-struct OperandTraits<BitcodeReaderValueList>
- : HungoffOperandTraits</*16 FIXME*/> {
-};
-
-DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BitcodeReaderValueList, Value)
-
class BitcodeReader : public ModuleProvider {
MemoryBuffer *Buffer;
BitstreamReader Stream;