[llvm-commits] [poolalloc] r132792 - in /poolalloc/trunk: include/assistDS/TypeChecks.h lib/AssistDS/TypeChecks.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Thu Jun 9 12:30:46 PDT 2011
Author: aggarwa4
Date: Thu Jun 9 14:30:46 2011
New Revision: 132792
URL: http://llvm.org/viewvc/llvm-project?rev=132792&view=rev
Log:
When visiting globals, create pretty gep's as against
the ugly gep's we were creating earlier.
Modified:
poolalloc/trunk/include/assistDS/TypeChecks.h
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
Modified: poolalloc/trunk/include/assistDS/TypeChecks.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/TypeChecks.h?rev=132792&r1=132791&r2=132792&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Thu Jun 9 14:30:46 2011
@@ -71,7 +71,7 @@
bool visitAllocaInst(Module &M, AllocaInst &AI);
bool visitGlobal(Module &M, GlobalVariable &GV,
- Constant *C, Instruction &I, unsigned offset);
+ Constant *C, Instruction &I, SmallVector<Value*,8>);
bool visitInternalByValFunction(Module &M, Function &F);
bool visitExternalByValFunction(Module &M, Function &F);
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=132792&r1=132791&r2=132792&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Thu Jun 9 14:30:46 2011
@@ -1127,7 +1127,8 @@
}
if(!I->hasInitializer())
continue;
- visitGlobal(M, *I, I->getInitializer(), *InsertPt, 0);
+ SmallVector<Value*,8>index;
+ visitGlobal(M, *I, I->getInitializer(), *InsertPt, index);
}
//
// Insert the run-time ctor into the ctor list.
@@ -1208,13 +1209,13 @@
}
bool TypeChecks::visitGlobal(Module &M, GlobalVariable &GV,
- Constant *C, Instruction &I, unsigned offset) {
+ Constant *C, Instruction &I, SmallVector<Value *,8> Indices) {
if(ConstantArray *CA = dyn_cast<ConstantArray>(C)) {
const Type * ElementType = CA->getType()->getElementType();
// Create the type entry for the first element
// using recursive creation till we get to the base types
- visitGlobal(M, GV, CA->getOperand(0), I, offset);
+ visitGlobal(M, GV, CA->getOperand(0), I, Indices);
// Copy the type metadata for the first element
// over for the rest of the elements.
@@ -1233,8 +1234,9 @@
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
if (SL->getElementOffset(i) < SL->getSizeInBytes()) {
Constant * ConstElement = cast<Constant>(CS->getOperand(i));
- unsigned field_offset = offset + (unsigned)SL->getElementOffset(i);
- visitGlobal(M, GV, ConstElement, I, field_offset);
+ Indices.push_back(ConstantInt::get(Int32Ty, i));
+ visitGlobal(M, GV, ConstElement, I, Indices);
+ Indices.pop_back();
}
}
} else if(ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(C)) {
@@ -1243,7 +1245,7 @@
const Type *Ty = CAZ->getType();
if(const ArrayType * ATy = dyn_cast<ArrayType>(Ty)) {
const Type * ElementType = ATy->getElementType();
- visitGlobal(M, GV, Constant::getNullValue(ElementType), I, offset);
+ visitGlobal(M, GV, Constant::getNullValue(ElementType), I, Indices);
CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
std::vector<Value *> Args;
Args.push_back(BCI);
@@ -1255,20 +1257,19 @@
const StructLayout *SL = TD->getStructLayout(STy);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
if (SL->getElementOffset(i) < SL->getSizeInBytes()) {
- unsigned field_offset = offset + (unsigned)SL->getElementOffset(i);
- visitGlobal(M, GV, Constant::getNullValue(STy->getElementType(i)), I, field_offset);
+ Indices.push_back(ConstantInt::get(Int32Ty, i));
+ visitGlobal(M, GV, Constant::getNullValue(STy->getElementType(i)), I, Indices);
+ Indices.pop_back();
}
}
} else {
// Zeroinitializer of a primitive type
- CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
- SmallVector<Value*, 8> Indices;
- Indices.push_back(ConstantInt::get(Int32Ty, offset));
- GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(BCI, Indices.begin(),
+ GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(&GV, Indices.begin(),
Indices.end(),"", &I) ;
+ CastInst *BCI = BitCastInst::CreatePointerCast(GEP, VoidPtrTy, "", &I);
std::vector<Value *> Args;
- Args.push_back(GEP);
+ Args.push_back(BCI);
Args.push_back(getTypeMarkerConstant(CAZ));
Args.push_back(getSizeConstant(CAZ->getType()));
Args.push_back(getTagCounter());
@@ -1277,20 +1278,17 @@
}
else {
// Primitive type value
- CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
- SmallVector<Value*, 8> Indices;
- Indices.push_back(ConstantInt::get(Int32Ty, offset));
- GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(BCI, Indices.begin(),
+ GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(&GV, Indices.begin(),
Indices.end(),"", &I) ;
+ CastInst *BCI = BitCastInst::CreatePointerCast(GEP, VoidPtrTy, "", &I);
std::vector<Value *> Args;
- Args.push_back(GEP);
+ Args.push_back(BCI);
Args.push_back(getTypeMarkerConstant(C));
Args.push_back(getSizeConstant(C->getType()));
Args.push_back(getTagCounter());
CallInst::Create(trackGlobal, Args.begin(), Args.end(), "", &I);
}
-
return true;
}
More information about the llvm-commits
mailing list