[llvm-commits] [poolalloc] r48915 - /poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
John Criswell
criswell at uiuc.edu
Fri Mar 28 07:26:44 PDT 2008
Author: criswell
Date: Fri Mar 28 09:26:37 2008
New Revision: 48915
URL: http://llvm.org/viewvc/llvm-project?rev=48915&view=rev
Log:
Added support for realloc().
Modified:
poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=48915&r1=48914&r2=48915&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Fri Mar 28 09:26:37 2008
@@ -166,6 +166,51 @@
ToFree.push_back(x);
ii->replaceAllUsesWith(CastInst::createPointerCast(x, ii->getType(), "", ii));
#endif
+ } else if (CallInst * CI = dyn_cast<CallInst>(ii)) {
+ CallSite CS(CI);
+ Function *CF = CS.getCalledFunction();
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CS.getCalledValue()))
+ if (CE->getOpcode() == Instruction::BitCast &&
+ isa<Function>(CE->getOperand(0)))
+ CF = cast<Function>(CE->getOperand(0));
+ if (CF && (CF->isDeclaration()) && (CF->getName() == "realloc")) {
+ // 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 *OldPtr = 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);
+
+ static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+ if (OldPtr->getType() != VoidPtrTy)
+ OldPtr = CastInst::createPointerCast (OldPtr,
+ VoidPtrTy,
+ OldPtr->getName(),
+ InsertPt);
+
+ std::string Name = CI->getName(); CI->setName("");
+ Value* Opts[3] = {TheGlobalPool, OldPtr, Size};
+ Instruction *V = new CallInst (PoolRealloc,
+ 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);
Value * FreedNode = castTo (FI->getPointerOperand(), VoidPtrTy, "cast", ii);
More information about the llvm-commits
mailing list