Revert yesterday's change by removing the LLVMContext parameter to AllocaInst and MallocInst.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75863 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2009-07-15 23:53:25 +00:00
parent 6d823cd39d
commit 50dead06ff
25 changed files with 83 additions and 104 deletions

View File

@ -40,12 +40,10 @@ class LLVMContext;
/// ///
class AllocationInst : public UnaryInstruction { class AllocationInst : public UnaryInstruction {
protected: protected:
LLVMContext &Context; AllocationInst(const Type *Ty, Value *ArraySize,
AllocationInst(LLVMContext &Context, const Type *Ty, Value *ArraySize,
unsigned iTy, unsigned Align, const std::string &Name = "", unsigned iTy, unsigned Align, const std::string &Name = "",
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);
AllocationInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, AllocationInst(const Type *Ty, Value *ArraySize,
unsigned iTy, unsigned Align, const std::string &Name, unsigned iTy, unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd); BasicBlock *InsertAtEnd);
public: public:
@ -103,32 +101,31 @@ public:
class MallocInst : public AllocationInst { class MallocInst : public AllocationInst {
MallocInst(const MallocInst &MI); MallocInst(const MallocInst &MI);
public: public:
explicit MallocInst(LLVMContext &Context, explicit MallocInst(const Type *Ty, Value *ArraySize = 0,
const Type *Ty, Value *ArraySize = 0,
const std::string &NameStr = "", const std::string &NameStr = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, ArraySize, Malloc, : AllocationInst(Ty, ArraySize, Malloc,
0, NameStr, InsertBefore) {} 0, NameStr, InsertBefore) {}
MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, MallocInst(const Type *Ty, Value *ArraySize,
const std::string &NameStr, BasicBlock *InsertAtEnd) const std::string &NameStr, BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {} : AllocationInst(Ty, ArraySize, Malloc, 0, NameStr, InsertAtEnd) {}
MallocInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr, MallocInst(const Type *Ty, const std::string &NameStr,
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, 0, Malloc, 0, NameStr, InsertBefore) {} : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertBefore) {}
MallocInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr, MallocInst(const Type *Ty, const std::string &NameStr,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {} : AllocationInst(Ty, 0, Malloc, 0, NameStr, InsertAtEnd) {}
MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, MallocInst(const Type *Ty, Value *ArraySize,
unsigned Align, const std::string &NameStr, unsigned Align, const std::string &NameStr,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, ArraySize, Malloc, : AllocationInst(Ty, ArraySize, Malloc,
Align, NameStr, InsertAtEnd) {} Align, NameStr, InsertAtEnd) {}
MallocInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, MallocInst(const Type *Ty, Value *ArraySize,
unsigned Align, const std::string &NameStr = "", unsigned Align, const std::string &NameStr = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, ArraySize, : AllocationInst(Ty, ArraySize,
Malloc, Align, NameStr, InsertBefore) {} Malloc, Align, NameStr, InsertBefore) {}
virtual MallocInst *clone(LLVMContext &Context) const; virtual MallocInst *clone(LLVMContext &Context) const;
@ -153,33 +150,33 @@ public:
class AllocaInst : public AllocationInst { class AllocaInst : public AllocationInst {
AllocaInst(const AllocaInst &); AllocaInst(const AllocaInst &);
public: public:
explicit AllocaInst(LLVMContext &Context, const Type *Ty, explicit AllocaInst(const Type *Ty,
Value *ArraySize = 0, Value *ArraySize = 0,
const std::string &NameStr = "", const std::string &NameStr = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, ArraySize, Alloca, : AllocationInst(Ty, ArraySize, Alloca,
0, NameStr, InsertBefore) {} 0, NameStr, InsertBefore) {}
AllocaInst(LLVMContext &Context, const Type *Ty, AllocaInst(const Type *Ty,
Value *ArraySize, const std::string &NameStr, Value *ArraySize, const std::string &NameStr,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {} : AllocationInst(Ty, ArraySize, Alloca, 0, NameStr, InsertAtEnd) {}
AllocaInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr, AllocaInst(const Type *Ty, const std::string &NameStr,
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, 0, Alloca, 0, NameStr, InsertBefore) {} : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertBefore) {}
AllocaInst(LLVMContext &Context, const Type *Ty, const std::string &NameStr, AllocaInst(const Type *Ty, const std::string &NameStr,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {} : AllocationInst(Ty, 0, Alloca, 0, NameStr, InsertAtEnd) {}
AllocaInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, AllocaInst(const Type *Ty, Value *ArraySize,
unsigned Align, const std::string &NameStr = "", unsigned Align, const std::string &NameStr = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: AllocationInst(Context, Ty, ArraySize, Alloca, : AllocationInst(Ty, ArraySize, Alloca,
Align, NameStr, InsertBefore) {} Align, NameStr, InsertBefore) {}
AllocaInst(LLVMContext &Context, const Type *Ty, Value *ArraySize, AllocaInst(const Type *Ty, Value *ArraySize,
unsigned Align, const std::string &NameStr, unsigned Align, const std::string &NameStr,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: AllocationInst(Context, Ty, ArraySize, Alloca, : AllocationInst(Ty, ArraySize, Alloca,
Align, NameStr, InsertAtEnd) {} Align, NameStr, InsertAtEnd) {}
virtual AllocaInst *clone(LLVMContext &Context) const; virtual AllocaInst *clone(LLVMContext &Context) const;

View File

@ -330,11 +330,11 @@ public:
MallocInst *CreateMalloc(const Type *Ty, Value *ArraySize = 0, MallocInst *CreateMalloc(const Type *Ty, Value *ArraySize = 0,
const char *Name = "") { const char *Name = "") {
return Insert(new MallocInst(Context, Ty, ArraySize), Name); return Insert(new MallocInst(Ty, ArraySize), Name);
} }
AllocaInst *CreateAlloca(const Type *Ty, Value *ArraySize = 0, AllocaInst *CreateAlloca(const Type *Ty, Value *ArraySize = 0,
const char *Name = "") { const char *Name = "") {
return Insert(new AllocaInst(Context, Ty, ArraySize), Name); return Insert(new AllocaInst(Ty, ArraySize), Name);
} }
FreeInst *CreateFree(Value *Ptr) { FreeInst *CreateFree(Value *Ptr) {
return Insert(new FreeInst(Ptr)); return Insert(new FreeInst(Ptr));

View File

@ -108,15 +108,14 @@ bool FoldBranchToCommonDest(BranchInst *BI);
/// invalidating the SSA information for the value. It returns the pointer to /// invalidating the SSA information for the value. It returns the pointer to
/// the alloca inserted to create a stack slot for X. /// the alloca inserted to create a stack slot for X.
/// ///
AllocaInst *DemoteRegToStack(LLVMContext &Context, Instruction &X, AllocaInst *DemoteRegToStack(Instruction &X,
bool VolatileLoads = false, bool VolatileLoads = false,
Instruction *AllocaPoint = 0); Instruction *AllocaPoint = 0);
/// DemotePHIToStack - This function takes a virtual register computed by a phi /// DemotePHIToStack - This function takes a virtual register computed by a phi
/// node and replaces it with a slot in the stack frame, allocated via alloca. /// node and replaces it with a slot in the stack frame, allocated via alloca.
/// The phi node is deleted and it returns the pointer to the alloca inserted. /// The phi node is deleted and it returns the pointer to the alloca inserted.
AllocaInst *DemotePHIToStack(LLVMContext &Context, PHINode *P, AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
Instruction *AllocaPoint = 0);
/// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used /// OnlyUsedByDbgIntrinsics - Return true if the instruction I is only used
/// by DbgIntrinsics. If DbgInUses is specified then the vector is filled /// by DbgIntrinsics. If DbgInUses is specified then the vector is filled

View File

@ -3182,9 +3182,9 @@ bool LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS,
return Error(SizeLoc, "element count must be i32"); return Error(SizeLoc, "element count must be i32");
if (Opc == Instruction::Malloc) if (Opc == Instruction::Malloc)
Inst = new MallocInst(Context, Ty, Size, Alignment); Inst = new MallocInst(Ty, Size, Alignment);
else else
Inst = new AllocaInst(Context, Ty, Size, Alignment); Inst = new AllocaInst(Ty, Size, Alignment);
return false; return false;
} }

View File

@ -1817,8 +1817,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
Value *Size = getFnValueByID(Record[1], Type::Int32Ty); Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
unsigned Align = Record[2]; unsigned Align = Record[2];
if (!Ty || !Size) return Error("Invalid MALLOC record"); if (!Ty || !Size) return Error("Invalid MALLOC record");
I = new MallocInst(Context, Ty->getElementType(), Size, I = new MallocInst(Ty->getElementType(), Size, (1 << Align) >> 1);
(1 << Align) >> 1);
break; break;
} }
case bitc::FUNC_CODE_INST_FREE: { // FREE: [op, opty] case bitc::FUNC_CODE_INST_FREE: { // FREE: [op, opty]
@ -1838,8 +1837,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
Value *Size = getFnValueByID(Record[1], Type::Int32Ty); Value *Size = getFnValueByID(Record[1], Type::Int32Ty);
unsigned Align = Record[2]; unsigned Align = Record[2];
if (!Ty || !Size) return Error("Invalid ALLOCA record"); if (!Ty || !Size) return Error("Invalid ALLOCA record");
I = new AllocaInst(Context, Ty->getElementType(), Size, I = new AllocaInst(Ty->getElementType(), Size, (1 << Align) >> 1);
(1 << Align) >> 1);
break; break;
} }
case bitc::FUNC_CODE_INST_LOAD: { // LOAD: [opty, op, align, vol] case bitc::FUNC_CODE_INST_LOAD: { // LOAD: [opty, op, align, vol]

View File

@ -354,8 +354,8 @@ Instruction *DwarfEHPrepare::CreateValueLoad(BasicBlock *BB) {
// Create the temporary if we didn't already. // Create the temporary if we didn't already.
if (!ExceptionValueVar) { if (!ExceptionValueVar) {
ExceptionValueVar = new AllocaInst(*Context, ExceptionValueVar = new AllocaInst(
PointerType::getUnqual(Type::Int8Ty), Context->getPointerTypeUnqual(Type::Int8Ty),
"eh.value", F->begin()->begin()); "eh.value", F->begin()->begin());
++NumStackTempsIntroduced; ++NumStackTempsIntroduced;
} }

View File

@ -154,7 +154,7 @@ bool StackProtector::InsertStackProtectors() {
BasicBlock &Entry = F->getEntryBlock(); BasicBlock &Entry = F->getEntryBlock();
Instruction *InsPt = &Entry.front(); Instruction *InsPt = &Entry.front();
AI = new AllocaInst(*Context, PtrTy, "StackGuardSlot", InsPt); AI = new AllocaInst(PtrTy, "StackGuardSlot", InsPt);
LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsPt); LoadInst *LI = new LoadInst(StackGuardVar, "StackGuard", false, InsPt);
Value *Args[] = { LI, AI }; Value *Args[] = { LI, AI };

View File

@ -755,7 +755,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Just add all the struct element types. // Just add all the struct element types.
const Type *AgTy = cast<PointerType>(I->getType())->getElementType(); const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
Value *TheAlloca = new AllocaInst(*Context, AgTy, 0, "", InsertPt); Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt);
const StructType *STy = cast<StructType>(AgTy); const StructType *STy = cast<StructType>(AgTy);
Value *Idxs[2] = { Context->getConstantInt(Type::Int32Ty, 0), 0 }; Value *Idxs[2] = { Context->getConstantInt(Type::Int32Ty, 0), 0 };

View File

@ -828,7 +828,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Type *NewTy = Context->getArrayType(MI->getAllocatedType(), Type *NewTy = Context->getArrayType(MI->getAllocatedType(),
NElements->getZExtValue()); NElements->getZExtValue());
MallocInst *NewMI = MallocInst *NewMI =
new MallocInst(*Context, NewTy, Context->getNullValue(Type::Int32Ty), new MallocInst(NewTy, Context->getNullValue(Type::Int32Ty),
MI->getAlignment(), MI->getName(), MI); MI->getAlignment(), MI->getName(), MI);
Value* Indices[2]; Value* Indices[2];
Indices[0] = Indices[1] = Context->getNullValue(Type::Int32Ty); Indices[0] = Indices[1] = Context->getNullValue(Type::Int32Ty);
@ -1291,7 +1291,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
GV->isThreadLocal()); GV->isThreadLocal());
FieldGlobals.push_back(NGV); FieldGlobals.push_back(NGV);
MallocInst *NMI = new MallocInst(*Context, FieldTy, MI->getArraySize(), MallocInst *NMI = new MallocInst(FieldTy, MI->getArraySize(),
MI->getName() + ".f" + utostr(FieldNo),MI); MI->getName() + ".f" + utostr(FieldNo),MI);
FieldMallocs.push_back(NMI); FieldMallocs.push_back(NMI);
new StoreInst(NMI, NGV, MI); new StoreInst(NMI, NGV, MI);
@ -1507,7 +1507,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// structs. malloc [100 x struct],1 -> malloc struct, 100 // structs. malloc [100 x struct],1 -> malloc struct, 100
if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) { if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) {
MallocInst *NewMI = MallocInst *NewMI =
new MallocInst(*Context, AllocSTy, new MallocInst(AllocSTy,
Context->getConstantInt(Type::Int32Ty, AT->getNumElements()), Context->getConstantInt(Type::Int32Ty, AT->getNumElements()),
"", MI); "", MI);
NewMI->takeName(MI); NewMI->takeName(MI);
@ -1703,8 +1703,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
Instruction* FirstI = GS.AccessingFunction->getEntryBlock().begin(); Instruction* FirstI = GS.AccessingFunction->getEntryBlock().begin();
const Type* ElemTy = GV->getType()->getElementType(); const Type* ElemTy = GV->getType()->getElementType();
// FIXME: Pass Global's alignment when globals have alignment // FIXME: Pass Global's alignment when globals have alignment
AllocaInst* Alloca = new AllocaInst(*Context, ElemTy, NULL, AllocaInst* Alloca = new AllocaInst(ElemTy, NULL, GV->getName(), FirstI);
GV->getName(), FirstI);
if (!isa<UndefValue>(GV->getInitializer())) if (!isa<UndefValue>(GV->getInitializer()))
new StoreInst(GV->getInitializer(), Alloca, FirstI); new StoreInst(GV->getInitializer(), Alloca, FirstI);

View File

@ -73,7 +73,7 @@ bool IndMemRemPass::runOnModule(Module &M) {
BasicBlock* bb = BasicBlock::Create("entry",FN); BasicBlock* bb = BasicBlock::Create("entry",FN);
Instruction* c = CastInst::CreateIntegerCast( Instruction* c = CastInst::CreateIntegerCast(
FN->arg_begin(), Type::Int32Ty, false, "c", bb); FN->arg_begin(), Type::Int32Ty, false, "c", bb);
Instruction* a = new MallocInst(*Context, Type::Int8Ty, c, "m", bb); Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb);
ReturnInst::Create(a, bb); ReturnInst::Create(a, bb);
++NumBounce; ++NumBounce;
NumBounceSites += F->getNumUses(); NumBounceSites += F->getNumUses();

View File

@ -311,7 +311,7 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func)
// Fill in the alloca and call to initialize the SJ map. // Fill in the alloca and call to initialize the SJ map.
const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty); const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
AllocaInst* Map = new AllocaInst(*Context, SBPTy, 0, "SJMap", Inst); AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
CallInst::Create(InitSJMap, Map, "", Inst); CallInst::Create(InitSJMap, Map, "", Inst);
return SJMap[Func] = Map; return SJMap[Func] = Map;
} }
@ -408,7 +408,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
UI != E; ++UI) UI != E; ++UI)
if (cast<Instruction>(*UI)->getParent() != ABlock || if (cast<Instruction>(*UI)->getParent() != ABlock ||
InstrsAfterCall.count(cast<Instruction>(*UI))) { InstrsAfterCall.count(cast<Instruction>(*UI))) {
DemoteRegToStack(*Context, *II); DemoteRegToStack(*II);
break; break;
} }
InstrsAfterCall.clear(); InstrsAfterCall.clear();

View File

@ -169,8 +169,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
CastInst::CreateIntegerCast(Source, Type::Int32Ty, false/*ZExt*/, CastInst::CreateIntegerCast(Source, Type::Int32Ty, false/*ZExt*/,
"MallocAmtCast", I); "MallocAmtCast", I);
MallocInst *MI = new MallocInst(*Context, Type::Int8Ty, MallocInst *MI = new MallocInst(Type::Int8Ty, Source, "", I);
Source, "", I);
MI->takeName(I); MI->takeName(I);
I->replaceAllUsesWith(MI); I->replaceAllUsesWith(MI);

View File

@ -110,8 +110,8 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
DOUT << "SretPromotion: sret argument will be promoted\n"; DOUT << "SretPromotion: sret argument will be promoted\n";
NumSRET++; NumSRET++;
// [1] Replace use of sret parameter // [1] Replace use of sret parameter
AllocaInst *TheAlloca = new AllocaInst (*Context, STy, NULL, "mrv", AllocaInst *TheAlloca = new AllocaInst(STy, NULL, "mrv",
F->getEntryBlock().begin()); F->getEntryBlock().begin());
Value *NFirstArg = F->arg_begin(); Value *NFirstArg = F->arg_begin();
NFirstArg->replaceAllUsesWith(TheAlloca); NFirstArg->replaceAllUsesWith(TheAlloca);

View File

@ -248,7 +248,7 @@ void GlobalRandomCounterOpt::PrepFunction(Function* F) {
//make a local temporary to cache the global //make a local temporary to cache the global
BasicBlock& bb = F->getEntryBlock(); BasicBlock& bb = F->getEntryBlock();
BasicBlock::iterator InsertPt = bb.begin(); BasicBlock::iterator InsertPt = bb.begin();
AI = new AllocaInst(*F->getContext(), T, 0, "localcounter", InsertPt); AI = new AllocaInst(T, 0, "localcounter", InsertPt);
LoadInst* l = new LoadInst(Counter, "counterload", InsertPt); LoadInst* l = new LoadInst(Counter, "counterload", InsertPt);
new StoreInst(l, AI, InsertPt); new StoreInst(l, AI, InsertPt);

View File

@ -7891,9 +7891,9 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
AllocationInst *New; AllocationInst *New;
if (isa<MallocInst>(AI)) if (isa<MallocInst>(AI))
New = new MallocInst(*Context, CastElTy, Amt, AI.getAlignment()); New = new MallocInst(CastElTy, Amt, AI.getAlignment());
else else
New = new AllocaInst(*Context, CastElTy, Amt, AI.getAlignment()); New = new AllocaInst(CastElTy, Amt, AI.getAlignment());
InsertNewInstBefore(New, AI); InsertNewInstBefore(New, AI);
New->takeName(&AI); New->takeName(&AI);
@ -11368,12 +11368,10 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
// Create and insert the replacement instruction... // Create and insert the replacement instruction...
if (isa<MallocInst>(AI)) if (isa<MallocInst>(AI))
New = new MallocInst(*Context, NewTy, 0, New = new MallocInst(NewTy, 0, AI.getAlignment(), AI.getName());
AI.getAlignment(), AI.getName());
else { else {
assert(isa<AllocaInst>(AI) && "Unknown type of allocation inst!"); assert(isa<AllocaInst>(AI) && "Unknown type of allocation inst!");
New = new AllocaInst(*Context, NewTy, 0, New = new AllocaInst(NewTy, 0, AI.getAlignment(), AI.getName());
AI.getAlignment(), AI.getName());
} }
InsertNewInstBefore(New, AI); InsertNewInstBefore(New, AI);

View File

@ -912,7 +912,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
// We found a use of I outside of BB. Create a new stack slot to // We found a use of I outside of BB. Create a new stack slot to
// break this inter-block usage pattern. // break this inter-block usage pattern.
DemoteRegToStack(*Context, *I); DemoteRegToStack(*I);
} }
// We are going to have to map operands from the original BB block to the new // We are going to have to map operands from the original BB block to the new

View File

@ -508,7 +508,7 @@ void LICM::sink(Instruction &I) {
AllocaInst *AI = 0; AllocaInst *AI = 0;
if (I.getType() != Type::VoidTy) { if (I.getType() != Type::VoidTy) {
AI = new AllocaInst(*Context, I.getType(), 0, I.getName(), AI = new AllocaInst(I.getType(), 0, I.getName(),
I.getParent()->getParent()->getEntryBlock().begin()); I.getParent()->getParent()->getEntryBlock().begin());
CurAST->add(AI); CurAST->add(AI);
} }
@ -853,8 +853,7 @@ void LICM::FindPromotableValuesInLoop(
continue; continue;
const Type *Ty = cast<PointerType>(V->getType())->getElementType(); const Type *Ty = cast<PointerType>(V->getType())->getElementType();
AllocaInst *AI = new AllocaInst(*Context, Ty, 0, AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart);
V->getName()+".tmp", FnStart);
PromotedValues.push_back(std::make_pair(AI, V)); PromotedValues.push_back(std::make_pair(AI, V));
// Update the AST and alias analysis. // Update the AST and alias analysis.

View File

@ -89,7 +89,7 @@ namespace {
NumRegsDemoted += worklist.size(); NumRegsDemoted += worklist.size();
for (std::list<Instruction*>::iterator ilb = worklist.begin(), for (std::list<Instruction*>::iterator ilb = worklist.begin(),
ile = worklist.end(); ilb != ile; ++ilb) ile = worklist.end(); ilb != ile; ++ilb)
DemoteRegToStack(*Context, **ilb, false, AllocaInsertionPoint); DemoteRegToStack(**ilb, false, AllocaInsertionPoint);
worklist.clear(); worklist.clear();
@ -105,7 +105,7 @@ namespace {
NumPhisDemoted += worklist.size(); NumPhisDemoted += worklist.size();
for (std::list<Instruction*>::iterator ilb = worklist.begin(), for (std::list<Instruction*>::iterator ilb = worklist.begin(),
ile = worklist.end(); ilb != ile; ++ilb) ile = worklist.end(); ilb != ile; ++ilb)
DemotePHIToStack(*Context, cast<PHINode>(*ilb), AllocaInsertionPoint); DemotePHIToStack(cast<PHINode>(*ilb), AllocaInsertionPoint);
return true; return true;
} }

View File

@ -302,16 +302,14 @@ bool SROA::performScalarRepl(Function &F) {
DOUT << "CONVERT TO VECTOR: " << *AI << " TYPE = " << *VectorTy <<"\n"; DOUT << "CONVERT TO VECTOR: " << *AI << " TYPE = " << *VectorTy <<"\n";
// Create and insert the vector alloca. // Create and insert the vector alloca.
NewAI = new AllocaInst(*Context, VectorTy, 0, "", NewAI = new AllocaInst(VectorTy, 0, "", AI->getParent()->begin());
AI->getParent()->begin());
ConvertUsesToScalar(AI, NewAI, 0); ConvertUsesToScalar(AI, NewAI, 0);
} else { } else {
DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n"; DOUT << "CONVERT TO SCALAR INTEGER: " << *AI << "\n";
// Create and insert the integer alloca. // Create and insert the integer alloca.
const Type *NewTy = Context->getIntegerType(AllocaSize*8); const Type *NewTy = Context->getIntegerType(AllocaSize*8);
NewAI = new AllocaInst(*Context, NewTy, 0, "", NewAI = new AllocaInst(NewTy, 0, "", AI->getParent()->begin());
AI->getParent()->begin());
ConvertUsesToScalar(AI, NewAI, 0); ConvertUsesToScalar(AI, NewAI, 0);
} }
NewAI->takeName(AI); NewAI->takeName(AI);
@ -336,8 +334,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) { if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
ElementAllocas.reserve(ST->getNumContainedTypes()); ElementAllocas.reserve(ST->getNumContainedTypes());
for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) { for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) {
AllocaInst *NA = new AllocaInst(*Context, AllocaInst *NA = new AllocaInst(ST->getContainedType(i), 0,
ST->getContainedType(i), 0,
AI->getAlignment(), AI->getAlignment(),
AI->getName() + "." + utostr(i), AI); AI->getName() + "." + utostr(i), AI);
ElementAllocas.push_back(NA); ElementAllocas.push_back(NA);
@ -348,7 +345,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
ElementAllocas.reserve(AT->getNumElements()); ElementAllocas.reserve(AT->getNumElements());
const Type *ElTy = AT->getElementType(); const Type *ElTy = AT->getElementType();
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) { for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
AllocaInst *NA = new AllocaInst(*Context, ElTy, 0, AI->getAlignment(), AllocaInst *NA = new AllocaInst(ElTy, 0, AI->getAlignment(),
AI->getName() + "." + utostr(i), AI); AI->getName() + "." + utostr(i), AI);
ElementAllocas.push_back(NA); ElementAllocas.push_back(NA);
WorkList.push_back(NA); // Add to worklist for recursive processing WorkList.push_back(NA); // Add to worklist for recursive processing

View File

@ -285,7 +285,7 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
if (I->isUsedOutsideOfBlock(DestBlock)) { if (I->isUsedOutsideOfBlock(DestBlock)) {
// We found a use outside of the tail. Create a new stack slot to // We found a use outside of the tail. Create a new stack slot to
// break this inter-block usage pattern. // break this inter-block usage pattern.
DemoteRegToStack(*Context, *I); DemoteRegToStack(*I);
} }
// We are going to have to map operands from the original block B to the new // We are going to have to map operands from the original block B to the new

View File

@ -372,8 +372,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
StructValues.push_back(*i); StructValues.push_back(*i);
} else { } else {
AllocaInst *alloca = AllocaInst *alloca =
new AllocaInst(*codeReplacer->getContext(), new AllocaInst((*i)->getType(), 0, (*i)->getName()+".loc",
(*i)->getType(), 0, (*i)->getName()+".loc",
codeReplacer->getParent()->begin()->begin()); codeReplacer->getParent()->begin()->begin());
ReloadOutputs.push_back(alloca); ReloadOutputs.push_back(alloca);
params.push_back(alloca); params.push_back(alloca);
@ -390,7 +389,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Allocate a struct at the beginning of this function // Allocate a struct at the beginning of this function
Type *StructArgTy = Context->getStructType(ArgTypes); Type *StructArgTy = Context->getStructType(ArgTypes);
Struct = Struct =
new AllocaInst(*codeReplacer->getContext(), StructArgTy, 0, "structArg", new AllocaInst(StructArgTy, 0, "structArg",
codeReplacer->getParent()->begin()->begin()); codeReplacer->getParent()->begin()->begin());
params.push_back(Struct); params.push_back(Struct);

View File

@ -29,8 +29,7 @@ using namespace llvm;
/// invalidating the SSA information for the value. It returns the pointer to /// invalidating the SSA information for the value. It returns the pointer to
/// the alloca inserted to create a stack slot for I. /// the alloca inserted to create a stack slot for I.
/// ///
AllocaInst* llvm::DemoteRegToStack(LLVMContext &Context, AllocaInst* llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
Instruction &I, bool VolatileLoads,
Instruction *AllocaPoint) { Instruction *AllocaPoint) {
if (I.use_empty()) { if (I.use_empty()) {
I.eraseFromParent(); I.eraseFromParent();
@ -40,11 +39,11 @@ AllocaInst* llvm::DemoteRegToStack(LLVMContext &Context,
// Create a stack slot to hold the value. // Create a stack slot to hold the value.
AllocaInst *Slot; AllocaInst *Slot;
if (AllocaPoint) { if (AllocaPoint) {
Slot = new AllocaInst(Context, I.getType(), 0, Slot = new AllocaInst(I.getType(), 0,
I.getName()+".reg2mem", AllocaPoint); I.getName()+".reg2mem", AllocaPoint);
} else { } else {
Function *F = I.getParent()->getParent(); Function *F = I.getParent()->getParent();
Slot = new AllocaInst(Context, I.getType(), 0, I.getName()+".reg2mem", Slot = new AllocaInst(I.getType(), 0, I.getName()+".reg2mem",
F->getEntryBlock().begin()); F->getEntryBlock().begin());
} }
@ -109,8 +108,7 @@ AllocaInst* llvm::DemoteRegToStack(LLVMContext &Context,
/// DemotePHIToStack - This function takes a virtual register computed by a phi /// DemotePHIToStack - This function takes a virtual register computed by a phi
/// node and replaces it with a slot in the stack frame, allocated via alloca. /// node and replaces it with a slot in the stack frame, allocated via alloca.
/// The phi node is deleted and it returns the pointer to the alloca inserted. /// The phi node is deleted and it returns the pointer to the alloca inserted.
AllocaInst* llvm::DemotePHIToStack(LLVMContext &Context, PHINode *P, AllocaInst* llvm::DemotePHIToStack(PHINode *P, Instruction *AllocaPoint) {
Instruction *AllocaPoint) {
if (P->use_empty()) { if (P->use_empty()) {
P->eraseFromParent(); P->eraseFromParent();
return 0; return 0;
@ -119,11 +117,11 @@ AllocaInst* llvm::DemotePHIToStack(LLVMContext &Context, PHINode *P,
// Create a stack slot to hold the value. // Create a stack slot to hold the value.
AllocaInst *Slot; AllocaInst *Slot;
if (AllocaPoint) { if (AllocaPoint) {
Slot = new AllocaInst(Context, P->getType(), 0, Slot = new AllocaInst(P->getType(), 0,
P->getName()+".reg2mem", AllocaPoint); P->getName()+".reg2mem", AllocaPoint);
} else { } else {
Function *F = P->getParent()->getParent(); Function *F = P->getParent()->getParent();
Slot = new AllocaInst(Context, P->getType(), 0, P->getName()+".reg2mem", Slot = new AllocaInst(P->getType(), 0, P->getName()+".reg2mem",
F->getEntryBlock().begin()); F->getEntryBlock().begin());
} }

View File

@ -309,7 +309,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
// Create the alloca. If we have TargetData, use nice alignment. // Create the alloca. If we have TargetData, use nice alignment.
unsigned Align = 1; unsigned Align = 1;
if (TD) Align = TD->getPrefTypeAlignment(AggTy); if (TD) Align = TD->getPrefTypeAlignment(AggTy);
Value *NewAlloca = new AllocaInst(*Context, AggTy, 0, Align, Value *NewAlloca = new AllocaInst(AggTy, 0, Align,
I->getName(), I->getName(),
&*Caller->begin()->begin()); &*Caller->begin()->begin());
// Emit a memcpy. // Emit a memcpy.

View File

@ -417,7 +417,7 @@ splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) {
// If we decided we need a spill, do it. // If we decided we need a spill, do it.
if (NeedsSpill) { if (NeedsSpill) {
++NumSpilled; ++NumSpilled;
DemoteRegToStack(*Context, *Inst, true); DemoteRegToStack(*Inst, true);
} }
} }
} }
@ -470,7 +470,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// alloca because the value needs to be live across invokes. // alloca because the value needs to be live across invokes.
unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0; unsigned Align = TLI ? TLI->getJumpBufAlignment() : 0;
AllocaInst *JmpBuf = AllocaInst *JmpBuf =
new AllocaInst(*Context, JBLinkTy, 0, Align, new AllocaInst(JBLinkTy, 0, Align,
"jblink", F.begin()->begin()); "jblink", F.begin()->begin());
std::vector<Value*> Idx; std::vector<Value*> Idx;
@ -494,7 +494,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create an alloca which keeps track of which invoke is currently // Create an alloca which keeps track of which invoke is currently
// executing. For normal calls it contains zero. // executing. For normal calls it contains zero.
AllocaInst *InvokeNum = new AllocaInst(*Context, Type::Int32Ty, 0, AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0,
"invokenum",EntryBB->begin()); "invokenum",EntryBB->begin());
new StoreInst(Context->getConstantInt(Type::Int32Ty, 0), InvokeNum, true, new StoreInst(Context->getConstantInt(Type::Int32Ty, 0), InvokeNum, true,
EntryBB->getTerminator()); EntryBB->getTerminator());

View File

@ -712,25 +712,21 @@ static Value *getAISize(LLVMContext &Context, Value *Amt) {
return Amt; return Amt;
} }
AllocationInst::AllocationInst(LLVMContext &C, AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name, unsigned Align, const std::string &Name,
Instruction *InsertBefore) Instruction *InsertBefore)
: UnaryInstruction(PointerType::getUnqual(Ty), iTy, : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
getAISize(Context, ArraySize), InsertBefore), getAISize(Ty->getContext(), ArraySize), InsertBefore) {
Context(C) {
setAlignment(Align); setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!"); assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name); setName(Name);
} }
AllocationInst::AllocationInst(LLVMContext &C, AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name, unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: UnaryInstruction(PointerType::getUnqual(Ty), iTy, : UnaryInstruction(Ty->getContext().getPointerTypeUnqual(Ty), iTy,
getAISize(Context, ArraySize), InsertAtEnd), getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
Context(C) {
setAlignment(Align); setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!"); assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name); setName(Name);
@ -757,7 +753,7 @@ const Type *AllocationInst::getAllocatedType() const {
} }
AllocaInst::AllocaInst(const AllocaInst &AI) AllocaInst::AllocaInst(const AllocaInst &AI)
: AllocationInst(AI.Context, AI.getType()->getElementType(), : AllocationInst(AI.getType()->getElementType(),
(Value*)AI.getOperand(0), Instruction::Alloca, (Value*)AI.getOperand(0), Instruction::Alloca,
AI.getAlignment()) { AI.getAlignment()) {
} }
@ -775,7 +771,7 @@ bool AllocaInst::isStaticAlloca() const {
} }
MallocInst::MallocInst(const MallocInst &MI) MallocInst::MallocInst(const MallocInst &MI)
: AllocationInst(MI.Context, MI.getType()->getElementType(), : AllocationInst(MI.getType()->getElementType(),
(Value*)MI.getOperand(0), Instruction::Malloc, (Value*)MI.getOperand(0), Instruction::Malloc,
MI.getAlignment()) { MI.getAlignment()) {
} }