[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerAllocations.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Mar 2 17:03:56 PST 2005
Changes in directory llvm/lib/Transforms/Scalar:
LowerAllocations.cpp updated: 1.51 -> 1.52
---
Log message:
Add an optional argument to lower to a specific constant value instead of
to a "sizeof" expression.
---
Diffs of the changes: (+14 -6)
LowerAllocations.cpp | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
Index: llvm/lib/Transforms/Scalar/LowerAllocations.cpp
diff -u llvm/lib/Transforms/Scalar/LowerAllocations.cpp:1.51 llvm/lib/Transforms/Scalar/LowerAllocations.cpp:1.52
--- llvm/lib/Transforms/Scalar/LowerAllocations.cpp:1.51 Mon Dec 13 14:00:02 2004
+++ llvm/lib/Transforms/Scalar/LowerAllocations.cpp Wed Mar 2 19:03:43 2005
@@ -31,8 +31,10 @@
class LowerAllocations : public BasicBlockPass {
Function *MallocFunc; // Functions in the module we are processing
Function *FreeFunc; // Initialized by doInitialization
+ bool LowerMallocArgToInteger;
public:
- LowerAllocations() : MallocFunc(0), FreeFunc(0) {}
+ LowerAllocations(bool LowerToInt = false)
+ : MallocFunc(0), FreeFunc(0), LowerMallocArgToInteger(LowerToInt) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>();
@@ -59,8 +61,8 @@
}
// createLowerAllocationsPass - Interface to this file...
-FunctionPass *llvm::createLowerAllocationsPass() {
- return new LowerAllocations();
+FunctionPass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
+ return new LowerAllocations(LowerMallocArgToInteger);
}
@@ -95,7 +97,8 @@
BasicBlock::InstListType &BBIL = BB.getInstList();
- const Type *IntPtrTy = getAnalysis<TargetData>().getIntPtrType();
+ const TargetData &TD = getAnalysis<TargetData>();
+ const Type *IntPtrTy = TD.getIntPtrType();
// Loop over all of the instructions, looking for malloc or free instructions
for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
@@ -103,8 +106,13 @@
const Type *AllocTy = MI->getType()->getElementType();
// malloc(type) becomes sbyte *malloc(size)
- Value *MallocArg = ConstantExpr::getCast(ConstantExpr::getSizeOf(AllocTy),
- IntPtrTy);
+ Value *MallocArg;
+ if (LowerMallocArgToInteger)
+ MallocArg = ConstantUInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
+ else
+ MallocArg = ConstantExpr::getSizeOf(AllocTy);
+ MallocArg = ConstantExpr::getCast(cast<Constant>(MallocArg), IntPtrTy);
+
if (MI->isArrayAllocation()) {
if (isa<ConstantInt>(MallocArg) &&
cast<ConstantInt>(MallocArg)->getRawValue() == 1) {
More information about the llvm-commits
mailing list