[llvm-commits] [poolalloc] r134701 - in /poolalloc/trunk/lib/AssistDS: TypeChecks.cpp TypeChecksOpt.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Fri Jul 8 09:29:49 PDT 2011
Author: aggarwa4
Date: Fri Jul 8 11:29:49 2011
New Revision: 134701
URL: http://llvm.org/viewvc/llvm-project?rev=134701&view=rev
Log:
We do not need to initialize the memory allocated by the
alloca, in the non optimized version. It is only when
we remove checks that initialization is needed.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/lib/AssistDS/TypeChecksOpt.cpp
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=134701&r1=134700&r2=134701&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Fri Jul 8 11:29:49 2011
@@ -1386,16 +1386,6 @@
// Insert code to set objects to 0
bool TypeChecks::visitAllocaInst(Module &M, AllocaInst &AI) {
- // Set the object to be zero
- //
- // Add the memset function to the program.
- Constant *memsetF = M.getOrInsertFunction ("llvm.memset.i64", VoidTy,
- VoidPtrTy,
- Int8Ty,
- Int64Ty,
- Int32Ty,
- NULL);
-
const PointerType * PT = AI.getType();
const Type * ET = PT->getElementType();
Value * AllocSize = ConstantInt::get(Int64Ty, TD->getTypeAllocSize(ET));
@@ -1406,13 +1396,6 @@
ArraySize->insertAfter(BCI);
BinaryOperator *Size = BinaryOperator::Create(Instruction::Mul, AllocSize, ArraySize);
Size->insertAfter(ArraySize);
- std::vector<Value *> Args2;
- Args2.push_back(BCI);
- Args2.push_back(ConstantInt::get(Int8Ty, 0));
- Args2.push_back(Size);
- Args2.push_back(ConstantInt::get(Int32Ty, AI.getAlignment()));
- CallInst *CI_Init = CallInst::Create(memsetF, Args2.begin(), Args2.end());
- CI_Init->insertAfter(Size);
// Setting metadata to be 0(BOTTOM/Uninitialized)
@@ -1421,7 +1404,7 @@
Args.push_back(Size);
Args.push_back(getTagCounter());
CallInst *CI = CallInst::Create(trackUnInitInst, Args.begin(), Args.end());
- CI->insertAfter(CI_Init);
+ CI->insertAfter(Size);
return true;
}
Modified: poolalloc/trunk/lib/AssistDS/TypeChecksOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecksOpt.cpp?rev=134701&r1=134700&r2=134701&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecksOpt.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecksOpt.cpp Fri Jul 8 11:29:49 2011
@@ -66,6 +66,12 @@
TypeTagTy = Int8Ty;
TypeTagPtrTy = PointerType::getUnqual(TypeTagTy);
+ Constant *memsetF = M.getOrInsertFunction ("llvm.memset.i64", VoidTy,
+ VoidPtrTy,
+ Int8Ty,
+ Int64Ty,
+ Int32Ty,
+ NULL);
trackGlobal = M.getOrInsertFunction("trackGlobal",
VoidTy,
VoidPtrTy,/*ptr*/
@@ -80,11 +86,11 @@
Int32Ty,/*tag*/
NULL);
trackUnInitInst = M.getOrInsertFunction("trackUnInitInst",
- VoidTy,
- VoidPtrTy,/*ptr*/
- Int64Ty,/*size*/
- Int32Ty,/*tag*/
- NULL);
+ VoidTy,
+ VoidPtrTy,/*ptr*/
+ Int64Ty,/*size*/
+ Int32Ty,/*tag*/
+ NULL);
trackStoreInst = M.getOrInsertFunction("trackStoreInst",
VoidTy,
VoidPtrTy,/*ptr*/
@@ -108,13 +114,13 @@
Int32Ty,/*tag*/
NULL);
setTypeInfo = M.getOrInsertFunction("setTypeInfo",
- VoidTy,
- VoidPtrTy,/*dest ptr*/
- TypeTagPtrTy,/*metadata*/
- Int64Ty,/*size*/
- TypeTagTy,
- Int32Ty,/*tag*/
- NULL);
+ VoidTy,
+ VoidPtrTy,/*dest ptr*/
+ TypeTagPtrTy,/*metadata*/
+ Int64Ty,/*size*/
+ TypeTagTy,
+ Int32Ty,/*tag*/
+ NULL);
trackStringInput = M.getOrInsertFunction("trackStringInput",
VoidTy,
VoidPtrTy,
@@ -145,7 +151,7 @@
for(Value::use_iterator User = checkTypeInst->use_begin(); User != checkTypeInst->use_end(); ++User) {
CallInst *CI = dyn_cast<CallInst>(User);
assert(CI);
-
+
if(TS->isTypeSafe(CI->getOperand(4)->stripPointerCasts(), CI->getParent()->getParent())) {
toDelete.push_back(CI);
}
@@ -154,7 +160,7 @@
for(Value::use_iterator User = trackStoreInst->use_begin(); User != trackStoreInst->use_end(); ++User) {
CallInst *CI = dyn_cast<CallInst>(User);
assert(CI);
-
+
if(TS->isTypeSafe(CI->getOperand(1)->stripPointerCasts(), CI->getParent()->getParent())) {
toDelete.push_back(CI);
}
@@ -165,11 +171,21 @@
for(Value::use_iterator User = trackUnInitInst->use_begin(); User != trackUnInitInst->use_end(); ) {
CallInst *CI = dyn_cast<CallInst>(User++);
assert(CI);
-
+
// check if operand is an alloca inst.
if(TS->isTypeSafe(CI->getOperand(1)->stripPointerCasts(), CI->getParent()->getParent())) {
CI->setCalledFunction(trackInitInst);
toDelete.push_back(CI);
+
+ if(AllocaInst *AI = dyn_cast<AllocaInst>(CI->getOperand(1)->stripPointerCasts())) {
+ // Initialize the allocation to NULL
+ std::vector<Value *> Args2;
+ Args2.push_back(CI->getOperand(1));
+ Args2.push_back(ConstantInt::get(Int8Ty, 0));
+ Args2.push_back(CI->getOperand(2));
+ Args2.push_back(ConstantInt::get(Int32Ty, AI->getAlignment()));
+ CallInst::Create(memsetF, Args2.begin(), Args2.end(), "", CI);
+ }
}
}
@@ -227,12 +243,6 @@
CallInst *CI = dyn_cast<CallInst>(User);
assert(CI);
if(TS->isTypeSafe(CI->getOperand(1)->stripPointerCasts(), CI->getParent()->getParent())) {
- Constant *memsetF = M.getOrInsertFunction ("llvm.memset.i64", VoidTy,
- VoidPtrTy,
- Int8Ty,
- Int64Ty,
- Int32Ty,
- NULL);
AllocaInst *AI = dyn_cast<AllocaInst>(CI->getOperand(3)->stripPointerCasts());
assert(AI);
std::vector<Value*>Args;
More information about the llvm-commits
mailing list