[llvm-commits] [llvm] r49497 - in /llvm/branches/ggreif/use-diet: include/llvm/User.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Reader/BitcodeReader.h
Gabor Greif
ggreif at gmail.com
Thu Apr 10 14:27:40 PDT 2008
Author: ggreif
Date: Thu Apr 10 16:27:40 2008
New Revision: 49497
URL: http://llvm.org/viewvc/llvm-project?rev=49497&view=rev
Log:
first attempt at repairing BitcodeReaderValueList
Modified:
llvm/branches/ggreif/use-diet/include/llvm/User.h
llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.h
Modified: llvm/branches/ggreif/use-diet/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/User.h?rev=49497&r1=49496&r2=49497&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Thu Apr 10 16:27:40 2008
@@ -252,6 +252,7 @@
return OperandTraits<User>::op_begin(const_cast<User*>(this))[Idx];
}
inline Use *allocHangoffUses(unsigned) const;
+ void dropHungoffUses(Use*);
Value *getOperand(unsigned i) const {
assert(i < NumOperands && "getOperand() out of range!");
Modified: llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.cpp?rev=49497&r1=49496&r2=49497&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.cpp Thu Apr 10 16:27:40 2008
@@ -23,6 +23,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/OperandTraits.h"
using namespace llvm;
void BitcodeReader::FreeState() {
@@ -115,7 +116,7 @@
}
}
-
+namespace llvm {
namespace {
/// @brief A class for maintaining the slot number definition
/// as a placeholder for the actual definition for forward constants defs.
@@ -128,51 +129,62 @@
return User::operator new(s, 1);
}
explicit ConstantPlaceHolder(const Type *Ty)
- : ConstantExpr(Ty, Instruction::UserOp1, /*&Op*/NULL, 1) {
+ : ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
Op<0>() = UndefValue::get(Type::Int32Ty);
}
+ /// Provide fast operand accessors
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
};
}
+
+ // FIXME: can we inherit this from ConstantExpr?
+template <>
+struct OperandTraits<ConstantPlaceHolder> : FixedNumOperandTraits<1> {
+};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantPlaceHolder, Value)
+}
+
Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx,
const Type *Ty) {
if (Idx >= size()) {
// Insert a bunch of null values.
-// Uses.resize(Idx+1);
+ resize(Idx * 2 + 1);
// OperandList = &Uses[0];
- NumOperands = Idx+1;
+// NumOperands = Idx+1;
}
-// if (Value *V = Uses[Idx]) {
-// assert(Ty == V->getType() && "Type mismatch in constant table!");
-// return cast<Constant>(V);
-// }
+ if (Value *V = OperandList[Idx]) {
+ assert(Ty == V->getType() && "Type mismatch in constant table!");
+ return cast<Constant>(V);
+ }
// Create and return a placeholder, which will later be RAUW'd.
Constant *C = new ConstantPlaceHolder(Ty);
-// Uses[Idx].init(C, this);
+ OperandList[Idx].init(C, this);
return C;
}
Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, const Type *Ty) {
if (Idx >= size()) {
// Insert a bunch of null values.
-// Uses.resize(Idx+1);
+ resize(Idx * 2 + 1);
// OperandList = &Uses[0];
- NumOperands = Idx+1;
+// NumOperands = Idx+1;
}
-/* if (Value *V = Uses[Idx]) {
+ if (Value *V = OperandList[Idx]) {
assert((Ty == 0 || Ty == V->getType()) && "Type mismatch in value table!");
return V;
- }*/
+ }
// No type specified, must be invalid reference.
if (Ty == 0) return 0;
// Create and return a placeholder, which will later be RAUW'd.
Value *V = new Argument(Ty);
-// Uses[Idx].init(V, this);
+ OperandList[Idx].init(V, this);
return V;
}
Modified: llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.h?rev=49497&r1=49496&r2=49497&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/branches/ggreif/use-diet/lib/Bitcode/Reader/BitcodeReader.h Thu Apr 10 16:27:40 2008
@@ -26,12 +26,35 @@
namespace llvm {
class MemoryBuffer;
+//===----------------------------------------------------------------------===//
+// HungoffOperand Trait Class
+//===----------------------------------------------------------------------===//
+
+template <unsigned MINARITY = 0>
+struct HungoffOperandTraits {
+ static Use *op_begin(User* U) {
+ return U->OperandList;
+ }
+ static Use *op_end(User* U) {
+ return U->OperandList + U->getNumOperands();
+ }
+ static unsigned operands(const User *U) {
+ return U->getNumOperands();
+ }
+ static inline void *allocate(unsigned); // FIXME
+};
+
+//===----------------------------------------------------------------------===//
+// BitcodeReaderValueList Class
+//===----------------------------------------------------------------------===//
+
class BitcodeReaderValueList : public User {
public:
BitcodeReaderValueList() : User(Type::VoidTy, Value::ArgumentVal, 0, 0) {}
// 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];
@@ -39,18 +62,20 @@
}
void clear() {
-// std::vector<Use>().swap(Uses);
+ dropHungoffUses(OperandList);
}
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;
+// NumOperands = N;
+ while (NumOperands > N)
+ pop_back();
}
virtual void print(std::ostream&) const {}
More information about the llvm-commits
mailing list