From a7235ea7245028a0723e8ab7fd011386b3900777 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 31 Jul 2009 20:28:14 +0000 Subject: Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are metadata related, which I'm waiting on to avoid conflicting with Devang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77721 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/LangImpl5.html | 2 +- docs/tutorial/LangImpl6.html | 2 +- docs/tutorial/LangImpl7.html | 2 +- examples/BrainF/BrainF.cpp | 2 +- examples/Kaleidoscope/toy.cpp | 2 +- include/llvm/Constant.h | 7 + include/llvm/LLVMContext.h | 8 -- include/llvm/Support/IRBuilder.h | 4 +- lib/Analysis/BasicAliasAnalysis.cpp | 16 +-- lib/Analysis/ConstantFolding.cpp | 18 +-- lib/Analysis/DebugInfo.cpp | 8 +- lib/Analysis/IPA/Andersens.cpp | 2 +- lib/Analysis/ScalarEvolution.cpp | 8 +- lib/Analysis/ScalarEvolutionExpander.cpp | 6 +- lib/Analysis/ValueTracking.cpp | 2 +- lib/AsmParser/LLParser.cpp | 2 +- lib/Bitcode/Reader/BitcodeReader.cpp | 4 +- lib/CodeGen/IntrinsicLowering.cpp | 6 +- lib/CodeGen/SelectionDAG/FastISel.cpp | 4 +- lib/CodeGen/ShadowStackGC.cpp | 4 +- lib/CodeGen/UnreachableBlockElim.cpp | 2 +- lib/Linker/LinkModules.cpp | 6 +- lib/Target/CBackend/CBackend.cpp | 10 +- lib/Target/X86/X86FastISel.cpp | 4 +- lib/Target/X86/X86InstrInfo.cpp | 4 +- lib/Transforms/IPO/ArgumentPromotion.cpp | 5 +- lib/Transforms/IPO/DeadArgumentElimination.cpp | 6 +- lib/Transforms/IPO/GlobalOpt.cpp | 30 ++--- lib/Transforms/IPO/LowerSetJmp.cpp | 2 +- lib/Transforms/Instrumentation/BlockProfiling.cpp | 4 +- lib/Transforms/Instrumentation/EdgeProfiling.cpp | 2 +- lib/Transforms/Instrumentation/ProfilingUtils.cpp | 11 +- lib/Transforms/Instrumentation/RSProfiling.cpp | 2 +- lib/Transforms/Scalar/CodeGenPrepare.cpp | 4 +- lib/Transforms/Scalar/InstructionCombining.cpp | 155 +++++++++++----------- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 4 +- lib/Transforms/Scalar/PredicateSimplifier.cpp | 28 ++-- lib/Transforms/Scalar/Reassociate.cpp | 12 +- lib/Transforms/Scalar/Reg2Mem.cpp | 2 +- lib/Transforms/Scalar/SCCP.cpp | 20 +-- lib/Transforms/Scalar/ScalarReplAggregates.cpp | 22 ++- lib/Transforms/Scalar/SimplifyLibCalls.cpp | 14 +- lib/Transforms/Utils/BasicBlockUtils.cpp | 3 +- lib/Transforms/Utils/CodeExtractor.cpp | 16 +-- lib/Transforms/Utils/LowerAllocations.cpp | 4 +- lib/Transforms/Utils/LowerInvoke.cpp | 26 ++-- lib/VMCore/ConstantFold.cpp | 116 ++++++++-------- lib/VMCore/Constants.cpp | 58 ++++++-- lib/VMCore/Core.cpp | 4 +- lib/VMCore/Instructions.cpp | 8 +- lib/VMCore/LLVMContext.cpp | 43 ------ tools/bugpoint/CrashDebugger.cpp | 3 +- tools/bugpoint/ExtractFunction.cpp | 2 +- tools/bugpoint/Miscompilation.cpp | 4 +- tools/bugpoint/TestPasses.cpp | 2 +- unittests/Support/ValueHandleTest.cpp | 2 +- 56 files changed, 350 insertions(+), 399 deletions(-) diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index 8d77d5ec89..9057cae384 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -856,7 +856,7 @@ the loop again and exiting the loop. Any future code is emitted in the NamedValues.erase(VarName); // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 0f714b385a..d845eb86c1 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -1570,7 +1570,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Function *PrototypeAST::Codegen() { diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html index 844c48fff2..691bfacb60 100644 --- a/docs/tutorial/LangImpl7.html +++ b/docs/tutorial/LangImpl7.html @@ -1858,7 +1858,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Value *VarExprAST::Codegen() { diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index e1615569d2..8651b6e918 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -145,7 +145,7 @@ void BrainF::header(LLVMContext& C) { //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0)) { - Constant *zero_32 = C.getNullValue(IntegerType::Int32Ty); + Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty); Constant *gep_params[] = { zero_32, diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 004c7b7c06..22b8285e92 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -856,7 +856,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return TheFunction->getContext().getNullValue(Type::DoubleTy); + return Constant::getNullValue(Type::DoubleTy); } Value *VarExprAST::Codegen() { diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h index 80c88b623f..3b3089748e 100644 --- a/include/llvm/Constant.h +++ b/include/llvm/Constant.h @@ -135,6 +135,13 @@ public: "implemented for all constants that have operands!"); assert(0 && "Constants that do not have operands cannot be using 'From'!"); } + + static Constant* getNullValue(const Type* Ty); + + /// @returns the value for an integer constant of the given type that has all + /// its bits set to true. + /// @brief Get the all ones value + static Constant* getAllOnesValue(const Type* Ty); }; } // End llvm namespace diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 91312f73a8..9150e6160e 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -65,14 +65,6 @@ public: LLVMContext(); ~LLVMContext(); - // Constant accessors - Constant* getNullValue(const Type* Ty); - - /// @returns the value for an integer constant of the given type that has all - /// its bits set to true. - /// @brief Get the all ones value - Constant* getAllOnesValue(const Type* Ty); - // MDNode accessors MDNode* getMDNode(Value* const* Vals, unsigned NumVals); diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index 223fe028e2..d0535c3604 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -705,13 +705,13 @@ public: /// CreateIsNull - Return an i1 value testing if \arg Arg is null. Value *CreateIsNull(Value *Arg, const char *Name = "") { - return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()), + return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name); } /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null. Value *CreateIsNotNull(Value *Arg, const char *Name = "") { - return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()), + return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name); } diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 2badd266c2..a89505549f 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -308,8 +308,6 @@ BasicAliasAnalysis::getModRefInfo(CallSite CS1, CallSite CS2) { AliasAnalysis::AliasResult BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size) { - LLVMContext &Context = V1->getType()->getContext(); - // Strip off any constant expression casts if they exist if (const ConstantExpr *CE = dyn_cast(V1)) if (CE->isCast() && isa(CE->getOperand(0)->getType())) @@ -394,13 +392,13 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, // the base pointers. while (isGEP(GEP1->getOperand(0)) && GEP1->getOperand(1) == - Context.getNullValue(GEP1->getOperand(1)->getType())) + Constant::getNullValue(GEP1->getOperand(1)->getType())) GEP1 = cast(GEP1->getOperand(0)); const Value *BasePtr1 = GEP1->getOperand(0); while (isGEP(GEP2->getOperand(0)) && GEP2->getOperand(1) == - Context.getNullValue(GEP2->getOperand(1)->getType())) + Constant::getNullValue(GEP2->getOperand(1)->getType())) GEP2 = cast(GEP2->getOperand(0)); const Value *BasePtr2 = GEP2->getOperand(0); @@ -480,7 +478,7 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, for (unsigned i = 0; i != GEPOperands.size(); ++i) if (!isa(GEPOperands[i])) GEPOperands[i] = - Context.getNullValue(GEPOperands[i]->getType()); + Constant::getNullValue(GEPOperands[i]->getType()); int64_t Offset = TD->getIndexedOffset(BasePtr->getType(), &GEPOperands[0], @@ -696,7 +694,7 @@ BasicAliasAnalysis::CheckGEPInstructions( // TargetData::getIndexedOffset. for (i = 0; i != MaxOperands; ++i) if (!isa(GEP1Ops[i])) - GEP1Ops[i] = Context.getNullValue(GEP1Ops[i]->getType()); + GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType()); // Okay, now get the offset. This is the relative offset for the full // instruction. int64_t Offset1 = TD->getIndexedOffset(GEPPointerTy, GEP1Ops, @@ -740,7 +738,7 @@ BasicAliasAnalysis::CheckGEPInstructions( const Type *ZeroIdxTy = GEPPointerTy; for (unsigned i = 0; i != FirstConstantOper; ++i) { if (!isa(ZeroIdxTy)) - GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Type::Int32Ty); + GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty); if (const CompositeType *CT = dyn_cast(ZeroIdxTy)) ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]); @@ -755,7 +753,7 @@ BasicAliasAnalysis::CheckGEPInstructions( // If they are equal, use a zero index... if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) { if (!isa(Op1)) - GEP1Ops[i] = GEP2Ops[i] = Context.getNullValue(Op1->getType()); + GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType()); // Otherwise, just keep the constants we have. } else { if (Op1) { @@ -800,7 +798,7 @@ BasicAliasAnalysis::CheckGEPInstructions( return MayAlias; // Be conservative with out-of-range accesses } } else { // Conservatively assume the minimum value for this index - GEP2Ops[i] = Context.getNullValue(Op2->getType()); + GEP2Ops[i] = Constant::getNullValue(Op2->getType()); } } } diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 12ef0174e4..57e781615a 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -215,7 +215,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, SmallVector Result; if (NumDstElt < NumSrcElt) { // Handle: bitcast (<4 x i32> to <2 x i64>) - Constant *Zero = Context.getNullValue(DstEltTy); + Constant *Zero = Constant::getNullValue(DstEltTy); unsigned Ratio = NumSrcElt/NumDstElt; unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits(); unsigned SrcElt = 0; @@ -419,7 +419,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, if (ElemIdx.ult(APInt(ElemIdx.getBitWidth(), AT->getNumElements()))) { Constant *Index[] = { - Context.getNullValue(CE->getType()), + Constant::getNullValue(CE->getType()), ConstantInt::get(Context, ElemIdx) }; return @@ -486,7 +486,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, // proper extension or truncation. Constant *C = ConstantExpr::getIntegerCast(CE0->getOperand(0), IntPtrTy, false); - Constant *NewOps[] = { C, Context.getNullValue(C->getType()) }; + Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, Context, TD); } @@ -496,7 +496,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, if (CE0->getOpcode() == Instruction::PtrToInt && CE0->getType() == IntPtrTy) { Constant *C = CE0->getOperand(0); - Constant *NewOps[] = { C, Context.getNullValue(C->getType()) }; + Constant *NewOps[] = { C, Constant::getNullValue(C->getType()) }; // FIXME! return ConstantFoldCompareInstOperands(Predicate, NewOps, 2, Context, TD); @@ -543,7 +543,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(unsigned Predicate, Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE, LLVMContext &Context) { - if (CE->getOperand(1) != Context.getNullValue(CE->getOperand(1)->getType())) + if (CE->getOperand(1) != Constant::getNullValue(CE->getOperand(1)->getType())) return 0; // Do not allow stepping over the value! // Loop over all of the operands, tracking down which value we are @@ -558,7 +558,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantStruct *CS = dyn_cast(C)) { C = CS->getOperand(El); } else if (isa(C)) { - C = Context.getNullValue(STy->getElementType(El)); + C = Constant::getNullValue(STy->getElementType(El)); } else if (isa(C)) { C = UndefValue::get(STy->getElementType(El)); } else { @@ -571,7 +571,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantArray *CA = dyn_cast(C)) C = CA->getOperand(CI->getZExtValue()); else if (isa(C)) - C = Context.getNullValue(ATy->getElementType()); + C = Constant::getNullValue(ATy->getElementType()); else if (isa(C)) C = UndefValue::get(ATy->getElementType()); else @@ -582,7 +582,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, if (ConstantVector *CP = dyn_cast(C)) C = CP->getOperand(CI->getZExtValue()); else if (isa(C)) - C = Context.getNullValue(PTy->getElementType()); + C = Constant::getNullValue(PTy->getElementType()); else if (isa(C)) C = UndefValue::get(PTy->getElementType()); else @@ -741,7 +741,7 @@ llvm::ConstantFoldCall(Function *F, if (V >= -0.0) return ConstantFoldFP(sqrt, V, Ty, Context); else // Undefined - return Context.getNullValue(Ty); + return Constant::getNullValue(Ty); } break; case 's': diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 5ecfdcdd44..1e2913477d 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -476,7 +476,7 @@ DIFactory::DIFactory(Module &m) /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { - if (D.isNull()) return VMContext.getNullValue(EmptyStructPtr); + if (D.isNull()) return llvm::Constant::getNullValue(EmptyStructPtr); return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); } @@ -576,7 +576,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), ConstantInt::get(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), @@ -737,7 +737,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), @@ -769,7 +769,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, bool isDefinition, llvm::GlobalVariable *Val) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), - VMContext.getNullValue(EmptyStructPtr), + llvm::Constant::getNullValue(EmptyStructPtr), getCastToEmpty(Context), GetStringConstant(Name), GetStringConstant(DisplayName), diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 84cde63f95..3c07d24bef 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -693,7 +693,7 @@ void Andersens::getMustAliases(Value *P, std::vector &RetVals) { // If the object in the points-to set is the null object, then the null // pointer is a must alias. if (Pointee == &GraphNodes[NullObject]) - RetVals.push_back(P->getContext().getNullValue(P->getType())); + RetVals.push_back(Constant::getNullValue(P->getType())); } } AliasAnalysis::getMustAliases(P, RetVals); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 8c4d191efb..03f3cd66ae 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2100,7 +2100,7 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) { const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); return getMulExpr(V, - getConstant(cast(getContext().getAllOnesValue(Ty)))); + getConstant(cast(Constant::getAllOnesValue(Ty)))); } /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V @@ -2112,7 +2112,7 @@ const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) { const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); const SCEV *AllOnes = - getConstant(cast(getContext().getAllOnesValue(Ty))); + getConstant(cast(Constant::getAllOnesValue(Ty))); return getMinusSCEV(AllOnes, V); } @@ -3479,10 +3479,10 @@ GetAddressedElementFromGlobal(LLVMContext &Context, GlobalVariable *GV, } else if (isa(Init)) { if (const StructType *STy = dyn_cast(Init->getType())) { assert(Idx < STy->getNumElements() && "Bad struct index!"); - Init = Context.getNullValue(STy->getElementType(Idx)); + Init = Constant::getNullValue(STy->getElementType(Idx)); } else if (const ArrayType *ATy = dyn_cast(Init->getType())) { if (Idx >= ATy->getNumElements()) return 0; // Bogus program - Init = Context.getNullValue(ATy->getElementType()); + Init = Constant::getNullValue(ATy->getElementType()); } else { llvm_unreachable("Unknown constant aggregate type!"); } diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index b6c30fbc67..40bf0a1a02 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -285,7 +285,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, Ops = NewOps; AnyNonZeroIndices |= !ScaledOps.empty(); Value *Scaled = ScaledOps.empty() ? - getContext().getNullValue(Ty) : + Constant::getNullValue(Ty) : expandCodeFor(SE.getAddExpr(ScaledOps), Ty); GepIndices.push_back(Scaled); @@ -401,7 +401,7 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) { // -1 * ... ---> 0 - ... if (FirstOp == 1) - V = InsertBinop(Instruction::Sub, getContext().getNullValue(Ty), V); + V = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), V); return V; } @@ -523,7 +523,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { BasicBlock *Preheader = L->getLoopPreheader(); PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin()); InsertedValues.insert(PN); - PN->addIncoming(getContext().getNullValue(Ty), Preheader); + PN->addIncoming(Constant::getNullValue(Ty), Preheader); pred_iterator HPI = pred_begin(Header); assert(HPI != pred_end(Header) && "Loop with zero preds???"); diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 70f11f4f72..0ed0bbdc33 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -917,7 +917,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, idx_begin, idx_end)); else if (isa(V)) - return Context.getNullValue(ExtractValueInst::getIndexedType(PTy, + return Constant::getNullValue(ExtractValueInst::getIndexedType(PTy, idx_begin, idx_end)); else if (Constant *C = dyn_cast(V)) { diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 16dc32f55d..ac3570216d 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2211,7 +2211,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, // FIXME: LabelTy should not be a first-class type. if (!Ty->isFirstClassType() || Ty == Type::LabelTy) return Error(ID.Loc, "invalid type for null constant"); - V = Context.getNullValue(Ty); + V = Constant::getNullValue(Ty); return false; case ValID::t_Constant: if (ID.ConstantVal->getType() != Ty) diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index a58e68f183..40920d87e9 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -898,7 +898,7 @@ bool BitcodeReader::ParseConstants() { CurTy = TypeList[Record[0]]; continue; // Skip the ValueList manipulation. case bitc::CST_CODE_NULL: // NULL - V = Context.getNullValue(CurTy); + V = Constant::getNullValue(CurTy); break; case bitc::CST_CODE_INTEGER: // INTEGER: [intval] if (!isa(CurTy) || Record.empty()) @@ -993,7 +993,7 @@ bool BitcodeReader::ParseConstants() { std::vector Elts; for (unsigned i = 0; i != Size; ++i) Elts.push_back(ConstantInt::get(EltTy, Record[i])); - Elts.push_back(Context.getNullValue(EltTy)); + Elts.push_back(Constant::getNullValue(EltTy)); V = ConstantArray::get(ATy, Elts); break; } diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 113eea0777..67e4e6f762 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -346,7 +346,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { } case Intrinsic::sigsetjmp: if (CI->getType() != Type::VoidTy) - CI->replaceAllUsesWith(Context.getNullValue(CI->getType())); + CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); break; case Intrinsic::longjmp: { @@ -393,7 +393,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { "save" : "restore") << " intrinsic.\n"; Warned = true; if (Callee->getIntrinsicID() == Intrinsic::stacksave) - CI->replaceAllUsesWith(Context.getNullValue(CI->getType())); + CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); break; } @@ -428,7 +428,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::eh_exception: case Intrinsic::eh_selector_i32: case Intrinsic::eh_selector_i64: - CI->replaceAllUsesWith(Context.getNullValue(CI->getType())); + CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); break; case Intrinsic::eh_typeid_for_i32: diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 01493bbba7..1b38fca93d 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -92,7 +92,7 @@ unsigned FastISel::getRegForValue(Value *V) { } else if (isa(V)) { // Translate this as an integer zero so that it can be // local-CSE'd with actual integer zeros. - Reg = getRegForValue(V->getContext().getNullValue(TD.getIntPtrType())); + Reg = getRegForValue(Constant::getNullValue(TD.getIntPtrType())); } else if (ConstantFP *CF = dyn_cast(V)) { Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); @@ -481,7 +481,7 @@ bool FastISel::SelectCall(User *I) { UpdateValueMap(I, ResultReg); } else { unsigned ResultReg = - getRegForValue(I->getContext().getNullValue(I->getType())); + getRegForValue(Constant::getNullValue(I->getType())); UpdateValueMap(I, ResultReg); } return true; diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index b412532e33..3aa86d04f8 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -294,10 +294,10 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) { // linkage! Head = new GlobalVariable(M, StackEntryPtrTy, false, GlobalValue::LinkOnceAnyLinkage, - M.getContext().getNullValue(StackEntryPtrTy), + Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain"); } else if (Head->hasExternalLinkage() && Head->isDeclaration()) { - Head->setInitializer(M.getContext().getNullValue(StackEntryPtrTy)); + Head->setInitializer(Constant::getNullValue(StackEntryPtrTy)); Head->setLinkage(GlobalValue::LinkOnceAnyLinkage); } diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp index 27b9627e59..c3b213cebe 100644 --- a/lib/CodeGen/UnreachableBlockElim.cpp +++ b/lib/CodeGen/UnreachableBlockElim.cpp @@ -68,7 +68,7 @@ bool UnreachableBlockElim::runOnFunction(Function &F) { BasicBlock *BB = I; DeadBlocks.push_back(BB); while (PHINode *PN = dyn_cast(BB->begin())) { - PN->replaceAllUsesWith(F.getContext().getNullValue(PN->getType())); + PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); BB->getInstList().pop_front(); } for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 4d9b061c08..ccab2de7eb 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1108,8 +1108,6 @@ static bool LinkAppendingVars(Module *M, std::string *ErrorMsg) { if (AppendingVars.empty()) return false; // Nothing to do. - LLVMContext &Context = M->getContext(); - // Loop over the multimap of appending vars, processing any variables with the // same name, forming a new appending global variable with both of the // initializers merged together, then rewrite references to the old variables @@ -1169,7 +1167,7 @@ static bool LinkAppendingVars(Module *M, Inits.push_back(I->getOperand(i)); } else { assert(isa(G1->getInitializer())); - Constant *CV = Context.getNullValue(T1->getElementType()); + Constant *CV = Constant::getNullValue(T1->getElementType()); for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) Inits.push_back(CV); } @@ -1178,7 +1176,7 @@ static bool LinkAppendingVars(Module *M, Inits.push_back(I->getOperand(i)); } else { assert(isa(G2->getInitializer())); - Constant *CV = Context.getNullValue(T2->getElementType()); + Constant *CV = Constant::getNullValue(T2->getElementType()); for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) Inits.push_back(CV); } diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index d110684c47..6e71d3bd60 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1236,7 +1236,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) { Out << '{'; if (AT->getNumElements()) { Out << ' '; - Constant *CZ = CPV->getContext().getNullValue(AT->getElementType()); + Constant *CZ = Constant::getNullValue(AT->getElementType()); printConstant(CZ, Static); for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { Out << ", "; @@ -1261,7 +1261,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) { assert(isa(CPV) || isa(CPV)); const VectorType *VT = cast(CPV->getType()); Out << "{ "; - Constant *CZ = CPV->getContext().getNullValue(VT->getElementType()); + Constant *CZ = Constant::getNullValue(VT->getElementType()); printConstant(CZ, Static); for (unsigned i = 1, e = VT->getNumElements(); i != e; ++i) { Out << ", "; @@ -1283,12 +1283,10 @@ void CWriter::printConstant(Constant *CPV, bool Static) { Out << '{'; if (ST->getNumElements()) { Out << ' '; - printConstant( - CPV->getContext().getNullValue(ST->getElementType(0)), Static); + printConstant(Constant::getNullValue(ST->getElementType(0)), Static); for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) { Out << ", "; - printConstant( - CPV->getContext().getNullValue(ST->getElementType(i)), Static); + printConstant(Constant::getNullValue(ST->getElementType(i)), Static); } } Out << " }"; diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index a01f2d09e2..de519e4fec 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -272,7 +272,7 @@ bool X86FastISel::X86FastEmitStore(MVT VT, Value *Val, const X86AddressMode &AM) { // Handle 'null' like i32/i64 0. if (isa(Val)) - Val = Val->getContext().getNullValue(TD.getIntPtrType()); + Val = Constant::getNullValue(TD.getIntPtrType()); // If this is a store of a simple constant, fold the constant into the store. if (ConstantInt *CI = dyn_cast(Val)) { @@ -672,7 +672,7 @@ bool X86FastISel::X86FastEmitCompare(Value *Op0, Value *Op1, MVT VT) { // Handle 'null' like i32/i64 0. if (isa(Op1)) - Op1 = Op0->getContext().getNullValue(TD.getIntPtrType()); + Op1 = Constant::getNullValue(TD.getIntPtrType()); // We have two options: compare with register or immediate. If the RHS of // the compare is an immediate that we can fold into this compare, use diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index afdb0f0f77..8ecb766847 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -2297,8 +2297,8 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF, MachineConstantPool &MCP = *MF.getConstantPool(); const VectorType *Ty = VectorType::get(Type::Int32Ty, 4); Constant *C = LoadMI->getOpcode() == X86::V_SET0 ? - MF.getFunction()->getContext().getNullValue(Ty) : - MF.getFunction()->getContext().getAllOnesValue(Ty); + Constant::getNullValue(Ty) : + Constant::getAllOnesValue(Ty); unsigned CPI = MCP.getConstantPoolIndex(C, 16); // Create operands to load from the constant pool entry. diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 69df49796a..f3e0b18573 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -576,7 +576,6 @@ 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. @@ -681,7 +680,7 @@ Function *ArgPromotion::DoPromotion(Function *F, } if (ExtraArgHack) - Args.push_back(Context.getNullValue(Type::Int32Ty)); + Args.push_back(Constant::getNullValue(Type::Int32Ty)); // Push any varargs arguments on the list for (; AI != CS.arg_end(); ++AI, ++ArgIndex) { @@ -845,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(Constant::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 fbdca723f6..47f5e65ccd 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -601,8 +601,6 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) { const Type *NRetTy = NULL; unsigned RetCount = NumRetVals(F); - LLVMContext &Context = RetTy->getContext(); - // -1 means unused, other numbers are the new index SmallVector NewRetIdxs(RetCount, -1); std::vector RetTypes; @@ -797,7 +795,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(Constant::getNullValue(Call->getType())); } else { assert(isa(RetTy) && "Return type changed, but not into a void. The old return type" @@ -860,7 +858,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(Constant::getNullValue(I->getType())); } // If we change the return value of the function we must rewrite any return diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index b6eb45d653..35e3fe91f5 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -261,10 +261,10 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx, } else if (isa(Agg)) { if (const StructType *STy = dyn_cast(Agg->getType())) { if (IdxV < STy->getNumElements()) - return Context.getNullValue(STy->getElementType(IdxV)); + return Constant::getNullValue(STy->getElementType(IdxV)); } else if (const SequentialType *STy = dyn_cast(Agg->getType())) { - return Context.getNullValue(STy->getElementType()); + return Constant::getNullValue(STy->getElementType()); } } else if (isa(Agg)) { if (const StructType *STy = dyn_cast(Agg->getType())) { @@ -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 = Constant::getNullValue(Type::Int32Ty); // Loop over all of the uses of the global, replacing the constantexpr geps, // with smaller constantexpr geps or direct references. @@ -828,10 +828,10 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, Type *NewTy = ArrayType::get(MI->getAllocatedType(), NElements->getZExtValue()); MallocInst *NewMI = - new MallocInst(NewTy, Context.getNullValue(Type::Int32Ty), + new MallocInst(NewTy, Constant::getNullValue(Type::Int32Ty), MI->getAlignment(), MI->getName(), MI); Value* Indices[2]; - Indices[0] = Indices[1] = Context.getNullValue(Type::Int32Ty); + Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty); Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2, NewMI->getName()+".el0", MI); MI->replaceAllUsesWith(NewGEP); @@ -1187,7 +1187,7 @@ static void RewriteHeapSROALoadUser(Instruction *LoadUser, Context); Value *New = new ICmpInst(SCI, SCI->getPredicate(), NPtr, - Context.getNullValue(NPtr->getType()), + Constant::getNullValue(NPtr->getType()), SCI->getName()); SCI->replaceAllUsesWith(New); SCI->eraseFromParent(); @@ -1286,7 +1286,7 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, GlobalVariable *NGV = new GlobalVariable(*GV->getParent(), PFieldTy, false, GlobalValue::InternalLinkage, - Context.getNullValue(PFieldTy), + Constant::getNullValue(PFieldTy), GV->getName() + ".f" + Twine(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()), + Constant::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()), + Constant::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(Constant::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(FieldGlobals[i]->getType()); - Constant *Null = Context.getNullValue(PT->getElementType()); + Constant *Null = Constant::getNullValue(PT->getElementType()); new StoreInst(Null, FieldGlobals[i], SI); } // Erase the original store. @@ -1958,7 +1958,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, } else { const Type *FTy = FunctionType::get(Type::VoidTy, false); const PointerType *PFTy = PointerType::getUnqual(FTy); - CSVals[1] = Context.getNullValue(PFTy); + CSVals[1] = Constant::getNullValue(PFTy); CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647); } CAList.push_back(ConstantStruct::get(CSVals)); @@ -2053,7 +2053,7 @@ 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(Context.getNullValue(STy->getElementType(i))); + Elts.push_back(Constant::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))); @@ -2080,7 +2080,7 @@ 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 = Context.getNullValue(ATy->getElementType()); + Constant *Elt = Constant::getNullValue(ATy->getElementType()); Elts.assign(ATy->getNumElements(), Elt); } else if (isa(Init)) { Constant *Elt = UndefValue::get(ATy->getElementType()); @@ -2369,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(Constant::getNullValue(Tmp->getType())); delete Tmp; } diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index 3a65ac7a8f..568798bd3a 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -427,7 +427,7 @@ 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(Inst->getContext().getNullValue(Type::Int32Ty), ABlock); + PHI->addIncoming(Constant::getNullValue(Type::Int32Ty), ABlock); // Add the case for this setjmp's number... SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func)); diff --git a/lib/Transforms/Instrumentation/BlockProfiling.cpp b/lib/Transforms/Instrumentation/BlockProfiling.cpp index 700260db46..9139c92235 100644 --- a/lib/Transforms/Instrumentation/BlockProfiling.cpp +++ b/lib/Transforms/Instrumentation/BlockProfiling.cpp @@ -66,7 +66,7 @@ bool FunctionProfiler::runOnModule(Module &M) { const Type *ATy = ArrayType::get(Type::Int32Ty, NumFunctions); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, - M.getContext().getNullValue(ATy), "FuncProfCounters"); + Constant::getNullValue(ATy), "FuncProfCounters"); // Instrument all of the functions... unsigned i = 0; @@ -111,7 +111,7 @@ bool BlockProfiler::runOnModule(Module &M) { const Type *ATy = ArrayType::get(Type::Int32Ty, NumBlocks); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, - M.getContext().getNullValue(ATy), "BlockProfCounters"); + Constant::getNullValue(ATy), "BlockProfCounters"); // Instrument all of the blocks... unsigned i = 0; diff --git a/lib/Transforms/Instrumentation/EdgeProfiling.cpp b/lib/Transforms/Instrumentation/EdgeProfiling.cpp index b900945dac..f291b44547 100644 --- a/lib/Transforms/Instrumentation/EdgeProfiling.cpp +++ b/lib/Transforms/Instrumentation/EdgeProfiling.cpp @@ -67,7 +67,7 @@ bool EdgeProfiler::runOnModule(Module &M) { const Type *ATy = ArrayType::get(Type::Int32Ty, NumEdges); GlobalVariable *Counters = new GlobalVariable(M, ATy, false, GlobalValue::InternalLinkage, - M.getContext().getNullValue(ATy), "EdgeProfCounters"); + Constant::getNullValue(ATy), "EdgeProfCounters"); // Instrument all of the edges... unsigned i = 0; diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp index 6e5b523d6c..dc34bf70a3 100644 --- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp @@ -23,7 +23,6 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Array) { - LLVMContext &Context = MainFn->getContext(); const Type *ArgVTy = PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)); const PointerType *UIntPtr = PointerType::getUnqual(Type::Int32Ty); @@ -35,15 +34,15 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, // This could force argc and argv into programs that wouldn't otherwise have // them, but instead we just pass null values in. std::vector Args(4); - Args[0] = Context.getNullValue(Type::Int32Ty); - Args[1] = Context.getNullValue(ArgVTy); + Args[0] = Constant::getNullValue(Type::Int32Ty); + Args[1] = Constant::getNullValue(ArgVTy); // Skip over any allocas in the entry block. BasicBlock *Entry = MainFn->begin(); BasicBlock::iterator InsertPos = Entry->begin(); while (isa(InsertPos)) ++InsertPos; - std::vector GEPIndices(2, Context.getNullValue(Type::Int32Ty)); + std::vector GEPIndices(2, Constant::getNullValue(Type::Int32Ty)); unsigned NumElements = 0; if (Array) { Args[2] = ConstantExpr::getGetElementPtr(Array, &GEPIndices[0], @@ -101,8 +100,6 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, GlobalValue *CounterArray) { - LLVMContext &Context = BB->getContext(); - // Insert the increment after any alloca or PHI instructions... BasicBlock::iterator InsertPos = BB->getFirstNonPHI(); while (isa(InsertPos)) @@ -110,7 +107,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, // Create the getelementptr constant expression std::vector Indices(2); - Indices[0] = Context.getNullValue(Type::Int32Ty); + Indices[0] = Constant::getNullValue(Type::Int32Ty); Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); Constant *ElementPtr = ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index 2afc0cb272..e2aa10924c 100644 --- a/lib/Transforms/Instrumentation/RSProfiling.cpp +++ b/lib/Transforms/Instrumentation/RSProfiling.cpp @@ -350,7 +350,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu // Create the getelementptr constant expression std::vector Indices(2); - Indices[0] = BB->getContext().getNullValue(Type::Int32Ty); + Indices[0] = Constant::getNullValue(Type::Int32Ty); Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); Constant *ElementPtr =ConstantExpr::getGetElementPtr(CounterArray, &Indices[0], 2); diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 4e8bc4b3bb..cae70cdd46 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -560,8 +560,6 @@ static bool IsNonLocalValue(Value *V, BasicBlock *BB) { bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, const Type *AccessTy, DenseMap &SunkAddrs) { - LLVMContext &Context = MemoryInst->getContext(); - // Figure out what addressing mode will be built up for this operation. SmallVector AddrModeInsts; ExtAddrMode AddrMode = AddressingModeMatcher::Match(Addr, AccessTy,MemoryInst, @@ -658,7 +656,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, } if (Result == 0) - SunkAddr = Context.getNullValue(Addr->getType()); + SunkAddr = Constant::getNullValue(Addr->getType()); else SunkAddr = new IntToPtrInst(Result, Addr->getType(), "sunkaddr",InsertPt); } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9f7ff59f11..0a6153db81 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -857,7 +857,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // If all of the demanded bits in the inputs are known zeros, return zero. if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask) - return Context->getNullValue(VTy); + return Constant::getNullValue(VTy); } else if (I->getOpcode() == Instruction::Or) { // We can simplify (X|Y) -> X or Y in the user's context if we know that @@ -926,7 +926,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // If all of the demanded bits in the inputs are known zeros, return zero. if ((DemandedMask & (RHSKnownZero|LHSKnownZero)) == DemandedMask) - return Context->getNullValue(VTy); + return Constant::getNullValue(VTy); // If the RHS is a constant, see if we can simplify it. if (ShrinkDemandedConstant(I, 1, DemandedMask & ~LHSKnownZero, Context)) @@ -1470,7 +1470,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, return 0; const Type *EltTy = cast(V->getType())->getElementType(); - Constant *Zero = Context->getNullValue(EltTy); + Constant *Zero = Constant::getNullValue(EltTy); Constant *Undef = UndefValue::get(EltTy); std::vector Elts; for (unsigned i = 0; i != VWidth; ++i) { @@ -1808,7 +1808,7 @@ static Instruction *AssociativeOpt(BinaryOperator &Root, const Functor &F, // Make what used to be the LHS of the root be the user of the root... Value *ExtraOperand = TmpLHSI->getOperand(1); if (&Root == TmpLHSI) { - Root.replaceAllUsesWith(Context->getNullValue(TmpLHSI->getType())); + Root.replaceAllUsesWith(Constant::getNullValue(TmpLHSI->getType())); return 0; } Root.replaceAllUsesWith(TmpLHSI); // Users now use TmpLHSI @@ -2187,7 +2187,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { // X + ~X --> -1 since ~X = -X-1 if (dyn_castNotVal(LHS, Context) == RHS || dyn_castNotVal(RHS, Context) == LHS) - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); // (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0 @@ -2417,7 +2417,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); if (Op0 == Op1) // sub X, X -> 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // If this is a 'B = x-(-A)', change to B = x+A... if (Value *V = dyn_castNegVal(Op1, Context)) @@ -2623,7 +2623,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { Value *Op0 = I.getOperand(0); if (isa(I.getOperand(1))) // undef * X -> 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // Simplify mul instructions with a constant RHS... if (Constant *Op1 = dyn_cast(I.getOperand(1))) { @@ -2904,7 +2904,7 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) { if (isa(Op0)) { if (Op0->getType()->isFPOrFPVector()) return ReplaceInstUsesWith(I, Op0); - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } // X / undef -> undef @@ -2952,7 +2952,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { if (ConstantInt *LHSRHS = dyn_cast(LHS->getOperand(1))) { if (MultiplyOverflows(RHS, LHSRHS, I.getOpcode()==Instruction::SDiv, Context)) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); else return BinaryOperator::Create(I.getOpcode(), LHS->getOperand(0), ConstantExpr::getMul(RHS, LHSRHS)); @@ -2971,7 +2971,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { // 0 / X == 0, we don't need to preserve faults! if (ConstantInt *LHS = dyn_cast(Op0)) if (LHS->equalsInt(0)) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // It can't be division by zero, hence it must be division by one. if (I.getType() == Type::Int1Ty) @@ -3007,7 +3007,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { Value *IC = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_ULT, Op0, C), I); - return SelectInst::Create(IC, Context->getNullValue(I.getType()), + return SelectInst::Create(IC, Constant::getNullValue(I.getType()), ConstantInt::get(I.getType(), 1)); } } @@ -3108,7 +3108,7 @@ Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) { if (isa(Op0)) { // undef % X -> 0 if (I.getType()->isFPOrFPVector()) return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } if (isa(Op1)) return ReplaceInstUsesWith(I, Op1); // X % undef -> undef @@ -3133,7 +3133,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) { // 0 % X == 0 for integer, we don't need to preserve faults! if (Constant *LHS = dyn_cast(Op0)) if (LHS->isNullValue()) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); if (ConstantInt *RHS = dyn_cast(Op1)) { // X % 0 == undef, we don't need to preserve faults! @@ -3141,7 +3141,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) { return ReplaceInstUsesWith(I, UndefValue::get(I.getType())); if (RHS->equalsInt(1)) // X % 1 == 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); if (Instruction *Op0I = dyn_cast(Op0)) { if (SelectInst *SI = dyn_cast(Op0I)) { @@ -3181,7 +3181,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) { if (RHSI->getOpcode() == Instruction::Shl && isa(RHSI->getOperand(0))) { if (cast(RHSI->getOperand(0))->getValue().isPowerOf2()) { - Constant *N1 = Context->getAllOnesValue(I.getType()); + Constant *N1 = Constant::getAllOnesValue(I.getType()); Value *Add = InsertNewInstBefore(BinaryOperator::CreateAdd(RHSI, N1, "tmp"), I); return BinaryOperator::CreateAnd(Op0, Add); @@ -4008,7 +4008,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); if (isa(Op1)) // X & undef -> 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // and X, X = X if (Op0 == Op1) @@ -4101,7 +4101,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { // (1 >> x) & 1 --> zext(x == 0) if (AndRHSMask == 1 && Op0LHS == AndRHS) { Instruction *NewICmp = new ICmpInst(*Context, ICmpInst::ICMP_EQ, - Op0RHS, Context->getNullValue(I.getType())); + Op0RHS, Constant::getNullValue(I.getType())); InsertNewInstBefore(NewICmp, I); return new ZExtInst(NewICmp, I.getType()); } @@ -4159,7 +4159,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { Value *Op1NotVal = dyn_castNotVal(Op1, Context); if (Op0NotVal == Op1 || Op1NotVal == Op0) // A & ~A == ~A & A == 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // (~A & ~B) == (~(A | B)) - De Morgan's Law if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) { @@ -4733,7 +4733,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); if (isa(Op1)) // X | undef -> -1 - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); // or X, X = X if (Op0 == Op1) @@ -4934,14 +4934,14 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { if (match(Op0, m_Not(m_Value(A)), *Context)) { // ~A | Op1 if (A == Op1) // ~A | A == -1 - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); } else { A = 0; } // Note, A is still live here! if (match(Op1, m_Not(m_Value(B)), *Context)) { // Op0 | ~B if (Op0 == B) - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); // (~A | ~B) == (~(A & B)) - De Morgan's Law if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) { @@ -5019,14 +5019,14 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (isa(Op0)) // Handle undef ^ undef -> 0 special case. This is a common // idiom (misuse). - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); return ReplaceInstUsesWith(I, Op1); // X ^ undef -> undef } // xor X, X = 0, even if X is nested in a sequence of Xor's. if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1), Context)) { assert(Result == &I && "AssociativeOpt didn't work?"); Result=Result; - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } // See if we can simplify any instructions used by the instruction whose sole @@ -5148,11 +5148,11 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (Value *X = dyn_castNotVal(Op0, Context)) // ~A ^ A == -1 if (X == Op1) - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); if (Value *X = dyn_castNotVal(Op1, Context)) // A ^ ~A == -1 if (X == Op0) - return ReplaceInstUsesWith(I, Context->getAllOnesValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType())); BinaryOperator *Op1I = dyn_cast(Op1); @@ -5378,7 +5378,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) { gep_type_iterator GTI = gep_type_begin(GEP); const Type *IntPtrTy = TD.getIntPtrType(); LLVMContext *Context = IC.getContext(); - Value *Result = Context->getNullValue(IntPtrTy); + Value *Result = Constant::getNullValue(IntPtrTy); // Build a mask for high order bits. unsigned IntPtrWidth = TD.getPointerSizeInBits(); @@ -5578,7 +5578,7 @@ Instruction *InstCombiner::FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, if (Offset == 0) Offset = EmitGEPOffset(GEPLHS, I, *this); return new ICmpInst(*Context, ICmpInst::getSignedPredicate(Cond), Offset, - Context->getNullValue(Offset->getType())); + Constant::getNullValue(Offset->getType())); } else if (GEPOperator *GEPRHS = dyn_cast(RHS)) { // If the base pointers are different, but the indices are the same, just // compare the base pointer. @@ -5892,7 +5892,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { case FCmpInst::FCMP_UNE: // True if unordered or not equal // Canonicalize these to be 'fcmp uno %X, 0.0'. I.setPredicate(FCmpInst::FCMP_UNO); - I.setOperand(1, Context->getNullValue(Op0->getType())); + I.setOperand(1, Constant::getNullValue(Op0->getType())); return &I; case FCmpInst::FCMP_ORD: // True if ordered (no nans) @@ -5901,7 +5901,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { case FCmpInst::FCMP_OLE: // True if ordered and less than or equal // Canonicalize these to be 'fcmp ord %X, 0.0'. I.setPredicate(FCmpInst::FCMP_ORD); - I.setOperand(1, Context->getNullValue(Op0->getType())); + I.setOperand(1, Constant::getNullValue(Op0->getType())); return &I; } } @@ -6165,7 +6165,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // (x (x >s -1) -> true if sign bit clear if (CI->isMinValue(true)) return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0, - Context->getAllOnesValue(Op0->getType())); + Constant::getAllOnesValue(Op0->getType())); } break; case ICmpInst::ICMP_UGT: @@ -6184,7 +6184,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // (x >u 2147483647) -> (x true if sign bit set if (CI->isMaxValue(true)) return new ICmpInst(*Context, ICmpInst::ICMP_SLT, Op0, - Context->getNullValue(Op0->getType())); + Constant::getNullValue(Op0->getType())); } break; case ICmpInst::ICMP_SLT: @@ -6292,7 +6292,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { } if (isAllZeros) return new ICmpInst(*Context, I.getPredicate(), LHSI->getOperand(0), - Context->getNullValue(LHSI->getOperand(0)->getType())); + Constant::getNullValue(LHSI->getOperand(0)->getType())); } break; @@ -6472,7 +6472,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { if (A == Op1 || B == Op1) { // (A^B) == A -> B == 0 Value *OtherVal = A == Op1 ? B : A; return new ICmpInst(*Context, I.getPredicate(), OtherVal, - Context->getNullValue(A->getType())); + Constant::getNullValue(A->getType())); } if (match(Op1, m_Xor(m_Value(C), m_Value(D)), *Context)) { @@ -6500,18 +6500,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // A == (A^B) -> B == 0 Value *OtherVal = A == Op0 ? B : A; return new ICmpInst(*Context, I.getPredicate(), OtherVal, - Context->getNullValue(A->getType())); + Constant::getNullValue(A->getType())); } // (A-B) == A -> B == 0 if (match(Op0, m_Sub(m_Specific(Op1), m_Value(B)), *Context)) return new ICmpInst(*Context, I.getPredicate(), B, - Context->getNullValue(B->getType())); + Constant::getNullValue(B->getType())); // A == (A-B) -> B == 0 if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B)), *Context)) return new ICmpInst(*Context, I.getPredicate(), B, - Context->getNullValue(B->getType())); + Constant::getNullValue(B->getType())); // (X&Z) == (Y&Z) -> (X^Y) & Z == 0 if (Op0->hasOneUse() && Op1->hasOneUse() && @@ -6533,7 +6533,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { Op1 = InsertNewInstBefore(BinaryOperator::CreateXor(X, Y, "tmp"), I); Op1 = InsertNewInstBefore(BinaryOperator::CreateAnd(Op1, Z, "tmp"), I); I.setOperand(0, Op1); - I.setOperand(1, Context->getNullValue(Op1->getType())); + I.setOperand(1, Constant::getNullValue(Op1->getType())); return &I; } } @@ -6956,7 +6956,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, return new ICmpInst(*Context, TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ, - And, Context->getNullValue(And->getType())); + And, Constant::getNullValue(And->getType())); } break; } @@ -7079,7 +7079,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, BO->getName()); InsertNewInstBefore(NewRem, ICI); return new ICmpInst(*Context, ICI.getPredicate(), NewRem, - Context->getNullValue(BO->getType())); + Constant::getNullValue(BO->getType())); } } break; @@ -7146,12 +7146,12 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (RHS == BOC && RHSV.isPowerOf2()) return new ICmpInst(*Context, isICMP_NE ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE, LHSI, - Context->getNullValue(RHS->getType())); + Constant::getNullValue(RHS->getType())); // Replace (and X, (1 << size(X)-1) != 0) with x s< 0 if (BOC->getValue().isSignBit()) { Value *X = BO->getOperand(0); - Constant *Zero = Context->getNullValue(X->getType()); + Constant *Zero = Constant::getNullValue(X->getType()); ICmpInst::Predicate pred = isICMP_NE ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE; return new ICmpInst(*Context, pred, X, Zero); @@ -7295,7 +7295,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) { if (isSignedExt) { // We're performing an unsigned comp with a sign extended value. // This is true if the input is >= 0. [aka >s -1] - Constant *NegOne = Context->getAllOnesValue(SrcTy); + Constant *NegOne = Constant::getAllOnesValue(SrcTy); Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT, LHSCIOp, NegOne, ICI.getName()), ICI); } else { @@ -7355,21 +7355,21 @@ Instruction *InstCombiner::commonShiftTransforms(BinaryOperator &I) { // shl X, 0 == X and shr X, 0 == X // shl 0, X == 0 and shr 0, X == 0 - if (Op1 == Context->getNullValue(Op1->getType()) || - Op0 == Context->getNullValue(Op0->getType())) + if (Op1 == Constant::getNullValue(Op1->getType()) || + Op0 == Constant::getNullValue(Op0->getType())) return ReplaceInstUsesWith(I, Op0); if (isa(Op0)) { if (I.getOpcode() == Instruction::AShr) // undef >>s X -> undef return ReplaceInstUsesWith(I, Op0); else // undef << X -> 0, undef >>u X -> 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } if (isa(Op1)) { if (I.getOpcode() == Instruction::AShr) // X >>s undef -> X return ReplaceInstUsesWith(I, Op0); else // X << undef, X >>u undef -> 0 - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); } // See if we can fold away this shift. @@ -7401,7 +7401,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, // if (Op1->uge(TypeBits)) { if (I.getOpcode() != Instruction::AShr) - return ReplaceInstUsesWith(I, Context->getNullValue(Op0->getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(Op0->getType())); else { I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1)); return &I; @@ -7629,7 +7629,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, // saturates. if (AmtSum >= TypeBits) { if (I.getOpcode() != Instruction::AShr) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); AmtSum = TypeBits-1; // Saturate to 31 for i32 ashr. } @@ -7638,7 +7638,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, } else if (ShiftOp->getOpcode() == Instruction::LShr && I.getOpcode() == Instruction::AShr) { if (AmtSum >= TypeBits) - return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); + return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType())); // ((X >>u C1) >>s C2) -> (X >>u (C1+C2)) since C1 != 0. return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum)); @@ -8477,7 +8477,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) { if (DestBitWidth == 1) { Constant *One = ConstantInt::get(Src->getType(), 1); Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI); - Value *Zero = Context->getNullValue(Src->getType()); + Value *Zero = Constant::getNullValue(Src->getType()); return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero); } @@ -8492,7 +8492,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) { APInt Mask(APInt::getLowBitsSet(SrcBitWidth, ShAmt).shl(DestBitWidth)); if (MaskedValueIsZero(ShiftOp, Mask)) { if (ShAmt >= DestBitWidth) // All zeros. - return ReplaceInstUsesWith(CI, Context->getNullValue(Ty)); + return ReplaceInstUsesWith(CI, Constant::getNullValue(Ty)); // Okay, we can shrink this. Truncate the input, then return a new // shift. @@ -8699,8 +8699,8 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { // Canonicalize sign-extend from i1 to a select. if (Src->getType() == Type::Int1Ty) return SelectInst::Create(Src, - Context->getAllOnesValue(CI.getType()), - Context->getNullValue(CI.getType())); + Constant::getAllOnesValue(CI.getType()), + Constant::getNullValue(CI.getType())); // See if the value being truncated is already sign extended. If so, just // eliminate the trunc/sext pair. @@ -8970,7 +8970,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { // If the source and destination are pointers, and this cast is equivalent // to a getelementptr X, 0, 0, 0... turn it into the appropriate gep. // This can enhance SROA and other transforms that want type-safe pointers. - Constant *ZeroUInt = Context->getNullValue(Type::Int32Ty); + Constant *ZeroUInt = Constant::getNullValue(Type::Int32Ty); unsigned NumZeros = 0; while (SrcElTy != DstElTy && isa(SrcElTy) && !isa(SrcElTy) && @@ -8996,7 +8996,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { Value *Elem = InsertCastBefore(Instruction::BitCast, Src, DestVTy->getElementType(), CI); return InsertElementInst::Create(UndefValue::get(DestTy), Elem, - Context->getNullValue(Type::Int32Ty)); + Constant::getNullValue(Type::Int32Ty)); } // FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast) } @@ -9006,7 +9006,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { if (SrcVTy->getNumElements() == 1) { if (!isa(DestTy)) { Instruction *Elem = - ExtractElementInst::Create(Src, Context->getNullValue(Type::Int32Ty)); + ExtractElementInst::Create(Src, Constant::getNullValue(Type::Int32Ty)); InsertNewInstBefore(Elem, CI); return CastInst::Create(Instruction::BitCast, Elem, DestTy); } @@ -9086,9 +9086,9 @@ static Constant *GetSelectFoldableConstant(Instruction *I, case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: - return Context->getNullValue(I->getType()); + return Constant::getNullValue(I->getType()); case Instruction::And: - return Context->getAllOnesValue(I->getType()); + return Constant::getAllOnesValue(I->getType()); case Instruction::Mul: return ConstantInt::get(I->getType(), 1); } @@ -9743,7 +9743,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) { InsertNewInstBefore(new StoreInst(L, Dest, false, DstAlign), *MI); // Set the size of the copy to 0, it will be deleted on the next iteration. - MI->setOperand(3, Context->getNullValue(MemOpLength->getType())); + MI->setOperand(3, Constant::getNullValue(MemOpLength->getType())); return MI; } @@ -9782,7 +9782,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { Dest, false, Alignment), *MI); // Set the size of the copy to 0, it will be deleted on the next iteration. - MI->setLength(Context->getNullValue(LenC->getType())); + MI->setLength(Constant::getNullValue(LenC->getType())); return MI; } @@ -10259,7 +10259,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // If the function takes more arguments than the call was taking, add them // now... for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) - Args.push_back(Context->getNullValue(FT->getParamType(i))); + Args.push_back(Constant::getNullValue(FT->getParamType(i))); // If we are removing arguments to the function, emit an obnoxious warning... if (FT->getNumParams() < NumActualArgs) { @@ -11092,9 +11092,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // With: T = long A+B; gep %P, T, ... // Value *Sum, *SO1 = SrcGEPOperands.back(), *GO1 = GEP.getOperand(1); - if (SO1 == Context->getNullValue(SO1->getType())) { + if (SO1 == Constant::getNullValue(SO1->getType())) { Sum = GO1; - } else if (GO1 == Context->getNullValue(GO1->getType())) { + } else if (GO1 == Constant::getNullValue(GO1->getType())) { Sum = SO1; } else { // If they aren't the same type, convert both to an integer of the @@ -11227,7 +11227,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { TD->getTypeAllocSize(cast(SrcElTy)->getElementType()) == TD->getTypeAllocSize(ResElTy)) { Value *Idx[2]; - Idx[0] = Context->getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = GEP.getOperand(1); GetElementPtrInst *NewGEP = GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()); @@ -11291,7 +11291,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // Insert the new GEP instruction. Value *Idx[2]; - Idx[0] = Context->getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = NewIdx; Instruction *NewGEP = GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()); @@ -11388,7 +11388,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { // Now that I is pointing to the first non-allocation-inst in the block, // insert our getelementptr instruction... // - Value *NullIdx = Context->getNullValue(Type::Int32Ty); + Value *NullIdx = Constant::getNullValue(Type::Int32Ty); Value *Idx[2]; Idx[0] = NullIdx; Idx[1] = NullIdx; @@ -11400,7 +11400,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { // allocation. return ReplaceInstUsesWith(AI, V); } else if (isa(AI.getArraySize())) { - return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType())); + return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType())); } } @@ -11409,7 +11409,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { // Note that we only do this for alloca's, because malloc should allocate // and return a unique pointer, even for a zero byte allocation. if (TD->getTypeAllocSize(AI.getAllocatedType()) == 0) - return ReplaceInstUsesWith(AI, Context->getNullValue(AI.getType())); + return ReplaceInstUsesWith(AI, Constant::getNullValue(AI.getType())); // If the alignment is 0 (unspecified), assign it the preferred alignment. if (AI.getAlignment() == 0) @@ -11521,7 +11521,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, if (Constant *CSrc = dyn_cast(CastOp)) if (ASrcTy->getNumElements() != 0) { Value *Idxs[2]; - Idxs[0] = Idxs[1] = Context->getNullValue(Type::Int32Ty); + Idxs[0] = Idxs[1] = Constant::getNullValue(Type::Int32Ty); CastOp = ConstantExpr::getGetElementPtr(CSrc, Idxs, 2); SrcTy = cast(CastOp->getType()); SrcPTy = SrcTy->getElementType(); @@ -11588,7 +11588,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // an unreachable instruction directly because we cannot modify the // CFG. new StoreInst(UndefValue::get(LI.getType()), - Context->getNullValue(Op->getType()), &LI); + Constant::getNullValue(Op->getType()), &LI); return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType())); } } @@ -11602,7 +11602,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // this code is not reachable. We do this instead of inserting an // unreachable instruction directly because we cannot modify the CFG. new StoreInst(UndefValue::get(LI.getType()), - Context->getNullValue(Op->getType()), &LI); + Constant::getNullValue(Op->getType()), &LI); return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType())); } @@ -11626,7 +11626,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { // an unreachable instruction directly because we cannot modify the // CFG. new StoreInst(UndefValue::get(LI.getType()), - Context->getNullValue(Op->getType()), &LI); + Constant::getNullValue(Op->getType()), &LI); return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType())); } @@ -11642,7 +11642,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { if (GlobalVariable *GV = dyn_cast(Op->getUnderlyingObject())){ if (GV->isConstant() && GV->hasDefinitiveInitializer()) { if (GV->getInitializer()->isNullValue()) - return ReplaceInstUsesWith(LI, Context->getNullValue(LI.getType())); + return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType())); else if (isa(GV->getInitializer())) return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType())); } @@ -11694,7 +11694,6 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { User *CI = cast(SI.getOperand(1)); Value *CastOp = CI->getOperand(0); - LLVMContext *Context = IC.getContext(); const Type *DestPTy = cast(CI->getType())->getElementType(); const PointerType *SrcTy = dyn_cast(CastOp->getType()); @@ -11716,7 +11715,7 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) { // constants. if (isa(SrcPTy) || isa(SrcPTy)) { // Index through pointer. - Constant *Zero = Context->getNullValue(Type::Int32Ty); + Constant *Zero = Constant::getNullValue(Type::Int32Ty); NewGEPIndices.push_back(Zero); while (1) { @@ -12190,7 +12189,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) { return ReplaceInstUsesWith(EV, UndefValue::get(EV.getType())); if (isa(C)) - return ReplaceInstUsesWith(EV, Context->getNullValue(EV.getType())); + return ReplaceInstUsesWith(EV, Constant::getNullValue(EV.getType())); if (isa(C) || isa(C)) { // Extract the element indexed by the first index out of the constant @@ -12337,7 +12336,7 @@ static Value *FindScalarElement(Value *V, unsigned EltNo, if (isa(V)) return UndefValue::get(PTy->getElementType()); else if (isa(V)) - return Context->getNullValue(PTy->getElementType()); + return Constant::getNullValue(PTy->getElementType()); else if (ConstantVector *CP = dyn_cast(V)) return CP->getOperand(EltNo); else if (InsertElementInst *III = dyn_cast(V)) { @@ -12377,7 +12376,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { // If vector val is constant 0, replace extract with scalar 0. if (isa(EI.getOperand(0))) - return ReplaceInstUsesWith(EI, Context->getNullValue(EI.getType())); + return ReplaceInstUsesWith(EI, Constant::getNullValue(EI.getType())); if (ConstantVector *C = dyn_cast(EI.getOperand(0))) { // If vector val is constant with all elements the same, replace EI with diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index df72d41745..6554d6a452 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1577,9 +1577,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, BasicBlock *LatchBlock = L->getLoopLatch(); Instruction *IVIncInsertPt = LatchBlock->getTerminator(); - LLVMContext &Context = Preheader->getContext(); - - Value *CommonBaseV = Context.getNullValue(ReplacedTy); + Value *CommonBaseV = Constant::getNullValue(ReplacedTy); const SCEV *RewriteFactor = SE->getIntegerSCEV(0, ReplacedTy); IVExpr ReuseIV(SE->getIntegerSCEV(0, Type::Int32Ty), diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index 5ec5bf79ae..f9427bb693 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -1761,7 +1761,7 @@ namespace { switch (BO->getOpcode()) { case Instruction::And: { // "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1 - ConstantInt *CI = cast(Context->getAllOnesValue(Ty)); + ConstantInt *CI = cast(Constant::getAllOnesValue(Ty)); if (Canonical == CI) { add(CI, Op0, ICmpInst::ICMP_EQ, NewContext); add(CI, Op1, ICmpInst::ICMP_EQ, NewContext); @@ -1769,7 +1769,7 @@ namespace { } break; case Instruction::Or: { // "or i32 %a, %b" EQ 0 then %a EQ 0 and %b EQ 0 - Constant *Zero = Context->getNullValue(Ty); + Constant *Zero = Constant::getNullValue(Ty); if (Canonical == Zero) { add(Zero, Op0, ICmpInst::ICMP_EQ, NewContext); add(Zero, Op1, ICmpInst::ICMP_EQ, NewContext); @@ -1793,10 +1793,10 @@ namespace { } if (Canonical == LHS) { if (isa(Canonical)) - add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_EQ, + add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ, NewContext); } else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) { - add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_NE, + add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_NE, NewContext); } } break; @@ -1841,10 +1841,10 @@ namespace { } // TODO: The GEPI indices are all zero. Copy from definition to operand, // jumping the type plane as needed. - if (isRelatedBy(GEPI, Context->getNullValue(GEPI->getType()), + if (isRelatedBy(GEPI, Constant::getNullValue(GEPI->getType()), ICmpInst::ICMP_NE)) { Value *Ptr = GEPI->getPointerOperand(); - add(Ptr, Context->getNullValue(Ptr->getType()), ICmpInst::ICMP_NE, + add(Ptr, Constant::getNullValue(Ptr->getType()), ICmpInst::ICMP_NE, NewContext); } } else if (CastInst *CI = dyn_cast(I)) { @@ -1898,9 +1898,9 @@ namespace { const Type *Ty = BO->getType(); assert(!Ty->isFPOrFPVector() && "Float in work queue!"); - Constant *Zero = Context->getNullValue(Ty); + Constant *Zero = Constant::getNullValue(Ty); Constant *One = ConstantInt::get(Ty, 1); - ConstantInt *AllOnes = cast(Context->getAllOnesValue(Ty)); + ConstantInt *AllOnes = cast(Constant::getAllOnesValue(Ty)); switch (Opcode) { default: break; @@ -2121,9 +2121,9 @@ namespace { // TODO: The GEPI indices are all zero. Copy from operand to definition, // jumping the type plane as needed. Value *Ptr = GEPI->getPointerOperand(); - if (isRelatedBy(Ptr, Context->getNullValue(Ptr->getType()), + if (isRelatedBy(Ptr, Constant::getNullValue(Ptr->getType()), ICmpInst::ICMP_NE)) { - add(GEPI, Context->getNullValue(GEPI->getType()), ICmpInst::ICMP_NE, + add(GEPI, Constant::getNullValue(GEPI->getType()), ICmpInst::ICMP_NE, NewContext); } } @@ -2515,7 +2515,7 @@ namespace { void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) { VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &AI); - VRP.add(AI.getContext().getNullValue(AI.getType()), + VRP.add(Constant::getNullValue(AI.getType()), &AI, ICmpInst::ICMP_NE); VRP.solve(); } @@ -2526,7 +2526,7 @@ namespace { if (isa(Ptr)) return; VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &LI); - VRP.add(LI.getContext().getNullValue(Ptr->getType()), + VRP.add(Constant::getNullValue(Ptr->getType()), Ptr, ICmpInst::ICMP_NE); VRP.solve(); } @@ -2536,7 +2536,7 @@ namespace { if (isa(Ptr)) return; VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI); - VRP.add(SI.getContext().getNullValue(Ptr->getType()), + VRP.add(Constant::getNullValue(Ptr->getType()), Ptr, ICmpInst::ICMP_NE); VRP.solve(); } @@ -2574,7 +2574,7 @@ namespace { case Instruction::SDiv: { Value *Divisor = BO.getOperand(1); VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &BO); - VRP.add(BO.getContext().getNullValue(Divisor->getType()), + VRP.add(Constant::getNullValue(Divisor->getType()), Divisor, ICmpInst::ICMP_NE); VRP.solve(); break; diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index cade3e6c04..e8bc859517 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -201,7 +201,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) { static Instruction *LowerNegateToMultiply(Instruction *Neg, std::map, unsigned> &ValueRankMap, LLVMContext &Context) { - Constant *Cst = Neg->getContext().getAllOnesValue(Neg->getType()); + Constant *Cst = Constant::getAllOnesValue(Neg->getType()); Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg); ValueRankMap.erase(Neg); @@ -563,8 +563,6 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, bool IterateOptimization = false; if (Ops.size() == 1) return Ops[0].Op; - LLVMContext &Context = I->getContext(); - unsigned Opcode = I->getOpcode(); if (Constant *V1 = dyn_cast(Ops[Ops.size()-2].Op)) @@ -626,10 +624,10 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, if (FoundX != i) { if (Opcode == Instruction::And) { // ...&X&~X = 0 ++NumAnnihil; - return Context.getNullValue(X->getType()); + return Constant::getNullValue(X->getType()); } else if (Opcode == Instruction::Or) { // ...|X|~X = -1 ++NumAnnihil; - return Context.getAllOnesValue(X->getType()); + return Constant::getAllOnesValue(X->getType()); } } } @@ -648,7 +646,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, assert(Opcode == Instruction::Xor); if (e == 2) { ++NumAnnihil; - return Context.getNullValue(Ops[0].Op->getType()); + return Constant::getNullValue(Ops[0].Op->getType()); } // ... X^X -> ... Ops.erase(Ops.begin()+i, Ops.begin()+i+2); @@ -673,7 +671,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, // Remove X and -X from the operand list. if (Ops.size() == 2) { ++NumAnnihil; - return Context.getNullValue(X->getType()); + return Constant::getNullValue(X->getType()); } else { Ops.erase(Ops.begin()+i); if (i < FoundX) diff --git a/lib/Transforms/Scalar/Reg2Mem.cpp b/lib/Transforms/Scalar/Reg2Mem.cpp index 2c1569dbda..e1075a650d 100644 --- a/lib/Transforms/Scalar/Reg2Mem.cpp +++ b/lib/Transforms/Scalar/Reg2Mem.cpp @@ -69,7 +69,7 @@ namespace { CastInst *AllocaInsertionPoint = CastInst::Create(Instruction::BitCast, - F.getContext().getNullValue(Type::Int32Ty), Type::Int32Ty, + Constant::getNullValue(Type::Int32Ty), Type::Int32Ty, "reg2mem alloca point", I); // Find the escaped instructions. But don't create stack slots for diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 7db39d5fb8..80629329b2 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -813,12 +813,12 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) { if (NonOverdefVal->isUndefined()) { // Could annihilate value. if (I.getOpcode() == Instruction::And) - markConstant(IV, &I, Context->getNullValue(I.getType())); + markConstant(IV, &I, Constant::getNullValue(I.getType())); else if (const VectorType *PT = dyn_cast(I.getType())) - markConstant(IV, &I, Context->getAllOnesValue(PT)); + markConstant(IV, &I, Constant::getAllOnesValue(PT)); else markConstant(IV, &I, - Context->getAllOnesValue(I.getType())); + Constant::getAllOnesValue(I.getType())); return; } else { if (I.getOpcode() == Instruction::And) { @@ -1134,7 +1134,7 @@ void SCCPSolver::visitLoadInst(LoadInst &I) { if (isa(Ptr) && cast(Ptr->getType())->getAddressSpace() == 0) { // load null -> null - markConstant(IV, &I, Context->getNullValue(I.getType())); + markConstant(IV, &I, Constant::getNullValue(I.getType())); return; } @@ -1376,22 +1376,22 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // to be handled here, because we don't know whether the top part is 1's // or 0's. assert(Op0LV.isUndefined()); - markForcedConstant(LV, I, Context->getNullValue(ITy)); + markForcedConstant(LV, I, Constant::getNullValue(ITy)); return true; case Instruction::Mul: case Instruction::And: // undef * X -> 0. X could be zero. // undef & X -> 0. X could be zero. - markForcedConstant(LV, I, Context->getNullValue(ITy)); + markForcedConstant(LV, I, Constant::getNullValue(ITy)); return true; case Instruction::Or: // undef | X -> -1. X could be -1. if (const VectorType *PTy = dyn_cast(ITy)) markForcedConstant(LV, I, - Context->getAllOnesValue(PTy)); + Constant::getAllOnesValue(PTy)); else - markForcedConstant(LV, I, Context->getAllOnesValue(ITy)); + markForcedConstant(LV, I, Constant::getAllOnesValue(ITy)); return true; case Instruction::SDiv: @@ -1404,7 +1404,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // undef / X -> 0. X could be maxint. // undef % X -> 0. X could be 1. - markForcedConstant(LV, I, Context->getNullValue(ITy)); + markForcedConstant(LV, I, Constant::getNullValue(ITy)); return true; case Instruction::AShr: @@ -1425,7 +1425,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // X >> undef -> 0. X could be 0. // X << undef -> 0. X could be 0. - markForcedConstant(LV, I, Context->getNullValue(ITy)); + markForcedConstant(LV, I, Constant::getNullValue(ITy)); return true; case Instruction::Select: // undef ? X : Y -> X or Y. There could be commonality between X/Y. diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 7877db4e4f..cacf3dbb4b 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -329,7 +329,6 @@ void SROA::DoScalarReplacement(AllocationInst *AI, std::vector &WorkList) { DOUT << "Found inst to SROA: " << *AI; SmallVector ElementAllocas; - LLVMContext &Context = AI->getContext(); if (const StructType *ST = dyn_cast(AI->getAllocatedType())) { ElementAllocas.reserve(ST->getNumContainedTypes()); for (unsigned i = 0, e = ST->getNumContainedTypes(); i != e; ++i) { @@ -418,7 +417,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI, // expanded itself once the worklist is rerun. // SmallVector NewArgs; - NewArgs.push_back(Context.getNullValue(Type::Int32Ty)); + NewArgs.push_back(Constant::getNullValue(Type::Int32Ty)); NewArgs.append(GEPI->op_begin()+3, GEPI->op_end()); RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(), NewArgs.end(), "", GEPI); @@ -512,7 +511,6 @@ static bool AllUsersAreLoads(Value *Ptr) { /// void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI, AllocaInfo &Info) { - LLVMContext &Context = User->getContext(); if (BitCastInst *C = dyn_cast(User)) return isSafeUseOfBitCastedAllocation(C, AI, Info); @@ -532,7 +530,7 @@ void SROA::isSafeUseOfAllocation(Instruction *User, AllocationInst *AI, // The GEP is not safe to transform if not of the form "GEP , 0, ". if (I == E || - I.getOperand() != Context.getNullValue(I.getOperand()->getType())) { + I.getOperand() != Constant::getNullValue(I.getOperand()->getType())) { return MarkUnsafe(Info); } @@ -766,7 +764,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, const Type *BytePtrTy = MI->getRawDest()->getType(); bool SROADest = MI->getRawDest() == BCInst; - Constant *Zero = Context.getNullValue(Type::Int32Ty); + Constant *Zero = Constant::getNullValue(Type::Int32Ty); for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { // If this is a memcpy/memmove, emit a GEP of the other element address. @@ -821,7 +819,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, Constant *StoreVal; if (ConstantInt *CI = dyn_cast(MI->getOperand(2))) { if (CI->isZero()) { - StoreVal = Context.getNullValue(EltTy); // 0.0, null, 0, <0,0> + StoreVal = Constant::getNullValue(EltTy); // 0.0, null, 0, <0,0> } else { // If EltTy is a vector type, get the element type. const Type *ValTy = EltTy->getScalarType(); @@ -1041,10 +1039,8 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, ArrayEltBitOffset = TD->getTypeAllocSizeInBits(ArrayEltTy); } - LLVMContext &Context = LI->getContext(); - Value *ResultVal = - Context.getNullValue(IntegerType::get(AllocaSizeBits)); + Constant::getNullValue(IntegerType::get(AllocaSizeBits)); for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { // Load the value from the alloca. If the NewElt is an aggregate, cast @@ -1189,10 +1185,8 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) { if (isa(I.getOperand())) return; - LLVMContext &Context = GEPI->getContext(); - if (NumElements == 1) { - GEPI->setOperand(2, Context.getNullValue(Type::Int32Ty)); + GEPI->setOperand(2, Constant::getNullValue(Type::Int32Ty)); return; } @@ -1200,11 +1194,11 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) { // All users of the GEP must be loads. At each use of the GEP, insert // two loads of the appropriate indexed GEP and select between them. Value *IsOne = new ICmpInst(GEPI, ICmpInst::ICMP_NE, I.getOperand(), - Context.getNullValue(I.getOperand()->getType()), + Constant::getNullValue(I.getOperand()->getType()), "isone"); // Insert the new GEP instructions, which are properly indexed. SmallVector Indices(GEPI->op_begin()+1, GEPI->op_end()); - Indices[1] = Context.getNullValue(Type::Int32Ty); + Indices[1] = Constant::getNullValue(Type::Int32Ty); Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0), Indices.begin(), Indices.end(), diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 04bc39b4e0..2ac980fbe6 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -679,7 +679,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { uint64_t i = 0; while (1) { if (i == Str.size()) // Didn't find the char. strchr returns null. - return Context->getNullValue(CI->getType()); + return Constant::getNullValue(CI->getType()); // Did we find our match? if (Str[i] == CharValue) break; @@ -918,7 +918,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization { Value *LHS = CI->getOperand(1), *RHS = CI->getOperand(2); if (LHS == RHS) // memcmp(s,s,x) -> 0 - return Context->getNullValue(CI->getType()); + return Constant::getNullValue(CI->getType()); // Make sure we have a constant length. ConstantInt *LenC = dyn_cast(CI->getOperand(3)); @@ -926,7 +926,7 @@ struct VISIBILITY_HIDDEN MemCmpOpt : public LibCallOptimization { uint64_t Len = LenC->getZExtValue(); if (Len == 0) // memcmp(s1,s2,0) -> 0 - return Context->getNullValue(CI->getType()); + return Constant::getNullValue(CI->getType()); if (Len == 1) { // memcmp(S1,S2,1) -> *LHS - *RHS Value *LHSV = B.CreateLoad(CastToCStr(LHS, B), "lhsv"); @@ -1163,7 +1163,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { // Constant fold. if (ConstantInt *CI = dyn_cast(Op)) { if (CI->getValue() == 0) // ffs(0) -> 0. - return Context->getNullValue(CI->getType()); + return Constant::getNullValue(CI->getType()); return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1 CI->getValue().countTrailingZeros()+1); } @@ -1176,7 +1176,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp"); V = B.CreateIntCast(V, Type::Int32Ty, false, "tmp"); - Value *Cond = B.CreateICmpNE(Op, Context->getNullValue(ArgType), "tmp"); + Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType), "tmp"); return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0)); } }; @@ -1235,7 +1235,7 @@ struct VISIBILITY_HIDDEN AbsOpt : public LibCallOptimization { // abs(x) -> x >s -1 ? x : -x Value *Op = CI->getOperand(1); Value *Pos = B.CreateICmpSGT(Op, - Context->getAllOnesValue(Op->getType()), + Constant::getAllOnesValue(Op->getType()), "ispos"); Value *Neg = B.CreateNeg(Op, "neg"); return B.CreateSelect(Pos, Op, Neg); @@ -1371,7 +1371,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { Value *Ptr = CastToCStr(CI->getOperand(1), B); B.CreateStore(V, Ptr); Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul"); - B.CreateStore(Context->getNullValue(Type::Int8Ty), Ptr); + B.CreateStore(Constant::getNullValue(Type::Int8Ty), Ptr); return ConstantInt::get(CI->getType(), 1); } diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index e6522749bc..4e1015968d 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -252,8 +252,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) { // Create a value to return... if the function doesn't return null... if (BB->getParent()->getReturnType() != Type::VoidTy) - RetVal = TI->getContext().getNullValue( - BB->getParent()->getReturnType()); + RetVal = Constant::getNullValue(BB->getParent()->getReturnType()); // Create the return... NewTI = ReturnInst::Create(RetVal); diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index d897c2acd1..80da263df5 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -239,8 +239,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs, DOUT << "inputs: " << inputs.size() << "\n"; DOUT << "outputs: " << outputs.size() << "\n"; - LLVMContext &Context = header->getContext(); - // This function returns unsigned, outputs will go back by reference. switch (NumExitBlocks) { case 0: @@ -304,7 +302,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs, Value *RewriteVal; if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Context.getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty, i); TerminatorInst *TI = newFunction->begin()->getTerminator(); GetElementPtrInst *GEP = @@ -352,8 +350,6 @@ Function *CodeExtractor::constructFunction(const Values &inputs, void CodeExtractor:: emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Values &inputs, Values &outputs) { - LLVMContext &Context = codeReplacer->getContext(); - // Emit a call to the new function, passing in: *pointer to struct (if // aggregating parameters), or plan inputs and allocated memory for outputs std::vector params, StructValues, ReloadOutputs; @@ -394,7 +390,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, for (unsigned i = 0, e = inputs.size(); i != e; ++i) { Value *Idx[2]; - Idx[0] = Context.getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty, i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, @@ -420,7 +416,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Value *Output = 0; if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Context.getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, @@ -442,7 +438,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Now we can emit a switch statement using the call as a value. SwitchInst *TheSwitch = - SwitchInst::Create(Context.getNullValue(Type::Int16Ty), + SwitchInst::Create(Constant::getNullValue(Type::Int16Ty), codeReplacer, 0, codeReplacer); // Since there may be multiple exits from the original region, make the new @@ -521,7 +517,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (DominatesDef) { if (AggregateArgs) { Value *Idx[2]; - Idx[0] = Context.getNullValue(Type::Int32Ty); + Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out); GetElementPtrInst *GEP = GetElementPtrInst::Create(OAI, Idx, Idx + 2, @@ -559,7 +555,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, } else { // Otherwise we must have code extracted an unwind or something, just // return whatever we want. - ReturnInst::Create(Context.getNullValue(OldFnRetTy), TheSwitch); + ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch); } TheSwitch->eraseFromParent(); diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 305897c8ff..ce7b04a497 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -103,8 +103,6 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { bool Changed = false; assert(MallocFunc && FreeFunc && "Pass not initialized!"); - LLVMContext &Context = BB.getContext(); - BasicBlock::InstListType &BBIL = BB.getInstList(); const TargetData &TD = getAnalysis(); @@ -156,7 +154,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { if (MCall->getType() != Type::VoidTy) MCast = new BitCastInst(MCall, MI->getType(), "", I); else - MCast = Context.getNullValue(MI->getType()); + MCast = Constant::getNullValue(MI->getType()); // Replace all uses of the old malloc inst with the cast inst MI->replaceAllUsesWith(MCast); diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index a9d218c5fd..4eac467e07 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -115,8 +115,6 @@ FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) { // doInitialization - Make sure that there is a prototype for abort in the // current module. bool LowerInvoke::doInitialization(Module &M) { - LLVMContext &Context = M.getContext(); - const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); AbortMessage = 0; if (ExpensiveEHSupport) { @@ -143,7 +141,7 @@ bool LowerInvoke::doInitialization(Module &M) { if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) { JBListHead = new GlobalVariable(M, PtrJBList, false, GlobalValue::LinkOnceAnyLinkage, - Context.getNullValue(PtrJBList), + Constant::getNullValue(PtrJBList), "llvm.sjljeh.jblist"); } @@ -177,8 +175,6 @@ bool LowerInvoke::doInitialization(Module &M) { } void LowerInvoke::createAbortMessage(Module *M) { - LLVMContext &Context = M->getContext(); - if (ExpensiveEHSupport) { // The abort message for expensive EH support tells the user that the // program 'unwound' without an 'invoke' instruction. @@ -189,7 +185,7 @@ void LowerInvoke::createAbortMessage(Module *M) { GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true, GlobalValue::InternalLinkage, Msg, "abortmsg"); - std::vector GEPIdx(2, Context.getNullValue(Type::Int32Ty)); + std::vector GEPIdx(2, Constant::getNullValue(Type::Int32Ty)); AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2); } else { // The abort message for cheap EH support tells the user that EH is not @@ -202,7 +198,7 @@ void LowerInvoke::createAbortMessage(Module *M) { GlobalVariable *MsgGV = new GlobalVariable(*M, Msg->getType(), true, GlobalValue::InternalLinkage, Msg, "abortmsg"); - std::vector GEPIdx(2, Context.getNullValue(Type::Int32Ty)); + std::vector GEPIdx(2, Constant::getNullValue(Type::Int32Ty)); AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, &GEPIdx[0], 2); } } @@ -223,7 +219,6 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) { } bool LowerInvoke::insertCheapEHSupport(Function &F) { - LLVMContext &Context = F.getContext(); bool Changed = false; for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) if (InvokeInst *II = dyn_cast(BB->getTerminator())) { @@ -256,7 +251,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { // Insert a return instruction. This really should be a "barrier", as it // is unreachable. ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 : - Context.getNullValue(F.getReturnType()), UI); + Constant::getNullValue(F.getReturnType()), UI); // Remove the unwind instruction now. BB->getInstList().erase(UI); @@ -271,7 +266,6 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, AllocaInst *InvokeNum, SwitchInst *CatchSwitch) { - LLVMContext &Context = II->getContext(); ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo); // If the unwind edge has phi nodes, split the edge. @@ -291,7 +285,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, BasicBlock::iterator NI = II->getNormalDest()->getFirstNonPHI(); // nonvolatile. - new StoreInst(Context.getNullValue(Type::Int32Ty), InvokeNum, false, NI); + new StoreInst(Constant::getNullValue(Type::Int32Ty), InvokeNum, false, NI); // Add a switch case to our unwind block. CatchSwitch->addCase(InvokeNoC, II->getUnwindDest()); @@ -433,8 +427,6 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { std::vector Unwinds; std::vector Invokes; - LLVMContext &Context = F.getContext(); - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) if (ReturnInst *RI = dyn_cast(BB->getTerminator())) { // Remember all return instructions in case we insert an invoke into this @@ -482,7 +474,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { "jblink", F.begin()->begin()); std::vector Idx; - Idx.push_back(Context.getNullValue(Type::Int32Ty)); + Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), "OldBuf", @@ -535,7 +527,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Compare the return value to zero. Value *IsNormal = new ICmpInst(EntryBB->getTerminator(), ICmpInst::ICMP_EQ, SJRet, - Context.getNullValue(SJRet->getType()), + Constant::getNullValue(SJRet->getType()), "notunwind"); // Nuke the uncond branch. EntryBB->getTerminator()->eraseFromParent(); @@ -569,14 +561,14 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Load the JBList, if it's null, then there was no catch! Value *NotNull = new ICmpInst(*UnwindHandler, ICmpInst::ICMP_NE, BufPtr, - Context.getNullValue(BufPtr->getType()), + Constant::getNullValue(BufPtr->getType()), "notnull"); BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler); // Create the block to do the longjmp. // Get a pointer to the jmpbuf and longjmp. std::vector Idx; - Idx.push_back(Context.getNullValue(Type::Int32Ty)); + Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", UnwindBlock); diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 8b56ed3570..081c780140 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -103,13 +103,13 @@ static Constant *FoldBitCast(LLVMContext &Context, if (const PointerType *DPTy = dyn_cast(DestTy)) if (PTy->getAddressSpace() == DPTy->getAddressSpace()) { SmallVector IdxList; - IdxList.push_back(Context.getNullValue(Type::Int32Ty)); + IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); const Type *ElTy = PTy->getElementType(); while (ElTy != DPTy->getElementType()) { if (const StructType *STy = dyn_cast(ElTy)) { if (STy->getNumElements() == 0) break; ElTy = STy->getElementType(0); - IdxList.push_back(Context.getNullValue(Type::Int32Ty)); + IdxList.push_back(Constant::getNullValue(Type::Int32Ty)); } else if (const SequentialType *STy = dyn_cast(ElTy)) { if (isa(ElTy)) break; // Can't index into pointers! @@ -134,7 +134,7 @@ static Constant *FoldBitCast(LLVMContext &Context, SrcTy = NULL; // First, check for null. Undef is already handled. if (isa(V)) - return Context.getNullValue(DestTy); + return Constant::getNullValue(DestTy); if (ConstantVector *CV = dyn_cast(V)) return BitCastConstantVector(Context, CV, DestPTy); @@ -186,7 +186,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, // [us]itofp(undef) = 0, because the result value is bounded. if (opc == Instruction::ZExt || opc == Instruction::SExt || opc == Instruction::UIToFP || opc == Instruction::SIToFP) - return Context.getNullValue(DestTy); + return Constant::getNullValue(DestTy); return UndefValue::get(DestTy); } // No compile-time operations on this type yet. @@ -337,7 +337,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context, if (isa(Val)) // ee(undef, x) -> undef return UndefValue::get(cast(Val->getType())->getElementType()); if (Val->isNullValue()) // ee(zero, x) -> zero - return Context.getNullValue( + return Constant::getNullValue( cast(Val->getType())->getElementType()); if (const ConstantVector *CVal = dyn_cast(Val)) { @@ -389,7 +389,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context, Ops.reserve(numOps); for (unsigned i = 0; i < numOps; ++i) { const Constant *Op = - (idxVal == i) ? Elt : Context.getNullValue(Elt->getType()); + (idxVal == i) ? Elt : Constant::getNullValue(Elt->getType()); Ops.push_back(const_cast(Op)); } return ConstantVector::get(Ops); @@ -418,7 +418,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C, const Type *EltTy = cast(C->getType())->getElementType(); if (isa(C)) - return Context.getNullValue(EltTy); + return Constant::getNullValue(EltTy); if (isa(C)) return UndefValue::get(EltTy); return 0; @@ -477,7 +477,7 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context, if (isa(Agg)) // ev(0, x) -> 0 return - Context.getNullValue(ExtractValueInst::getIndexedType(Agg->getType(), + Constant::getNullValue(ExtractValueInst::getIndexedType(Agg->getType(), Idxs, Idxs + NumIdx)); @@ -542,9 +542,9 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context, const Constant *Op = (*Idxs == i) ? ConstantFoldInsertValueInstruction(Context, - Context.getNullValue(MemberTy), + Constant::getNullValue(MemberTy), Val, Idxs+1, NumIdx-1) : - Context.getNullValue(MemberTy); + Constant::getNullValue(MemberTy); Ops[i] = const_cast(Op); } if (isa(AggTy)) @@ -590,29 +590,29 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, if (isa(C1) && isa(C2)) // Handle undef ^ undef -> 0 special case. This is a common // idiom (misuse). - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); // Fallthrough case Instruction::Add: case Instruction::Sub: return UndefValue::get(C1->getType()); case Instruction::Mul: case Instruction::And: - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); case Instruction::UDiv: case Instruction::SDiv: case Instruction::URem: case Instruction::SRem: if (!isa(C2)) // undef / X -> 0 - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); return const_cast(C2); // X / undef -> undef case Instruction::Or: // X | undef -> -1 if (const VectorType *PTy = dyn_cast(C1->getType())) - return Context.getAllOnesValue(PTy); - return Context.getAllOnesValue(C1->getType()); + return Constant::getAllOnesValue(PTy); + return Constant::getAllOnesValue(C1->getType()); case Instruction::LShr: if (isa(C2) && isa(C1)) return const_cast(C1); // undef lshr undef -> undef - return Context.getNullValue(C1->getType()); // X lshr undef -> 0 + return Constant::getNullValue(C1->getType()); // X lshr undef -> 0 // undef lshr X -> 0 case Instruction::AShr: if (!isa(C2)) @@ -623,7 +623,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, return const_cast(C1); // X ashr undef --> X case Instruction::Shl: // undef << X -> 0 or X << undef -> 0 - return Context.getNullValue(C1->getType()); + return Constant::getNullValue(C1->getType()); } } @@ -651,7 +651,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, case Instruction::URem: case Instruction::SRem: if (CI2->equalsInt(1)) - return Context.getNullValue(CI2->getType()); // X % 1 == 0 + return Constant::getNullValue(CI2->getType()); // X % 1 == 0 if (CI2->equalsInt(0)) return UndefValue::get(CI2->getType()); // X % 0 == undef break; @@ -688,7 +688,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, // If checking bits we know are clear, return zero. if ((CI2->getValue() & BitsNotSet) == CI2->getValue()) - return Context.getNullValue(CI2->getType()); + return Constant::getNullValue(CI2->getType()); } } } @@ -824,144 +824,144 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, break; case Instruction::Add: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAdd(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::FAdd: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFAdd(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::Sub: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSub(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::FSub: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFSub(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::Mul: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getMul(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::FMul: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFMul(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::UDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getUDiv(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::SDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSDiv(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::FDiv: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFDiv(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::URem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getURem(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::SRem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getSRem(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::FRem: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getFRem(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::And: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAnd(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::Or: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getOr(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::Xor: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getXor(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::LShr: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getLShr(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::AShr: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getAShr(const_cast(C1), const_cast(C2))); } return ConstantVector::get(Res); case Instruction::Shl: for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy); - C2 = CP2 ? CP2->getOperand(i) : Context.getNullValue(EltTy); + C1 = CP1 ? CP1->getOperand(i) : Constant::getNullValue(EltTy); + C2 = CP2 ? CP2->getOperand(i) : Constant::getNullValue(EltTy); Res.push_back(ConstantExpr::getShl(const_cast(C1), const_cast(C2))); } @@ -1236,7 +1236,7 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context, if (CE1->getOpcode() == Instruction::ZExt) isSigned = false; if (CE1->getOpcode() == Instruction::SExt) isSigned = true; return evaluateICmpRelation(Context, CE1Op0, - Context.getNullValue(CE1Op0->getType()), + Constant::getNullValue(CE1Op0->getType()), sgnd); } @@ -1379,10 +1379,10 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // Fold FCMP_FALSE/FCMP_TRUE unconditionally. if (pred == FCmpInst::FCMP_FALSE) - return Context.getNullValue(ResultTy); + return Constant::getNullValue(ResultTy); if (pred == FCmpInst::FCMP_TRUE) - return Context.getAllOnesValue(ResultTy); + return Constant::getAllOnesValue(ResultTy); // Handle some degenerate cases first if (isa(C1) || isa(C2)) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index af3892a9bd..4f0c411e2f 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -43,6 +43,48 @@ using namespace llvm; // Becomes a no-op when multithreading is disabled. ManagedStatic > ConstantsLock; +// Constructor to create a '0' constant of arbitrary type... +static const uint64_t zero[2] = {0, 0}; +Constant* Constant::getNullValue(const Type* Ty) { + switch (Ty->getTypeID()) { + case Type::IntegerTyID: + return ConstantInt::get(Ty, 0); + case Type::FloatTyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0))); + case Type::DoubleTyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0))); + case Type::X86_FP80TyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero))); + case Type::FP128TyID: + return ConstantFP::get(Ty->getContext(), + APFloat(APInt(128, 2, zero), true)); + case Type::PPC_FP128TyID: + return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero))); + case Type::PointerTyID: + return ConstantPointerNull::get(cast(Ty)); + case Type::StructTyID: + case Type::ArrayTyID: + case Type::VectorTyID: + return ConstantAggregateZero::get(Ty); + default: + // Function, Label, or Opaque type? + assert(!"Cannot create a null constant of that type!"); + return 0; + } +} + +Constant* Constant::getAllOnesValue(const Type* Ty) { + if (const IntegerType* ITy = dyn_cast(Ty)) + return ConstantInt::get(Ty->getContext(), + APInt::getAllOnesValue(ITy->getBitWidth())); + + std::vector Elts; + const VectorType* VTy = cast(Ty); + Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType())); + assert(Elts[0] && "Not a vector integer type!"); + return cast(ConstantVector::get(Elts)); +} + void Constant::destroyConstantImpl() { // When a Constant is destroyed, there may be lingering // references to the constant by other constants in the constant pool. These @@ -148,7 +190,7 @@ void Constant::getVectorElements(LLVMContext &Context, const VectorType *VT = cast(getType()); if (isa(this)) { Elts.assign(VT->getNumElements(), - Context.getNullValue(VT->getElementType())); + Constant::getNullValue(VT->getElementType())); return; } @@ -296,14 +338,13 @@ Constant* ConstantFP::get(const Type* Ty, double V) { ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) { LLVMContext &Context = Ty->getContext(); - APFloat apf = cast (Context.getNullValue(Ty))->getValueAPF(); + APFloat apf = cast (Constant::getNullValue(Ty))->getValueAPF(); apf.changeSign(); return get(Context, apf); } Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) { - LLVMContext &Context = Ty->getContext(); if (const VectorType *PTy = dyn_cast(Ty)) if (PTy->getElementType()->isFloatingPoint()) { std::vector zeros(PTy->getNumElements(), @@ -314,7 +355,7 @@ Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) { if (Ty->isFloatingPoint()) return getNegativeZero(Ty); - return Context.getNullValue(Ty); + return Constant::getNullValue(Ty); } @@ -1751,18 +1792,16 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { Constant* ConstantExpr::getSizeOf(const Type* Ty) { // sizeof is implemented as: (i64) gep (Ty*)null, 1 // Note that a non-inbounds gep is used, as null isn't within any object. - LLVMContext &Context = Ty->getContext(); Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1); Constant *GEP = getGetElementPtr( - Context.getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1); + Constant::getNullValue(PointerType::getUnqual(Ty)), &GEPIdx, 1); return getCast(Instruction::PtrToInt, GEP, Type::Int64Ty); } Constant* ConstantExpr::getAlignOf(const Type* Ty) { - LLVMContext &Context = Ty->getContext(); // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1 const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL); - Constant *NullPtr = Context.getNullValue(AligningTy->getPointerTo()); + Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo()); Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); Constant *One = ConstantInt::get(Type::Int32Ty, 1); Constant *Indices[2] = { Zero, One }; @@ -2029,8 +2068,7 @@ Constant* ConstantExpr::getFNeg(Constant* C) { Constant* ConstantExpr::getNot(Constant* C) { assert(C->getType()->isIntOrIntVector() && "Cannot NOT a nonintegral value!"); - LLVMContext &Context = C->getType()->getContext(); - return get(Instruction::Xor, C, Context.getAllOnesValue(C->getType())); + return get(Instruction::Xor, C, Constant::getAllOnesValue(C->getType())); } Constant* ConstantExpr::getAdd(Constant* C1, Constant* C2) { diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index be71d37947..89983500b7 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -327,11 +327,11 @@ LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) /*--.. Operations on constants of any type .................................--*/ LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) { - return wrap(getGlobalContext().getNullValue(unwrap(Ty))); + return wrap(Constant::getNullValue(unwrap(Ty))); } LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) { - return wrap(getGlobalContext().getAllOnesValue(unwrap(Ty))); + return wrap(Constant::getAllOnesValue(unwrap(Ty))); } LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) { diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 368914652d..e7983e07dc 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1613,11 +1613,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, Instruction *InsertBefore) { Constant *C; if (const VectorType *PTy = dyn_cast(Op->getType())) { - C = Context.getAllOnesValue(PTy->getElementType()); + C = Constant::getAllOnesValue(PTy->getElementType()); C = ConstantVector::get( std::vector(PTy->getNumElements(), C)); } else { - C = Context.getAllOnesValue(Op->getType()); + C = Constant::getAllOnesValue(Op->getType()); } return new BinaryOperator(Instruction::Xor, Op, C, @@ -1630,11 +1630,11 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context, Constant *AllOnes; if (const VectorType *PTy = dyn_cast(Op->getType())) { // Create a vector of all ones values. - Constant *Elt = Context.getAllOnesValue(PTy->getElementType()); + Constant *Elt = Constant::getAllOnesValue(PTy->getElementType()); AllOnes = ConstantVector::get( std::vector(PTy->getNumElements(), Elt)); } else { - AllOnes = Context.getAllOnesValue(Op->getType()); + AllOnes = Constant::getAllOnesValue(Op->getType()); } return new BinaryOperator(Instruction::Xor, Op, AllOnes, diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 7dcfcf484c..107905f40a 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -32,49 +32,6 @@ LLVMContext& llvm::getGlobalContext() { LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { } LLVMContext::~LLVMContext() { delete pImpl; } -// Constant accessors - -// Constructor to create a '0' constant of arbitrary type... -static const uint64_t zero[2] = {0, 0}; -Constant* LLVMContext::getNullValue(const Type* Ty) { - switch (Ty->getTypeID()) { - case Type::IntegerTyID: - return ConstantInt::get(Ty, 0); - case Type::FloatTyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(32, 0))); - case Type::DoubleTyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(64, 0))); - case Type::X86_FP80TyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(80, 2, zero))); - case Type::FP128TyID: - return ConstantFP::get(Ty->getContext(), - APFloat(APInt(128, 2, zero), true)); - case Type::PPC_FP128TyID: - return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero))); - case Type::PointerTyID: - return ConstantPointerNull::get(cast(Ty)); - case Type::StructTyID: - case Type::ArrayTyID: - case Type::VectorTyID: - return ConstantAggregateZero::get(Ty); - default: - // Function, Label, or Opaque type? - assert(!"Cannot create a null constant of that type!"); - return 0; - } -} - -Constant* LLVMContext::getAllOnesValue(const Type* Ty) { - if (const IntegerType* ITy = dyn_cast(Ty)) - return ConstantInt::get(*this, APInt::getAllOnesValue(ITy->getBitWidth())); - - std::vector Elts; - const VectorType* VTy = cast(Ty); - Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType())); - assert(Elts[0] && "Not a vector integer type!"); - return cast(ConstantVector::get(Elts)); -} - // MDNode accessors MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) { return pImpl->getMDNode(Vals, NumVals); diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 4e73b8f9e9..9d4e98ca50 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -298,8 +298,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { if (isa(BBTerm->getType())) BBTerm->replaceAllUsesWith(UndefValue::get(BBTerm->getType())); else if (BB->getTerminator()->getType() != Type::VoidTy) - BBTerm->replaceAllUsesWith( - BD.getContext().getNullValue(BBTerm->getType())); + BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType())); // Replace the old terminator instruction. BB->getInstList().pop_back(); diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index f443f36d0b..f15fa90345 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -74,7 +74,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I, if (isa(TheInst->getType())) TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType())); else if (TheInst->getType() != Type::VoidTy) - TheInst->replaceAllUsesWith(Context.getNullValue(TheInst->getType())); + TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType())); // Remove the instruction from the program. TheInst->getParent()->getInstList().erase(TheInst); diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 0fedfe3439..00f26fe823 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -650,8 +650,6 @@ bool BugDriver::debugMiscompilation() { /// static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, Module *Safe) { - LLVMContext &Context = BD.getContext(); - // Clean up the modules, removing extra cruft that we don't need anymore... Test = BD.performFinalCleanups(Test); @@ -723,7 +721,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, // sbyte* so it matches the signature of the resolver function. // GetElementPtr *funcName, ulong 0, ulong 0 - std::vector GEPargs(2, Context.getNullValue(Type::Int32Ty)); + std::vector GEPargs(2, Constant::getNullValue(Type::Int32Ty)); Value *GEP = ConstantExpr::getGetElementPtr(funcName, &GEPargs[0], 2); std::vector ResolverArgs; diff --git a/tools/bugpoint/TestPasses.cpp b/tools/bugpoint/TestPasses.cpp index 4bfc42c818..900bf632a8 100644 --- a/tools/bugpoint/TestPasses.cpp +++ b/tools/bugpoint/TestPasses.cpp @@ -60,7 +60,7 @@ namespace { for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) if (CallInst *CI = dyn_cast(I)) { if (!CI->use_empty()) - CI->replaceAllUsesWith(BB.getContext().getNullValue(CI->getType())); + CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); CI->getParent()->getInstList().erase(CI); break; } diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp index fc2b9de7e4..833c68405b 100644 --- a/unittests/Support/ValueHandleTest.cpp +++ b/unittests/Support/ValueHandleTest.cpp @@ -295,7 +295,7 @@ TEST_F(ValueHandle, CallbackVH_DeletionCanRAUW) { private: virtual void deleted() { - getValPtr()->replaceAllUsesWith(Context->getNullValue(Type::Int32Ty)); + getValPtr()->replaceAllUsesWith(Constant::getNullValue(Type::Int32Ty)); setValPtr(NULL); } virtual void allUsesReplacedWith(Value *new_value) { -- cgit v1.2.3