[llvm-commits] [llvm] r49576 - in /llvm/branches/ggreif/use-diet: include/llvm/Instructions.h lib/VMCore/Instructions.cpp
Gabor Greif
ggreif at gmail.com
Fri Apr 11 23:48:45 PDT 2008
Author: ggreif
Date: Sat Apr 12 01:48:44 2008
New Revision: 49576
URL: http://llvm.org/viewvc/llvm-project?rev=49576&view=rev
Log:
convert GEP
Modified:
llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
Modified: llvm/branches/ggreif/use-diet/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/Instructions.h?rev=49576&r1=49575&r2=49576&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/Instructions.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/Instructions.h Sat Apr 12 01:48:44 2008
@@ -385,14 +385,15 @@
/// access elements of arrays and structs
///
class GetElementPtrInst : public Instruction {
- GetElementPtrInst(const GetElementPtrInst &GEPI)
+ GetElementPtrInst(const GetElementPtrInst &GEPI);/*
: Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
0, GEPI.getNumOperands()) {
- Use *OL = OperandList = 0; // FIXME: GEPI.dupHangoffUses(this, NumOperands, GEPI.OperandList) new Use[NumOperands];
+ OperandList = &Op<0>();
+ Use *OL = OperandList;
Use *GEPIOL = GEPI.OperandList;
for (unsigned i = 0, E = NumOperands; i != E; ++i)
OL[i].init(GEPIOL[i], this);
- }
+ }*/
void init(Value *Ptr, Value* const *Idx, unsigned NumIdx);
void init(Value *Ptr, Value *Idx);
@@ -407,7 +408,8 @@
if (NumIdx > 0) {
// This requires that the iterator points to contiguous memory.
- init(Ptr, &*IdxBegin, NumIdx);
+ init(Ptr, &*IdxBegin, NumIdx); // FIXME: for the general case
+ // we have to build an array here
}
else {
init(Ptr, 0, NumIdx);
@@ -455,24 +457,26 @@
template<typename InputIterator>
GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd,
- const std::string &Name = "",
- Instruction *InsertBefore = 0)
+ unsigned Values,
+ const std::string &Name,
+ Instruction *InsertBefore)
: Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true)),
cast<PointerType>(Ptr->getType())->getAddressSpace()),
- GetElementPtr, 0, 0, InsertBefore) {
+ GetElementPtr, 0, Values, InsertBefore) {
init(Ptr, IdxBegin, IdxEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category());
}
template<typename InputIterator>
GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
+ unsigned Values,
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true)),
cast<PointerType>(Ptr->getType())->getAddressSpace()),
- GetElementPtr, 0, 0, InsertAtEnd) {
+ GetElementPtr, 0, Values, InsertAtEnd) {
init(Ptr, IdxBegin, IdxEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category());
}
@@ -489,28 +493,35 @@
InputIterator IdxEnd,
const std::string &Name = "",
Instruction *InsertBefore = 0) {
- return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
+ typename std::iterator_traits<InputIterator>::difference_type Values =
+ 1 + std::distance(IdxBegin, IdxEnd);
+ return new(Values) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertBefore);
}
template<typename InputIterator>
static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
const std::string &Name, BasicBlock *InsertAtEnd) {
- return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
+ typename std::iterator_traits<InputIterator>::difference_type Values =
+ 1 + std::distance(IdxBegin, IdxEnd);
+ return new(Values) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Values, Name, InsertAtEnd);
}
/// Constructors - These two constructors are convenience methods because one
/// and two index getelementptr instructions are so common.
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
const std::string &Name = "", Instruction *InsertBefore = 0) {
- return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
+ return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
}
static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
const std::string &Name, BasicBlock *InsertAtEnd) {
- return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
+ return new(2) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
}
~GetElementPtrInst();
virtual GetElementPtrInst *clone() const;
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
// getType - Overload to return most specific pointer type...
const PointerType *getType() const {
return reinterpret_cast<const PointerType*>(Instruction::getType());
@@ -577,6 +588,23 @@
}
};
+template <>
+struct OperandTraits<GetElementPtrInst> : VariadicOperandTraits<1> {
+};
+
+GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
+ : Instruction(reinterpret_cast<const Type*>(GEPI.getType()), GetElementPtr,
+ OperandTraits<GetElementPtrInst>::op_end(this) - GEPI.getNumOperands(),
+ GEPI.getNumOperands()) {
+ Use *OL = OperandList;
+ Use *GEPIOL = GEPI.OperandList;
+ for (unsigned i = 0, E = NumOperands; i != E; ++i)
+ OL[i].init(GEPIOL[i], this);
+}
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)
+
+
//===----------------------------------------------------------------------===//
// ICmpInst Class
//===----------------------------------------------------------------------===//
Modified: llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp?rev=49576&r1=49575&r2=49576&view=diff
==============================================================================
--- llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/ggreif/use-diet/lib/VMCore/Instructions.cpp Sat Apr 12 01:48:44 2008
@@ -973,8 +973,8 @@
}
void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
- NumOperands = 1+NumIdx;
- Use *OL = OperandList = allocHangoffUses(NumOperands);
+ assert(NumOperands == 1+NumIdx && "NumOperands not initialized?");
+ Use *OL = OperandList;
OL[0].init(Ptr, this);
for (unsigned i = 0; i != NumIdx; ++i)
@@ -982,8 +982,8 @@
}
void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
- NumOperands = 2;
- Use *OL = OperandList = allocHangoffUses(2);
+ assert(NumOperands == 2 && "NumOperands not initialized?");
+ Use *OL = OperandList;
OL[0].init(Ptr, this);
OL[1].init(Idx, this);
}
@@ -992,7 +992,9 @@
const std::string &Name, Instruction *InBe)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx)),
retrieveAddrSpace(Ptr)),
- GetElementPtr, 0, 0, InBe) {
+ GetElementPtr,
+ OperandTraits<GetElementPtrInst>::op_end(this) - 2,
+ 2, InBe) {
init(Ptr, Idx);
setName(Name);
}
@@ -1001,13 +1003,15 @@
const std::string &Name, BasicBlock *IAE)
: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx)),
retrieveAddrSpace(Ptr)),
- GetElementPtr, 0, 0, IAE) {
+ GetElementPtr,
+ OperandTraits<GetElementPtrInst>::op_end(this) - 2,
+ 2, IAE) {
init(Ptr, Idx);
setName(Name);
}
GetElementPtrInst::~GetElementPtrInst() {
- delete[] OperandList;
+ // delete[] OperandList;
}
// getIndexedType - Returns the type of the element that would be loaded with
More information about the llvm-commits
mailing list