summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-22 00:24:57 +0000
committerOwen Anderson <resistor@mac.com>2009-07-22 00:24:57 +0000
commite922c0201916e0b980ab3cfe91e1413e68d55647 (patch)
tree663be741b84470d97945f01da459a3627af683fd /lib/Transforms/Utils
parent7cf12c7efd37dc12c3ed536a3f4c373dddac2b85 (diff)
downloadllvm-e922c0201916e0b980ab3cfe91e1413e68d55647.tar.gz
llvm-e922c0201916e0b980ab3cfe91e1413e68d55647.tar.bz2
llvm-e922c0201916e0b980ab3cfe91e1413e68d55647.tar.xz
Get rid of the Pass+Context magic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76702 91177308-0d34-0410-b5e6-96231b3b80d8
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] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);
Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty),
"tmp", UnwindBlock);
- Idx[1] = Context->getConstantInt(Type::Int32Ty, 1);
+ Idx[1] = Context.getConstantInt(Type::Int32Ty, 1);
CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
new UnreachableInst(UnwindBlock);
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index 2a7124c9aa..b4121479db 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -162,7 +162,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode);
- ICmpInst* Comp = new ICmpInst(*Default->getContext(), ICmpInst::ICMP_SLT,
+ ICmpInst* Comp = new ICmpInst(Default->getContext(), ICmpInst::ICMP_SLT,
Val, Pivot.Low, "Pivot");
NewNode->getInstList().push_back(Comp);
BranchInst::Create(LBranch, RBranch, Comp, NewNode);
@@ -180,6 +180,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
BasicBlock* Default)
{
Function* F = OrigBlock->getParent();
+ LLVMContext &Context = F->getContext();
BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock");
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewLeaf);
@@ -202,11 +203,11 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
"SwitchLeaf");
} else {
// Emit V-Lo <=u Hi-Lo
- Constant* NegLo = Context->getConstantExprNeg(Leaf.Low);
+ Constant* NegLo = Context.getConstantExprNeg(Leaf.Low);
Instruction* Add = BinaryOperator::CreateAdd(Val, NegLo,
Val->getName()+".off",
NewLeaf);
- Constant *UpperBound = Context->getConstantExprAdd(NegLo, Leaf.High);
+ Constant *UpperBound = Context.getConstantExprAdd(NegLo, Leaf.High);
Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Add, UpperBound,
"SwitchLeaf");
}
diff --git a/lib/Transforms/Utils/Mem2Reg.cpp b/lib/Transforms/Utils/Mem2Reg.cpp
index 3110299887..5df08326d8 100644
--- a/lib/Transforms/Utils/Mem2Reg.cpp
+++ b/lib/Transforms/Utils/Mem2Reg.cpp
@@ -75,7 +75,7 @@ bool PromotePass::runOnFunction(Function &F) {
if (Allocas.empty()) break;
- PromoteMemToReg(Allocas, DT, DF, Context);
+ PromoteMemToReg(Allocas, DT, DF, F.getContext());
NumPromoted += Allocas.size();
Changed = true;
}
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index a05170e926..bad7e4c950 100644
--- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -183,7 +183,7 @@ namespace {
///
AliasSetTracker *AST;
- LLVMContext *Context;
+ LLVMContext &Context;
/// AllocaLookup - Reverse mapping of Allocas.
///
@@ -216,7 +216,7 @@ namespace {
public:
PromoteMem2Reg(const std::vector<AllocaInst*> &A, DominatorTree &dt,
DominanceFrontier &df, AliasSetTracker *ast,
- LLVMContext *C)
+ LLVMContext &C)
: Allocas(A), DT(dt), DF(df), AST(ast), Context(C) {}
void run();
@@ -449,7 +449,7 @@ void PromoteMem2Reg::run() {
//
RenamePassData::ValVector Values(Allocas.size());
for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
- Values[i] = Context->getUndef(Allocas[i]->getAllocatedType());
+ Values[i] = Context.getUndef(Allocas[i]->getAllocatedType());
// Walks all basic blocks in the function performing the SSA rename algorithm
// and inserting the phi nodes we marked as necessary
@@ -476,7 +476,7 @@ void PromoteMem2Reg::run() {
// Just delete the users now.
//
if (!A->use_empty())
- A->replaceAllUsesWith(Context->getUndef(A->getType()));
+ A->replaceAllUsesWith(Context.getUndef(A->getType()));
if (AST) AST->deleteValue(A);
A->eraseFromParent();
}
@@ -562,7 +562,7 @@ void PromoteMem2Reg::run() {
BasicBlock::iterator BBI = BB->begin();
while ((SomePHI = dyn_cast<PHINode>(BBI++)) &&
SomePHI->getNumIncomingValues() == NumBadPreds) {
- Value *UndefVal = Context->getUndef(SomePHI->getType());
+ Value *UndefVal = Context.getUndef(SomePHI->getType());
for (unsigned pred = 0, e = Preds.size(); pred != e; ++pred)
SomePHI->addIncoming(UndefVal, Preds[pred]);
}
@@ -808,7 +808,7 @@ void PromoteMem2Reg::PromoteSingleBlockAlloca(AllocaInst *AI, AllocaInfo &Info,
if (StoresByIndex.empty()) {
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;)
if (LoadInst *LI = dyn_cast<LoadInst>(*UI++)) {
- LI->replaceAllUsesWith(Context->getUndef(LI->getType()));
+ LI->replaceAllUsesWith(Context.getUndef(LI->getType()));
if (AST && isa<PointerType>(LI->getType()))
AST->deleteValue(LI);
LBI.deleteValue(LI);
@@ -999,7 +999,7 @@ NextIteration:
///
void llvm::PromoteMemToReg(const std::vector<AllocaInst*> &Allocas,
DominatorTree &DT, DominanceFrontier &DF,
- LLVMContext *Context, AliasSetTracker *AST) {
+ LLVMContext &Context, AliasSetTracker *AST) {
// If there is nothing to do, bail out...
if (Allocas.empty()) return;
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 3b6b77f5fb..e155c295e0 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -927,7 +927,7 @@ HoistTerminator:
return true;
// Okay, it is safe to hoist the terminator.
- Instruction *NT = I1->clone(*BB1->getContext());
+ Instruction *NT = I1->clone(BB1->getContext());
BIParent->getInstList().insert(BI, NT);
if (NT->getType() != Type::VoidTy) {
I1->replaceAllUsesWith(NT);
@@ -1167,7 +1167,7 @@ static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
/// ultimate destination.
static bool FoldCondBranchOnPHI(BranchInst *BI) {
BasicBlock *BB = BI->getParent();
- LLVMContext *Context = BB->getContext();
+ LLVMContext &Context = BB->getContext();
PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
// NOTE: we currently cannot transform this case if the PHI node is used
// outside of the block.
@@ -1220,7 +1220,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
TranslateMap[PN] = PN->getIncomingValueForBlock(PredBB);
} else {
// Clone the instruction.
- Instruction *N = BBI->clone(*Context);
+ Instruction *N = BBI->clone(Context);
if (BBI->hasName()) N->setName(BBI->getName()+".c");
// Update operands due to translation.
@@ -1265,7 +1265,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
/// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
/// PHI node, see if we can eliminate it.
static bool FoldTwoEntryPHINode(PHINode *PN) {
- LLVMContext *Context = PN->getParent()->getContext();
+ LLVMContext &Context = PN->getParent()->getContext();
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
// statement", which has a very simple dominance structure. Basically, we
@@ -1304,7 +1304,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN) {
if (PN->getIncomingValue(0) != PN)
PN->replaceAllUsesWith(PN->getIncomingValue(0));
else
- PN->replaceAllUsesWith(Context->getUndef(PN->getType()));
+ PN->replaceAllUsesWith(Context.getUndef(PN->getType()));
} else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
&AggressiveInsts) ||
!DominatesMergePoint(PN->getIncomingValue(1), BB,
@@ -1559,7 +1559,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
// If we need to invert the condition in the pred block to match, do so now.
if (InvertPredCond) {
Value *NewCond =
- BinaryOperator::CreateNot(*BI->getParent()->getContext(),
+ BinaryOperator::CreateNot(BI->getParent()->getContext(),
PBI->getCondition(),
PBI->getCondition()->getName()+".not", PBI);
PBI->setCondition(NewCond);
@@ -1571,7 +1571,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
// Clone Cond into the predecessor basic block, and or/and the
// two conditions together.
- Instruction *New = Cond->clone(*BB->getContext());
+ Instruction *New = Cond->clone(BB->getContext());
PredBlock->getInstList().insert(PBI, New);
New->takeName(Cond);
Cond->setName(New->getName()+".old");
@@ -1599,7 +1599,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
assert(PBI->isConditional() && BI->isConditional());
BasicBlock *BB = BI->getParent();
- LLVMContext *Context = BB->getContext();
+ LLVMContext &Context = BB->getContext();
// If this block ends with a branch instruction, and if there is a
// predecessor that ends on a branch of the same condition, make
@@ -1611,7 +1611,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
if (BB->getSinglePredecessor()) {
// Turn this into a branch on constant.
bool CondIsTrue = PBI->getSuccessor(0) == BB;
- BI->setCondition(Context->getConstantInt(Type::Int1Ty, CondIsTrue));
+ BI->setCondition(Context.getConstantInt(Type::Int1Ty, CondIsTrue));
return true; // Nuke the branch on constant.
}
@@ -1631,7 +1631,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
PBI->getCondition() == BI->getCondition() &&
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
bool CondIsTrue = PBI->getSuccessor(0) == BB;
- NewPN->addIncoming(Context->getConstantInt(Type::Int1Ty,
+ NewPN->addIncoming(Context.getConstantInt(Type::Int1Ty,
CondIsTrue), *PI);
} else {
NewPN->addIncoming(BI->getCondition(), *PI);
@@ -1716,12 +1716,12 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
// Make sure we get to CommonDest on True&True directions.
Value *PBICond = PBI->getCondition();
if (PBIOp)
- PBICond = BinaryOperator::CreateNot(*Context, PBICond,
+ PBICond = BinaryOperator::CreateNot(Context, PBICond,
PBICond->getName()+".not",
PBI);
Value *BICond = BI->getCondition();
if (BIOp)
- BICond = BinaryOperator::CreateNot(*Context, BICond,
+ BICond = BinaryOperator::CreateNot(Context, BICond,
BICond->getName()+".not",
PBI);
// Merge the conditions.
@@ -1831,7 +1831,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
<< "INTO UNCOND BRANCH PRED: " << *Pred;
Instruction *UncondBranch = Pred->getTerminator();
// Clone the return and add it to the end of the predecessor.
- Instruction *NewRet = RI->clone(*BB->getContext());
+ Instruction *NewRet = RI->clone(BB->getContext());
Pred->getInstList().push_back(NewRet);
BasicBlock::iterator BBI = RI;
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index f0b24c1fa9..0dc012e4d9 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -23,7 +23,7 @@
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
-Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) {
+Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
Value *&VMSlot = VM[V];
if (VMSlot) return VMSlot; // Does it exist in the map yet?
@@ -55,7 +55,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) {
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
- return VM[V] = Context->getConstantArray(CA->getType(), Values);
+ return VM[V] = Context.getConstantArray(CA->getType(), Values);
}
}
return VM[V] = C;
@@ -75,7 +75,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) {
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
- return VM[V] = Context->getConstantStruct(CS->getType(), Values);
+ return VM[V] = Context.getConstantStruct(CS->getType(), Values);
}
}
return VM[V] = C;
@@ -100,7 +100,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) {
Values.push_back(cast<Constant>(MV));
for (++i; i != e; ++i)
Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
- return VM[V] = Context->getConstantVector(Values);
+ return VM[V] = Context.getConstantVector(Values);
}
}
return VM[V] = C;
@@ -121,7 +121,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext *Context) {
Values.push_back(MV);
for (++i; i != e; ++i)
Values.push_back(MapValue(*i, VM, Context));
- return VM[V] = Context->getMDNode(Values.data(), Values.size());
+ return VM[V] = Context.getMDNode(Values.data(), Values.size());
}
}
return VM[V] = C;