From: Owen Anderson Date: Mon, 6 Jul 2009 01:34:54 +0000 (+0000) Subject: More LLVMContext-ification. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=14ce9ef2e9013ba56e1daafebd91fe3ee1e8647e;p=oota-llvm.git More LLVMContext-ification. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74811 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index a6126340161..75a0415fadf 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -36,6 +36,7 @@ #include "llvm/Module.h" #include "llvm/CallGraphSCCPass.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CallGraph.h" #include "llvm/Target/TargetData.h" @@ -585,7 +586,7 @@ Function *ArgPromotion::DoPromotion(Function *F, } // Construct the new function type using the new arguments. - FunctionType *NFTy = FunctionType::get(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()); @@ -636,9 +637,9 @@ Function *ArgPromotion::DoPromotion(Function *F, // Emit a GEP and load for each element of the struct. const Type *AgTy = cast(I->getType())->getElementType(); const StructType *STy = cast(AgTy); - Value *Idxs[2] = { ConstantInt::get(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] = ConstantInt::get(Type::Int32Ty, i); + Idxs[1] = Context->getConstantInt(Type::Int32Ty, i); Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2, (*AI)->getName()+"."+utostr(i), Call); @@ -663,7 +664,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(ElTy) ? Type::Int32Ty : Type::Int64Ty); - Ops.push_back(ConstantInt::get(IdxTy, *II)); + Ops.push_back(Context->getConstantInt(IdxTy, *II)); // Keep track of the type we're currently indexing ElTy = cast(ElTy)->getTypeAtIndex(*II); } @@ -679,7 +680,7 @@ Function *ArgPromotion::DoPromotion(Function *F, } if (ExtraArgHack) - Args.push_back(Constant::getNullValue(Type::Int32Ty)); + Args.push_back(Context->getNullValue(Type::Int32Ty)); // Push any varargs arguments on the list for (; AI != CS.arg_end(); ++AI, ++ArgIndex) { @@ -756,10 +757,10 @@ Function *ArgPromotion::DoPromotion(Function *F, const Type *AgTy = cast(I->getType())->getElementType(); Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt); const StructType *STy = cast(AgTy); - Value *Idxs[2] = { ConstantInt::get(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] = ConstantInt::get(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); @@ -842,7 +843,7 @@ Function *ArgPromotion::DoPromotion(Function *F, // Notify the alias analysis implementation that we inserted a new argument. if (ExtraArgHack) - AA.copyValue(Constant::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/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index e480dadca89..2e913914d6b 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -24,6 +24,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/CallSite.h" @@ -196,7 +197,8 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { // the old function, but doesn't have isVarArg set. const FunctionType *FTy = Fn.getFunctionType(); std::vector Params(FTy->param_begin(), FTy->param_end()); - FunctionType *NFTy = FunctionType::get(FTy->getReturnType(), Params, false); + FunctionType *NFTy = Context->getFunctionType(FTy->getReturnType(), + Params, false); unsigned NumArgs = Params.size(); // Create the new function body and insert it into the module... @@ -633,7 +635,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 = StructType::get(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. @@ -701,7 +703,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } // Create the new function type based on the recomputed parameters. - FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg()); + FunctionType *NFTy = Context->getFunctionType(NRetTy, Params, + FTy->isVarArg()); // No change? if (NFTy == FTy) @@ -750,7 +753,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { } if (ExtraArgHack) - Args.push_back(UndefValue::get(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) { @@ -789,7 +792,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(Constant::getNullValue(Call->getType())); + Call->replaceAllUsesWith(Context->getNullValue(Call->getType())); } else { assert(isa(RetTy) && "Return type changed, but not into a void. The old return type" @@ -806,7 +809,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 = llvm::UndefValue::get(RetTy); + Value *RetVal = Context->getUndef(RetTy); for (unsigned i = 0; i != RetCount; ++i) if (NewRetIdxs[i] != -1) { Value *V; @@ -852,7 +855,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(Constant::getNullValue(I->getType())); + I->replaceAllUsesWith(Context->getNullValue(I->getType())); } // If we change the return value of the function we must rewrite any return @@ -873,7 +876,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { // clean that up. Value *OldRet = RI->getOperand(0); // Start out building up our return value from undef - RetVal = llvm::UndefValue::get(NRetTy); + RetVal = Context->getUndef(NRetTy); for (unsigned i = 0; i != RetCount; ++i) if (NewRetIdxs[i] != -1) { ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i, diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index 0c529d239d9..8cd5deb6dfe 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Constants.h" @@ -99,14 +100,14 @@ namespace { // by putting them in the used array { std::vector AUGs; - const Type *SBP= PointerType::getUnqual(Type::Int8Ty); + const Type *SBP= Context->getPointerTypeUnqual(Type::Int8Ty); for (std::vector::iterator GI = Named.begin(), GE = Named.end(); GI != GE; ++GI) { (*GI)->setLinkage(GlobalValue::ExternalLinkage); - AUGs.push_back(ConstantExpr::getBitCast(*GI, SBP)); + AUGs.push_back(Context->getConstantExprBitCast(*GI, SBP)); } - ArrayType *AT = ArrayType::get(SBP, AUGs.size()); - Constant *Init = ConstantArray::get(AT, AUGs); + ArrayType *AT = Context->getArrayType(SBP, AUGs.size()); + Constant *Init = Context->getConstantArray(AT, AUGs); GlobalValue *gv = new GlobalVariable(AT, false, GlobalValue::AppendingLinkage, Init, "llvm.used", &M); diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 7fe097c7c57..919da786517 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -20,6 +20,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/ConstantFolding.h" @@ -244,7 +245,8 @@ static bool AnalyzeGlobal(Value *V, GlobalStatus &GS, return false; } -static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx) { +static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx, + LLVMContext* Context) { ConstantInt *CI = dyn_cast(Idx); if (!CI) return 0; unsigned IdxV = CI->getZExtValue(); @@ -258,18 +260,18 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx) { } else if (isa(Agg)) { if (const StructType *STy = dyn_cast(Agg->getType())) { if (IdxV < STy->getNumElements()) - return Constant::getNullValue(STy->getElementType(IdxV)); + return Context->getNullValue(STy->getElementType(IdxV)); } else if (const SequentialType *STy = dyn_cast(Agg->getType())) { - return Constant::getNullValue(STy->getElementType()); + return Context->getNullValue(STy->getElementType()); } } else if (isa(Agg)) { if (const StructType *STy = dyn_cast(Agg->getType())) { if (IdxV < STy->getNumElements()) - return UndefValue::get(STy->getElementType(IdxV)); + return Context->getUndef(STy->getElementType(IdxV)); } else if (const SequentialType *STy = dyn_cast(Agg->getType())) { - return UndefValue::get(STy->getElementType()); + return Context->getUndef(STy->getElementType()); } } return 0; @@ -461,7 +463,8 @@ static bool GlobalUsersSafeToSRA(GlobalValue *GV) { /// behavior of the program in a more fine-grained way. We have determined that /// 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) { +static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, + LLVMContext* Context) { // Make sure this global only has simple uses that we can SRA. if (!GlobalUsersSafeToSRA(GV)) return 0; @@ -483,7 +486,8 @@ 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, - ConstantInt::get(Type::Int32Ty, i)); + Context->getConstantInt(Type::Int32Ty, i), + Context); assert(In && "Couldn't get element of initializer?"); GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false, GlobalVariable::InternalLinkage, @@ -517,7 +521,8 @@ 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, - ConstantInt::get(Type::Int32Ty, i)); + Context->getConstantInt(Type::Int32Ty, i), + Context); assert(In && "Couldn't get element of initializer?"); GlobalVariable *NGV = new GlobalVariable(STy->getElementType(), false, @@ -543,7 +548,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD) { DOUT << "PERFORMING GLOBAL SRA ON: " << *GV; - Constant *NullInt = Constant::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. @@ -568,7 +573,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 = ConstantExpr::getGetElementPtr(cast(NewPtr), + NewPtr = Context->getConstantExprGetElementPtr(cast(NewPtr), &Idxs[0], Idxs.size()); } else { GetElementPtrInst *GEPI = cast(GEP); @@ -667,7 +672,8 @@ static bool AllUsesOfLoadedValueWillTrapIfNull(GlobalVariable *GV) { return true; } -static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { +static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV, + LLVMContext* Context) { bool Changed = false; for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ) { Instruction *I = cast(*UI++); @@ -699,8 +705,8 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { } } else if (CastInst *CI = dyn_cast(I)) { Changed |= OptimizeAwayTrappingUsesOfValue(CI, - ConstantExpr::getCast(CI->getOpcode(), - NewV, CI->getType())); + Context->getConstantExprCast(CI->getOpcode(), + NewV, CI->getType()), Context); if (CI->use_empty()) { Changed = true; CI->eraseFromParent(); @@ -717,8 +723,8 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { break; if (Idxs.size() == GEPI->getNumOperands()-1) Changed |= OptimizeAwayTrappingUsesOfValue(GEPI, - ConstantExpr::getGetElementPtr(NewV, &Idxs[0], - Idxs.size())); + Context->getConstantExprGetElementPtr(NewV, &Idxs[0], + Idxs.size()), Context); if (GEPI->use_empty()) { Changed = true; GEPI->eraseFromParent(); @@ -734,7 +740,8 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { /// value stored into it. If there are uses of the loaded value that would trap /// 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) { +static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV, + LLVMContext* Context) { bool Changed = false; // Keep track of whether we are able to remove all the uses of the global @@ -745,7 +752,7 @@ static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV) { for (Value::use_iterator GUI = GV->use_begin(), E = GV->use_end(); GUI != E;){ User *GlobalUser = *GUI++; if (LoadInst *LI = dyn_cast(GlobalUser)) { - Changed |= OptimizeAwayTrappingUsesOfValue(LI, LV); + Changed |= OptimizeAwayTrappingUsesOfValue(LI, LV, Context); // If we were able to delete all uses of the loads if (LI->use_empty()) { LI->eraseFromParent(); @@ -808,20 +815,21 @@ static void ConstantPropUsersOf(Value *V) { /// malloc, there is no reason to actually DO the malloc. Instead, turn the /// malloc into a global, and any loads of GV as uses of the new global. static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, - MallocInst *MI) { + MallocInst *MI, + LLVMContext* Context) { DOUT << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI; ConstantInt *NElements = cast(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 = ArrayType::get(MI->getAllocatedType(), + Type *NewTy = Context->getArrayType(MI->getAllocatedType(), NElements->getZExtValue()); MallocInst *NewMI = - new MallocInst(NewTy, Constant::getNullValue(Type::Int32Ty), + new MallocInst(NewTy, Context->getNullValue(Type::Int32Ty), MI->getAlignment(), MI->getName(), MI); Value* Indices[2]; - Indices[0] = Indices[1] = Constant::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); @@ -831,7 +839,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, // Create the new global variable. The contents of the malloc'd memory is // undefined, so initialize with an undef value. - Constant *Init = UndefValue::get(MI->getAllocatedType()); + Constant *Init = Context->getUndef(MI->getAllocatedType()); GlobalVariable *NewGV = new GlobalVariable(MI->getAllocatedType(), false, GlobalValue::InternalLinkage, Init, GV->getName()+".body", @@ -847,14 +855,14 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, Constant *RepValue = NewGV; if (NewGV->getType() != GV->getType()->getElementType()) - RepValue = ConstantExpr::getBitCast(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(Type::Int1Ty, false, GlobalValue::InternalLinkage, - ConstantInt::getFalse(), GV->getName()+".init", + Context->getConstantIntFalse(), GV->getName()+".init", (Module *)NULL, GV->isThreadLocal()); bool InitBoolUsed = false; @@ -875,7 +883,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, default: assert(0 && "Unknown ICmp Predicate!"); case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_SLT: - LV = ConstantInt::getFalse(); // X < null -> always false + LV = Context->getConstantIntFalse(); // X < null -> always false break; case ICmpInst::ICMP_ULE: case ICmpInst::ICMP_SLE: @@ -897,7 +905,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, } else { StoreInst *SI = cast(GV->use_back()); // The global is initialized when the store to it occurs. - new StoreInst(ConstantInt::getTrue(), InitBool, SI); + new StoreInst(Context->getConstantIntTrue(), InitBool, SI); SI->eraseFromParent(); } @@ -1121,7 +1129,8 @@ static bool AllGlobalLoadUsesSimpleEnoughForHeapSRA(GlobalVariable *GV, static Value *GetHeapSROAValue(Value *V, unsigned FieldNo, DenseMap > &InsertedScalarizedValues, - std::vector > &PHIsToRewrite) { + std::vector > &PHIsToRewrite, + LLVMContext* Context) { std::vector &FieldVals = InsertedScalarizedValues[V]; if (FieldNo >= FieldVals.size()) @@ -1139,7 +1148,7 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo, // a new Load of the scalarized global. Result = new LoadInst(GetHeapSROAValue(LI->getOperand(0), FieldNo, InsertedScalarizedValues, - PHIsToRewrite), + PHIsToRewrite, Context), LI->getName()+".f" + utostr(FieldNo), LI); } else if (PHINode *PN = dyn_cast(V)) { // PN's type is pointer to struct. Make a new PHI of pointer to struct @@ -1147,7 +1156,8 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo, const StructType *ST = cast(cast(PN->getType())->getElementType()); - Result =PHINode::Create(PointerType::getUnqual(ST->getElementType(FieldNo)), + Result = + PHINode::Create(Context->getPointerTypeUnqual(ST->getElementType(FieldNo)), PN->getName()+".f"+utostr(FieldNo), PN); PHIsToRewrite.push_back(std::make_pair(PN, FieldNo)); } else { @@ -1162,17 +1172,19 @@ static Value *GetHeapSROAValue(Value *V, unsigned FieldNo, /// the load, rewrite the derived value to use the HeapSRoA'd load. static void RewriteHeapSROALoadUser(Instruction *LoadUser, DenseMap > &InsertedScalarizedValues, - std::vector > &PHIsToRewrite) { + std::vector > &PHIsToRewrite, + LLVMContext* Context) { // If this is a comparison against null, handle it. if (ICmpInst *SCI = dyn_cast(LoadUser)) { assert(isa(SCI->getOperand(1))); // If we have a setcc of the loaded pointer, we can use a setcc of any // field. Value *NPtr = GetHeapSROAValue(SCI->getOperand(0), 0, - InsertedScalarizedValues, PHIsToRewrite); + InsertedScalarizedValues, PHIsToRewrite, + Context); Value *New = new ICmpInst(SCI->getPredicate(), NPtr, - Constant::getNullValue(NPtr->getType()), + Context->getNullValue(NPtr->getType()), SCI->getName(), SCI); SCI->replaceAllUsesWith(New); SCI->eraseFromParent(); @@ -1187,7 +1199,8 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser, // Load the pointer for this field. unsigned FieldNo = cast(GEPI->getOperand(2))->getZExtValue(); Value *NewPtr = GetHeapSROAValue(GEPI->getOperand(0), FieldNo, - InsertedScalarizedValues, PHIsToRewrite); + InsertedScalarizedValues, PHIsToRewrite, + Context); // Create the new GEP idx vector. SmallVector GEPIdx; @@ -1219,7 +1232,8 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser, // users. for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); UI != E; ) { Instruction *User = cast(*UI++); - RewriteHeapSROALoadUser(User, InsertedScalarizedValues, PHIsToRewrite); + RewriteHeapSROALoadUser(User, InsertedScalarizedValues, PHIsToRewrite, + Context); } } @@ -1229,11 +1243,13 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser, /// AllGlobalLoadUsesSimpleEnoughForHeapSRA. static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load, DenseMap > &InsertedScalarizedValues, - std::vector > &PHIsToRewrite) { + std::vector > &PHIsToRewrite, + LLVMContext* Context) { for (Value::use_iterator UI = Load->use_begin(), E = Load->use_end(); UI != E; ) { Instruction *User = cast(*UI++); - RewriteHeapSROALoadUser(User, InsertedScalarizedValues, PHIsToRewrite); + RewriteHeapSROALoadUser(User, InsertedScalarizedValues, PHIsToRewrite, + Context); } if (Load->use_empty()) { @@ -1244,7 +1260,8 @@ 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){ +static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, + LLVMContext* Context){ DOUT << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *MI; const StructType *STy = cast(MI->getAllocatedType()); @@ -1261,11 +1278,11 @@ 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 = PointerType::getUnqual(FieldTy); + const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy); GlobalVariable *NGV = new GlobalVariable(PFieldTy, false, GlobalValue::InternalLinkage, - Constant::getNullValue(PFieldTy), + Context->getNullValue(PFieldTy), GV->getName() + ".f" + utostr(FieldNo), GV, GV->isThreadLocal()); FieldGlobals.push_back(NGV); @@ -1291,7 +1308,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(ICmpInst::ICMP_EQ, FieldMallocs[i], - Constant::getNullValue(FieldMallocs[i]->getType()), + Context->getNullValue(FieldMallocs[i]->getType()), "isnull", MI); if (!RunningOr) RunningOr = Cond; // First seteq @@ -1318,7 +1335,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(ICmpInst::ICMP_NE, GVVal, - Constant::getNullValue(GVVal->getType()), + Context->getNullValue(GVVal->getType()), "tmp", NullPtrBlock); BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent()); BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent()); @@ -1326,7 +1343,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ // Fill in FreeBlock. new FreeInst(GVVal, FreeBlock); - new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i], + new StoreInst(Context->getNullValue(GVVal->getType()), FieldGlobals[i], FreeBlock); BranchInst::Create(NextBlock, FreeBlock); @@ -1353,7 +1370,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ Instruction *User = cast(*UI++); if (LoadInst *LI = dyn_cast(User)) { - RewriteUsesOfLoadForHeapSRoA(LI, InsertedScalarizedValues, PHIsToRewrite); + RewriteUsesOfLoadForHeapSRoA(LI, InsertedScalarizedValues, PHIsToRewrite, + Context); continue; } @@ -1365,7 +1383,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(FieldGlobals[i]->getType()); - Constant *Null = Constant::getNullValue(PT->getElementType()); + Constant *Null = Context->getNullValue(PT->getElementType()); new StoreInst(Null, FieldGlobals[i], SI); } // Erase the original store. @@ -1384,7 +1402,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { Value *InVal = PN->getIncomingValue(i); InVal = GetHeapSROAValue(InVal, FieldNo, InsertedScalarizedValues, - PHIsToRewrite); + PHIsToRewrite, Context); FieldPN->addIncoming(InVal, PN->getIncomingBlock(i)); } } @@ -1422,7 +1440,8 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, MallocInst *MI, Module::global_iterator &GVI, - TargetData &TD) { + TargetData &TD, + LLVMContext* Context) { // If this is a malloc of an abstract type, don't touch it. if (!MI->getAllocatedType()->isSized()) return false; @@ -1458,7 +1477,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, // something. if (NElements->getZExtValue()* TD.getTypeAllocSize(MI->getAllocatedType()) < 2048) { - GVI = OptimizeGlobalAddressOfMalloc(GV, MI); + GVI = OptimizeGlobalAddressOfMalloc(GV, MI, Context); return true; } } @@ -1485,7 +1504,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, if (const ArrayType *AT = dyn_cast(MI->getAllocatedType())) { MallocInst *NewMI = new MallocInst(AllocSTy, - ConstantInt::get(Type::Int32Ty, AT->getNumElements()), + Context->getConstantInt(Type::Int32Ty, AT->getNumElements()), "", MI); NewMI->takeName(MI); Value *Cast = new BitCastInst(NewMI, MI->getType(), "tmp", MI); @@ -1494,7 +1513,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, MI = NewMI; } - GVI = PerformHeapAllocSRoA(GV, MI); + GVI = PerformHeapAllocSRoA(GV, MI, Context); return true; } } @@ -1506,7 +1525,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) { + TargetData &TD, LLVMContext* Context) { // Ignore no-op GEPs and bitcasts. StoredOnceVal = StoredOnceVal->stripPointerCasts(); @@ -1518,13 +1537,14 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, GV->getInitializer()->isNullValue()) { if (Constant *SOVC = dyn_cast(StoredOnceVal)) { if (GV->getInitializer()->getType() != SOVC->getType()) - SOVC = ConstantExpr::getBitCast(SOVC, GV->getInitializer()->getType()); + SOVC = + Context->getConstantExprBitCast(SOVC, GV->getInitializer()->getType()); // Optimize away any trapping uses of the loaded value. - if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC)) + if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC, Context)) return true; } else if (MallocInst *MI = dyn_cast(StoredOnceVal)) { - if (TryToOptimizeStoreOfMallocToGlobal(GV, MI, GVI, TD)) + if (TryToOptimizeStoreOfMallocToGlobal(GV, MI, GVI, TD, Context)) return true; } } @@ -1536,7 +1556,8 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, /// two values ever stored into GV are its initializer and OtherVal. See if we /// 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) { +static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, + LLVMContext* Context) { const Type *GVElType = GV->getType()->getElementType(); // If GVElType is already i1, it is already shrunk. If the type of the GV is @@ -1558,7 +1579,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { // Create the new global, initializing it to false. GlobalVariable *NewGV = new GlobalVariable(Type::Int1Ty, false, - GlobalValue::InternalLinkage, ConstantInt::getFalse(), + GlobalValue::InternalLinkage, Context->getConstantIntFalse(), GV->getName()+".b", (Module *)NULL, GV->isThreadLocal()); @@ -1581,7 +1602,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 = ConstantInt::get(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 @@ -1725,7 +1746,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, return true; } else if (!GV->getInitializer()->getType()->isSingleValueType()) { if (GlobalVariable *FirstNewGV = SRAGlobal(GV, - getAnalysis())) { + getAnalysis(), + Context)) { GVI = FirstNewGV; // Don't skip the newly produced globals! return true; } @@ -1757,13 +1779,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())) + getAnalysis(), Context)) return true; // Otherwise, if the global was not a boolean, we can shrink it to be a // boolean. if (Constant *SOVConstant = dyn_cast(GS.StoredOnceValue)) - if (TryToShrinkGlobalToBoolean(GV, SOVConstant)) { + if (TryToShrinkGlobalToBoolean(GV, SOVConstant, Context)) { ++NumShrunkToBool; return true; } @@ -1916,10 +1938,11 @@ static std::vector ParseGlobalCtors(GlobalVariable *GV) { /// InstallGlobalCtors - Given a specified llvm.global_ctors list, install the /// specified array, returning the new global to use. static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, - const std::vector &Ctors) { + const std::vector &Ctors, + LLVMContext* Context) { // If we made a change, reassemble the initializer list. std::vector CSVals; - CSVals.push_back(ConstantInt::get(Type::Int32Ty, 65535)); + CSVals.push_back(Context->getConstantInt(Type::Int32Ty, 65535)); CSVals.push_back(0); // Create the new init list. @@ -1928,19 +1951,19 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, if (Ctors[i]) { CSVals[1] = Ctors[i]; } else { - const Type *FTy = FunctionType::get(Type::VoidTy, false); - const PointerType *PFTy = PointerType::getUnqual(FTy); - CSVals[1] = Constant::getNullValue(PFTy); - CSVals[0] = ConstantInt::get(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(ConstantStruct::get(CSVals)); + CAList.push_back(Context->getConstantStruct(CSVals)); } // Create the array initializer. const Type *StructTy = cast(GCL->getType()->getElementType())->getElementType(); - Constant *CA = ConstantArray::get(ArrayType::get(StructTy, CAList.size()), - CAList); + 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. if (CA->getType() == GCL->getInitializer()->getType()) { @@ -1960,7 +1983,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, if (!GCL->use_empty()) { Constant *V = NGV; if (V->getType() != GCL->getType()) - V = ConstantExpr::getBitCast(V, GCL->getType()); + V = Context->getConstantExprBitCast(V, GCL->getType()); GCL->replaceAllUsesWith(V); } GCL->eraseFromParent(); @@ -2007,7 +2030,8 @@ static bool isSimpleEnoughPointerToCommit(Constant *C) { /// initializer. This returns 'Init' modified to reflect 'Val' stored into it. /// 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) { + ConstantExpr *Addr, unsigned OpNo, + LLVMContext* Context) { // Base case of the recursion. if (OpNo == Addr->getNumOperands()) { assert(Val->getType() == Init->getType() && "Type mismatch!"); @@ -2023,10 +2047,10 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, Elts.push_back(cast(*i)); } else if (isa(Init)) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) - Elts.push_back(Constant::getNullValue(STy->getElementType(i))); + Elts.push_back(Context->getNullValue(STy->getElementType(i))); } else if (isa(Init)) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) - Elts.push_back(UndefValue::get(STy->getElementType(i))); + Elts.push_back(Context->getUndef(STy->getElementType(i))); } else { assert(0 && "This code is out of sync with " " ConstantFoldLoadThroughGEPConstantExpr"); @@ -2036,10 +2060,10 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, ConstantInt *CU = cast(Addr->getOperand(OpNo)); unsigned Idx = CU->getZExtValue(); assert(Idx < STy->getNumElements() && "Struct index out of range!"); - Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1); + Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1, Context); // Return the modified struct. - return ConstantStruct::get(&Elts[0], Elts.size(), STy->isPacked()); + return Context->getConstantStruct(&Elts[0], Elts.size(), STy->isPacked()); } else { ConstantInt *CI = cast(Addr->getOperand(OpNo)); const ArrayType *ATy = cast(Init->getType()); @@ -2050,10 +2074,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(*i)); } else if (isa(Init)) { - Constant *Elt = Constant::getNullValue(ATy->getElementType()); + Constant *Elt = Context->getNullValue(ATy->getElementType()); Elts.assign(ATy->getNumElements(), Elt); } else if (isa(Init)) { - Constant *Elt = UndefValue::get(ATy->getElementType()); + Constant *Elt = Context->getUndef(ATy->getElementType()); Elts.assign(ATy->getNumElements(), Elt); } else { assert(0 && "This code is out of sync with " @@ -2062,14 +2086,15 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val, assert(CI->getZExtValue() < ATy->getNumElements()); Elts[CI->getZExtValue()] = - EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1); - return ConstantArray::get(ATy, Elts); + EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1, Context); + 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) { +static void CommitValueTo(Constant *Val, Constant *Addr, + LLVMContext* Context) { if (GlobalVariable *GV = dyn_cast(Addr)) { assert(GV->hasInitializer()); GV->setInitializer(Val); @@ -2080,7 +2105,7 @@ static void CommitValueTo(Constant *Val, Constant *Addr) { GlobalVariable *GV = cast(CE->getOperand(0)); Constant *Init = GV->getInitializer(); - Init = EvaluateStoreInto(Init, Val, CE, 2); + Init = EvaluateStoreInto(Init, Val, CE, 2, Context); GV->setInitializer(Init); } @@ -2126,6 +2151,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, if (std::find(CallStack.begin(), CallStack.end(), F) != CallStack.end()) return false; + LLVMContext* Context = F->getContext(); + CallStack.push_back(F); /// Values - As we compute SSA register values, we store their contents here. @@ -2158,19 +2185,20 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, Constant *Val = getVal(Values, SI->getOperand(0)); MutatedMemory[Ptr] = Val; } else if (BinaryOperator *BO = dyn_cast(CurInst)) { - InstResult = ConstantExpr::get(BO->getOpcode(), + InstResult = Context->getConstantExpr(BO->getOpcode(), getVal(Values, BO->getOperand(0)), getVal(Values, BO->getOperand(1))); } else if (CmpInst *CI = dyn_cast(CurInst)) { - InstResult = ConstantExpr::getCompare(CI->getPredicate(), + InstResult = Context->getConstantExprCompare(CI->getPredicate(), getVal(Values, CI->getOperand(0)), getVal(Values, CI->getOperand(1))); } else if (CastInst *CI = dyn_cast(CurInst)) { - InstResult = ConstantExpr::getCast(CI->getOpcode(), + InstResult = Context->getConstantExprCast(CI->getOpcode(), getVal(Values, CI->getOperand(0)), CI->getType()); } else if (SelectInst *SI = dyn_cast(CurInst)) { - InstResult = ConstantExpr::getSelect(getVal(Values, SI->getOperand(0)), + InstResult = + Context->getConstantExprSelect(getVal(Values, SI->getOperand(0)), getVal(Values, SI->getOperand(1)), getVal(Values, SI->getOperand(2))); } else if (GetElementPtrInst *GEP = dyn_cast(CurInst)) { @@ -2179,7 +2207,8 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, for (User::op_iterator i = GEP->op_begin() + 1, e = GEP->op_end(); i != e; ++i) GEPOps.push_back(getVal(Values, *i)); - InstResult = ConstantExpr::getGetElementPtr(P, &GEPOps[0], GEPOps.size()); + InstResult = + Context->getConstantExprGetElementPtr(P, &GEPOps[0], GEPOps.size()); } else if (LoadInst *LI = dyn_cast(CurInst)) { if (LI->isVolatile()) return false; // no volatile accesses. InstResult = ComputeLoadResult(getVal(Values, LI->getOperand(0)), @@ -2190,7 +2219,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal, const Type *Ty = AI->getType()->getElementType(); AllocaTmps.push_back(new GlobalVariable(Ty, false, GlobalValue::InternalLinkage, - UndefValue::get(Ty), + Context->getUndef(Ty), AI->getName())); InstResult = AllocaTmps.back(); } else if (CallInst *CI = dyn_cast(CurInst)) { @@ -2319,7 +2348,7 @@ static bool EvaluateStaticConstructor(Function *F) { << " stores.\n"; for (DenseMap::iterator I = MutatedMemory.begin(), E = MutatedMemory.end(); I != E; ++I) - CommitValueTo(I->second, I->first); + CommitValueTo(I->second, I->first, F->getContext()); } // At this point, we are done interpreting. If we created any 'alloca' @@ -2332,7 +2361,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(Constant::getNullValue(Tmp->getType())); + Tmp->replaceAllUsesWith(F->getContext()->getNullValue(Tmp->getType())); delete Tmp; } @@ -2376,7 +2405,7 @@ bool GlobalOpt::OptimizeGlobalCtorsList(GlobalVariable *&GCL) { if (!MadeChange) return false; - GCL = InstallGlobalCtors(GCL, Ctors); + GCL = InstallGlobalCtors(GCL, Ctors, Context); return true; } diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index e4a9deadd97..d3869a8ee4b 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -19,6 +19,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/ValueTracking.h" @@ -133,7 +134,7 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) { continue; Value *V = ArgumentConstants[i].first; - if (V == 0) V = UndefValue::get(AI->getType()); + if (V == 0) V = Context->getUndef(AI->getType()); AI->replaceAllUsesWith(V); ++NumArgumentsProped; MadeChange = true; @@ -164,9 +165,9 @@ bool IPCP::PropagateConstantReturn(Function &F) { const StructType *STy = dyn_cast(F.getReturnType()); if (STy) for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i) - RetVals.push_back(UndefValue::get(STy->getElementType(i))); + RetVals.push_back(Context->getUndef(STy->getElementType(i))); else - RetVals.push_back(UndefValue::get(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/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index dfc040b8334..dfdf5b6f2d4 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -39,6 +39,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" #include "llvm/Intrinsics.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/CFG.h" @@ -200,8 +201,8 @@ bool LowerSetJmp::runOnModule(Module& M) { // This function is always successful, unless it isn't. bool LowerSetJmp::doInitialization(Module& M) { - const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty); - const Type *SBPPTy = PointerType::getUnqual(SBPTy); + 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. @@ -257,7 +258,7 @@ bool LowerSetJmp::IsTransformableFunction(const std::string& Name) { // throwing the exception for us. void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) { - const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type* SBPTy = Context->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 @@ -288,7 +289,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) Removed = &BB->back(); // If the removed instructions have any users, replace them now. if (!Removed->use_empty()) - Removed->replaceAllUsesWith(UndefValue::get(Removed->getType())); + Removed->replaceAllUsesWith(Context->getUndef(Removed->getType())); Removed->eraseFromParent(); } while (Removed != Inst); @@ -309,7 +310,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 = PointerType::getUnqual(Type::Int8Ty); + const Type *SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty); AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst); CallInst::Create(InitSJMap, Map, "", Inst); return SJMap[Func] = Map; @@ -375,12 +376,12 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) Function* Func = ABlock->getParent(); // Add this setjmp to the setjmp map. - const Type* SBPTy = PointerType::getUnqual(Type::Int8Ty); + const Type* SBPTy = Context->getPointerTypeUnqual(Type::Int8Ty); CastInst* BufPtr = new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst); std::vector Args = make_vector(GetSetJmpMap(Func), BufPtr, - ConstantInt::get(Type::Int32Ty, + Context->getConstantInt(Type::Int32Ty, SetJmpIDMap[Func]++), 0); CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst); @@ -427,12 +428,13 @@ 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(ConstantInt::getNullValue(Type::Int32Ty), ABlock); + PHI->addIncoming(Context->getNullValue(Type::Int32Ty), ABlock); // Add the case for this setjmp's number... SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func)); - SVP.first->addCase(ConstantInt::get(Type::Int32Ty, SetJmpIDMap[Func] - 1), - SetJmpContBlock); + SVP.first->addCase(Context->getConstantInt(Type::Int32Ty, + SetJmpIDMap[Func] - 1), + SetJmpContBlock); // Value coming from the handling of the exception. PHI->addIncoming(SVP.second, SVP.second->getParent()); diff --git a/lib/Transforms/IPO/MergeFunctions.cpp b/lib/Transforms/IPO/MergeFunctions.cpp index 5693cc0fc3b..9d87403bdc5 100644 --- a/lib/Transforms/IPO/MergeFunctions.cpp +++ b/lib/Transforms/IPO/MergeFunctions.cpp @@ -47,6 +47,7 @@ #include "llvm/Constants.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Support/CallSite.h" @@ -517,7 +518,7 @@ static void AliasGToF(Function *F, Function *G) { GlobalAlias *GA = new GlobalAlias( G->getType(), G->getLinkage(), "", - ConstantExpr::getBitCast(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()); diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 2b52f464b67..d1b4a379055 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -19,6 +19,7 @@ #include "llvm/CallGraphSCCPass.h" #include "llvm/Constants.h" #include "llvm/Function.h" +#include "llvm/LLVMContext.h" #include "llvm/Instructions.h" #include "llvm/IntrinsicInst.h" #include "llvm/Analysis/CallGraph.h" @@ -242,7 +243,7 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) { } else if (InvokeInst *II = dyn_cast(I)) CGN->removeCallEdgeFor(II); if (!I->use_empty()) - I->replaceAllUsesWith(UndefValue::get(I->getType())); + I->replaceAllUsesWith(Context->getUndef(I->getType())); } // Get the list of successors of this block. diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp index 99003689fb1..6c320509097 100644 --- a/lib/Transforms/IPO/RaiseAllocations.cpp +++ b/lib/Transforms/IPO/RaiseAllocations.cpp @@ -16,6 +16,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Instructions.h" #include "llvm/Pass.h" @@ -77,7 +78,7 @@ void RaiseAllocations::doInitialization(Module &M) { // Get the expected prototype for malloc const FunctionType *Malloc1Type = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), + Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty), std::vector(1, Type::Int64Ty), false); // Chck to see if we got the expected malloc @@ -85,14 +86,15 @@ 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 = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), + Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty), std::vector(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 = - FunctionType::get(PointerType::getUnqual(Type::Int8Ty), true); + Context->getFunctionType(Context->getPointerTypeUnqual(Type::Int8Ty), + true); if (TyWeHave != Malloc3Type) // Give up MallocFunc = 0; @@ -105,19 +107,22 @@ void RaiseAllocations::doInitialization(Module &M) { const FunctionType* TyWeHave = FreeFunc->getFunctionType(); // Get the expected prototype for void free(i8*) - const FunctionType *Free1Type = FunctionType::get(Type::VoidTy, - std::vector(1, PointerType::getUnqual(Type::Int8Ty)), false); + const FunctionType *Free1Type = Context->getFunctionType(Type::VoidTy, + std::vector(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 = FunctionType::get(Type::VoidTy, true); + 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 = FunctionType::get(Type::Int32Ty, true); + const FunctionType* Free3Type = Context->getFunctionType(Type::Int32Ty, + true); if (TyWeHave != Free3Type) { // Give up. @@ -216,7 +221,7 @@ bool RaiseAllocations::runOnModule(Module &M) { Value *Source = *CS.arg_begin(); if (!isa(Source->getType())) Source = new IntToPtrInst(Source, - PointerType::getUnqual(Type::Int8Ty), + Context->getPointerTypeUnqual(Type::Int8Ty), "FreePtrCast", I); new FreeInst(Source, I); @@ -227,7 +232,7 @@ bool RaiseAllocations::runOnModule(Module &M) { // Delete the old call site if (I->getType() != Type::VoidTy) - I->replaceAllUsesWith(UndefValue::get(I->getType())); + I->replaceAllUsesWith(Context->getUndef(I->getType())); I->eraseFromParent(); Changed = true; ++NumRaised; diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index 046e0441b1d..323d1800a9b 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -24,6 +24,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Analysis/DebugInfo.h" @@ -236,7 +237,7 @@ bool StripDebugInfo(Module &M) { if (!GV) continue; if (!GV->use_empty() && llvmUsedValues.count(I) == 0) { if (strncmp(GV->getNameStart(), "llvm.dbg", 8) == 0) { - GV->replaceAllUsesWith(UndefValue::get(GV->getType())); + GV->replaceAllUsesWith(M.getContext().getUndef(GV->getType())); } } } diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index 9f54388aa45..94b37a21911 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -23,6 +23,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/CallGraphSCCPass.h" #include "llvm/Instructions.h" @@ -229,7 +230,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, AttributesVec.push_back(AttributeWithIndex::get(~0, attrs)); - FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg()); + FunctionType *NFTy = Context->getFunctionType(STy, Params, FTy->isVarArg()); Function *NF = Function::Create(NFTy, F->getLinkage()); NF->takeName(F); NF->copyAttributesFrom(F);