summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO
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
commit47db941fd3e5a698c4417e38686ff6da6b2d81ee (patch)
treef1bc8ce05f4b4c0c6f5eb775c3e5b12eda35e2f1 /llvm/lib/Transforms/IPO
parent4565ef5b65b7d0b778b41836d70b806196cc8e24 (diff)
downloadbcm5719-llvm-47db941fd3e5a698c4417e38686ff6da6b2d81ee.tar.gz
bcm5719-llvm-47db941fd3e5a698c4417e38686ff6da6b2d81ee.zip
Get rid of the Pass+Context magic.
llvm-svn: 76702
Diffstat (limited to 'llvm/lib/Transforms/IPO')
-rw-r--r--llvm/lib/Transforms/IPO/ArgumentPromotion.cpp17
-rw-r--r--llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp22
-rw-r--r--llvm/lib/Transforms/IPO/DeadTypeElimination.cpp1
-rw-r--r--llvm/lib/Transforms/IPO/ExtractGV.cpp11
-rw-r--r--llvm/lib/Transforms/IPO/GlobalDCE.cpp1
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp172
-rw-r--r--llvm/lib/Transforms/IPO/IPConstantPropagation.cpp10
-rw-r--r--llvm/lib/Transforms/IPO/IndMemRemoval.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/Internalize.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/LowerSetJmp.cpp22
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp4
-rw-r--r--llvm/lib/Transforms/IPO/PartialInlining.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/PartialSpecialization.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/PruneEH.cpp2
-rw-r--r--llvm/lib/Transforms/IPO/RaiseAllocations.cpp24
-rw-r--r--llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp1
-rw-r--r--llvm/lib/Transforms/IPO/StripSymbols.cpp1
-rw-r--r--llvm/lib/Transforms/IPO/StructRetPromotion.cpp3
18 files changed, 147 insertions, 152 deletions
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 75a0415fadf..3a97aa83b53 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -576,6 +576,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
const Type *RetTy = FTy->getReturnType();
+ LLVMContext &Context = RetTy->getContext();
// Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
// have zero fixed arguments.
@@ -586,7 +587,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
}
// Construct the new function type using the new arguments.
- FunctionType *NFTy = Context->getFunctionType(RetTy, Params, FTy->isVarArg());
+ FunctionType *NFTy = Context.getFunctionType(RetTy, Params, FTy->isVarArg());
// Create the new function body and insert it into the module...
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
@@ -637,9 +638,9 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Emit a GEP and load for each element of the struct.
const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
const StructType *STy = cast<StructType>(AgTy);
- Value *Idxs[2] = { Context->getConstantInt(Type::Int32Ty, 0), 0 };
+ Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 };
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
- Idxs[1] = Context->getConstantInt(Type::Int32Ty, i);
+ Idxs[1] = Context.getConstantInt(Type::Int32Ty, i);
Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
(*AI)->getName()+"."+utostr(i),
Call);
@@ -664,7 +665,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Use i32 to index structs, and i64 for others (pointers/arrays).
// This satisfies GEP constraints.
const Type *IdxTy = (isa<StructType>(ElTy) ? Type::Int32Ty : Type::Int64Ty);
- Ops.push_back(Context->getConstantInt(IdxTy, *II));
+ Ops.push_back(Context.getConstantInt(IdxTy, *II));
// Keep track of the type we're currently indexing
ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(*II);
}
@@ -680,7 +681,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
}
if (ExtraArgHack)
- Args.push_back(Context->getNullValue(Type::Int32Ty));
+ Args.push_back(Context.getNullValue(Type::Int32Ty));
// Push any varargs arguments on the list
for (; AI != CS.arg_end(); ++AI, ++ArgIndex) {
@@ -757,10 +758,10 @@ Function *ArgPromotion::DoPromotion(Function *F,
const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt);
const StructType *STy = cast<StructType>(AgTy);
- Value *Idxs[2] = { Context->getConstantInt(Type::Int32Ty, 0), 0 };
+ Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 };
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
- Idxs[1] = Context->getConstantInt(Type::Int32Ty, i);
+ Idxs[1] = Context.getConstantInt(Type::Int32Ty, i);
std::string Name = TheAlloca->getName()+"."+utostr(i);
Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
Name, InsertPt);
@@ -843,7 +844,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Notify the alias analysis implementation that we inserted a new argument.
if (ExtraArgHack)
- AA.copyValue(Context->getNullValue(Type::Int32Ty), NF->arg_begin());
+ AA.copyValue(Context.getNullValue(Type::Int32Ty), NF->arg_begin());
// Tell the alias analysis that the old function is about to disappear.
diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
index e86f619dcb0..3491b1c85bf 100644
--- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -196,8 +196,10 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
// Start by computing a new prototype for the function, which is the same as
// the old function, but doesn't have isVarArg set.
const FunctionType *FTy = Fn.getFunctionType();
+ LLVMContext &Context = FTy->getContext();
+
std::vector<const Type*> Params(FTy->param_begin(), FTy->param_end());
- FunctionType *NFTy = Context->getFunctionType(FTy->getReturnType(),
+ FunctionType *NFTy = Context.getFunctionType(FTy->getReturnType(),
Params, false);
unsigned NumArgs = Params.size();
@@ -598,6 +600,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
const Type *RetTy = FTy->getReturnType();
const Type *NRetTy = NULL;
unsigned RetCount = NumRetVals(F);
+
+ LLVMContext &Context = RetTy->getContext();
+
// -1 means unused, other numbers are the new index
SmallVector<int, 5> NewRetIdxs(RetCount, -1);
std::vector<const Type*> RetTypes;
@@ -635,7 +640,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// something and {} into void.
// Make the new struct packed if we used to return a packed struct
// already.
- NRetTy = Context->getStructType(RetTypes, STy->isPacked());
+ NRetTy = Context.getStructType(RetTypes, STy->isPacked());
else if (RetTypes.size() == 1)
// One return type? Just a simple value then, but only if we didn't use to
// return a struct with that simple value before.
@@ -703,7 +708,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
}
// Create the new function type based on the recomputed parameters.
- FunctionType *NFTy = Context->getFunctionType(NRetTy, Params,
+ FunctionType *NFTy = Context.getFunctionType(NRetTy, Params,
FTy->isVarArg());
// No change?
@@ -753,7 +758,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
}
if (ExtraArgHack)
- Args.push_back(Context->getUndef(Type::Int32Ty));
+ Args.push_back(Context.getUndef(Type::Int32Ty));
// Push any varargs arguments on the list. Don't forget their attributes.
for (CallSite::arg_iterator E = CS.arg_end(); I != E; ++I, ++i) {
@@ -792,7 +797,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else if (New->getType() == Type::VoidTy) {
// Our return value has uses, but they will get removed later on.
// Replace by null for now.
- Call->replaceAllUsesWith(Context->getNullValue(Call->getType()));
+ Call->replaceAllUsesWith(Context.getNullValue(Call->getType()));
} else {
assert(isa<StructType>(RetTy) &&
"Return type changed, but not into a void. The old return type"
@@ -809,7 +814,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// extract/insertvalue chaining and let instcombine clean that up.
//
// Start out building up our return value from undef
- Value *RetVal = Context->getUndef(RetTy);
+ Value *RetVal = Context.getUndef(RetTy);
for (unsigned i = 0; i != RetCount; ++i)
if (NewRetIdxs[i] != -1) {
Value *V;
@@ -855,7 +860,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
} else {
// If this argument is dead, replace any uses of it with null constants
// (these are guaranteed to become unused later on).
- I->replaceAllUsesWith(Context->getNullValue(I->getType()));
+ I->replaceAllUsesWith(Context.getNullValue(I->getType()));
}
// If we change the return value of the function we must rewrite any return
@@ -876,7 +881,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// clean that up.
Value *OldRet = RI->getOperand(0);
// Start out building up our return value from undef
- RetVal = Context->getUndef(NRetTy);
+ RetVal = Context.getUndef(NRetTy);
for (unsigned i = 0; i != RetCount; ++i)
if (NewRetIdxs[i] != -1) {
ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i,
@@ -908,7 +913,6 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
bool DAE::runOnModule(Module &M) {
bool Changed = false;
- Context = &M.getContext();
// First pass: Do a simple check to see if any functions can have their "..."
// removed. We can do this if they never call va_start. This loop cannot be
diff --git a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp b/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp
index f202403d804..85aed2b7915 100644
--- a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp
+++ b/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp
@@ -77,7 +77,6 @@ static inline bool ShouldNukeSymtabEntry(const Type *Ty){
//
bool DTE::runOnModule(Module &M) {
bool Changed = false;
- Context = &M.getContext();
TypeSymbolTable &ST = M.getTypeSymbolTable();
std::set<const Type *> UsedTypes = getAnalysis<FindUsedTypes>().getTypes();
diff --git a/llvm/lib/Transforms/IPO/ExtractGV.cpp b/llvm/lib/Transforms/IPO/ExtractGV.cpp
index fa3a055b20d..57cd1ca1d63 100644
--- a/llvm/lib/Transforms/IPO/ExtractGV.cpp
+++ b/llvm/lib/Transforms/IPO/ExtractGV.cpp
@@ -44,7 +44,6 @@ namespace {
return false; // Nothing to extract
}
- Context = &M.getContext();
if (deleteStuff)
return deleteGV();
@@ -87,6 +86,8 @@ namespace {
}
bool isolateGV(Module &M) {
+ LLVMContext &Context = M.getContext();
+
// Mark all globals internal
// FIXME: what should we do with private linkage?
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
@@ -102,14 +103,14 @@ namespace {
// by putting them in the used array
{
std::vector<Constant *> AUGs;
- const Type *SBP= Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type *SBP= Context.getPointerTypeUnqual(Type::Int8Ty);
for (std::vector<GlobalValue*>::iterator GI = Named.begin(),
GE = Named.end(); GI != GE; ++GI) {
(*GI)->setLinkage(GlobalValue::ExternalLinkage);
- AUGs.push_back(Context->getConstantExprBitCast(*GI, SBP));
+ AUGs.push_back(Context.getConstantExprBitCast(*GI, SBP));
}
- ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
- Constant *Init = Context->getConstantArray(AT, AUGs);
+ ArrayType *AT = Context.getArrayType(SBP, AUGs.size());
+ Constant *Init = Context.getConstantArray(AT, AUGs);
GlobalValue *gv = new GlobalVariable(M, AT, false,
GlobalValue::AppendingLinkage,
Init, "llvm.used");
diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
index 9ecc494d9b5..8e57768570a 100644
--- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp
@@ -58,7 +58,6 @@ ModulePass *llvm::createGlobalDCEPass() { return new GlobalDCE(); }
bool GlobalDCE::runOnModule(Module &M) {
bool Changed = false;
- Context = &M.getContext();
// Loop over the module, adding globals which are obviously necessary.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 9d048b53001..b0363d32b1f 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -247,7 +247,7 @@ static bool AnalyzeGlobal(Value *V, GlobalStatus &GS,
}
static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
- LLVMContext *Context) {
+ LLVMContext &Context) {
ConstantInt *CI = dyn_cast<ConstantInt>(Idx);
if (!CI) return 0;
unsigned IdxV = CI->getZExtValue();
@@ -261,18 +261,18 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
} else if (isa<ConstantAggregateZero>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
if (IdxV < STy->getNumElements())
- return Context->getNullValue(STy->getElementType(IdxV));
+ return Context.getNullValue(STy->getElementType(IdxV));
} else if (const SequentialType *STy =
dyn_cast<SequentialType>(Agg->getType())) {
- return Context->getNullValue(STy->getElementType());
+ return Context.getNullValue(STy->getElementType());
}
} else if (isa<UndefValue>(Agg)) {
if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
if (IdxV < STy->getNumElements())
- return Context->getUndef(STy->getElementType(IdxV));
+ return Context.getUndef(STy->getElementType(IdxV));
} else if (const SequentialType *STy =
dyn_cast<SequentialType>(Agg->getType())) {
- return Context->getUndef(STy->getElementType());
+ return Context.getUndef(STy->getElementType());
}
}
return 0;
@@ -284,7 +284,7 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
/// quick scan over the use list to clean up the easy and obvious cruft. This
/// returns true if it made a change.
static bool CleanupConstantGlobalUsers(Value *V, Constant *Init,
- LLVMContext *Context) {
+ LLVMContext &Context) {
bool Changed = false;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;) {
User *U = *UI++;
@@ -466,7 +466,7 @@ static bool GlobalUsersSafeToSRA(GlobalValue *GV) {
/// this transformation is safe already. We return the first global variable we
/// insert so that the caller can reprocess it.
static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// Make sure this global only has simple uses that we can SRA.
if (!GlobalUsersSafeToSRA(GV))
return 0;
@@ -488,10 +488,10 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
const StructLayout &Layout = *TD.getStructLayout(STy);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
Constant *In = getAggregateConstantElement(Init,
- Context->getConstantInt(Type::Int32Ty, i),
+ Context.getConstantInt(Type::Int32Ty, i),
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(*Context,
+ GlobalVariable *NGV = new GlobalVariable(Context,
STy->getElementType(i), false,
GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i),
@@ -523,11 +523,11 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
unsigned EltAlign = TD.getABITypeAlignment(STy->getElementType());
for (unsigned i = 0, e = NumElements; i != e; ++i) {
Constant *In = getAggregateConstantElement(Init,
- Context->getConstantInt(Type::Int32Ty, i),
+ Context.getConstantInt(Type::Int32Ty, i),
Context);
assert(In && "Couldn't get element of initializer?");
- GlobalVariable *NGV = new GlobalVariable(*Context,
+ GlobalVariable *NGV = new GlobalVariable(Context,
STy->getElementType(), false,
GlobalVariable::InternalLinkage,
In, GV->getName()+"."+utostr(i),
@@ -550,7 +550,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
DOUT << "PERFORMING GLOBAL SRA ON: " << *GV;
- Constant *NullInt = Context->getNullValue(Type::Int32Ty);
+ Constant *NullInt = Context.getNullValue(Type::Int32Ty);
// Loop over all of the uses of the global, replacing the constantexpr geps,
// with smaller constantexpr geps or direct references.
@@ -575,7 +575,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
Idxs.push_back(NullInt);
for (unsigned i = 3, e = CE->getNumOperands(); i != e; ++i)
Idxs.push_back(CE->getOperand(i));
- NewPtr = Context->getConstantExprGetElementPtr(cast<Constant>(NewPtr),
+ NewPtr = Context.getConstantExprGetElementPtr(cast<Constant>(NewPtr),
&Idxs[0], Idxs.size());
} else {
GetElementPtrInst *GEPI = cast<GetElementPtrInst>(GEP);
@@ -675,7 +675,7 @@ static bool AllUsesOfLoadedValueWillTrapIfNull(GlobalVariable *GV) {
}
static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
- LLVMContext *Context) {
+ LLVMContext &Context) {
bool Changed = false;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ) {
Instruction *I = cast<Instruction>(*UI++);
@@ -707,7 +707,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
}
} else if (CastInst *CI = dyn_cast<CastInst>(I)) {
Changed |= OptimizeAwayTrappingUsesOfValue(CI,
- Context->getConstantExprCast(CI->getOpcode(),
+ Context.getConstantExprCast(CI->getOpcode(),
NewV, CI->getType()), Context);
if (CI->use_empty()) {
Changed = true;
@@ -725,7 +725,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
break;
if (Idxs.size() == GEPI->getNumOperands()-1)
Changed |= OptimizeAwayTrappingUsesOfValue(GEPI,
- Context->getConstantExprGetElementPtr(NewV, &Idxs[0],
+ Context.getConstantExprGetElementPtr(NewV, &Idxs[0],
Idxs.size()), Context);
if (GEPI->use_empty()) {
Changed = true;
@@ -743,7 +743,7 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV,
/// if the loaded value is dynamically null, then we know that they cannot be
/// reachable with a null optimize away the load.
static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV,
- LLVMContext *Context) {
+ LLVMContext &Context) {
bool Changed = false;
// Keep track of whether we are able to remove all the uses of the global
@@ -797,7 +797,7 @@ static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV,
/// ConstantPropUsersOf - Walk the use list of V, constant folding all of the
/// instructions that are foldable.
-static void ConstantPropUsersOf(Value *V, LLVMContext *Context) {
+static void ConstantPropUsersOf(Value *V, LLVMContext &Context) {
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; )
if (Instruction *I = dyn_cast<Instruction>(*UI++))
if (Constant *NewC = ConstantFoldInstruction(I, Context)) {
@@ -818,20 +818,20 @@ static void ConstantPropUsersOf(Value *V, LLVMContext *Context) {
/// malloc into a global, and any loads of GV as uses of the new global.
static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
MallocInst *MI,
- LLVMContext *Context) {
+ LLVMContext &Context) {
DOUT << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI;
ConstantInt *NElements = cast<ConstantInt>(MI->getArraySize());
if (NElements->getZExtValue() != 1) {
// If we have an array allocation, transform it to a single element
// allocation to make the code below simpler.
- Type *NewTy = Context->getArrayType(MI->getAllocatedType(),
+ Type *NewTy = Context.getArrayType(MI->getAllocatedType(),
NElements->getZExtValue());
MallocInst *NewMI =
- new MallocInst(NewTy, Context->getNullValue(Type::Int32Ty),
+ new MallocInst(NewTy, Context.getNullValue(Type::Int32Ty),
MI->getAlignment(), MI->getName(), MI);
Value* Indices[2];
- Indices[0] = Indices[1] = Context->getNullValue(Type::Int32Ty);
+ Indices[0] = Indices[1] = Context.getNullValue(Type::Int32Ty);
Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2,
NewMI->getName()+".el0", MI);
MI->replaceAllUsesWith(NewGEP);
@@ -844,7 +844,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// FIXME: This new global should have the alignment returned by malloc. Code
// could depend on malloc returning large alignment (on the mac, 16 bytes) but
// this would only guarantee some lower alignment.
- Constant *Init = Context->getUndef(MI->getAllocatedType());
+ Constant *Init = Context.getUndef(MI->getAllocatedType());
GlobalVariable *NewGV = new GlobalVariable(*GV->getParent(),
MI->getAllocatedType(), false,
GlobalValue::InternalLinkage, Init,
@@ -857,15 +857,15 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
Constant *RepValue = NewGV;
if (NewGV->getType() != GV->getType()->getElementType())
- RepValue = Context->getConstantExprBitCast(RepValue,
+ RepValue = Context.getConstantExprBitCast(RepValue,
GV->getType()->getElementType());
// If there is a comparison against null, we will insert a global bool to
// keep track of whether the global was initialized yet or not.
GlobalVariable *InitBool =
- new GlobalVariable(*Context, Type::Int1Ty, false,
+ new GlobalVariable(Context, Type::Int1Ty, false,
GlobalValue::InternalLinkage,
- Context->getFalse(), GV->getName()+".init",
+ Context.getFalse(), GV->getName()+".init",
GV->isThreadLocal());
bool InitBoolUsed = false;
@@ -886,12 +886,12 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
default: llvm_unreachable("Unknown ICmp Predicate!");
case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_SLT:
- LV = Context->getFalse(); // X < null -> always false
+ LV = Context.getFalse(); // X < null -> always false
break;
case ICmpInst::ICMP_ULE:
case ICmpInst::ICMP_SLE:
case ICmpInst::ICMP_EQ:
- LV = BinaryOperator::CreateNot(*Context, LV, "notinit", CI);
+ LV = BinaryOperator::CreateNot(Context, LV, "notinit", CI);
break;
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
@@ -908,7 +908,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
} else {
StoreInst *SI = cast<StoreInst>(GV->use_back());
// The global is initialized when the store to it occurs.
- new StoreInst(Context->getTrue(), InitBool, SI);
+ new StoreInst(Context.getTrue(), InitBool, SI);
SI->eraseFromParent();
}
@@ -1133,7 +1133,7 @@ static bool AllGlobalLoadUsesSimpleEnoughForHeapSRA(GlobalVariable *GV,
static Value *GetHeapSROAValue(Value *V, unsigned FieldNo,
DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite,
- LLVMContext *Context) {
+ LLVMContext &Context) {
std::vector<Value*> &FieldVals = InsertedScalarizedValues[V];
if (FieldNo >= FieldVals.size())
@@ -1160,7 +1160,7 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo,
cast<StructType>(cast<PointerType>(PN->getType())->getElementType());
Result =
- PHINode::Create(Context->getPointerTypeUnqual(ST->getElementType(FieldNo)),
+ PHINode::Create(Context.getPointerTypeUnqual(ST->getElementType(FieldNo)),
PN->getName()+".f"+utostr(FieldNo), PN);
PHIsToRewrite.push_back(std::make_pair(PN, FieldNo));
} else {
@@ -1176,7 +1176,7 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo,
static void RewriteHeapSROALoadUser(Instruction *LoadUser,
DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// If this is a comparison against null, handle it.
if (ICmpInst *SCI = dyn_cast<ICmpInst>(LoadUser)) {
assert(isa<ConstantPointerNull>(SCI->getOperand(1)));
@@ -1187,7 +1187,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
Context);
Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr,
- Context->getNullValue(NPtr->getType()),
+ Context.getNullValue(NPtr->getType()),
SCI->getName());
SCI->replaceAllUsesWith(New);
SCI->eraseFromParent();
@@ -1247,7 +1247,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser,
static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load,
DenseMap<Value*, std::vector<Value*> > &InsertedScalarizedValues,
std::vector<std::pair<PHINode*, unsigned> > &PHIsToRewrite,
- LLVMContext *Context) {
+ LLVMContext &Context) {
for (Value::use_iterator UI = Load->use_begin(), E = Load->use_end();
UI != E; ) {
Instruction *User = cast<Instruction>(*UI++);
@@ -1264,7 +1264,7 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load,
/// PerformHeapAllocSRoA - MI is an allocation of an array of structures. Break
/// it up into multiple allocations of arrays of the fields.
static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
- LLVMContext *Context){
+ LLVMContext &Context){
DOUT << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *MI;
const StructType *STy = cast<StructType>(MI->getAllocatedType());
@@ -1281,12 +1281,12 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
for (unsigned FieldNo = 0, e = STy->getNumElements(); FieldNo != e;++FieldNo){
const Type *FieldTy = STy->getElementType(FieldNo);
- const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy);
+ const Type *PFieldTy = Context.getPointerTypeUnqual(FieldTy);
GlobalVariable *NGV =
new GlobalVariable(*GV->getParent(),
PFieldTy, false, GlobalValue::InternalLinkage,
- Context->getNullValue(PFieldTy),
+ Context.getNullValue(PFieldTy),
GV->getName() + ".f" + utostr(FieldNo), GV,
GV->isThreadLocal());
FieldGlobals.push_back(NGV);
@@ -1312,7 +1312,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
Value *RunningOr = 0;
for (unsigned i = 0, e = FieldMallocs.size(); i != e; ++i) {
Value *Cond = new ICmpInst(MI, ICmpInst::ICMP_EQ, FieldMallocs[i],
- Context->getNullValue(FieldMallocs[i]->getType()),
+ Context.getNullValue(FieldMallocs[i]->getType()),
"isnull");
if (!RunningOr)
RunningOr = Cond; // First seteq
@@ -1339,7 +1339,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *GVVal = new LoadInst(FieldGlobals[i], "tmp", NullPtrBlock);
Value *Cmp = new ICmpInst(*NullPtrBlock, ICmpInst::ICMP_NE, GVVal,
- Context->getNullValue(GVVal->getType()),
+ Context.getNullValue(GVVal->getType()),
"tmp");
BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
@@ -1347,7 +1347,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Fill in FreeBlock.
new FreeInst(GVVal, FreeBlock);
- new StoreInst(Context->getNullValue(GVVal->getType()), FieldGlobals[i],
+ new StoreInst(Context.getNullValue(GVVal->getType()), FieldGlobals[i],
FreeBlock);
BranchInst::Create(NextBlock, FreeBlock);
@@ -1387,7 +1387,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI,
// Insert a store of null into each global.
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
const PointerType *PT = cast<PointerType>(FieldGlobals[i]->getType());
- Constant *Null = Context->getNullValue(PT->getElementType());
+ Constant *Null = Context.getNullValue(PT->getElementType());
new StoreInst(Null, FieldGlobals[i], SI);
}
// Erase the original store.
@@ -1445,7 +1445,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
MallocInst *MI,
Module::global_iterator &GVI,
TargetData &TD,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// If this is a malloc of an abstract type, don't touch it.
if (!MI->getAllocatedType()->isSized())
return false;
@@ -1508,7 +1508,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) {
MallocInst *NewMI =
new MallocInst(AllocSTy,
- Context->getConstantInt(Type::Int32Ty, AT->getNumElements()),
+ Context.getConstantInt(Type::Int32Ty, AT->getNumElements()),
"", MI);
NewMI->takeName(MI);
Value *Cast = new BitCastInst(NewMI, MI->getType(), "tmp", MI);
@@ -1529,7 +1529,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
// that only one value (besides its initializer) is ever stored to the global.
static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
Module::global_iterator &GVI,
- TargetData &TD, LLVMContext *Context) {
+ TargetData &TD, LLVMContext &Context) {
// Ignore no-op GEPs and bitcasts.
StoredOnceVal = StoredOnceVal->stripPointerCasts();
@@ -1542,7 +1542,7 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
if (Constant *SOVC = dyn_cast<Constant>(StoredOnceVal)) {
if (GV->getInitializer()->getType() != SOVC->getType())
SOVC =
- Context->getConstantExprBitCast(SOVC, GV->getInitializer()->getType());
+ Context.getConstantExprBitCast(SOVC, GV->getInitializer()->getType());
// Optimize away any trapping uses of the loaded value.
if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, Context))
@@ -1561,7 +1561,7 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
/// can shrink the global into a boolean and select between the two values
/// whenever it is used. This exposes the values to other scalar optimizations.
static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
- LLVMContext *Context) {
+ LLVMContext &Context) {
const Type *GVElType = GV->getType()->getElementType();
// If GVElType is already i1, it is already shrunk. If the type of the GV is
@@ -1582,8 +1582,8 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
DOUT << " *** SHRINKING TO BOOL: " << *GV;
// Create the new global, initializing it to false.
- GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
- GlobalValue::InternalLinkage, Context->getFalse(),
+ GlobalVariable *NewGV = new GlobalVariable(Context, Type::Int1Ty, false,
+ GlobalValue::InternalLinkage, Context.getFalse(),
GV->getName()+".b",
GV->isThreadLocal());
GV->getParent()->getGlobalList().insert(GV, NewGV);
@@ -1605,7 +1605,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
// Only do this if we weren't storing a loaded value.
Value *StoreVal;
if (StoringOther || SI->getOperand(0) == InitVal)
- StoreVal = Context->getConstantInt(Type::Int1Ty, StoringOther);
+ StoreVal = Context.getConstantInt(Type::Int1Ty, StoringOther);
else {
// Otherwise, we are storing a previously loaded copy. To do this,
// change the copy from copying the original value to just copying the
@@ -1721,7 +1721,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
// Delete any stores we can find to the global. We may not be able to
// make it completely dead though.
bool Changed = CleanupConstantGlobalUsers(GV, GV->getInitializer(),
- Context);
+ GV->getContext());
// If the global is dead now, delete it.
if (GV->use_empty()) {
@@ -1736,7 +1736,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
GV->setConstant(true);
// Clean up any obviously simplifiable users now.
- CleanupConstantGlobalUsers(GV, GV->getInitializer(), Context);
+ CleanupConstantGlobalUsers(GV, GV->getInitializer(), GV->getContext());
// If the global is dead now, just nuke it.
if (GV->use_empty()) {
@@ -1751,7 +1751,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
} else if (!GV->getInitializer()->getType()->isSingleValueType()) {
if (GlobalVariable *FirstNewGV = SRAGlobal(GV,
getAnalysis<TargetData>(),
- Context)) {
+ GV->getContext())) {
GVI = FirstNewGV; // Don't skip the newly produced globals!
return true;
}
@@ -1766,7 +1766,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
GV->setInitializer(SOVConstant);
// Clean up any obviously simplifiable users now.
- CleanupConstantGlobalUsers(GV, GV->getInitializer(), Context);
+ CleanupConstantGlobalUsers(GV, GV->getInitializer(),
+ GV->getContext());
if (GV->use_empty()) {
DOUT << " *** Substituting initializer allowed us to "
@@ -1783,13 +1784,13 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV,
// Try to optimize globals based on the knowledge that only one value
// (besides its initializer) is ever stored to the global.
if (OptimizeOnceStoredGlobal(GV, GS.StoredOnceValue, GVI,
- getAnalysis<TargetData>(), Context))
+ getAnalysis<TargetData>(), GV->getContext()))
return true;
// Otherwise, if the global was not a boolean, we can shrink it to be a
// boolean.
if (Constant *SOVConstant = dyn_cast<Constant>(GS.StoredOnceValue))
- if (TryToShrinkGlobalToBoolean(GV, SOVConstant, Context)) {
+ if (TryToShrinkGlobalToBoolean(GV, SOVConstant, GV->getContext())) {
++NumShrunkToBool;
return true;
}
@@ -1943,10 +1944,10 @@ static std::vector<Function*> ParseGlobalCtors(GlobalVariable *GV) {
/// specified array, returning the new global to use.
static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
const std::vector<Function*> &Ctors,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// If we made a change, reassemble the initializer list.
std::vector<Constant*> CSVals;
- CSVals.push_back(Context->getConstantInt(Type::Int32Ty, 65535));
+ CSVals.push_back(Context.getConstantInt(Type::Int32Ty, 65535));
CSVals.push_back(0);
// Create the new init list.
@@ -1955,18 +1956,18 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
if (Ctors[i]) {
CSVals[1] = Ctors[i];
} else {
- const Type *FTy = Context->getFunctionType(Type::VoidTy, false);
- const PointerType *PFTy = Context->getPointerTypeUnqual(FTy);
- CSVals[1] = Context->getNullValue(PFTy);
- CSVals[0] = Context->getConstantInt(Type::Int32Ty, 2147483647);
+ const Type *FTy = Context.getFunctionType(Type::VoidTy, false);
+ const PointerType *PFTy = Context.getPointerTypeUnqual(FTy);
+ CSVals[1] = Context.getNullValue(PFTy);
+ CSVals[0] = Context.getConstantInt(Type::Int32Ty, 2147483647);
}
- CAList.push_back(Context->getConstantStruct(CSVals));
+ CAList.push_back(Context.getConstantStruct(CSVals));
}
// Create the array initializer.
const Type *StructTy =
cast<ArrayType>(GCL->getType()->getElementType())->getElementType();
- Constant *CA = Context->getConstantArray(ArrayType::get(StructTy,
+ Constant *CA = Context.getConstantArray(ArrayType::get(StructTy,
CAList.size()), CAList);
// If we didn't change the number of elements, don't create a new GV.
@@ -1976,7 +1977,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
}
// Create the new global and insert it next to the existing list.
- GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
+ GlobalVariable *NGV = new GlobalVariable(Context, CA->getType(),
GCL->isConstant(),
GCL->getLinkage(), CA, "",
GCL->isThreadLocal());
@@ -1987,7 +1988,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
if (!GCL->use_empty()) {
Constant *V = NGV;
if (V->getType() != GCL->getType())
- V = Context->getConstantExprBitCast(V, GCL->getType());
+ V = Context.getConstantExprBitCast(V, GCL->getType());
GCL->replaceAllUsesWith(V);
}
GCL->eraseFromParent();
@@ -2011,7 +2012,7 @@ static Constant *getVal(DenseMap<Value*, Constant*> &ComputedValues,
/// enough for us to understand. In particular, if it is a cast of something,
/// we punt. We basically just support direct accesses to globals and GEP's of
/// globals. This should be kept up to date with CommitValueTo.
-static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext *Context) {
+static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
return false; // do not allow weak/linkonce/dllimport/dllexport linkage.
@@ -2036,7 +2037,7 @@ static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext *Context) {
/// At this point, the GEP operands of Addr [0, OpNo) have been stepped into.
static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
ConstantExpr *Addr, unsigned OpNo,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// Base case of the recursion.
if (OpNo == Addr->getNumOperands()) {
assert(Val->getType() == Init->getType() && "Type mismatch!");
@@ -2052,10 +2053,10 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
- Elts.push_back(Context->getNullValue(STy->getElementType(i)));
+ Elts.push_back(Context.getNullValue(STy->getElementType(i)));
} else if (isa<UndefValue>(Init)) {
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
- Elts.push_back(Context->getUndef(STy->getElementType(i)));
+ Elts.push_back(Context.getUndef(STy->getElementType(i)));
} else {
llvm_unreachable("This code is out of sync with "
" ConstantFoldLoadThroughGEPConstantExpr");
@@ -2068,7 +2069,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1, Context);
// Return the modified struct.
- return Context->getConstantStruct(&Elts[0], Elts.size(), STy->isPacked());
+ return Context.getConstantStruct(&Elts[0], Elts.size(), STy->isPacked());
} else {
ConstantInt *CI = cast<ConstantInt>(Addr->getOperand(OpNo));
const ArrayType *ATy = cast<ArrayType>(Init->getType());
@@ -2079,10 +2080,10 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
for (User::op_iterator i = CA->op_begin(), e = CA->op_end(); i != e; ++i)
Elts.push_back(cast<Constant>(*i));
} else if (isa<ConstantAggregateZero>(Init)) {
- Constant *Elt = Context->getNullValue(ATy->getElementType());
+ Constant *Elt = Context.getNullValue(ATy->getElementType());
Elts.assign(ATy->getNumElements(), Elt);
} else if (isa<UndefValue>(Init)) {
- Constant *Elt = Context->getUndef(ATy->getElementType());
+ Constant *Elt = Context.getUndef(ATy->getElementType());
Elts.assign(ATy->getNumElements(), Elt);
} else {
llvm_unreachable("This code is out of sync with "
@@ -2092,14 +2093,14 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
assert(CI->getZExtValue() < ATy->getNumElements());
Elts[CI->getZExtValue()] =
EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1, Context);
- return Context->getConstantArray(ATy, Elts);
+ return Context.getConstantArray(ATy, Elts);
}
}
/// CommitValueTo - We have decided that Addr (which satisfies the predicate
/// isSimpleEnoughPointerToCommit) should get Val as its value. Make it happen.
static void CommitValueTo(Constant *Val, Constant *Addr,
- LLVMContext *Context) {
+ LLVMContext &Context) {
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Addr)) {
assert(GV->hasInitializer());
GV->setInitializer(Val);
@@ -2119,7 +2120,7 @@ static void CommitValueTo(Constant *Val, Constant *Addr,
/// decide, return null.
static Constant *ComputeLoadResult(Constant *P,
const DenseMap<Constant*, Constant*> &Memory,
- LLVMContext *Context) {
+ LLVMContext &Context) {
// If this memory location has been recently stored, use the stored value: it
// is the most up-to-date.
DenseMap<Constant*, Constant*>::const_iterator I = Memory.find(P);
@@ -2158,7 +2159,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
if (std::find(CallStack.begin(), CallStack.end(), F) != CallStack.end())
return false;
- LLVMContext *Context = F->getContext();
+ LLVMContext &Context = F->getContext();
CallStack.push_back(F);
@@ -2192,20 +2193,20 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
Constant *Val = getVal(Values, SI->getOperand(0));
MutatedMemory[Ptr] = Val;
} else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CurInst)) {
- InstResult = Context->getConstantExpr(BO->getOpcode(),
+ InstResult = Context.getConstantExpr(BO->getOpcode(),
getVal(Values, BO->getOperand(0)),
getVal(Values, BO->getOperand(1)));
} else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) {
- InstResult = Context->getConstantExprCompare(CI->getPredicate(),
+ InstResult = Context.getConstantExprCompare(CI->getPredicate(),
getVal(Values, CI->getOperand(0)),
getVal(Values, CI->getOperand(1)));
} else if (CastInst *CI = dyn_cast<CastInst>(CurInst)) {
- InstResult = Context->getConstantExprCast(CI->getOpcode(),
+ InstResult = Context.getConstantExprCast(CI->getOpcode(),
getVal(Values, CI->getOperand(0)),
CI->getType());
} else if (SelectInst *SI = dyn_cast<SelectInst>(CurInst)) {
InstResult =
- Context->getConstantExprSelect(getVal(Values, SI->getOperand(0)),
+ Context.getConstantExprSelect(getVal(Values, SI->getOperand(0)),
getVal(Values, SI->getOperand(1)),
getVal(Values, SI->getOperand(2)));
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
@@ -2215,7 +2216,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
i != e; ++i)
GEPOps.push_back(getVal(Values, *i));
InstResult =
- Context->getConstantExprGetElementPtr(P, &GEPOps[0], GEPOps.size());
+ Context.getConstantExprGetElementPtr(P, &GEPOps[0], GEPOps.size());
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
if (LI->isVolatile()) return false; // no volatile accesses.
InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)),
@@ -2224,9 +2225,9 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
} else if (AllocaInst *AI = dyn_cast<AllocaInst>(CurInst)) {
if (AI->isArrayAllocation()) return false; // Cannot handle array allocs.
const Type *Ty = AI->getType()->getElementType();
- AllocaTmps.push_back(new GlobalVariable(*Context, Ty, false,
+ AllocaTmps.push_back(new GlobalVariable(Context, Ty, false,
GlobalValue::InternalLinkage,
- Context->getUndef(Ty),
+ Context.getUndef(Ty),
AI->getName()));
InstResult = AllocaTmps.back();
} else if (CallInst *CI = dyn_cast<CallInst>(CurInst)) {
@@ -2368,7 +2369,7 @@ static bool EvaluateStaticConstructor(Function *F) {
// silly, e.g. storing the address of the alloca somewhere and using it
// later. Since this is undefined, we'll just make it be null.
if (!Tmp->use_empty())
- Tmp->replaceAllUsesWith(F->getContext()->getNullValue(Tmp->getType()));
+ Tmp->replaceAllUsesWith(F->getContext().getNullValue(Tmp->getType()));
delete Tmp;
}
@@ -2412,7 +2413,7 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) {
if (!MadeChange) return false;
- GCL = InstallGlobalCtors(GCL, Ctors, Context);
+ GCL = InstallGlobalCtors(GCL, Ctors, GCL->getContext());
return true;
}
@@ -2476,7 +2477,6 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
bool GlobalOpt::runOnModule(Module &M) {
bool Changed = false;
- Context = &M.getContext();
// Try to find the llvm.globalctors list.
GlobalVariable *GlobalCtors = FindGlobalCtors(M);
diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
index 30834e2d672..adb52426397 100644
--- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -56,8 +56,6 @@ bool IPCP::runOnModule(Module &M) {
bool Changed = false;
bool LocalChange = true;
- Context = &M.getContext();
-
// FIXME: instead of using smart algorithms, we just iterate until we stop
// making changes.
while (LocalChange) {
@@ -136,7 +134,7 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
continue;
Value *V = ArgumentConstants[i].first;
- if (V == 0) V = Context->getUndef(AI->getType());
+ if (V == 0) V = F.getContext().getUndef(AI->getType());
AI->replaceAllUsesWith(V);
++NumArgumentsProped;
MadeChange = true;
@@ -161,15 +159,17 @@ bool IPCP::PropagateConstantReturn(Function &F) {
// propagate information about its results into callers.
if (F.mayBeOverridden())
return false;
+
+ LLVMContext &Context = F.getContext();
// Check to see if this function returns a constant.
SmallVector<Value *,4> RetVals;
const StructType *STy = dyn_cast<StructType>(F.getReturnType());
if (STy)
for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i)
- RetVals.push_back(Context->getUndef(STy->getElementType(i)));
+ RetVals.push_back(Context.getUndef(STy->getElementType(i)));
else
- RetVals.push_back(Context->getUndef(F.getReturnType()));
+ RetVals.push_back(Context.getUndef(F.getReturnType()));
unsigned NumNonConstant = 0;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
diff --git a/llvm/lib/Transforms/IPO/IndMemRemoval.cpp b/llvm/lib/Transforms/IPO/IndMemRemoval.cpp
index 7b9b0ccb8b2..2086a166833 100644
--- a/llvm/lib/Transforms/IPO/IndMemRemoval.cpp
+++ b/llvm/lib/Transforms/IPO/IndMemRemoval.cpp
@@ -44,8 +44,6 @@ static RegisterPass<IndMemRemPass>
X("indmemrem","Indirect Malloc and Free Removal");
bool IndMemRemPass::runOnModule(Module &M) {
- Context = &M.getContext();
-
// In theory, all direct calls of malloc and free should be promoted
// to intrinsics. Therefore, this goes through and finds where the
// address of free or malloc are taken and replaces those with bounce
diff --git a/llvm/lib/Transforms/IPO/Internalize.cpp b/llvm/lib/Transforms/IPO/Internalize.cpp
index da92634abf7..042f477e327 100644
--- a/llvm/lib/Transforms/IPO/Internalize.cpp
+++ b/llvm/lib/Transforms/IPO/Internalize.cpp
@@ -102,8 +102,6 @@ bool InternalizePass::runOnModule(Module &M) {
CallGraph *CG = getAnalysisIfAvailable<CallGraph>();
CallGraphNode *ExternalNode = CG ? CG->getExternalCallingNode() : 0;
- Context = &M.getContext();
-
if (ExternalNames.empty()) {
// Return if we're not in 'all but main' mode and have no external api
if (!AllButMain)
diff --git a/llvm/lib/Transforms/IPO/LowerSetJmp.cpp b/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
index bfa2bd9bc24..e5ac22e8c72 100644
--- a/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/llvm/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -134,8 +134,6 @@ static RegisterPass<LowerSetJmp> X("lowersetjmp", "Lower Set Jump");
bool LowerSetJmp::runOnModule(Module& M) {
bool Changed = false;
- Context = &M.getContext();
-
// These are what the functions are called.
Function* SetJmp = M.getFunction("llvm.setjmp");
Function* LongJmp = M.getFunction("llvm.longjmp");
@@ -203,8 +201,9 @@ bool LowerSetJmp::runOnModule(Module& M) {
// This function is always successful, unless it isn't.
bool LowerSetJmp::doInitialization(Module& M)
{
- const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
- const Type *SBPPTy = Context->getPointerTypeUnqual(SBPTy);
+ LLVMContext &Context = M.getContext();
+ const Type *SBPTy = Context.getPointerTypeUnqual(Type::Int8Ty);
+ const Type *SBPPTy = Context.getPointerTypeUnqual(SBPTy);
// N.B. See llvm/runtime/GCCLibraries/libexception/SJLJ-Exception.h for
// a description of the following library functions.
@@ -260,7 +259,7 @@ bool LowerSetJmp::IsTransformableFunction(const std::string& Name) {
// throwing the exception for us.
void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
{
- const Type* SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type* SBPTy = Inst->getContext().getPointerTypeUnqual(Type::Int8Ty);
// Create the call to "__llvm_sjljeh_throw_longjmp". This takes the
// same parameters as "longjmp", except that the buffer is cast to a
@@ -291,7 +290,8 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
Removed = &BB->back();
// If the removed instructions have any users, replace them now.
if (!Removed->use_empty())
- Removed->replaceAllUsesWith(Context->getUndef(Removed->getType()));
+ Removed->replaceAllUsesWith(
+ Inst->getContext().getUndef(Removed->getType()));
Removed->eraseFromParent();
} while (Removed != Inst);
@@ -312,7 +312,7 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func)
assert(Inst && "Couldn't find even ONE instruction in entry block!");
// Fill in the alloca and call to initialize the SJ map.
- const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type *SBPTy = Func->getContext().getPointerTypeUnqual(Type::Int8Ty);
AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
CallInst::Create(InitSJMap, Map, "", Inst);
return SJMap[Func] = Map;
@@ -378,12 +378,12 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
Function* Func = ABlock->getParent();
// Add this setjmp to the setjmp map.
- const Type* SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty);
+ const Type* SBPTy = Inst->getContext().getPointerTypeUnqual(Type::Int8Ty);
CastInst* BufPtr =
new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
std::vector<Value*> Args =
make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
- Context->getConstantInt(Type::Int32Ty,
+ Inst->getContext().getConstantInt(Type::Int32Ty,
SetJmpIDMap[Func]++), 0);
CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst);
@@ -430,11 +430,11 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst);
// Coming from a call to setjmp, the return is 0.
- PHI->addIncoming(Context->getNullValue(Type::Int32Ty), ABlock);
+ PHI->addIncoming(Inst->getContext().getNullValue(Type::Int32Ty), ABlock);
// Add the case for this setjmp's number...
SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));
- SVP.first->addCase(Context->getConstantInt(Type::Int32Ty,
+ SVP.first->addCase(Inst->getContext().getConstantInt(Type::Int32Ty,
SetJmpIDMap[Func] - 1),
SetJmpContBlock);
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index 6d6ecf2b22b..6558100bbb8 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -520,7 +520,7 @@ static void AliasGToF(Function *F, Function *G) {
GlobalAlias *GA = new GlobalAlias(
G->getType(), G->getLinkage(), "",
- F->getContext()->getConstantExprBitCast(F, G->getType()), G->getParent());
+ F->getContext().getConstantExprBitCast(F, G->getType()), G->getParent());
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
@@ -616,8 +616,6 @@ static bool fold(std::vector<Function *> &FnVec, unsigned i, unsigned j) {
bool MergeFunctions::runOnModule(Module &M) {
bool Changed = false;
- Context = &M.getContext();
-
std::map<unsigned long, std::vector<Function *> > FnMap;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp
index a6e090b3170..73ec9c10763 100644
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -141,8 +141,6 @@ Function* PartialInliner::unswitchFunction(Function* F) {
}
bool PartialInliner::runOnModule(Module& M) {
- Context = &M.getContext();
-
std::vector<Function*> worklist;
worklist.reserve(M.size());
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI)
diff --git a/llvm/lib/Transforms/IPO/PartialSpecialization.cpp b/llvm/lib/Transforms/IPO/PartialSpecialization.cpp
index 3b2ce148603..0e1fdb9915a 100644
--- a/llvm/lib/Transforms/IPO/PartialSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/PartialSpecialization.cpp
@@ -108,8 +108,6 @@ SpecializeFunction(Function* F,
bool PartSpec::runOnModule(Module &M) {
- Context = &M.getContext();
-
bool Changed = false;
for (Module::iterator I = M.begin(); I != M.end(); ++I) {
Function &F = *I;
diff --git a/llvm/lib/Transforms/IPO/PruneEH.cpp b/llvm/lib/Transforms/IPO/PruneEH.cpp
index d1b4a379055..a98a7934616 100644
--- a/llvm/lib/Transforms/IPO/PruneEH.cpp
+++ b/llvm/lib/Transforms/IPO/PruneEH.cpp
@@ -243,7 +243,7 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
} else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
CGN->removeCallEdgeFor(II);
if (!I->use_empty())
- I->replaceAllUsesWith(Context->getUndef(I->getType()));
+ I->replaceAllUsesWith(BB->getContext().getUndef(I->getType()));
}
// Get the list of successors of this block.
diff --git a/llvm/lib/Transforms/IPO/RaiseAllocations.cpp b/llvm/lib/Transforms/IPO/RaiseAllocations.cpp
index 8d2a9cbdd5a..3c9178ed0ad 100644
--- a/llvm/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/llvm/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -70,8 +70,8 @@ ModulePass *llvm::createRaiseAllocationsPass() {
// function into the appropriate instruction.
//
void RaiseAllocations::doInitialization(Module &M) {
- Context = &M.getContext();
-
+ LLVMContext &Context = M.getContext();
+
// Get Malloc and free prototypes if they exist!
MallocFunc = M.getFunction("malloc");
if (MallocFunc) {
@@ -79,7 +79,7 @@ void RaiseAllocations::doInitialization(Module &M) {
// Get the expected prototype for malloc
const FunctionType *Malloc1Type =
- Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
+ Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
std::vector<const Type*>(1, Type::Int64Ty), false);
// Chck to see if we got the expected malloc
@@ -87,14 +87,14 @@ void RaiseAllocations::doInitialization(Module &M) {
// Check to see if the prototype is wrong, giving us i8*(i32) * malloc
// This handles the common declaration of: 'void *malloc(unsigned);'
const FunctionType *Malloc2Type =
- Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
+ Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
std::vector<const Type*>(1, Type::Int32Ty), false);
if (TyWeHave != Malloc2Type) {
// Check to see if the prototype is missing, giving us
// i8*(...) * malloc
// This handles the common declaration of: 'void *malloc();'
const FunctionType *Malloc3Type =
- Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty),
+ Context.getFunctionType(Context.getPointerTypeUnqual(Type::Int8Ty),
true);
if (TyWeHave != Malloc3Type)
// Give up
@@ -108,21 +108,21 @@ void RaiseAllocations::doInitialization(Module &M) {
const FunctionType* TyWeHave = FreeFunc->getFunctionType();
// Get the expected prototype for void free(i8*)
- const FunctionType *Free1Type = Context->getFunctionType(Type::VoidTy,
- std::vector<const Type*>(1, Context->getPointerTypeUnqual(Type::Int8Ty)),
+ const FunctionType *Free1Type = Context.getFunctionType(Type::VoidTy,
+ std::vector<const Type*>(1, Context.getPointerTypeUnqual(Type::Int8Ty)),
false);
if (TyWeHave != Free1Type) {
// Check to see if the prototype was forgotten, giving us
// void (...) * free
// This handles the common forward declaration of: 'void free();'
- const FunctionType* Free2Type = Context->getFunctionType(Type::VoidTy,
+ const FunctionType* Free2Type = Context.getFunctionType(Type::VoidTy,
true);
if (TyWeHave != Free2Type) {
// One last try, check to see if we can find free as
// int (...)* free. This handles the case where NOTHING was declared.
- const FunctionType* Free3Type = Context->getFunctionType(Type::Int32Ty,
+ const FunctionType* Free3Type = Context.getFunctionType(Type::Int32Ty,
true);
if (TyWeHave != Free3Type) {
@@ -143,6 +143,8 @@ void RaiseAllocations::doInitialization(Module &M) {
bool RaiseAllocations::runOnModule(Module &M) {
// Find the malloc/free prototypes...
doInitialization(M);
+
+ LLVMContext &Context = M.getContext();
bool Changed = false;
@@ -222,7 +224,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
Value *Source = *CS.arg_begin();
if (!isa<PointerType>(Source->getType()))
Source = new IntToPtrInst(Source,
- Context->getPointerTypeUnqual(Type::Int8Ty),
+ Context.getPointerTypeUnqual(Type::Int8Ty),
"FreePtrCast", I);
new FreeInst(Source, I);
@@ -233,7 +235,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
// Delete the old call site
if (I->getType() != Type::VoidTy)
- I->replaceAllUsesWith(Context->getUndef(I->getType()));
+ I->replaceAllUsesWith(Context.getUndef(I->getType()));
I->eraseFromParent();
Changed = true;
++NumRaised;
diff --git a/llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp b/llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
index 2a1779107a5..a94d78e276c 100644
--- a/llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
+++ b/llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
@@ -42,7 +42,6 @@ X("strip-dead-prototypes", "Strip Unused Function Prototypes");
bool StripDeadPrototypesPass::runOnModule(Module &M) {
bool MadeChange = false;
- Context = &M.getContext();
// Erase dead function prototypes.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index 8f3a7f4a649..d584a906c57 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -369,7 +369,6 @@ bool StripDebugInfo(Module &M) {
}
bool StripSymbols::runOnModule(Module &M) {
- Context = &M.getContext();
bool Changed = false;
Changed |= StripDebugInfo(M);
if (!OnlyDebugInfo)
diff --git a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp b/llvm/lib/Transforms/IPO/StructRetPromotion.cpp
index 933bbb05783..d55e3cce882 100644
--- a/llvm/lib/Transforms/IPO/StructRetPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/StructRetPromotion.cpp
@@ -230,7 +230,8 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
- FunctionType *NFTy = Context->getFunctionType(STy, Params, FTy->isVarArg());
+ FunctionType *NFTy =
+ F->getContext().getFunctionType(STy, Params, FTy->isVarArg());
Function *NF = Function::Create(NFTy, F->getLinkage());
NF->takeName(F);
NF->copyAttributesFrom(F);
OpenPOWER on IntegriCloud