//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
bool LowerMallocArgToInteger;
public:
static char ID; // Pass ID, replacement for typeid
- LowerAllocations(bool LowerToInt = false)
- : BasicBlockPass((intptr_t)&ID), MallocFunc(0), FreeFunc(0),
+ explicit LowerAllocations(bool LowerToInt = false)
+ : BasicBlockPass(&ID), MallocFunc(0), FreeFunc(0),
LowerMallocArgToInteger(LowerToInt) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
// This is a cluster of orthogonal Transforms:
AU.addPreserved<UnifyFunctionExitNodes>();
AU.addPreservedID(PromoteMemoryToRegisterID);
- AU.addPreservedID(LowerSelectID);
AU.addPreservedID(LowerSwitchID);
AU.addPreservedID(LowerInvokePassID);
}
bool doInitialization(Module &M);
virtual bool doInitialization(Function &F) {
- return BasicBlockPass::doInitialization(F);
+ return doInitialization(*F.getParent());
}
/// runOnBasicBlock - This method does the actual work of converting
///
bool runOnBasicBlock(BasicBlock &BB);
};
-
- char LowerAllocations::ID = 0;
- RegisterPass<LowerAllocations>
- X("lowerallocs", "Lower allocations from instructions to calls");
}
+char LowerAllocations::ID = 0;
+static RegisterPass<LowerAllocations>
+X("lowerallocs", "Lower allocations from instructions to calls");
+
// Publically exposed interface to pass...
-const PassInfo *llvm::LowerAllocationsID = X.getPassInfo();
+const PassInfo *const llvm::LowerAllocationsID = &X;
// createLowerAllocationsPass - Interface to this file...
Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
return new LowerAllocations(LowerMallocArgToInteger);
// This function is always successful.
//
bool LowerAllocations::doInitialization(Module &M) {
- const Type *BPTy = PointerType::get(Type::Int8Ty);
+ const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
// Prototype malloc as "char* malloc(...)", because we don't know in
// doInitialization whether size_t is int or long.
FunctionType *FT = FunctionType::get(BPTy, std::vector<const Type*>(), true);
// malloc(type) becomes sbyte *malloc(size)
Value *MallocArg;
if (LowerMallocArgToInteger)
- MallocArg = ConstantInt::get(Type::Int64Ty, TD.getTypeSize(AllocTy));
+ MallocArg = ConstantInt::get(Type::Int64Ty,
+ TD.getTypePaddedSize(AllocTy));
else
MallocArg = ConstantExpr::getSizeOf(AllocTy);
MallocArg = ConstantExpr::getTruncOrBitCast(cast<Constant>(MallocArg),
} else {
Value *Scale = MI->getOperand(0);
if (Scale->getType() != IntPtrTy)
- Scale = CastInst::createIntegerCast(Scale, IntPtrTy, false /*ZExt*/,
+ Scale = CastInst::CreateIntegerCast(Scale, IntPtrTy, false /*ZExt*/,
"", I);
// Multiply it by the array size if necessary...
- MallocArg = BinaryOperator::create(Instruction::Mul, Scale,
+ MallocArg = BinaryOperator::Create(Instruction::Mul, Scale,
MallocArg, "", I);
}
}
// Create the call to Malloc.
- CallInst *MCall = new CallInst(MallocFunc, MallocArg, "", I);
+ CallInst *MCall = CallInst::Create(MallocFunc, MallocArg, "", I);
MCall->setTailCall();
// Create a cast instruction to convert to the right type...
Changed = true;
++NumLowered;
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
- Value *PtrCast = new BitCastInst(FI->getOperand(0),
- PointerType::get(Type::Int8Ty), "", I);
+ Value *PtrCast =
+ new BitCastInst(FI->getOperand(0),
+ PointerType::getUnqual(Type::Int8Ty), "", I);
// Insert a call to the free function...
- (new CallInst(FreeFunc, PtrCast, "", I))->setTailCall();
+ CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
// Delete the old free instruction
I = --BBIL.erase(I);