forked from OSchip/llvm-project
parent
ecb0bac0ec
commit
1f45f4e4d8
|
@ -15,8 +15,6 @@
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "Support/Statistic.h"
|
#include "Support/Statistic.h"
|
||||||
|
|
||||||
using std::vector;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Statistic<> NumLowered("lowerallocs", "Number of allocations lowered");
|
Statistic<> NumLowered("lowerallocs", "Number of allocations lowered");
|
||||||
|
|
||||||
|
@ -62,10 +60,11 @@ Pass *createLowerAllocationsPass() {
|
||||||
bool LowerAllocations::doInitialization(Module &M) {
|
bool LowerAllocations::doInitialization(Module &M) {
|
||||||
const FunctionType *MallocType =
|
const FunctionType *MallocType =
|
||||||
FunctionType::get(PointerType::get(Type::SByteTy),
|
FunctionType::get(PointerType::get(Type::SByteTy),
|
||||||
vector<const Type*>(1, Type::UIntTy), false);
|
std::vector<const Type*>(1, Type::UIntTy), false);
|
||||||
const FunctionType *FreeType =
|
const FunctionType *FreeType =
|
||||||
FunctionType::get(Type::VoidTy,
|
FunctionType::get(Type::VoidTy,
|
||||||
vector<const Type*>(1, PointerType::get(Type::SByteTy)),
|
std::vector<const Type*>(1,
|
||||||
|
PointerType::get(Type::SByteTy)),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
MallocFunc = M.getOrInsertFunction("malloc", MallocType);
|
MallocFunc = M.getOrInsertFunction("malloc", MallocType);
|
||||||
|
@ -105,7 +104,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
||||||
|
|
||||||
// Create the call to Malloc...
|
// Create the call to Malloc...
|
||||||
CallInst *MCall = new CallInst(MallocFunc,
|
CallInst *MCall = new CallInst(MallocFunc,
|
||||||
vector<Value*>(1, MallocArg), "", I);
|
std::vector<Value*>(1, MallocArg), "", I);
|
||||||
|
|
||||||
// Create a cast instruction to convert to the right type...
|
// Create a cast instruction to convert to the right type...
|
||||||
CastInst *MCast = new CastInst(MCall, MI->getType(), "", I);
|
CastInst *MCast = new CastInst(MCall, MI->getType(), "", I);
|
||||||
|
@ -121,7 +120,8 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
||||||
PointerType::get(Type::UByteTy), "", I);
|
PointerType::get(Type::UByteTy), "", I);
|
||||||
|
|
||||||
// Insert a call to the free function...
|
// Insert a call to the free function...
|
||||||
CallInst *FCall = new CallInst(FreeFunc, vector<Value*>(1, MCast), "", I);
|
CallInst *FCall = new CallInst(FreeFunc, std::vector<Value*>(1, MCast),
|
||||||
|
"", I);
|
||||||
|
|
||||||
// Delete the old free instruction
|
// Delete the old free instruction
|
||||||
I = --BBIL.erase(I);
|
I = --BBIL.erase(I);
|
||||||
|
|
Loading…
Reference in New Issue