[llvm-commits] [poolalloc] r49926 - in /poolalloc/trunk: include/poolalloc/PoolAllocate.h lib/PoolAllocate/PASimple.cpp lib/PoolAllocate/PoolAllocate.cpp
John Criswell
criswell at uiuc.edu
Fri Apr 18 14:19:07 PDT 2008
Author: criswell
Date: Fri Apr 18 16:19:07 2008
New Revision: 49926
URL: http://llvm.org/viewvc/llvm-project?rev=49926&view=rev
Log:
Added support in the simple pool allocator for calloc().
Modified:
poolalloc/trunk/include/poolalloc/PoolAllocate.h
poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=49926&r1=49925&r2=49926&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Fri Apr 18 16:19:07 2008
@@ -160,6 +160,7 @@
#endif
Constant *PoolInit, *PoolDestroy, *PoolAlloc, *PoolRealloc, *PoolMemAlign;
Constant *PoolFree;
+ Constant *PoolCalloc;
Constant *PoolStrdup;
static const Type *PoolDescPtrTy;
Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=49926&r1=49925&r2=49926&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Fri Apr 18 16:19:07 2008
@@ -217,6 +217,48 @@
// Update def-use info
CI->replaceAllUsesWith(Casted);
+ } else if (CF && (CF->isDeclaration()) && (CF->getName() == "calloc")) {
+ // Associate the global pool decriptor with the DSNode
+ DSNode * Node = ECG.getNodeForValue(CI).getNode();
+ FInfo.PoolDescriptors.insert(make_pair(Node,TheGlobalPool));
+
+ // Mark the realloc as an instruction to delete
+ toDelete.push_back(ii);
+
+ // Insertion point - Instruction before which all our instructions go
+ Instruction *InsertPt = CI;
+ Value *NumElements = CS.getArgument(0);
+ Value *Size = CS.getArgument(1);
+
+ // Ensure the size and pointer arguments are of the correct type
+ if (Size->getType() != Type::Int32Ty)
+ Size = CastInst::createIntegerCast (Size,
+ Type::Int32Ty,
+ false,
+ Size->getName(),
+ InsertPt);
+
+ if (NumElements->getType() != Type::Int32Ty)
+ NumElements = CastInst::createIntegerCast (Size,
+ Type::Int32Ty,
+ false,
+ NumElements->getName(),
+ InsertPt);
+
+ std::string Name = CI->getName(); CI->setName("");
+ Value* Opts[3] = {TheGlobalPool, NumElements, Size};
+ Instruction *V = CallInst::Create (PoolCalloc,
+ Opts,
+ Opts + 3,
+ Name,
+ InsertPt);
+
+ Instruction *Casted = V;
+ if (V->getType() != CI->getType())
+ Casted = CastInst::createPointerCast (V, CI->getType(), V->getName(), InsertPt);
+
+ // Update def-use info
+ CI->replaceAllUsesWith(Casted);
}
} else if (FreeInst * FI = dyn_cast<FreeInst>(ii)) {
Type * VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=49926&r1=49925&r2=49926&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Fri Apr 18 16:19:07 2008
@@ -213,6 +213,12 @@
PoolRealloc = M->getOrInsertFunction("poolrealloc",
VoidPtrTy, PoolDescPtrTy,
VoidPtrTy, Type::Int32Ty, NULL);
+
+ // The poolcalloc function.
+ PoolCalloc = M->getOrInsertFunction("poolcalloc",
+ VoidPtrTy, PoolDescPtrTy,
+ Type::Int32Ty, Type::Int32Ty, NULL);
+
// The poolmemalign function.
PoolMemAlign = M->getOrInsertFunction("poolmemalign",
VoidPtrTy, PoolDescPtrTy,
More information about the llvm-commits
mailing list