[llvm-commits] CVS: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Feb 13 12:36:25 PST 2005
Changes in directory llvm-poolalloc/lib/PoolAllocate:
PointerCompress.cpp updated: 1.8 -> 1.9
---
Log message:
Implement the simple and common 3-operand form of getelementptr: gep P, 0, uint
---
Diffs of the changes: (+28 -1)
PointerCompress.cpp | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletion(-)
Index: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.8 llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.9
--- llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.8 Sun Feb 13 09:57:23 2005
+++ llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp Sun Feb 13 14:36:10 2005
@@ -248,13 +248,14 @@
const PointerCompress::PoolInfoMap &PoolInfo;
+ const TargetData &TD;
const DSGraph &DSG;
PointerCompress &PtrComp;
public:
InstructionRewriter(const PointerCompress::PoolInfoMap &poolInfo,
const DSGraph &dsg, PointerCompress &ptrcomp)
- : PoolInfo(poolInfo), DSG(dsg), PtrComp(ptrcomp) {
+ : PoolInfo(poolInfo), TD(dsg.getTargetData()), DSG(dsg), PtrComp(ptrcomp){
}
~InstructionRewriter();
@@ -318,6 +319,7 @@
void visitCastInst(CastInst &CI);
void visitPHINode(PHINode &PN);
void visitSetCondInst(SetCondInst &SCI);
+ void visitGetElementPtrInst(GetElementPtrInst &GEPI);
void visitLoadInst(LoadInst &LI);
void visitStoreInst(StoreInst &SI);
@@ -406,6 +408,31 @@
SCI.eraseFromParent();
}
+void InstructionRewriter::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
+ const CompressedPoolInfo *PI = getPoolInfo(&GEPI);
+ if (PI == 0) return;
+
+ // For now, we only support very very simple getelementptr instructions, with
+ // two indices, where the first is zero.
+ assert(GEPI.getNumOperands() == 3 && isa<Constant>(GEPI.getOperand(1)) &&
+ cast<Constant>(GEPI.getOperand(1))->isNullValue());
+ const Type *IdxTy =
+ cast<PointerType>(GEPI.getOperand(0)->getType())->getElementType();
+ assert(isa<StructType>(IdxTy) && "Can only handle structs right now!");
+
+ Value *Val = getTransformedValue(GEPI.getOperand(0));
+
+ unsigned Field = (unsigned)cast<ConstantUInt>(GEPI.getOperand(2))->getValue();
+ if (Field) {
+ const StructType *NTy = cast<StructType>(PI->getNewType());
+ uint64_t FieldOffs = TD.getStructLayout(NTy)->MemberOffsets[Field];
+ Constant *FieldOffsCst = ConstantUInt::get(UINTTYPE, FieldOffs);
+ Val = BinaryOperator::createAdd(Val, FieldOffsCst, GEPI.getName(), &GEPI);
+ }
+
+ setTransformedValue(GEPI, Val);
+}
+
void InstructionRewriter::visitLoadInst(LoadInst &LI) {
if (isa<ConstantPointerNull>(LI.getOperand(0))) return; // load null ??
More information about the llvm-commits
mailing list