summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-08-13 21:58:54 +0000
committerOwen Anderson <resistor@mac.com>2009-08-13 21:58:54 +0000
commit1d0be15f89cb5056e20e2d24faa8d6afb1573bca (patch)
tree2cdabe223bfce83bd12e10dd557147a2f68c9bf8 /lib/Transforms/Utils
parentd163e8b14c8aa5bbbb129e3f0dffdbe7213a3c72 (diff)
downloadllvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.gz
llvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.bz2
llvm-1d0be15f89cb5056e20e2d24faa8d6afb1573bca.tar.xz
Push LLVMContexts through the IntegerType APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp8
-rw-r--r--lib/Transforms/Utils/BreakCriticalEdges.cpp4
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp4
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp54
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp12
-rw-r--r--lib/Transforms/Utils/InstructionNamer.cpp4
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp5
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp13
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp71
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp6
-rw-r--r--lib/Transforms/Utils/SSI.cpp2
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp30
-rw-r--r--lib/Transforms/Utils/UnifyFunctionExitNodes.cpp18
13 files changed, 131 insertions, 100 deletions
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 4e1015968d..3072cee61c 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -251,11 +251,11 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
Value *RetVal = 0;
// Create a value to return... if the function doesn't return null...
- if (BB->getParent()->getReturnType() != Type::VoidTy)
+ if (BB->getParent()->getReturnType() != Type::getVoidTy(TI->getContext()))
RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
// Create the return...
- NewTI = ReturnInst::Create(RetVal);
+ NewTI = ReturnInst::Create(TI->getContext(), RetVal);
}
break;
@@ -360,8 +360,8 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
unsigned NumPreds, const char *Suffix,
Pass *P) {
// Create new basic block, insert right before the original block.
- BasicBlock *NewBB =
- BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB);
+ BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix,
+ BB->getParent(), BB);
// The new block unconditionally branches to the old block.
BranchInst *BI = BranchInst::Create(BB, NewBB);
diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp
index bef1119502..632aa2b723 100644
--- a/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -129,8 +129,8 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
BasicBlock *DestBB = TI->getSuccessor(SuccNum);
// Create a new basic block, linking it into the CFG.
- BasicBlock *NewBB = BasicBlock::Create(TIBB->getName() + "." +
- DestBB->getName() + "_crit_edge");
+ BasicBlock *NewBB = BasicBlock::Create(TI->getContext(),
+ TIBB->getName() + "." + DestBB->getName() + "_crit_edge");
// Create our unconditional branch...
BranchInst::Create(DestBB, NewBB);
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 2b2fcb1052..a6df161740 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -35,7 +35,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
DenseMap<const Value*, Value*> &ValueMap,
const char *NameSuffix, Function *F,
ClonedCodeInfo *CodeInfo) {
- BasicBlock *NewBB = BasicBlock::Create("", F);
+ BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), "", F);
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
@@ -219,7 +219,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
// Nope, clone it now.
BasicBlock *NewBB;
- BBEntry = NewBB = BasicBlock::Create();
+ BBEntry = NewBB = BasicBlock::Create(BB->getContext());
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index d4f0c8095a..c98317bf80 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -242,9 +242,9 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
case 0:
- case 1: RetTy = Type::VoidTy; break;
- case 2: RetTy = Type::Int1Ty; break;
- default: RetTy = Type::Int16Ty; break;
+ case 1: RetTy = Type::getVoidTy(header->getContext()); break;
+ case 2: RetTy = Type::getInt1Ty(header->getContext()); break;
+ default: RetTy = Type::getInt16Ty(header->getContext()); break;
}
std::vector<const Type*> paramTy;
@@ -302,8 +302,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
Value *RewriteVal;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, i);
+ Idx[0] = Constant::getNullValue(Type::getInt32Ty(header->getContext()));
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), i);
TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP =
GetElementPtrInst::Create(AI, Idx, Idx+2,
@@ -353,6 +353,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Emit a call to the new function, passing in: *pointer to struct (if
// aggregating parameters), or plan inputs and allocated memory for outputs
std::vector<Value*> params, StructValues, ReloadOutputs;
+
+ LLVMContext &Context = newFunction->getContext();
// Add inputs as params, or to be filled into the struct
for (Values::iterator i = inputs.begin(), e = inputs.end(); i != e; ++i)
@@ -390,8 +392,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, i);
+ Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), i);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName());
@@ -416,8 +418,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Value *Output = 0;
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
+ Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), FirstOut + i);
GetElementPtrInst *GEP
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName());
@@ -438,7 +440,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch =
- SwitchInst::Create(Constant::getNullValue(Type::Int16Ty),
+ SwitchInst::Create(Constant::getNullValue(Type::getInt16Ty(Context)),
codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new
@@ -460,7 +462,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (!NewTarget) {
// If we don't already have an exit stub for this non-extracted
// destination, create one now!
- NewTarget = BasicBlock::Create(OldTarget->getName() + ".exitStub",
+ NewTarget = BasicBlock::Create(Context,
+ OldTarget->getName() + ".exitStub",
newFunction);
unsigned SuccNum = switchVal++;
@@ -469,17 +472,18 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
case 0:
case 1: break; // No value needed.
case 2: // Conditional branch, return a bool
- brVal = ConstantInt::get(Type::Int1Ty, !SuccNum);
+ brVal = ConstantInt::get(Type::getInt1Ty(Context), !SuccNum);
break;
default:
- brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
+ brVal = ConstantInt::get(Type::getInt16Ty(Context), SuccNum);
break;
}
- ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
+ ReturnInst *NTRet = ReturnInst::Create(Context, brVal, NewTarget);
// Update the switch instruction.
- TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
+ TheSwitch->addCase(ConstantInt::get(Type::getInt16Ty(Context),
+ SuccNum),
OldTarget);
// Restore values just before we exit
@@ -517,8 +521,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (DominatesDef) {
if (AggregateArgs) {
Value *Idx[2];
- Idx[0] = Constant::getNullValue(Type::Int32Ty);
- Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
+ Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(Context),
+ FirstOut+out);
GetElementPtrInst *GEP =
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(),
@@ -547,15 +552,16 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// this should be rewritten as a `ret'
// Check if the function should return a value
- if (OldFnRetTy == Type::VoidTy) {
- ReturnInst::Create(0, TheSwitch); // Return void
+ if (OldFnRetTy == Type::getVoidTy(Context)) {
+ ReturnInst::Create(Context, 0, TheSwitch); // Return void
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
// return what we have
- ReturnInst::Create(TheSwitch->getCondition(), TheSwitch);
+ ReturnInst::Create(Context, TheSwitch->getCondition(), TheSwitch);
} else {
// Otherwise we must have code extracted an unwind or something, just
// return whatever we want.
- ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
+ ReturnInst::Create(Context,
+ Constant::getNullValue(OldFnRetTy), TheSwitch);
}
TheSwitch->eraseFromParent();
@@ -648,12 +654,14 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
Function *oldFunction = header->getParent();
// This takes place of the original loop
- BasicBlock *codeReplacer = BasicBlock::Create("codeRepl", oldFunction,
+ BasicBlock *codeReplacer = BasicBlock::Create(header->getContext(),
+ "codeRepl", oldFunction,
header);
// The new function needs a root node because other nodes can branch to the
// head of the region, but the entry node of a function cannot have preds.
- BasicBlock *newFuncRoot = BasicBlock::Create("newFuncRoot");
+ BasicBlock *newFuncRoot = BasicBlock::Create(header->getContext(),
+ "newFuncRoot");
newFuncRoot->getInstList().push_back(BranchInst::Create(header));
// Find inputs to, outputs from the code region.
diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp
index d6382af379..c0d10f4898 100644
--- a/lib/Transforms/Utils/InlineFunction.cpp
+++ b/lib/Transforms/Utils/InlineFunction.cpp
@@ -304,7 +304,8 @@ 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 = PointerType::getUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy =
+ PointerType::getUnqual(Type::getInt8Ty(Context));
// Create the alloca. If we have TargetData, use nice alignment.
unsigned Align = 1;
@@ -313,7 +314,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
I->getName(),
&*Caller->begin()->begin());
// Emit a memcpy.
- const Type *Tys[] = { Type::Int64Ty };
+ const Type *Tys[] = { Type::getInt64Ty(Context) };
Function *MemCpyFn = Intrinsic::getDeclaration(Caller->getParent(),
Intrinsic::memcpy,
Tys, 1);
@@ -324,14 +325,15 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
if (TD == 0)
Size = ConstantExpr::getSizeOf(AggTy);
else
- Size = ConstantInt::get(Type::Int64Ty,
+ Size = ConstantInt::get(Type::getInt64Ty(Context),
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, ConstantInt::get(Type::Int32Ty, 1)
+ DestCast, SrcCast, Size,
+ ConstantInt::get(Type::getInt32Ty(Context), 1)
};
CallInst *TheMemCpy =
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
@@ -490,7 +492,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
BB != E; ++BB) {
TerminatorInst *Term = BB->getTerminator();
if (isa<UnwindInst>(Term)) {
- new UnreachableInst(Term);
+ new UnreachableInst(Context, Term);
BB->getInstList().erase(Term);
}
}
diff --git a/lib/Transforms/Utils/InstructionNamer.cpp b/lib/Transforms/Utils/InstructionNamer.cpp
index 4f8a160394..1fa51a3b6a 100644
--- a/lib/Transforms/Utils/InstructionNamer.cpp
+++ b/lib/Transforms/Utils/InstructionNamer.cpp
@@ -32,7 +32,7 @@ namespace {
bool runOnFunction(Function &F) {
for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end();
AI != AE; ++AI)
- if (!AI->hasName() && AI->getType() != Type::VoidTy)
+ if (!AI->hasName() && AI->getType() != Type::getVoidTy(F.getContext()))
AI->setName("tmp");
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
@@ -40,7 +40,7 @@ namespace {
BB->setName("BB");
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
- if (!I->hasName() && I->getType() != Type::VoidTy)
+ if (!I->hasName() && I->getType() != Type::getVoidTy(F.getContext()))
I->setName("tmp");
}
return true;
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 69a208405d..c981a014cb 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -161,7 +161,7 @@ bool LoopSimplify::runOnFunction(Function &F) {
TI->getSuccessor(i)->removePredecessor(BB);
// Add a new unreachable instruction before the old terminator.
- new UnreachableInst(TI);
+ new UnreachableInst(TI->getContext(), TI);
// Delete the dead terminator.
if (AA) AA->deleteValue(TI);
@@ -586,7 +586,8 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L, BasicBlock *Preheader) {
if (*I != Preheader) BackedgeBlocks.push_back(*I);
// Create and insert the new backedge block...
- BasicBlock *BEBlock = BasicBlock::Create(Header->getName()+".backedge", F);
+ BasicBlock *BEBlock = BasicBlock::Create(Header->getContext(),
+ Header->getName()+".backedge", F);
BranchInst *BETerminator = BranchInst::Create(Header, BEBlock);
// Move the new backedge block to right after the last backedge block.
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index ce7b04a497..bfeab3775b 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -87,12 +87,13 @@ Pass *llvm::createLowerAllocationsPass(bool LowerMallocArgToInteger) {
// This function is always successful.
//
bool LowerAllocations::doInitialization(Module &M) {
- const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
+ const Type *BPTy = PointerType::getUnqual(Type::getInt8Ty(M.getContext()));
// Prototype malloc as "char* malloc(...)", because we don't know in
// doInitialization whether size_t is int or long.
FunctionType *FT = FunctionType::get(BPTy, true);
MallocFunc = M.getOrInsertFunction("malloc", FT);
- FreeFunc = M.getOrInsertFunction("free" , Type::VoidTy, BPTy, (Type *)0);
+ FreeFunc = M.getOrInsertFunction("free" , Type::getVoidTy(M.getContext()),
+ BPTy, (Type *)0);
return true;
}
@@ -106,7 +107,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
BasicBlock::InstListType &BBIL = BB.getInstList();
const TargetData &TD = getAnalysis<TargetData>();
- const Type *IntPtrTy = TD.getIntPtrType();
+ const Type *IntPtrTy = TD.getIntPtrType(BB.getContext());
// Loop over all of the instructions, looking for malloc or free instructions
for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) {
@@ -116,7 +117,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
// malloc(type) becomes i8 *malloc(size)
Value *MallocArg;
if (LowerMallocArgToInteger)
- MallocArg = ConstantInt::get(Type::Int64Ty,
+ MallocArg = ConstantInt::get(Type::getInt64Ty(BB.getContext()),
TD.getTypeAllocSize(AllocTy));
else
MallocArg = ConstantExpr::getSizeOf(AllocTy);
@@ -151,7 +152,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
// Create a cast instruction to convert to the right type...
Value *MCast;
- if (MCall->getType() != Type::VoidTy)
+ if (MCall->getType() != Type::getVoidTy(BB.getContext()))
MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
MCast = Constant::getNullValue(MI->getType());
@@ -164,7 +165,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
Value *PtrCast =
new BitCastInst(FI->getOperand(0),
- PointerType::getUnqual(Type::Int8Ty), "", I);
+ PointerType::getUnqual(Type::getInt8Ty(BB.getContext())), "", 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 d16ceb4280..b18a2307e1 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -115,7 +115,8 @@ 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) {
- const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+ const Type *VoidPtrTy =
+ PointerType::getUnqual(Type::getInt8Ty(M.getContext()));
AbortMessage = 0;
if (ExpensiveEHSupport) {
// Insert a type for the linked list of jump buffers.
@@ -164,7 +165,8 @@ bool LowerInvoke::doInitialization(Module &M) {
}
// We need the 'write' and 'abort' functions for both models.
- AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, (Type *)0);
+ AbortFn = M.getOrInsertFunction("abort", Type::getVoidTy(M.getContext()),
+ (Type *)0);
#if 0 // "write" is Unix-specific.. code is going away soon anyway.
WriteFn = M.getOrInsertFunction("write", Type::VoidTy, Type::Int32Ty,
VoidPtrTy, Type::Int32Ty, (Type *)0);
@@ -179,26 +181,30 @@ void LowerInvoke::createAbortMessage(Module *M) {
// The abort message for expensive EH support tells the user that the
// program 'unwound' without an 'invoke' instruction.
Constant *Msg =
- ConstantArray::get("ERROR: Exception thrown, but not caught!\n");
+ ConstantArray::get(M->getContext(),
+ "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, Constant::getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2,
+ Constant::getNullValue(Type::getInt32Ty(M->getContext())));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
} else {
// The abort message for cheap EH support tells the user that EH is not
// enabled.
Constant *Msg =
- ConstantArray::get("Exception handler needed, but not enabled."
+ ConstantArray::get(M->getContext(),
+ "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, Constant::getNullValue(Type::Int32Ty));
+ std::vector<Constant*> GEPIdx(2, Constant::getNullValue(
+ Type::getInt32Ty(M->getContext())));
AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2);
}
}
@@ -250,8 +256,9 @@ 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 :
- Constant::getNullValue(F.getReturnType()), UI);
+ ReturnInst::Create(F.getContext(),
+ F.getReturnType() == Type::getVoidTy(F.getContext()) ?
+ 0 : Constant::getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now.
BB->getInstList().erase(UI);
@@ -266,7 +273,8 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
AllocaInst *InvokeNum,
SwitchInst *CatchSwitch) {
- ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo);
+ ConstantInt *InvokeNoC = ConstantInt::get(Type::getInt32Ty(II->getContext()),
+ InvokeNo);
// If the unwind edge has phi nodes, split the edge.
if (isa<PHINode>(II->getUnwindDest()->begin())) {
@@ -285,7 +293,8 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI();
// nonvolatile.
- new StoreInst(Constant::getNullValue(Type::Int32Ty), InvokeNum, false, NI);
+ new StoreInst(Constant::getNullValue(Type::getInt32Ty(II->getContext())),
+ InvokeNum, false, NI);
// Add a switch case to our unwind block.
CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
@@ -474,8 +483,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"jblink", F.begin()->begin());
std::vector<Value*> Idx;
- Idx.push_back(Constant::getNullValue(Type::Int32Ty));
- Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
+ Idx.push_back(Constant::getNullValue(Type::getInt32Ty(F.getContext())));
+ Idx.push_back(ConstantInt::get(Type::getInt32Ty(F.getContext()), 1));
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"OldBuf",
EntryBB->getTerminator());
@@ -490,20 +499,21 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create the catch block. The catch block is basically a big switch
// statement that goes to all of the invoke catch blocks.
- BasicBlock *CatchBB = BasicBlock::Create("setjmp.catch", &F);
+ BasicBlock *CatchBB =
+ BasicBlock::Create(F.getContext(), "setjmp.catch", &F);
// Create an alloca which keeps track of which invoke is currently
// executing. For normal calls it contains zero.
- AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0,
+ AllocaInst *InvokeNum = new AllocaInst(Type::getInt32Ty(F.getContext()), 0,
"invokenum",EntryBB->begin());
- new StoreInst(ConstantInt::get(Type::Int32Ty, 0), InvokeNum, true,
- EntryBB->getTerminator());
+ new StoreInst(ConstantInt::get(Type::getInt32Ty(F.getContext()), 0),
+ InvokeNum, true, EntryBB->getTerminator());
// Insert a load in the Catch block, and a switch on its value. By default,
// we go to a block that just does an unwind (which is the correct action
// for a standard call).
- BasicBlock *UnwindBB = BasicBlock::Create("unwindbb", &F);
- Unwinds.push_back(new UnwindInst(UnwindBB));
+ BasicBlock *UnwindBB = BasicBlock::Create(F.getContext(), "unwindbb", &F);
+ Unwinds.push_back(new UnwindInst(F.getContext(), UnwindBB));
Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB);
SwitchInst *CatchSwitch =
@@ -515,11 +525,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
"setjmp.cont");
- Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 0);
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"TheJmpBuf",
EntryBB->getTerminator());
- JmpBufPtr = new BitCastInst(JmpBufPtr, PointerType::getUnqual(Type::Int8Ty),
+ JmpBufPtr = new BitCastInst(JmpBufPtr,
+ PointerType::getUnqual(Type::getInt8Ty(F.getContext())),
"tmp", EntryBB->getTerminator());
Value *SJRet = CallInst::Create(SetJmpFn, JmpBufPtr, "sjret",
EntryBB->getTerminator());
@@ -545,9 +556,10 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create three new blocks, the block to load the jmpbuf ptr and compare
// against null, the block to do the longjmp, and the error block for if it
// is null. Add them at the end of the function because they are not hot.
- BasicBlock *UnwindHandler = BasicBlock::Create("dounwind", &F);
- BasicBlock *UnwindBlock = BasicBlock::Create("unwind", &F);
- BasicBlock *TermBlock = BasicBlock::Create("unwinderror", &F);
+ BasicBlock *UnwindHandler = BasicBlock::Create(F.getContext(),
+ "dounwind", &F);
+ BasicBlock *UnwindBlock = BasicBlock::Create(F.getContext(), "unwind", &F);
+ BasicBlock *TermBlock = BasicBlock::Create(F.getContext(), "unwinderror", &F);
// If this function contains an invoke, restore the old jumpbuf ptr.
Value *BufPtr;
@@ -568,18 +580,19 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
// Create the block to do the longjmp.
// Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx;
- Idx.push_back(Constant::getNullValue(Type::Int32Ty));
- Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
+ Idx.push_back(Constant::getNullValue(Type::getInt32Ty(F.getContext())));
+ Idx.push_back(ConstantInt::get(Type::getInt32Ty(F.getContext()), 0));
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock);
- Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty),
+ Idx[0] = new BitCastInst(Idx[0],
+ PointerType::getUnqual(Type::getInt8Ty(F.getContext())),
"tmp", UnwindBlock);
- Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
+ Idx[1] = ConstantInt::get(Type::getInt32Ty(F.getContext()), 1);
CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
- new UnreachableInst(UnwindBlock);
+ new UnreachableInst(F.getContext(), UnwindBlock);
// Set up the term block ("throw without a catch").
- new UnreachableInst(TermBlock);
+ new UnreachableInst(F.getContext(), TermBlock);
// Insert a new call to write(2, AbortMessage, AbortMessageLength);
writeAbortMessage(TermBlock->getTerminator());
diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp
index 4cc92e9824..974698d45c 100644
--- a/lib/Transforms/Utils/LowerSwitch.cpp
+++ b/lib/Transforms/Utils/LowerSwitch.cpp
@@ -155,7 +155,7 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End,
// Create a new node that checks if the value is < pivot. Go to the
// left branch if it is and right branch if not.
Function* F = OrigBlock->getParent();
- BasicBlock* NewNode = BasicBlock::Create("NodeBlock");
+ BasicBlock* NewNode = BasicBlock::Create(Val->getContext(), "NodeBlock");
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode);
@@ -177,7 +177,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
BasicBlock* Default)
{
Function* F = OrigBlock->getParent();
- BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock");
+ BasicBlock* NewLeaf = BasicBlock::Create(Val->getContext(), "LeafBlock");
Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewLeaf);
@@ -289,7 +289,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
// Create a new, empty default block so that the new hierarchy of
// if-then statements go to this and the PHI nodes are happy.
- BasicBlock* NewDefault = BasicBlock::Create("NewDefault");
+ BasicBlock* NewDefault = BasicBlock::Create(SI->getContext(), "NewDefault");
F->getBasicBlockList().insert(Default, NewDefault);
BranchInst::Create(Default, NewDefault);
diff --git a/lib/Transforms/Utils/SSI.cpp b/lib/Transforms/Utils/SSI.cpp
index 8178367dd4..63ca354793 100644
--- a/lib/Transforms/Utils/SSI.cpp
+++ b/lib/Transforms/Utils/SSI.cpp
@@ -421,7 +421,7 @@ bool SSIEverything::runOnFunction(Function &F) {
for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B)
for (BasicBlock::iterator I = B->begin(), E = B->end(); I != E; ++I)
- if (I->getType() != Type::VoidTy)
+ if (I->getType() != Type::getVoidTy(F.getContext()))
Insts.push_back(I);
ssi.createSSI(Insts);
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index d6d8f28e7e..bb0cf4234c 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -838,7 +838,8 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
if (InfLoopBlock == 0) {
// Insert it at the end of the function, because it's either code,
// or it won't matter if it's hot. :)
- InfLoopBlock = BasicBlock::Create("infloop", BB->getParent());
+ InfLoopBlock = BasicBlock::Create(BB->getContext(),
+ "infloop", BB->getParent());
BranchInst::Create(InfLoopBlock, InfLoopBlock);
}
NewSI->setSuccessor(i, InfLoopBlock);
@@ -930,7 +931,7 @@ HoistTerminator:
// Okay, it is safe to hoist the terminator.
Instruction *NT = I1->clone(BB1->getContext());
BIParent->getInstList().insert(BI, NT);
- if (NT->getType() != Type::VoidTy) {
+ if (NT->getType() != Type::getVoidTy(BB1->getContext())) {
I1->replaceAllUsesWith(NT);
I2->replaceAllUsesWith(NT);
NT->takeName(I1);
@@ -1189,7 +1190,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
ConstantInt *CB;
if ((CB = dyn_cast<ConstantInt>(PN->getIncomingValue(i))) &&
- CB->getType() == Type::Int1Ty) {
+ CB->getType() == Type::getInt1Ty(BB->getContext())) {
// Okay, we now know that all edges from PredBB should be revectored to
// branch to RealDest.
BasicBlock *PredBB = PN->getIncomingBlock(i);
@@ -1201,7 +1202,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
// difficult cases. Instead of being smart about this, just insert a new
// block that jumps to the destination block, effectively splitting
// the edge we are about to create.
- BasicBlock *EdgeBB = BasicBlock::Create(RealDest->getName()+".critedge",
+ BasicBlock *EdgeBB = BasicBlock::Create(BB->getContext(),
+ RealDest->getName()+".critedge",
RealDest->getParent(), RealDest);
BranchInst::Create(RealDest, EdgeBB);
PHINode *PN;
@@ -1419,7 +1421,7 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI) {
if (FalseRet->getNumOperands() == 0) {
TrueSucc->removePredecessor(BI->getParent());
FalseSucc->removePredecessor(BI->getParent());
- ReturnInst::Create(0, BI);
+ ReturnInst::Create(BI->getContext(), 0, BI);
EraseTerminatorInstAndDCECond(BI);
return true;
}
@@ -1468,8 +1470,8 @@ static bool SimplifyCondBranchToTwoReturns(BranchInst *BI) {
}
Value *RI = !TrueValue ?
- ReturnInst::Create(BI) :
- ReturnInst::Create(TrueValue, BI);
+ ReturnInst::Create(BI->getContext(), BI) :
+ ReturnInst::Create(BI->getContext(), TrueValue, BI);
DOUT << "\nCHANGING BRANCH TO TWO RETURNS INTO SELECT:"
<< "\n " << *BI << "NewRet = " << *RI
@@ -1608,7 +1610,8 @@ 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(ConstantInt::get(Type::Int1Ty, CondIsTrue));
+ BI->setCondition(ConstantInt::get(Type::getInt1Ty(BB->getContext()),
+ CondIsTrue));
return true; // Nuke the branch on constant.
}
@@ -1616,7 +1619,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
// in the constant and simplify the block result. Subsequent passes of
// simplifycfg will thread the block.
if (BlockIsSimpleEnoughToThreadThrough(BB)) {
- PHINode *NewPN = PHINode::Create(Type::Int1Ty,
+ PHINode *NewPN = PHINode::Create(Type::getInt1Ty(BB->getContext()),
BI->getCondition()->getName() + ".pr",
BB->begin());
// Okay, we're going to insert the PHI node. Since PBI is not the only
@@ -1628,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(ConstantInt::get(Type::Int1Ty,
+ NewPN->addIncoming(ConstantInt::get(Type::getInt1Ty(BB->getContext()),
CondIsTrue), *PI);
} else {
NewPN->addIncoming(BI->getCondition(), *PI);
@@ -1700,7 +1703,8 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
if (OtherDest == BB) {
// Insert it at the end of the function, because it's either code,
// or it won't matter if it's hot. :)
- BasicBlock *InfLoopBlock = BasicBlock::Create("infloop", BB->getParent());
+ BasicBlock *InfLoopBlock = BasicBlock::Create(BB->getContext(),
+ "infloop", BB->getParent());
BranchInst::Create(InfLoopBlock, InfLoopBlock);
OtherDest = InfLoopBlock;
}
@@ -1885,7 +1889,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (BranchInst *BI = dyn_cast<BranchInst>(Pred->getTerminator())) {
if (BI->isUnconditional()) {
Pred->getInstList().pop_back(); // nuke uncond branch
- new UnwindInst(Pred); // Use unwind.
+ new UnwindInst(Pred->getContext(), Pred); // Use unwind.
Changed = true;
}
} else if (InvokeInst *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
@@ -2034,7 +2038,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isUnconditional()) {
if (BI->getSuccessor(0) == BB) {
- new UnreachableInst(TI);
+ new UnreachableInst(TI->getContext(), TI);
TI->eraseFromParent();
Changed = true;
}
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 848f2b87c4..30cb94d903 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -66,8 +66,8 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
} else if (UnwindingBlocks.size() == 1) {
UnwindBlock = UnwindingBlocks.front();
} else {
- UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F);
- new UnwindInst(UnwindBlock);
+ UnwindBlock = BasicBlock::Create(F.getContext(), "UnifiedUnwindBlock", &F);
+ new UnwindInst(F.getContext(), UnwindBlock);
for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(),
E = UnwindingBlocks.end(); I != E; ++I) {
@@ -83,8 +83,9 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
} else if (UnreachableBlocks.size() == 1) {
UnreachableBlock = UnreachableBlocks.front();
} else {
- UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F);
- new UnreachableInst(UnreachableBlock);
+ UnreachableBlock = BasicBlock::Create(F.getContext(),
+ "UnifiedUnreachableBlock", &F);
+ new UnreachableInst(F.getContext(), UnreachableBlock);
for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(),
E = UnreachableBlocks.end(); I != E; ++I) {
@@ -107,16 +108,17 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
// nodes (if the function returns values), and convert all of the return
// instructions into unconditional branches.
//
- BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F);
+ BasicBlock *NewRetBlock = BasicBlock::Create(F.getContext(),
+ "UnifiedReturnBlock", &F);
PHINode *PN = 0;
- if (F.getReturnType() == Type::VoidTy) {
- ReturnInst::Create(NULL, NewRetBlock);
+ if (F.getReturnType() == Type::getVoidTy(F.getContext())) {
+ ReturnInst::Create(F.getContext(), NULL, NewRetBlock);
} else {
// If the function doesn't return void... add a PHI node to the block...
PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal");
NewRetBlock->getInstList().push_back(PN);
- ReturnInst::Create(PN, NewRetBlock);
+ ReturnInst::Create(F.getContext(), PN, NewRetBlock);
}
// Loop over all of the blocks, replacing the return instruction with an