aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/AddrModeMatcher.cpp2
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp10
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp14
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp4
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp38
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp18
-rw-r--r--lib/Transforms/Utils/LCSSA.cpp2
-rw-r--r--lib/Transforms/Utils/Local.cpp6
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp2
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp23
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp56
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp7
-rw-r--r--lib/Transforms/Utils/Mem2Reg.cpp2
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp14
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp26
-rw-r--r--lib/Transforms/Utils/ValueMapper.cpp10
16 files changed, 120 insertions, 114 deletions
diff --git a/lib/Transforms/Utils/AddrModeMatcher.cpp b/lib/Transforms/Utils/AddrModeMatcher.cpp
index 36091e6fe2..21c84abf07 100644
--- a/lib/Transforms/Utils/AddrModeMatcher.cpp
+++ b/lib/Transforms/Utils/AddrModeMatcher.cpp
@@ -97,7 +97,7 @@ bool AddressingModeMatcher::MatchScaledValue(Value *ScaleReg, int64_t Scale,
ConstantInt *CI = 0; Value *AddLHS = 0;
if (isa<Instruction>(ScaleReg) && // not a constant expr.
match(ScaleReg, m_Add(m_Value(AddLHS), m_ConstantInt(CI)),
- *MemoryInst->getParent()->getContext())) {
+ MemoryInst->getContext())) {
TestAddrMode.ScaledReg = AddLHS;
TestAddrMode.BaseOffs += CI->getSExtValue()*TestAddrMode.Scale;
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index b8663de194..c4b3474d99 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -51,7 +51,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
// contained within it must dominate their uses, that all uses will
// eventually be removed (they are themselves dead).
if (!I.use_empty())
- I.replaceAllUsesWith(BB->getContext()->getUndef(I.getType()));
+ I.replaceAllUsesWith(BB->getContext().getUndef(I.getType()));
BB->getInstList().pop_back();
}
@@ -71,7 +71,7 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
if (PN->getIncomingValue(0) != PN)
PN->replaceAllUsesWith(PN->getIncomingValue(0));
else
- PN->replaceAllUsesWith(BB->getContext()->getUndef(PN->getType()));
+ PN->replaceAllUsesWith(BB->getContext().getUndef(PN->getType()));
PN->eraseFromParent();
}
}
@@ -252,7 +252,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
// Create a value to return... if the function doesn't return null...
if (BB->getParent()->getReturnType() != Type::VoidTy)
- RetVal = TI->getParent()->getContext()->getNullValue(
+ RetVal = TI->getContext().getNullValue(
BB->getParent()->getReturnType());
// Create the return...
@@ -387,7 +387,7 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
if (NumPreds == 0) {
// Insert dummy values as the incoming value.
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
- cast<PHINode>(I)->addIncoming(BB->getContext()->getUndef(I->getType()),
+ cast<PHINode>(I)->addIncoming(BB->getContext().getUndef(I->getType()),
NewBB);
return NewBB;
}
@@ -618,7 +618,7 @@ void llvm::CopyPrecedingStopPoint(Instruction *I,
if (I != I->getParent()->begin()) {
BasicBlock::iterator BBI = I; --BBI;
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BBI)) {
- CallInst *newDSPI = DSPI->clone(*I->getParent()->getContext());
+ CallInst *newDSPI = DSPI->clone(I->getContext());
newDSPI->insertBefore(InsertPos);
}
}
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index f05c5dc8a7..dae39b7a79 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -43,7 +43,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
// Loop over all instructions, and copy them over.
for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
- Instruction *NewInst = II->clone(*BB->getContext());
+ Instruction *NewInst = II->clone(BB->getContext());
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
@@ -152,7 +152,7 @@ Function *llvm::CloneFunction(const Function *F,
// Create a new function type...
FunctionType *FTy =
- F->getContext()->getFunctionType(F->getFunctionType()->getReturnType(),
+ F->getContext().getFunctionType(F->getFunctionType()->getReturnType(),
ArgTypes, F->getFunctionType()->isVarArg());
// Create the new function...
@@ -249,7 +249,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
continue;
}
- Instruction *NewInst = II->clone(*BB->getContext());
+ Instruction *NewInst = II->clone(BB->getContext());
if (II->hasName())
NewInst->setName(II->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
@@ -297,7 +297,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
}
if (!TerminatorDone) {
- Instruction *NewInst = OldTI->clone(*BB->getContext());
+ Instruction *NewInst = OldTI->clone(BB->getContext());
if (OldTI->hasName())
NewInst->setName(OldTI->getName()+NameSuffix);
NewBB->getInstList().push_back(NewInst);
@@ -325,7 +325,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
/// mapping its operands through ValueMap if they are available.
Constant *PruningFunctionCloner::
ConstantFoldMappedInstruction(const Instruction *I) {
- LLVMContext *Context = I->getParent()->getContext();
+ LLVMContext &Context = I->getContext();
SmallVector<Constant*, 8> Ops;
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
@@ -367,7 +367,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
ClonedCodeInfo *CodeInfo,
const TargetData *TD) {
assert(NameSuffix && "NameSuffix cannot be null!");
- LLVMContext *Context = OldFunc->getContext();
+ LLVMContext &Context = OldFunc->getContext();
#ifndef NDEBUG
for (Function::const_arg_iterator II = OldFunc->arg_begin(),
@@ -490,7 +490,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
BasicBlock::iterator I = NewBB->begin();
BasicBlock::const_iterator OldI = OldBB->begin();
while ((PN = dyn_cast<PHINode>(I++))) {
- Value *NV = OldFunc->getContext()->getUndef(PN->getType());
+ Value *NV = OldFunc->getContext().getUndef(PN->getType());
PN->replaceAllUsesWith(NV);
assert(ValueMap[OldI] == PN && "ValueMap mismatch");
ValueMap[OldI] = NV;
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index bb5f3e6f6e..13b2d46971 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -90,7 +90,7 @@ Module *llvm::CloneModule(const Module *M,
if (I->hasInitializer())
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
ValueMap,
- &M->getContext())));
+ M->getContext())));
GV->setLinkage(I->getLinkage());
GV->setThreadLocal(I->isThreadLocal());
GV->setConstant(I->isConstant());
@@ -121,7 +121,7 @@ Module *llvm::CloneModule(const Module *M,
GlobalAlias *GA = cast<GlobalAlias>(ValueMap[I]);
GA->setLinkage(I->getLinkage());
if (const Constant* C = I->getAliasee())
- GA->setAliasee(cast<Constant>(MapValue(C, ValueMap, &M->getContext())));
+ GA->setAliasee(cast<Constant>(MapValue(C, ValueMap, M->getContext())));
}
return New;
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index be02560de0..a0193992a7 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -239,7 +239,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
DOUT << "inputs: " << inputs.size() << "\n";
DOUT << "outputs: " << outputs.size() << "\n";
- LLVMContext *Context = header->getContext();
+ LLVMContext &Context = header->getContext();
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
@@ -267,7 +267,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
paramTy.push_back((*I)->getType());
else
paramTy.push_back(
- header->getContext()->getPointerTypeUnqual((*I)->getType()));
+ header->getContext().getPointerTypeUnqual((*I)->getType()));
}
DOUT << "Function type: " << *RetTy << " f(";
@@ -278,12 +278,12 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
PointerType *StructPtr =
- Context->getPointerTypeUnqual(Context->getStructType(paramTy));
+ Context.getPointerTypeUnqual(Context.getStructType(paramTy));
paramTy.clear();
paramTy.push_back(StructPtr);
}
const FunctionType *funcType =
- Context->getFunctionType(RetTy, paramTy, false);
+ Context.getFunctionType(RetTy, paramTy, false);
// Create the new function
Function *newFunction = Function::Create(funcType,
@@ -305,8 +305,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
- Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
+ Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
std::string GEPname = "gep_" + inputs[i]->getName();
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
@@ -353,7 +353,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
void CodeExtractor::
emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Values &inputs, Values &outputs) {
- LLVMContext *Context = codeReplacer->getContext();
+ LLVMContext &Context = codeReplacer->getContext();
// Emit a call to the new function, passing in: *pointer to struct (if
// aggregating parameters), or plan inputs and allocated memory for outputs
@@ -387,7 +387,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
ArgTypes.push_back((*v)->getType());
// Allocate a struct at the beginning of this function
- Type *StructArgTy = Context->getStructType(ArgTypes);
+ Type *StructArgTy = Context.getStructType(ArgTypes);
Struct =
new AllocaInst(StructArgTy, 0, "structArg",
codeReplacer->getParent()->begin()->begin());
@@ -395,8 +395,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
- Idx[1] = Context->getConstantInt(Type::Int32Ty, i);
+ Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName());
@@ -421,8 +421,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
- Idx[1] = Context->getConstantInt(Type::Int32Ty, FirstOut + i);
+ Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName());
@@ -443,7 +443,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
- SwitchInst::Create(Context->getNullValue(Type::Int16Ty),
+ SwitchInst::Create(Context.getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@@ -474,17 +474,17 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
case 0:
case 1: break; // No value needed.
case 2: // Conditional branch, return a bool
- brVal = Context->getConstantInt(Type::Int1Ty, !SuccNum);
+ brVal = Context.getConstantInt(Type::Int1Ty, !SuccNum);
break;
default:
- brVal = Context->getConstantInt(Type::Int16Ty, SuccNum);
+ brVal = Context.getConstantInt(Type::Int16Ty, SuccNum);
break;
}
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
// Update the switch instruction.
- TheSwitch->addCase(Context->getConstantInt(Type::Int16Ty, SuccNum),
+ TheSwitch->addCase(Context.getConstantInt(Type::Int16Ty, SuccNum),
OldTarget);
// Restore values just before we exit
@@ -522,8 +522,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Context->getNullValue(Type::Int32Ty);
- Idx[1] = Context->getConstantInt(Type::Int32Ty,FirstOut+out);
+ Idx[0] = Context.getNullValue(Type::Int32Ty);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(),
@@ -560,7 +560,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
- ReturnInst::Create(Context->getNullValue(OldFnRetTy), TheSwitch);
+ ReturnInst::Create(Context.getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index e1b493c204..ae0b5ee84b 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -239,7 +239,7 @@ static const DbgRegionEndInst *findFnRegionEndMarker(const Function *F) {
//
bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
Instruction *TheCall = CS.getInstruction();
- LLVMContext *Context = TheCall->getParent()->getContext();
+ LLVMContext &Context = TheCall->getContext();
assert(TheCall->getParent() && TheCall->getParent()->getParent() &&
"Instruction not in function!");
@@ -304,7 +304,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
if (CalledFunc->paramHasAttr(ArgNo+1, Attribute::ByVal) &&
!CalledFunc->onlyReadsMemory()) {
const Type *AggTy = cast<PointerType>(I->getType())->getElementType();
- const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy = Context.getPointerTypeUnqual(Type::Int8Ty);
// Create the alloca. If we have TargetData, use nice alignment.
unsigned Align = 1;
@@ -322,16 +322,16 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
Value *Size;
if (TD == 0)
- Size = Context->getConstantExprSizeOf(AggTy);
+ Size = Context.getConstantExprSizeOf(AggTy);
else
- Size = Context->getConstantInt(Type::Int64Ty,
+ Size = Context.getConstantInt(Type::Int64Ty,
TD->getTypeStoreSize(AggTy));
// Always generate a memcpy of alignment 1 here because we don't know
// the alignment of the src pointer. Other optimizations can infer
// better alignment.
Value *CallArgs[] = {
- DestCast, SrcCast, Size, Context->getConstantInt(Type::Int32Ty, 1)
+ DestCast, SrcCast, Size, Context.getConstantInt(Type::Int32Ty, 1)
};
CallInst *TheMemCpy =
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
@@ -362,7 +362,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
BE = TheCall->getParent()->end(); BI != BE; ++BI) {
if (DbgStopPointInst *DSPI = dyn_cast<DbgStopPointInst>(BI)) {
if (DbgRegionEndInst *NewDREI =
- dyn_cast<DbgRegionEndInst>(DREI->clone(*Context)))
+ dyn_cast<DbgRegionEndInst>(DREI->clone(Context)))
NewDREI->insertAfter(DSPI);
break;
}
@@ -521,7 +521,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
if (!TheCall->use_empty()) {
ReturnInst *R = Returns[0];
if (TheCall == R->getReturnValue())
- TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
else
TheCall->replaceAllUsesWith(R->getReturnValue());
}
@@ -614,7 +614,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
// using the return value of the call with the computed value.
if (!TheCall->use_empty()) {
if (TheCall == Returns[0]->getReturnValue())
- TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
else
TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
}
@@ -634,7 +634,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
} else if (!TheCall->use_empty()) {
// No returns, but something is using the return value of the call. Just
// nuke the result.
- TheCall->replaceAllUsesWith(Context->getUndef(TheCall->getType()));
+ TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
}
// Since we are now done with the Call/Invoke, we can delete it.
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp
index 1c31dc9e27..1b72849528 100644
--- a/lib/Transforms/Utils/LCSSA.cpp
+++ b/lib/Transforms/Utils/LCSSA.cpp
@@ -243,7 +243,7 @@ Value *LCSSA::GetValueForBlock(DomTreeNode *BB, Instruction *OrigInst,
DenseMap<DomTreeNode*, Value*> &Phis) {
// If there is no dominator info for this BB, it is unreachable.
if (BB == 0)
- return Context->getUndef(OrigInst->getType());
+ return OrigInst->getContext().getUndef(OrigInst->getType());
// If we have already computed this value, return the previously computed val.
if (Phis.count(BB)) return Phis[BB];
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 0bb9614557..e9be0e263b 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -263,7 +263,7 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
/// too, recursively.
void
llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
- LLVMContext *Context = PN->getParent()->getContext();
+ LLVMContext &Context = PN->getContext();
// We can remove a PHI if it is on a cycle in the def-use graph
// where each node in the cycle has degree one, i.e. only one use,
@@ -281,7 +281,7 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
if (PHINode *JP = dyn_cast<PHINode>(J))
if (!PHIs.insert(cast<PHINode>(JP))) {
// Break the cycle and delete the PHI and its operands.
- JP->replaceAllUsesWith(Context->getUndef(JP->getType()));
+ JP->replaceAllUsesWith(Context.getUndef(JP->getType()));
RecursivelyDeleteTriviallyDeadInstructions(JP);
break;
}
@@ -301,7 +301,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
Value *NewVal = PN->getIncomingValue(0);
// Replace self referencing PHI with undef, it must be dead.
- if (NewVal == PN) NewVal = DestBB->getContext()->getUndef(PN->getType());
+ if (NewVal == PN) NewVal = DestBB->getContext().getUndef(PN->getType());
PN->replaceAllUsesWith(NewVal);
PN->eraseFromParent();
}
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 81fa4f96c4..045b428df9 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -166,7 +166,7 @@ bool LoopSimplify::runOnFunction(Function &F) {
// Delete the dead terminator.
if (AA) AA->deleteValue(TI);
if (!TI->use_empty())
- TI->replaceAllUsesWith(Context->getUndef(TI->getType()));
+ TI->replaceAllUsesWith(F.getContext().getUndef(TI->getType()));
TI->eraseFromParent();
Changed |= true;
}
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index d7ca3134cf..8f61d88089 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -87,13 +87,10 @@ Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
// This function is always successful.
//
bool LowerAllocations::doInitialization(Module &M) {
- // Ensure context initialization.
- BasicBlockPass::doInitialization(M);
-
- const Type *BPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type *BPTy = M.getContext().getPointerTypeUnqual(Type::Int8Ty);
// Prototype malloc as "char* malloc(...)", because we don't know in
// doInitialization whether size_t is int or long.
- FunctionType *FT = Context->getFunctionType(BPTy, true);
+ FunctionType *FT = M.getContext().getFunctionType(BPTy, true);
MallocFunc = M.getOrInsertFunction("malloc", FT);
FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
return true;
@@ -106,6 +103,8 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
bool Changed = false;
assert(MallocFunc && FreeFunc && "Pass not initialized!");
+ LLVMContext &Context = BB.getContext();
+
BasicBlock::InstListType &BBIL = BB.getInstList();
const TargetData &TD = getAnalysis<TargetData>();
@@ -119,12 +118,12 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
// malloc(type) becomes i8 *malloc(size)
Value *MallocArg;
if (LowerMallocArgToInteger)
- MallocArg = Context->getConstantInt(Type::Int64Ty,
+ MallocArg = Context.getConstantInt(Type::Int64Ty,
TD.getTypeAllocSize(AllocTy));
else
- MallocArg = Context->getConstantExprSizeOf(AllocTy);
+ MallocArg = Context.getConstantExprSizeOf(AllocTy);
MallocArg =
- Context->getConstantExprTruncOrBitCast(cast<Constant>(MallocArg),
+ Context.getConstantExprTruncOrBitCast(cast<Constant>(MallocArg),
IntPtrTy);
if (MI->isArrayAllocation()) {
@@ -133,8 +132,8 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
MallocArg = MI->getOperand(0); // Operand * 1 = Operand
} else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
CO =
- Context->getConstantExprIntegerCast(CO, IntPtrTy, false /*ZExt*/);
- MallocArg = Context->getConstantExprMul(CO,
+ Context.getConstantExprIntegerCast(CO, IntPtrTy, false /*ZExt*/);
+ MallocArg = Context.getConstantExprMul(CO,
cast<Constant>(MallocArg));
} else {
Value *Scale = MI->getOperand(0);
@@ -157,7 +156,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
if (MCall->getType() != Type::VoidTy)
MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
- MCast = Context->getNullValue(MI->getType());
+ MCast = Context.getNullValue(MI->getType());
// Replace all uses of the old malloc inst with the cast inst
MI->replaceAllUsesWith(MCast);
@@ -167,7 +166,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
Value *PtrCast =
new BitCastInst(FI->getOperand(0),
- Context->getPointerTypeUnqual(Type::Int8Ty), "", I);
+ Context.getPointerTypeUnqual(Type::Int8Ty), "", I);
// Insert a call to the free function...
CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index 1417f10e64..9f20f3954d 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -115,35 +115,35 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) {
// doInitialization - Make sure that there is a prototype for abort in the
// current module.
bool LowerInvoke::doInitialization(Module &M) {
- Context = &M.getContext();
+ LLVMContext &Context = M.getContext();
- const Type *VoidPtrTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy = Context.getPointerTypeUnqual(Type::Int8Ty);
AbortMessage = 0;
if (ExpensiveEHSupport) {
// Insert a type for the linked list of jump buffers.
unsigned JBSize = TLI ? TLI->getJumpBufSize() : 0;
JBSize = JBSize ? JBSize : 200;
- const Type *JmpBufTy = Context->getArrayType(VoidPtrTy, JBSize);
+ const Type *JmpBufTy = Context.getArrayType(VoidPtrTy, JBSize);
{ // The type is recursive, so use a type holder.
std::vector<const Type*> Elements;
Elements.push_back(JmpBufTy);
- OpaqueType *OT = Context->getOpaqueType();
- Elements.push_back(Context->getPointerTypeUnqual(OT));
- PATypeHolder JBLType(Context->getStructType(Elements));
+ OpaqueType *OT = Context.getOpaqueType();
+ Elements.push_back(Context.getPointerTypeUnqual(OT));
+ PATypeHolder JBLType(Context.getStructType(Elements));
OT->refineAbstractTypeTo(JBLType.get()); // Complete the cycle.
JBLinkTy = JBLType.get();
M.addTypeName("llvm.sjljeh.jmpbufty", JBLinkTy);
}
- const Type *PtrJBList = Context->getPointerTypeUnqual(JBLinkTy);
+ const Type *PtrJBList = Context.getPointerTypeUnqual(JBLinkTy);
// Now that we've done that, insert the jmpbuf list head global, unless it
// already exists.
if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
JBListHead = new GlobalVariable(M, PtrJBList, false,
GlobalValue::LinkOnceAnyLinkage,
- Context->getNullValue(PtrJBList),
+ Context.getNullValue(PtrJBList),
"llvm.sjljeh.jblist");
}
@@ -177,30 +177,32 @@ bool LowerInvoke::doInitialization(Module &M) {
}
void LowerInvoke::createAbortMessage(Module *M) {
+ LLVMContext &Context = M->getContext();
+
if (ExpensiveEHSupport) {
// The abort message for expensive EH support tells the user that the
// program 'unwound' without an 'invoke' instruction.
Constant *Msg =
- Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
+ Context.getConstantArray("ERROR: Exception thrown, but not caught!\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
- std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
- AbortMessage = Context->getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
+ std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
+ AbortMessage = Context.getConstantExprGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
// The abort message for cheap EH support tells the user that EH is not
// enabled.
Constant *Msg =
- Context->getConstantArray("Exception handler needed, but not enabled."
+ Context.getConstantArray("Exception handler needed, but not enabled."
"Recompile program with -enable-correct-eh-support.\n");
AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true,
GlobalValue::InternalLinkage,
Msg, "abortmsg");
- std::vector<Constant*> GEPIdx(2, Context->getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2, Context.getNullValue(Type::Int32Ty));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}
}
@@ -221,6 +223,7 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) {
}
bool LowerInvoke::insertCheapEHSupport(Function &F) {
+ LLVMContext &Context = F.getContext();
bool Changed = false;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
@@ -253,7 +256,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
// Insert a return instruction. This really should be a "barrier", as it
// is unreachable.
ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 :
- Context->getNullValue(F.getReturnType()), UI);
+ Context.getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now.
BB->getInstList().erase(UI);
@@ -268,7 +271,8 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
AllocaInst *InvokeNum,
SwitchInst *CatchSwitch) {
- ConstantInt *InvokeNoC = Context->getConstantInt(Type::Int32Ty, InvokeNo);
+ LLVMContext &Context = II->getContext();
+ ConstantInt *InvokeNoC = Context.getConstantInt(Type::Int32Ty, InvokeNo);
// If the unwind edge has phi nodes, split the edge.
if (isa<PHINode>(II->getUnwindDest()->begin())) {
@@ -287,7 +291,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI();
// nonvolatile.
- new StoreInst(Context->getNullValue(Type::Int32Ty), InvokeNum, false, NI);
+ new StoreInst(Context.getNullValue(Type::Int32Ty), InvokeNum, false, NI);
// Add a switch case to our unwind block.
CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
@@ -429,6 +433,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<UnwindInst*> Unwinds;
std::vector<InvokeInst*> Invokes;
+ LLVMContext &Context = F.getContext();
+
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
// Remember all return instructions in case we insert an invoke into this
@@ -476,8 +482,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"jblink", F.begin()->begin());
std::vector<Value*> Idx;
- Idx.push_back(Context->getNullValue(Type::Int32Ty));
- Idx.push_back(Context->getConstantInt(Type::Int32Ty, 1));
+ Idx.push_back(Context.getNullValue(Type::Int32Ty));
+ Idx.push_back(Context.getConstantInt(Type::Int32Ty, 1));
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"OldBuf",
EntryBB->getTerminator());
@@ -498,7 +504,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// executing. For normal calls it contains zero.
AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0,
"invokenum",EntryBB->begin());
- new StoreInst(Context->getConstantInt(Type::Int32Ty, 0), InvokeNum, true,
+ new StoreInst(Context.getConstantInt(Type::Int32Ty, 0), InvokeNum, true,
EntryBB->getTerminator());
// Insert a load in the Catch block, and a switch on its value. By default,
@@ -517,7 +523,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
"setjmp.cont");
- Idx[1] = Context->getConstantInt(Type::Int32Ty, 0);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty, 0);
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"TheJmpBuf",
EntryBB->getTerminator());
@@ -529,7 +535,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Compare the return value to zero.
Value *IsNormal = new ICmpInst(EntryBB->getTerminator(),
ICmpInst::ICMP_EQ, SJRet,
- Context->getNullValue(SJRet->getType()),
+ Context.getNullValue(SJRet->getType()),
"notunwind");
// Nuke the uncond branch.
EntryBB->getTerminator()->eraseFromParent();
@@ -563,20 +569,20 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Load the JBList, if it's null, then there was no catch!
Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr,
- Context->getNullValue(BufPtr->getType()),
+ Context.getNullValue(BufPtr->getType()),
"notnull");
BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp.
// Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx;
- Idx.push_back(Context->getNullValue(Type::Int32Ty));
- Idx.push_back(Context->getConstantInt(Type::Int32Ty, 0));
+ Idx.push_back(Context.getNullValue(Type::Int32Ty));
+ Idx.push_back(Context.getConstantInt(Type::Int32Ty, 0));
Idx[0] = GetElementPtrI