From eed707b1e6097aac2bb6b3d47271f6300ace7f2e Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 24 Jul 2009 23:12:02 +0000 Subject: Revert the ConstantInt constructors back to their 2.5 forms where possible, thanks to contexts-on-types. More to come. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77011 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicAliasAnalysis.cpp | 4 +- lib/Analysis/ConstantFolding.cpp | 20 +- lib/Analysis/DebugInfo.cpp | 68 ++-- lib/Analysis/ScalarEvolution.cpp | 31 +- lib/Analysis/ScalarEvolutionExpander.cpp | 9 +- lib/AsmParser/LLParser.cpp | 2 +- lib/Bitcode/Reader/BitcodeReader.cpp | 11 +- lib/CodeGen/IntrinsicLowering.cpp | 62 ++-- lib/CodeGen/SelectionDAG/FastISel.cpp | 2 +- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 2 +- lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp | 2 +- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- lib/CodeGen/ShadowStackGC.cpp | 18 +- lib/ExecutionEngine/JIT/JIT.cpp | 6 +- lib/Target/ARM/ARMBaseRegisterInfo.cpp | 3 +- lib/Target/ARM/ARMISelDAGToDAG.cpp | 3 +- lib/Target/ARM/Thumb1RegisterInfo.cpp | 3 +- lib/Target/ARM/Thumb2RegisterInfo.cpp | 3 +- lib/Target/Alpha/AlphaISelDAGToDAG.cpp | 2 +- lib/Target/CBackend/CBackend.cpp | 2 +- lib/Target/X86/X86ISelLowering.cpp | 8 +- lib/Target/XCore/XCoreISelDAGToDAG.cpp | 3 +- lib/Transforms/IPO/ArgumentPromotion.cpp | 10 +- lib/Transforms/IPO/GlobalOpt.cpp | 12 +- lib/Transforms/IPO/LowerSetJmp.cpp | 8 +- lib/Transforms/Instrumentation/ProfilingUtils.cpp | 6 +- lib/Transforms/Instrumentation/RSProfiling.cpp | 28 +- lib/Transforms/Scalar/CodeGenPrepare.cpp | 4 +- lib/Transforms/Scalar/IndVarSimplify.cpp | 6 +- lib/Transforms/Scalar/InstructionCombining.cpp | 264 +++++++-------- lib/Transforms/Scalar/JumpThreading.cpp | 5 +- lib/Transforms/Scalar/LoopIndexSplit.cpp | 4 +- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 8 +- lib/Transforms/Scalar/LoopUnswitch.cpp | 2 +- lib/Transforms/Scalar/MemCpyOptimizer.cpp | 6 +- lib/Transforms/Scalar/PredicateSimplifier.cpp | 23 +- lib/Transforms/Scalar/Reassociate.cpp | 2 +- lib/Transforms/Scalar/ScalarReplAggregates.cpp | 34 +- lib/Transforms/Scalar/SimplifyLibCalls.cpp | 80 ++--- lib/Transforms/Utils/CodeExtractor.cpp | 14 +- lib/Transforms/Utils/InlineFunction.cpp | 4 +- lib/Transforms/Utils/LowerAllocations.cpp | 2 +- lib/Transforms/Utils/LowerInvoke.cpp | 12 +- lib/Transforms/Utils/SimplifyCFG.cpp | 4 +- lib/VMCore/AutoUpgrade.cpp | 36 +- lib/VMCore/ConstantFold.cpp | 90 ++--- lib/VMCore/Constants.cpp | 336 ++++--------------- lib/VMCore/Core.cpp | 3 +- lib/VMCore/Instructions.cpp | 2 +- lib/VMCore/LLVMContext.cpp | 59 +--- lib/VMCore/LLVMContextImpl.cpp | 386 +--------------------- lib/VMCore/LLVMContextImpl.h | 350 +++++++++++++++++++- 52 files changed, 887 insertions(+), 1179 deletions(-) (limited to 'lib') diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 49d771a42d..ed78c7ea46 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -780,10 +780,10 @@ BasicAliasAnalysis::CheckGEPInstructions( // if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) GEP1Ops[i] = - Context.getConstantInt(Type::Int64Ty,AT->getNumElements()-1); + ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1); else if (const VectorType *VT = dyn_cast(BasePtr1Ty)) GEP1Ops[i] = - Context.getConstantInt(Type::Int64Ty,VT->getNumElements()-1); + ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1); } } diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index d60b4f6800..7ac8b97768 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -113,7 +113,7 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) && GV1 == GV2) { // (&GV+C1) - (&GV+C2) -> C1-C2, pointer arithmetic cannot overflow. - return Context.getConstantInt(Op0->getType(), Offs1-Offs2); + return ConstantInt::get(Op0->getType(), Offs1-Offs2); } } @@ -151,7 +151,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps, uint64_t Offset = TD->getIndexedOffset(Ptr->getType(), (Value**)Ops+1, NumOps-1); - Constant *C = Context.getConstantInt(TD->getIntPtrType(), Offset+BasePtr); + Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr); return Context.getConstantExprIntToPtr(C, ResultTy); } @@ -232,7 +232,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, // Shift it to the right place, depending on endianness. Src = Context.getConstantExprShl(Src, - Context.getConstantInt(Src->getType(), ShiftAmt)); + ConstantInt::get(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize; // Mix it in. @@ -255,7 +255,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy, // Shift the piece of the value into the right place, depending on // endianness. Constant *Elt = Context.getConstantExprLShr(Src, - Context.getConstantInt(Src->getType(), ShiftAmt)); + ConstantInt::get(Src->getType(), ShiftAmt)); ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize; // Truncate and remember this piece. @@ -376,7 +376,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, unsigned InWidth = Input->getType()->getScalarSizeInBits(); if (TD->getPointerSizeInBits() < InWidth) { Constant *Mask = - Context.getConstantInt(APInt::getLowBitsSet(InWidth, + ConstantInt::get(Context, APInt::getLowBitsSet(InWidth, TD->getPointerSizeInBits())); Input = Context.getConstantExprAnd(Input, Mask); } @@ -420,7 +420,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, AT->getNumElements()))) { Constant *Index[] = { Context.getNullValue(CE->getType()), - Context.getConstantInt(ElemIdx) + ConstantInt::get(Context, ElemIdx) }; return Context.getConstantExprGetElementPtr(GV, &Index[0], 2); @@ -801,13 +801,13 @@ llvm::ConstantFoldCall(Function *F, } } else if (ConstantInt *Op = dyn_cast(Operands[0])) { if (Len > 11 && !memcmp(Str, "llvm.bswap", 10)) - return Context.getConstantInt(Op->getValue().byteSwap()); + return ConstantInt::get(Context, Op->getValue().byteSwap()); else if (Len > 11 && !memcmp(Str, "llvm.ctpop", 10)) - return Context.getConstantInt(Ty, Op->getValue().countPopulation()); + return ConstantInt::get(Ty, Op->getValue().countPopulation()); else if (Len > 10 && !memcmp(Str, "llvm.cttz", 9)) - return Context.getConstantInt(Ty, Op->getValue().countTrailingZeros()); + return ConstantInt::get(Ty, Op->getValue().countTrailingZeros()); else if (Len > 10 && !memcmp(Str, "llvm.ctlz", 9)) - return Context.getConstantInt(Ty, Op->getValue().countLeadingZeros()); + return ConstantInt::get(Ty, Op->getValue().countLeadingZeros()); } } else if (NumOperands == 2) { if (ConstantFP *Op1 = dyn_cast(Operands[0])) { diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index f1ad08aefa..aded6d8eee 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -482,7 +482,7 @@ Constant *DIFactory::getCastToEmpty(DIDescriptor D) { Constant *DIFactory::GetTagConstant(unsigned TAG) { assert((TAG & LLVMDebugVersionMask) == 0 && "Tag too large for debug encoding!"); - return VMContext.getConstantInt(Type::Int32Ty, TAG | LLVMDebugVersion); + return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); } Constant *DIFactory::GetStringConstant(const std::string &String) { @@ -541,8 +541,8 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subrange_type), - VMContext.getConstantInt(Type::Int64Ty, Lo), - VMContext.getConstantInt(Type::Int64Ty, Hi) + ConstantInt::get(Type::Int64Ty, Lo), + ConstantInt::get(Type::Int64Ty, Hi) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -577,14 +577,14 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), VMContext.getNullValue(EmptyStructPtr), - VMContext.getConstantInt(Type::Int32Ty, LangID), + ConstantInt::get(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), GetStringConstant(Producer), - VMContext.getConstantInt(Type::Int1Ty, isMain), - VMContext.getConstantInt(Type::Int1Ty, isOptimized), + ConstantInt::get(Type::Int1Ty, isMain), + ConstantInt::get(Type::Int1Ty, isOptimized), GetStringConstant(Flags), - VMContext.getConstantInt(Type::Int32Ty, RunTimeVer) + ConstantInt::get(Type::Int32Ty, RunTimeVer) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -603,7 +603,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_enumerator), GetStringConstant(Name), - VMContext.getConstantInt(Type::Int64Ty, Val) + ConstantInt::get(Type::Int64Ty, Val) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -632,12 +632,12 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNumber), - VMContext.getConstantInt(Type::Int64Ty, SizeInBits), - VMContext.getConstantInt(Type::Int64Ty, AlignInBits), - VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), - VMContext.getConstantInt(Type::Int32Ty, Flags), - VMContext.getConstantInt(Type::Int32Ty, Encoding) + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, Encoding) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -668,11 +668,11 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNumber), - VMContext.getConstantInt(Type::Int64Ty, SizeInBits), - VMContext.getConstantInt(Type::Int64Ty, AlignInBits), - VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), - VMContext.getConstantInt(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom) }; @@ -706,14 +706,14 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNumber), - VMContext.getConstantInt(Type::Int64Ty, SizeInBits), - VMContext.getConstantInt(Type::Int64Ty, AlignInBits), - VMContext.getConstantInt(Type::Int64Ty, OffsetInBits), - VMContext.getConstantInt(Type::Int32Ty, Flags), + ConstantInt::get(Type::Int32Ty, LineNumber), + ConstantInt::get(Type::Int64Ty, SizeInBits), + ConstantInt::get(Type::Int64Ty, AlignInBits), + ConstantInt::get(Type::Int64Ty, OffsetInBits), + ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - VMContext.getConstantInt(Type::Int32Ty, RuntimeLang) + ConstantInt::get(Type::Int32Ty, RuntimeLang) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -748,10 +748,10 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type), - VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), - VMContext.getConstantInt(Type::Int1Ty, isDefinition) + ConstantInt::get(Type::Int1Ty, isLocalToUnit), + ConstantInt::get(Type::Int1Ty, isDefinition) }; Constant *Init = VMContext.getConstantStruct(Elts, @@ -781,10 +781,10 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, GetStringConstant(DisplayName), GetStringConstant(LinkageName), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type), - VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit), - VMContext.getConstantInt(Type::Int1Ty, isDefinition), + ConstantInt::get(Type::Int1Ty, isLocalToUnit), + ConstantInt::get(Type::Int1Ty, isDefinition), VMContext.getConstantExprBitCast(Val, EmptyStructPtr) }; @@ -810,7 +810,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), - VMContext.getConstantInt(Type::Int32Ty, LineNo), + ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type) }; @@ -862,8 +862,8 @@ void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo, // Invoke llvm.dbg.stoppoint Value *Args[] = { - VMContext.getConstantInt(llvm::Type::Int32Ty, LineNo), - VMContext.getConstantInt(llvm::Type::Int32Ty, ColNo), + ConstantInt::get(llvm::Type::Int32Ty, LineNo), + ConstantInt::get(llvm::Type::Int32Ty, ColNo), getCastToEmpty(CU) }; CallInst::Create(StopPointFn, Args, Args+3, "", BB); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 28e9902ab7..6b64648f17 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -192,13 +192,13 @@ const SCEV *ScalarEvolution::getConstant(ConstantInt *V) { } const SCEV *ScalarEvolution::getConstant(const APInt& Val) { - return getConstant(getContext().getConstantInt(Val)); + return getConstant(ConstantInt::get(getContext(), Val)); } const SCEV * ScalarEvolution::getConstant(const Type *Ty, uint64_t V, bool isSigned) { return getConstant( - getContext().getConstantInt(cast(Ty), V, isSigned)); + ConstantInt::get(cast(Ty), V, isSigned)); } const Type *SCEVConstant::getType() const { return V->getType(); } @@ -1518,7 +1518,8 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl &Ops) { ++Idx; while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! - ConstantInt *Fold = getContext().getConstantInt(LHSC->getValue()->getValue() * + ConstantInt *Fold = ConstantInt::get(getContext(), + LHSC->getValue()->getValue() * RHSC->getValue()->getValue()); Ops[0] = getConstant(Fold); Ops.erase(Ops.begin()+1); // Erase the folded element @@ -1869,7 +1870,7 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl &Ops) { assert(Idx < Ops.size()); while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! - ConstantInt *Fold = getContext().getConstantInt( + ConstantInt *Fold = ConstantInt::get(getContext(), APIntOps::smax(LHSC->getValue()->getValue(), RHSC->getValue()->getValue())); Ops[0] = getConstant(Fold); @@ -1966,7 +1967,7 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl &Ops) { assert(Idx < Ops.size()); while (const SCEVConstant *RHSC = dyn_cast(Ops[Idx])) { // We found two constants, fold them together! - ConstantInt *Fold = getContext().getConstantInt( + ConstantInt *Fold = ConstantInt::get(getContext(), APIntOps::umax(LHSC->getValue()->getValue(), RHSC->getValue()->getValue())); Ops[0] = getConstant(Fold); @@ -2133,7 +2134,7 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) { /// specified signed integer value and return a SCEV for the constant. const SCEV *ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { const IntegerType *ITy = cast(getEffectiveSCEVType(Ty)); - return getConstant(getContext().getConstantInt(ITy, Val)); + return getConstant(ConstantInt::get(ITy, Val)); } /// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V @@ -2896,7 +2897,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { // Turn shift left of a constant amount into a multiply. if (ConstantInt *SA = dyn_cast(U->getOperand(1))) { uint32_t BitWidth = cast(V->getType())->getBitWidth(); - Constant *X = getContext().getConstantInt( + Constant *X = ConstantInt::get(getContext(), APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth))); return getMulExpr(getSCEV(U->getOperand(0)), getSCEV(X)); } @@ -2906,7 +2907,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) { // Turn logical shift right of a constant into a unsigned divide. if (ConstantInt *SA = dyn_cast(U->getOperand(1))) { uint32_t BitWidth = cast(V->getType())->getBitWidth(); - Constant *X = getContext().getConstantInt( + Constant *X = ConstantInt::get(getContext(), APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth))); return getUDivExpr(getSCEV(U->getOperand(0)), getSCEV(X)); } @@ -3558,7 +3559,7 @@ ScalarEvolution::ComputeLoadConstantCompareBackedgeTakenCount( unsigned MaxSteps = MaxBruteForceIterations; for (unsigned IterationNum = 0; IterationNum != MaxSteps; ++IterationNum) { - ConstantInt *ItCst = getContext().getConstantInt( + ConstantInt *ItCst = ConstantInt::get( cast(IdxExpr->getType()), IterationNum); ConstantInt *Val = EvaluateConstantChrecAtConstant(IdxExpr, ItCst, *this); @@ -4072,9 +4073,9 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) { LLVMContext &Context = SE.getContext(); ConstantInt *Solution1 = - Context.getConstantInt((NegB + SqrtVal).sdiv(TwoA)); + ConstantInt::get(Context, (NegB + SqrtVal).sdiv(TwoA)); ConstantInt *Solution2 = - Context.getConstantInt((NegB - SqrtVal).sdiv(TwoA)); + ConstantInt::get(Context, (NegB - SqrtVal).sdiv(TwoA)); return std::make_pair(SE.getConstant(Solution1), SE.getConstant(Solution2)); @@ -4836,7 +4837,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, // The exit value should be (End+A)/A. APInt ExitVal = (End + A).udiv(A); - ConstantInt *ExitValue = SE.getContext().getConstantInt(ExitVal); + ConstantInt *ExitValue = ConstantInt::get(SE.getContext(), ExitVal); // Evaluate at the exit value. If we really did fall out of the valid // range, then we computed our trip count, otherwise wrap around or other @@ -4848,7 +4849,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, // Ensure that the previous value is in the range. This is a sanity check. assert(Range.contains( EvaluateConstantChrecAtConstant(this, - SE.getContext().getConstantInt(ExitVal - One), SE)->getValue()) && + ConstantInt::get(SE.getContext(), ExitVal - One), SE)->getValue()) && "Linear scev computation is off in a bad way!"); return SE.getConstant(ExitValue); } else if (isQuadratic()) { @@ -4883,7 +4884,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, if (Range.contains(R1Val->getValue())) { // The next iteration must be out of the range... ConstantInt *NextVal = - SE.getContext().getConstantInt(R1->getValue()->getValue()+1); + ConstantInt::get(SE.getContext(), R1->getValue()->getValue()+1); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); if (!Range.contains(R1Val->getValue())) @@ -4894,7 +4895,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range, // If R1 was not in the range, then it is a good return value. Make // sure that R1-1 WAS in the range though, just in case. ConstantInt *NextVal = - SE.getContext().getConstantInt(R1->getValue()->getValue()-1); + ConstantInt::get(SE.getContext(), R1->getValue()->getValue()-1); R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE); if (Range.contains(R1Val->getValue())) return R1; diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp index 6d55ffc421..eb2236b2d7 100644 --- a/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/lib/Analysis/ScalarEvolutionExpander.cpp @@ -167,7 +167,7 @@ static bool FactorOutConstant(const SCEV *&S, // For a Constant, check for a multiple of the given factor. if (const SCEVConstant *C = dyn_cast(S)) { ConstantInt *CI = - SE.getContext().getConstantInt(C->getValue()->getValue().sdiv(Factor)); + ConstantInt::get(SE.getContext(), C->getValue()->getValue().sdiv(Factor)); // If the quotient is zero and the remainder is non-zero, reject // the value at this scale. It will be considered for subsequent // smaller scales. @@ -298,8 +298,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, uint64_t FullOffset = C->getValue()->getZExtValue(); if (FullOffset < SL.getSizeInBytes()) { unsigned ElIdx = SL.getElementContainingOffset(FullOffset); - GepIndices.push_back( - getContext().getConstantInt(Type::Int32Ty, ElIdx)); + GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx)); ElTy = STy->getTypeAtIndex(ElIdx); Ops[0] = SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx)); @@ -412,7 +411,7 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) { const APInt &RHS = SC->getValue()->getValue(); if (RHS.isPowerOf2()) return InsertBinop(Instruction::LShr, LHS, - getContext().getConstantInt(Ty, RHS.logBase2())); + ConstantInt::get(Ty, RHS.logBase2())); } Value *RHS = expandCodeFor(S->getRHS(), Ty); @@ -532,7 +531,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) { // Insert a unit add instruction right before the terminator corresponding // to the back-edge. - Constant *One = getContext().getConstantInt(Ty, 1); + Constant *One = ConstantInt::get(Ty, 1); Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next", (*HPI)->getTerminator()); InsertedValues.insert(Add); diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index 45e70c8f9c..10d9470d40 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2138,7 +2138,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, if (!isa(Ty)) return Error(ID.Loc, "integer constant must have integer type"); ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits()); - V = Context.getConstantInt(ID.APSIntVal); + V = ConstantInt::get(Context, ID.APSIntVal); return false; case ValID::t_APFloat: if (!Ty->isFloatingPoint() || diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 01b3eb3bce..cf90c64ac6 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -877,7 +877,7 @@ bool BitcodeReader::ParseConstants() { case bitc::CST_CODE_INTEGER: // INTEGER: [intval] if (!isa(CurTy) || Record.empty()) return Error("Invalid CST_INTEGER record"); - V = Context.getConstantInt(CurTy, DecodeSignRotatedValue(Record[0])); + V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0])); break; case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval] if (!isa(CurTy) || Record.empty()) @@ -888,8 +888,9 @@ bool BitcodeReader::ParseConstants() { Words.resize(NumWords); for (unsigned i = 0; i != NumWords; ++i) Words[i] = DecodeSignRotatedValue(Record[i]); - V = Context.getConstantInt(APInt(cast(CurTy)->getBitWidth(), - NumWords, &Words[0])); + V = ConstantInt::get(Context, + APInt(cast(CurTy)->getBitWidth(), + NumWords, &Words[0])); break; } case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval] @@ -951,7 +952,7 @@ bool BitcodeReader::ParseConstants() { unsigned Size = Record.size(); std::vector Elts; for (unsigned i = 0; i != Size; ++i) - Elts.push_back(Context.getConstantInt(EltTy, Record[i])); + Elts.push_back(ConstantInt::get(EltTy, Record[i])); V = Context.getConstantArray(ATy, Elts); break; } @@ -965,7 +966,7 @@ bool BitcodeReader::ParseConstants() { unsigned Size = Record.size(); std::vector Elts; for (unsigned i = 0; i != Size; ++i) - Elts.push_back(Context.getConstantInt(EltTy, Record[i])); + Elts.push_back(ConstantInt::get(EltTy, Record[i])); Elts.push_back(Context.getNullValue(EltTy)); V = Context.getConstantArray(ATy, Elts); break; diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 34cbf2f9b2..113eea0777 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -159,27 +159,27 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { switch(BitSize) { default: llvm_unreachable("Unhandled type size of value to byteswap!"); case 16: { - Value *Tmp1 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), + Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), "bswap.2"); - Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), + Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), "bswap.1"); V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16"); break; } case 32: { - Value *Tmp4 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24), + Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), "bswap.4"); - Value *Tmp3 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), + Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), "bswap.3"); - Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), + Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), "bswap.2"); - Value *Tmp1 = Builder.CreateLShr(V,Context.getConstantInt(V->getType(), 24), + Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24), "bswap.1"); Tmp3 = Builder.CreateAnd(Tmp3, - Context.getConstantInt(Type::Int32Ty, 0xFF0000), + ConstantInt::get(Type::Int32Ty, 0xFF0000), "bswap.and3"); Tmp2 = Builder.CreateAnd(Tmp2, - Context.getConstantInt(Type::Int32Ty, 0xFF00), + ConstantInt::get(Type::Int32Ty, 0xFF00), "bswap.and2"); Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1"); Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2"); @@ -187,44 +187,44 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { break; } case 64: { - Value *Tmp8 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 56), + Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56), "bswap.8"); - Value *Tmp7 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 40), + Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40), "bswap.7"); - Value *Tmp6 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24), + Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), "bswap.6"); - Value *Tmp5 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), + Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), "bswap.5"); - Value* Tmp4 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), + Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), "bswap.4"); Value* Tmp3 = Builder.CreateLShr(V, - Context.getConstantInt(V->getType(), 24), + ConstantInt::get(V->getType(), 24), "bswap.3"); Value* Tmp2 = Builder.CreateLShr(V, - Context.getConstantInt(V->getType(), 40), + ConstantInt::get(V->getType(), 40), "bswap.2"); Value* Tmp1 = Builder.CreateLShr(V, - Context.getConstantInt(V->getType(), 56), + ConstantInt::get(V->getType(), 56), "bswap.1"); Tmp7 = Builder.CreateAnd(Tmp7, - Context.getConstantInt(Type::Int64Ty, + ConstantInt::get(Type::Int64Ty, 0xFF000000000000ULL), "bswap.and7"); Tmp6 = Builder.CreateAnd(Tmp6, - Context.getConstantInt(Type::Int64Ty, + ConstantInt::get(Type::Int64Ty, 0xFF0000000000ULL), "bswap.and6"); Tmp5 = Builder.CreateAnd(Tmp5, - Context.getConstantInt(Type::Int64Ty, 0xFF00000000ULL), + ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL), "bswap.and5"); Tmp4 = Builder.CreateAnd(Tmp4, - Context.getConstantInt(Type::Int64Ty, 0xFF000000ULL), + ConstantInt::get(Type::Int64Ty, 0xFF000000ULL), "bswap.and4"); Tmp3 = Builder.CreateAnd(Tmp3, - Context.getConstantInt(Type::Int64Ty, 0xFF0000ULL), + ConstantInt::get(Type::Int64Ty, 0xFF0000ULL), "bswap.and3"); Tmp2 = Builder.CreateAnd(Tmp2, - Context.getConstantInt(Type::Int64Ty, 0xFF00ULL), + ConstantInt::get(Type::Int64Ty, 0xFF00ULL), "bswap.and2"); Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1"); Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2"); @@ -254,23 +254,23 @@ static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) { unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); unsigned WordSize = (BitSize + 63) / 64; - Value *Count = Context.getConstantInt(V->getType(), 0); + Value *Count = ConstantInt::get(V->getType(), 0); for (unsigned n = 0; n < WordSize; ++n) { Value *PartValue = V; for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize); i <<= 1, ++ct) { - Value *MaskCst = Context.getConstantInt(V->getType(), MaskValues[ct]); + Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]); Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1"); Value *VShift = Builder.CreateLShr(PartValue, - Context.getConstantInt(V->getType(), i), + ConstantInt::get(V->getType(), i), "ctpop.sh"); Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2"); PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step"); } Count = Builder.CreateAdd(PartValue, Count, "ctpop.part"); if (BitSize > 64) { - V = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 64), + V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64), "ctpop.part.sh"); BitSize -= 64; } @@ -287,7 +287,7 @@ static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) { unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); for (unsigned i = 1; i < BitSize; i <<= 1) { - Value *ShVal = Context.getConstantInt(V->getType(), i); + Value *ShVal = ConstantInt::get(V->getType(), i); ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh"); V = Builder.CreateOr(V, ShVal, "ctlz.step"); } @@ -378,7 +378,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { Value *Src = CI->getOperand(1); Value *NotSrc = Builder.CreateNot(Src); NotSrc->setName(Src->getName() + ".not"); - Value *SrcM1 = Context.getConstantInt(Src->getType(), 1); + Value *SrcM1 = ConstantInt::get(Src->getType(), 1); SrcM1 = Builder.CreateSub(Src, SrcM1); Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI); CI->replaceAllUsesWith(Src); @@ -414,7 +414,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::readcyclecounter: { cerr << "WARNING: this target does not support the llvm.readcyclecoun" << "ter intrinsic. It is being lowered to a constant 0\n"; - CI->replaceAllUsesWith(Context.getConstantInt(Type::Int64Ty, 0)); + CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0)); break; } @@ -434,7 +434,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::eh_typeid_for_i32: case Intrinsic::eh_typeid_for_i64: // Return something different to eh_selector. - CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1)); + CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); break; case Intrinsic::var_annotation: @@ -506,7 +506,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::flt_rounds: // Lower to "round to the nearest" if (CI->getType() != Type::VoidTy) - CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1)); + CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1)); break; } diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 547a7bf281..01493bbba7 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -109,7 +109,7 @@ unsigned FastISel::getRegForValue(Value *V) { APInt IntVal(IntBitWidth, 2, x); unsigned IntegerReg = - getRegForValue(V->getContext().getConstantInt(IntVal)); + getRegForValue(ConstantInt::get(V->getContext(), IntVal)); if (IntegerReg != 0) Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg); } diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 787f7ed8f9..4f4c255b08 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -2038,7 +2038,7 @@ SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float) } if (TLI.isLittleEndian()) FF <<= 32; - Constant *FudgeFactor = DAG.getContext()->getConstantInt(Type::Int64Ty, FF); + Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); unsigned Alignment = cast(CPIdx)->getAlignment(); diff --git a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 1447ee339a..dd66f7bb85 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -2306,7 +2306,7 @@ SDValue DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) { // Build a 64 bit pair (0, FF) in the constant pool, with FF in the lo bits. SDValue FudgePtr = DAG.getConstantPool( - DAG.getContext()->getConstantInt(FF.zext(64)), + ConstantInt::get(*DAG.getContext(), FF.zext(64)), TLI.getPointerTy()); // Get a pointer to FF if the sign bit was set, or to 0 otherwise. diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index c2595bced3..5a46288e58 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -874,7 +874,7 @@ SDValue SelectionDAG::getConstant(uint64_t Val, MVT VT, bool isT) { } SDValue SelectionDAG::getConstant(const APInt &Val, MVT VT, bool isT) { - return getConstant(*Context->getConstantInt(Val), VT, isT); + return getConstant(*ConstantInt::get(*Context, Val), VT, isT); } SDValue SelectionDAG::getConstant(const ConstantInt &Val, MVT VT, bool isT) { diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index fe843f7250..e3281d2492 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -203,8 +203,8 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) { } Constant *BaseElts[] = { - Context.getConstantInt(Type::Int32Ty, Roots.size(), false), - Context.getConstantInt(Type::Int32Ty, NumMeta, false), + ConstantInt::get(Type::Int32Ty, Roots.size(), false), + ConstantInt::get(Type::Int32Ty, NumMeta, false), }; Constant *DescriptorElts[] = { @@ -236,8 +236,8 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) { GlobalVariable::InternalLinkage, FrameMap, "__gc_" + F.getName()); - Constant *GEPIndices[2] = { Context.getConstantInt(Type::Int32Ty, 0), - Context.getConstantInt(Type::Int32Ty, 0) }; + Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0), + ConstantInt::get(Type::Int32Ty, 0) }; return Context.getConstantExprGetElementPtr(GV, GEPIndices, 2); } @@ -342,9 +342,9 @@ void ShadowStackGC::CollectRoots(Function &F) { GetElementPtrInst * ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, int Idx, int Idx2, const char *Name) { - Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0), - Context.getConstantInt(Type::Int32Ty, Idx), - Context.getConstantInt(Type::Int32Ty, Idx2) }; + Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0), + ConstantInt::get(Type::Int32Ty, Idx), + ConstantInt::get(Type::Int32Ty, Idx2) }; Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name); assert(isa(Val) && "Unexpected folded constant"); @@ -355,8 +355,8 @@ ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, GetElementPtrInst * ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr, int Idx, const char *Name) { - Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0), - Context.getConstantInt(Type::Int32Ty, Idx) }; + Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0), + ConstantInt::get(Type::Int32Ty, Idx) }; Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name); assert(isa(Val) && "Unexpected folded constant"); diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index ec170fe1bf..a9b062d85e 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -487,7 +487,7 @@ GenericValue JIT::runFunction(Function *F, switch (ArgTy->getTypeID()) { default: llvm_unreachable("Unknown argument type for function call!"); case Type::IntegerTyID: - C = Context.getConstantInt(AV.IntVal); + C = ConstantInt::get(F->getContext(), AV.IntVal); break; case Type::FloatTyID: C = Context.getConstantFP(APFloat(AV.FloatVal)); @@ -503,9 +503,9 @@ GenericValue JIT::runFunction(Function *F, case Type::PointerTyID: void *ArgPtr = GVTOP(AV); if (sizeof(void*) == 4) - C = Context.getConstantInt(Type::Int32Ty, (int)(intptr_t)ArgPtr); + C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr); else - C = Context.getConstantInt(Type::Int64Ty, (intptr_t)ArgPtr); + C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr); // Cast the integer to pointer C = Context.getConstantExprIntToPtr(C, ArgTy); break; diff --git a/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/lib/Target/ARM/ARMBaseRegisterInfo.cpp index d93c4edb4e..6b0692c763 100644 --- a/lib/Target/ARM/ARMBaseRegisterInfo.cpp +++ b/lib/Target/ARM/ARMBaseRegisterInfo.cpp @@ -903,8 +903,7 @@ emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = - MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val); + Constant *C = ConstantInt::get(Type::Int32Ty, Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp)) diff --git a/lib/Target/ARM/ARMISelDAGToDAG.cpp b/lib/Target/ARM/ARMISelDAGToDAG.cpp index cdb27c252f..794692d839 100644 --- a/lib/Target/ARM/ARMISelDAGToDAG.cpp +++ b/lib/Target/ARM/ARMISelDAGToDAG.cpp @@ -877,8 +877,7 @@ SDNode *ARMDAGToDAGISel::Select(SDValue Op) { !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs. if (UseCP) { SDValue CPIdx = - CurDAG->getTargetConstantPool( - CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val), + CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val), TLI.getPointerTy()); SDNode *ResNode; diff --git a/lib/Target/ARM/Thumb1RegisterInfo.cpp b/lib/Target/ARM/Thumb1RegisterInfo.cpp index 0ae54b54a2..bf721a5e99 100644 --- a/lib/Target/ARM/Thumb1RegisterInfo.cpp +++ b/lib/Target/ARM/Thumb1RegisterInfo.cpp @@ -58,8 +58,7 @@ void Thumb1RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = - MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val); + Constant *C = ConstantInt::get(Type::Int32Ty, Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::tLDRcp)) diff --git a/lib/Target/ARM/Thumb2RegisterInfo.cpp b/lib/Target/ARM/Thumb2RegisterInfo.cpp index f2351e25de..106bc256df 100644 --- a/lib/Target/ARM/Thumb2RegisterInfo.cpp +++ b/lib/Target/ARM/Thumb2RegisterInfo.cpp @@ -52,8 +52,7 @@ void Thumb2RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB, unsigned PredReg) const { MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); - Constant *C = - MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val); + Constant *C = ConstantInt::get(Type::Int32Ty, Val); unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); BuildMI(MBB, MBBI, dl, TII.get(ARM::t2LDRpci)) diff --git a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp index 4f7ac3cf6b..f783b8bd39 100644 --- a/lib/Target/Alpha/AlphaISelDAGToDAG.cpp +++ b/lib/Target/Alpha/AlphaISelDAGToDAG.cpp @@ -305,7 +305,7 @@ SDNode *AlphaDAGToDAGISel::Select(SDValue Op) { // val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true break; //(zext (LDAH (LDA))) //Else use the constant pool - ConstantInt *C = CurDAG->getContext()->getConstantInt(Type::Int64Ty, uval); + ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval); SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64); SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, dl, MVT::i64, CPI, SDValue(getGlobalBaseReg(), 0)); diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index d49a02397b..4defaec163 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -3500,7 +3500,7 @@ void CWriter::visitStoreInst(StoreInst &I) { if (!ITy->isPowerOf2ByteWidth()) // We have a bit width that doesn't match an even power-of-2 byte // size. Consequently we must & the value with the type's bit mask - BitMask = I.getContext().getConstantInt(ITy, ITy->getBitMask()); + BitMask = ConstantInt::get(ITy, ITy->getBitMask()); if (BitMask) Out << "(("; writeOperand(Operand); diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 81f502b278..15c6dfead4 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4889,10 +4889,10 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) { // Build some magic constants. std::vector CV0; - CV0.push_back(Context->getConstantInt(APInt(32, 0x45300000))); - CV0.push_back(Context->getConstantInt(APInt(32, 0x43300000))); - CV0.push_back(Context->getConstantInt(APInt(32, 0))); - CV0.push_back(Context->getConstantInt(APInt(32, 0))); + CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x45300000))); + CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x43300000))); + CV0.push_back(ConstantInt::get(*Context, APInt(32, 0))); + CV0.push_back(ConstantInt::get(*Context, APInt(32, 0))); Constant *C0 = Context->getConstantVector(CV0); SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16); diff --git a/lib/Target/XCore/XCoreISelDAGToDAG.cpp b/lib/Target/XCore/XCoreISelDAGToDAG.cpp index 7f6532790c..ebd0a261b8 100644 --- a/lib/Target/XCore/XCoreISelDAGToDAG.cpp +++ b/lib/Target/XCore/XCoreISelDAGToDAG.cpp @@ -174,8 +174,7 @@ SDNode *XCoreDAGToDAGISel::Select(SDValue Op) { else if (! Predicate_immU16(N)) { unsigned Val = cast(N)->getZExtValue(); SDValue CPIdx = - CurDAG->getTargetConstantPool( - CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val), + CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val), TLI.getPointerTy()); return CurDAG->getTargetNode(XCore::LDWCP_lru6, dl, MVT::i32, MVT::Other, CPIdx, diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 472f4eaa11..90077cd50b 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -638,9 +638,9 @@ Function *ArgPromotion::DoPromotion(Function *F, // Emit a GEP and load for each element of the struct. const Type *AgTy = cast(I->getType())->getElementType(); const StructType *STy = cast(AgTy); - Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 }; + Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 }; for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { - Idxs[1] = Context.getConstantInt(Type::Int32Ty, i); + Idxs[1] = ConstantInt::get(Type::Int32Ty, i); Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2, (*AI)->getName()+"."+utostr(i), Call); @@ -665,7 +665,7 @@ Function *ArgPromotion::DoPromotion(Function *F, // Use i32 to index structs, and i64 for others (pointers/arrays). // This satisfies GEP constraints. const Type *IdxTy = (isa(ElTy) ? Type::Int32Ty : Type::Int64Ty); - Ops.push_back(Context.getConstantInt(IdxTy, *II)); + Ops.push_back(ConstantInt::get(IdxTy, *II)); // Keep track of the type we're currently indexing ElTy = cast(ElTy)->getTypeAtIndex(*II); } @@ -758,10 +758,10 @@ Function *ArgPromotion::DoPromotion(Function *F, const Type *AgTy = cast(I->getType())->getElementType(); Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt); const StructType *STy = cast(AgTy); - Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 }; + Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 }; for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { - Idxs[1] = Context.getConstantInt(Type::Int32Ty, i); + Idxs[1] = ConstantInt::get(Type::Int32Ty, i); Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2, TheAlloca->getName()+"."+utostr(i), diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index b0363d32b1..c16db835d4 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -488,7 +488,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, const StructLayout &Layout = *TD.getStructLayout(STy); for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Constant *In = getAggregateConstantElement(Init, - Context.getConstantInt(Type::Int32Ty, i), + ConstantInt::get(Type::Int32Ty, i), Context); assert(In && "Couldn't get element of initializer?"); GlobalVariable *NGV = new GlobalVariable(Context, @@ -523,7 +523,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, unsigned EltAlign = TD.getABITypeAlignment(STy->getElementType()); for (unsigned i = 0, e = NumElements; i != e; ++i) { Constant *In = getAggregateConstantElement(Init, - Context.getConstantInt(Type::Int32Ty, i), + ConstantInt::get(Type::Int32Ty, i), Context); assert(In && "Couldn't get element of initializer?"); @@ -1508,7 +1508,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV, if (const ArrayType *AT = dyn_cast(MI->getAllocatedType())) { MallocInst *NewMI = new MallocInst(AllocSTy, - Context.getConstantInt(Type::Int32Ty, AT->getNumElements()), + ConstantInt::get(Type::Int32Ty, AT->getNumElements()), "", MI); NewMI->takeName(MI); Value *Cast = new BitCastInst(NewMI, MI->getType(), "tmp", MI); @@ -1605,7 +1605,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, // Only do this if we weren't storing a loaded value. Value *StoreVal; if (StoringOther || SI->getOperand(0) == InitVal) - StoreVal = Context.getConstantInt(Type::Int1Ty, StoringOther); + StoreVal = ConstantInt::get(Type::Int1Ty, StoringOther); else { // Otherwise, we are storing a previously loaded copy. To do this, // change the copy from copying the original value to just copying the @@ -1947,7 +1947,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, LLVMContext &Context) { // If we made a change, reassemble the initializer list. std::vector CSVals; - CSVals.push_back(Context.getConstantInt(Type::Int32Ty, 65535)); + CSVals.push_back(ConstantInt::get(Type::Int32Ty, 65535)); CSVals.push_back(0); // Create the new init list. @@ -1959,7 +1959,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, const Type *FTy = Context.getFunctionType(Type::VoidTy, false); const PointerType *PFTy = Context.getPointerTypeUnqual(FTy); CSVals[1] = Context.getNullValue(PFTy); - CSVals[0] = Context.getConstantInt(Type::Int32Ty, 2147483647); + CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647); } CAList.push_back(Context.getConstantStruct(CSVals)); } diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index e5ac22e8c7..980123af57 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -383,8 +383,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst); std::vector Args = make_vector(GetSetJmpMap(Func), BufPtr, - Inst->getContext().getConstantInt(Type::Int32Ty, - SetJmpIDMap[Func]++), 0); + ConstantInt::get(Type::Int32Ty,SetJmpIDMap[Func]++), 0); CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst); // We are guaranteed that there are no values live across basic blocks @@ -434,9 +433,8 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) // Add the case for this setjmp's number... SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func)); - SVP.first->addCase(Inst->getContext().getConstantInt(Type::Int32Ty, - SetJmpIDMap[Func] - 1), - SetJmpContBlock); + SVP.first->addCase(ConstantInt::get(Type::Int32Ty, SetJmpIDMap[Func] - 1), + SetJmpContBlock); // Value coming from the handling of the exception. PHI->addIncoming(SVP.second, SVP.second->getParent()); diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp index b43ca0a4c5..5e6b71a3e4 100644 --- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp @@ -55,7 +55,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, // pass null. Args[2] = Context.getConstantPointerNull(UIntPtr); } - Args[3] = Context.getConstantInt(Type::Int32Ty, NumElements); + Args[3] = ConstantInt::get(Type::Int32Ty, NumElements); Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(), "newargc", InsertPos); @@ -111,7 +111,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, // Create the getelementptr constant expression std::vector Indices(2); Indices[0] = Context.getNullValue(Type::Int32Ty); - Indices[1] = Context.getConstantInt(Type::Int32Ty, CounterNum); + Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); Constant *ElementPtr = Context.getConstantExprGetElementPtr(CounterArray, &Indices[0], Indices.size()); @@ -119,7 +119,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum, // Load, increment and store the value back. Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos); Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal, - Context.getConstantInt(Type::Int32Ty, 1), + ConstantInt::get(Type::Int32Ty, 1), "NewFuncCounter", InsertPos); new StoreInst(NewVal, ElementPtr, InsertPos); } diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index 05196cd310..30c2dc7162 100644 --- a/lib/Transforms/Instrumentation/RSProfiling.cpp +++ b/lib/Transforms/Instrumentation/RSProfiling.cpp @@ -197,7 +197,7 @@ static void getBackEdges(Function& F, T& BackEdges); GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t, uint64_t resetval) : T(t) { - ConstantInt* Init = M.getContext().getConstantInt(T, resetval); + ConstantInt* Init = ConstantInt::get(T, resetval); ResetValue = Init; Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage, Init, "RandomSteeringCounter"); @@ -209,16 +209,15 @@ void GlobalRandomCounter::PrepFunction(Function* F) {} void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext &Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(Counter, "counter", t); ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l, - Context.getConstantInt(T, 0), + ConstantInt::get(T, 0), "countercc"); - Value* nv = BinaryOperator::CreateSub(l, Context.getConstantInt(T, 1), + Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1), "counternew", t); new StoreInst(nv, Counter, t); t->setCondition(s); @@ -236,7 +235,7 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t, uint64_t resetval) : AI(0), T(t) { - ConstantInt* Init = M.getContext().getConstantInt(T, resetval); + ConstantInt* Init = ConstantInt::get(T, resetval); ResetValue = Init; Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage, Init, "RandomSteeringCounter"); @@ -283,16 +282,15 @@ void GlobalRandomCounterOpt::PrepFunction(Function* F) { void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext &Context = bb->getContext(); //decrement counter LoadInst* l = new LoadInst(AI, "counter", t); ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l, - Context.getConstantInt(T, 0), + ConstantInt::get(T, 0), "countercc"); - Value* nv = BinaryOperator::CreateSub(l, Context.getConstantInt(T, 1), + Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1), "counternew", t); new StoreInst(nv, AI, t); t->setCondition(s); @@ -318,15 +316,14 @@ void CycleCounter::PrepFunction(Function* F) {} void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast(bb->getTerminator()); - LLVMContext &Context = bb->getContext(); CallInst* c = CallInst::Create(F, "rdcc", t); BinaryOperator* b = - BinaryOperator::CreateAnd(c, Context.getConstantInt(Type::Int64Ty, rm), + BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm), "mrdcc", t); ICmpInst *s = new ICmpInst(t, ICmpInst::ICMP_EQ, b, - Context.getConstantInt(Type::Int64Ty, 0), + ConstantInt::get(Type::Int64Ty, 0), "mrdccc"); t->setCondition(s); @@ -353,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[1] = BB->getContext().getConstantInt(Type::Int32Ty, CounterNum); + Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum); Constant *ElementPtr = BB->getContext().getConstantExprGetElementPtr(CounterArray, &Indices[0], 2); @@ -362,7 +359,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos); profcode.insert(OldVal); Value *NewVal = BinaryOperator::CreateAdd(OldVal, - BB->getContext().getConstantInt(Type::Int32Ty, 1), + ConstantInt::get(Type::Int32Ty, 1), "NewCounter", InsertPos); profcode.insert(NewVal); profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos)); @@ -483,7 +480,7 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F) //b: BranchInst::Create(cast(Translate(dst)), bbC); BranchInst::Create(dst, cast(Translate(dst)), - F.getContext().getConstantInt(Type::Int1Ty, true), bbCp); + ConstantInt::get(Type::Int1Ty, true), bbCp); //c: { TerminatorInst* iB = src->getTerminator(); @@ -540,8 +537,7 @@ bool ProfilerRS::runOnFunction(Function& F) { ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0), cast( Translate(T->getSuccessor(0))), - F.getContext().getConstantInt(Type::Int1Ty, - true))); + ConstantInt::get(Type::Int1Ty, true))); //do whatever is needed now that the function is duplicated c->PrepFunction(&F); diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 8c8d26164b..b67bd7f7bf 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -617,7 +617,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, V = new SExtInst(V, IntPtrTy, "sunkaddr", InsertPt); } if (AddrMode.Scale != 1) - V = BinaryOperator::CreateMul(V, Context.getConstantInt(IntPtrTy, + V = BinaryOperator::CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale), "sunkaddr", InsertPt); Result = V; @@ -649,7 +649,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr, // Add in the Base Offset if present. if (AddrMode.BaseOffs) { - Value *V = Context.getConstantInt(IntPtrTy, AddrMode.BaseOffs); + Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs); if (Result) Result = BinaryOperator::CreateAdd(Result, V, "sunkaddr", InsertPt); else diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 66a786287f..1b650ec6dd 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -718,18 +718,18 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) { // Insert new integer induction variable. PHINode *NewPHI = PHINode::Create(Type::Int32Ty, PH->getName()+".int", PH); - NewPHI->addIncoming(Context.getConstantInt(Type::Int32Ty, newInitValue), + NewPHI->addIncoming(ConstantInt::get(Type::Int32Ty, newInitValue), PH->getIncomingBlock(IncomingEdge)); Value *NewAdd = BinaryOperator::CreateAdd(NewPHI, - Context.getConstantInt(Type::Int32Ty, + ConstantInt::get(Type::Int32Ty, newIncrValue), Incr->getName()+".int", Incr); NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge)); // The back edge is edge 1 of newPHI, whatever it may have been in the // original PHI. - ConstantInt *NewEV = Context.getConstantInt(Type::Int32Ty, intEV); + ConstantInt *NewEV = ConstantInt::get(Type::Int32Ty, intEV); Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(1) : NewEV); Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(1)); ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(), diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 367a4d7af5..4a777b331b 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -599,7 +599,7 @@ static inline Value *dyn_castNotVal(Value *V, LLVMContext *Context) { // Constants can be considered to be not'ed values... if (ConstantInt *C = dyn_cast(V)) - return Context->getConstantInt(~C->getValue()); + return ConstantInt::get(*Context, ~C->getValue()); return 0; } @@ -620,7 +620,7 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST, // The multiplier is really 1 << CST. uint32_t BitWidth = cast(V->getType())->getBitWidth(); uint32_t CSTVal = CST->getLimitedValue(BitWidth); - CST = Context->getConstantInt(APInt(BitWidth, 1).shl(CSTVal)); + CST = ConstantInt::get(*Context, APInt(BitWidth, 1).shl(CSTVal)); return I->getOperand(0); } } @@ -640,12 +640,12 @@ static User *dyn_castGetElementPtr(Value *V) { /// AddOne - Add one to a ConstantInt static Constant *AddOne(Constant *C, LLVMContext *Context) { return Context->getConstantExprAdd(C, - Context->getConstantInt(C->getType(), 1)); + ConstantInt::get(C->getType(), 1)); } /// SubOne - Subtract one from a ConstantInt static Constant *SubOne(ConstantInt *C, LLVMContext *Context) { return Context->getConstantExprSub(C, - Context->getConstantInt(C->getType(), 1)); + ConstantInt::get(C->getType(), 1)); } /// MultiplyOverflows - True if the multiply can not be expressed in an int /// this size. @@ -692,7 +692,7 @@ static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo, // This instruction is producing bits that are not demanded. Shrink the RHS. Demanded &= OpC->getValue(); - I->setOperand(OpNo, Context->getConstantInt(Demanded)); + I->setOperand(OpNo, ConstantInt::get(*Context, Demanded)); return true; } @@ -1023,7 +1023,8 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) { // all known if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) { - Constant *AndC = Context->getConstantInt(~RHSKnownOne & DemandedMask); + Constant *AndC = ConstantInt::get(*Context, + ~RHSKnownOne & DemandedMask); Instruction *And = BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp"); return InsertNewInstBefore(And, *I); @@ -1395,10 +1396,10 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, Instruction *NewVal; if (InputBit > ResultBit) NewVal = BinaryOperator::CreateLShr(I->getOperand(1), - Context->getConstantInt(I->getType(), InputBit-ResultBit)); + ConstantInt::get(I->getType(), InputBit-ResultBit)); else NewVal = BinaryOperator::CreateShl(I->getOperand(1), - Context->getConstantInt(I->getType(), ResultBit-InputBit)); + ConstantInt::get(I->getType(), ResultBit-InputBit)); NewVal->takeName(I); return InsertNewInstBefore(NewVal, *I); } @@ -1415,7 +1416,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // If the client is only demanding bits that we know, return the known // constant. if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) { - Constant *C = Context->getConstantInt(RHSKnownOne); + Constant *C = ConstantInt::get(*Context, RHSKnownOne); if (isa(V->getType())) C = Context->getConstantExprIntToPtr(C, V->getType()); return C; @@ -1602,7 +1603,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, if (UndefElts[i]) Elts.push_back(Context->getUndef(Type::Int32Ty)); else - Elts.push_back(Context->getConstantInt(Type::Int32Ty, + Elts.push_back(ConstantInt::get(Type::Int32Ty, Shuffle->getMaskValue(i))); } I->setOperand(2, Context->getConstantVector(Elts)); @@ -1733,9 +1734,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, Value *RHS = II->getOperand(2); // Extract the element as scalars. LHS = InsertNewInstBefore(new ExtractElementInst(LHS, - Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II); + ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II); RHS = InsertNewInstBefore(new ExtractElementInst(RHS, - Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II); + ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II); switch (II->getIntrinsicID()) { default: llvm_unreachable("Case stmts out of sync!"); @@ -1754,7 +1755,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, Instruction *New = InsertElementInst::Create( Context->getUndef(II->getType()), TmpV, - Context->getConstantInt(Type::Int32Ty, 0U, false), II->getName()); + ConstantInt::get(Type::Int32Ty, 0U, false), II->getName()); InsertNewInstBefore(New, *II); AddSoonDeadInstToWorklist(*II, 0); return New; @@ -1860,7 +1861,7 @@ struct AddRHS { bool shouldApply(Value *LHS) const { return LHS == RHS; } Instruction *apply(BinaryOperator &Add) const { return BinaryOperator::CreateShl(Add.getOperand(0), - Context->getConstantInt(Add.getType(), 1)); + ConstantInt::get(Add.getType(), 1)); } }; @@ -2543,7 +2544,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { ConstantInt *C2 = 0; if (dyn_castFoldableMul(Op1I, C2, Context) == Op0) { Constant *CP1 = - Context->getConstantExprSub(Context->getConstantInt(I.getType(), 1), + Context->getConstantExprSub(ConstantInt::get(I.getType(), 1), C2); return BinaryOperator::CreateMul(Op0, CP1); } @@ -2654,7 +2655,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { const APInt& Val = cast(CI)->getValue(); if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C return BinaryOperator::CreateShl(Op0, - Context->getConstantInt(Op0->getType(), Val.logBase2())); + ConstantInt::get(Op0->getType(), Val.logBase2())); } } else if (isa(Op1->getType())) { if (Op1->isNullValue()) @@ -2761,7 +2762,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { isSignBitCheck(SCI->getPredicate(), cast(SCIOp1), TIS) && TIS) { // Shift the X value right to turn it into "all signbits". - Constant *Amt = Context->getConstantInt(SCIOp0->getType(), + Constant *Amt = ConstantInt::get(SCIOp0->getType(), SCOpTy->getPrimitiveSizeInBits()-1); Value *V = InsertNewInstBefore( @@ -2932,12 +2933,12 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { // (sdiv X, X) --> 1 (udiv X, X) --> 1 if (Op0 == Op1) { if (const VectorType *Ty = dyn_cast(I.getType())) { - Constant *CI = Context->getConstantInt(Ty->getElementType(), 1); + Constant *CI = ConstantInt::get(Ty->getElementType(), 1); std::vector Elts(Ty->getNumElements(), CI); return ReplaceInstUsesWith(I, Context->getConstantVector(Elts)); } - Constant *CI = Context->getConstantInt(I.getType(), 1); + Constant *CI = ConstantInt::get(I.getType(), 1); return ReplaceInstUsesWith(I, CI); } @@ -3008,7 +3009,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { // if so, convert to a right shift. if (C->getValue().isPowerOf2()) // 0 not included in isPowerOf2 return BinaryOperator::CreateLShr(Op0, - Context->getConstantInt(Op0->getType(), C->getValue().logBase2())); + ConstantInt::get(Op0->getType(), C->getValue().logBase2())); // X udiv C, where C >= signbit if (C->getValue().isNegative()) { @@ -3016,7 +3017,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { ICmpInst::ICMP_ULT, Op0, C), I); return SelectInst::Create(IC, Context->getNullValue(I.getType()), - Context->getConstantInt(I.getType(), 1)); + ConstantInt::get(I.getType(), 1)); } } @@ -3029,7 +3030,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { Value *N = RHSI->getOperand(1); const Type *NTy = N->getType(); if (uint32_t C2 = C1.logBase2()) { - Constant *C2V = Context->getConstantInt(NTy, C2); + Constant *C2V = ConstantInt::get(NTy, C2); N = InsertNewInstBefore(BinaryOperator::CreateAdd(N, C2V, "tmp"), I); } return BinaryOperator::CreateLShr(Op0, N); @@ -3047,13 +3048,13 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { // Compute the shift amounts uint32_t TSA = TVA.logBase2(), FSA = FVA.logBase2(); // Construct the "on true" case of the select - Constant *TC = Context->getConstantInt(Op0->getType(), TSA); + Constant *TC = ConstantInt::get(Op0->getType(), TSA); Instruction *TSI = BinaryOperator::CreateLShr( Op0, TC, SI->getName()+".t"); TSI = InsertNewInstBefore(TSI, I); // Construct the "on false" case of the select - Constant *FC = Context->getConstantInt(Op0->getType(), FSA); + Constant *FC = ConstantInt::get(Op0->getType(), FSA); Instruction *FSI = BinaryOperator::CreateLShr( Op0, FC, SI->getName()+".f"); FSI = InsertNewInstBefore(FSI, I); @@ -3577,7 +3578,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op, uint32_t BitWidth = AndRHS->getType()->getBitWidth(); uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth); APInt ShlMask(APInt::getHighBitsSet(BitWidth, BitWidth-OpRHSVal)); - ConstantInt *CI = Context->getConstantInt(AndRHS->getValue() & ShlMask); + ConstantInt *CI = ConstantInt::get(*Context, AndRHS->getValue() & ShlMask); if (CI->getValue() == ShlMask) { // Masking out bits that the shift already masks @@ -3597,7 +3598,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op, uint32_t BitWidth = AndRHS->getType()->getBitWidth(); uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth); APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal)); - ConstantInt *CI = Context->getConstantInt(AndRHS->getValue() & ShrMask); + ConstantInt *CI = ConstantInt::get(*Context, AndRHS->getValue() & ShrMask); if (CI->getValue() == ShrMask) { // Masking out bits that the shift already masks. @@ -3616,7 +3617,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op, uint32_t BitWidth = AndRHS->getType()->getBitWidth(); uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth); APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal)); - Constant *C = Context->getConstantInt(AndRHS->getValue() & ShrMask); + Constant *C = ConstantInt::get(*Context, AndRHS->getValue() & ShrMask); if (C == AndRHS) { // Masking out bits shifted in. // (Val ashr C1) & C2 -> (Val lshr C1) & C2 // Make the argument unsigned. @@ -3856,7 +3857,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I, Val->getName()+".off"); InsertNewInstBefore(Add, I); return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add, - Context->getConstantInt(Add->getType(), 1)); + ConstantInt::get(Add->getType(), 1)); } break; // (X != 13 & X != 15) -> no change } @@ -4770,7 +4771,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { InsertNewInstBefore(Or, I); Or->takeName(Op0); return BinaryOperator::CreateAnd(Or, - Context->getConstantInt(RHS->getValue() | C1->getValue())); + ConstantInt::get(*Context, RHS->getValue() | C1->getValue())); } // (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2) @@ -4780,7 +4781,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { InsertNewInstBefore(Or, I); Or->takeName(Op0); return BinaryOperator::CreateXor(Or, - Context->getConstantInt(C1->getValue() & ~RHS->getValue())); + ConstantInt::get(*Context, C1->getValue() & ~RHS->getValue())); } // Try to fold constant and into select arguments. @@ -5107,7 +5108,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (Constant *Op0I0C = dyn_cast(Op0I->getOperand(0))) { Constant *NegOp0I0C = Context->getConstantExprNeg(Op0I0C); Constant *ConstantRHS = Context->getConstantExprSub(NegOp0I0C, - Context->getConstantInt(I.getType(), 1)); + ConstantInt::get(I.getType(), 1)); return BinaryOperator::CreateAdd(Op0I->getOperand(1), ConstantRHS); } @@ -5118,12 +5119,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { Constant *NegOp0CI = Context->getConstantExprNeg(Op0CI); return BinaryOperator::CreateSub( Context->getConstantExprSub(NegOp0CI, - Context->getConstantInt(I.getType(), 1)), + ConstantInt::get(I.getType(), 1)), Op0I->getOperand(0)); } else if (RHS->getValue().isSignBit()) { // (X + C) ^ signbit -> (X + C + signbit) - Constant *C = - Context->getConstantInt(RHS->getValue() + Op0CI->getValue()); + Constant *C = ConstantInt::get(*Context, + RHS->getValue() + Op0CI->getValue()); return BinaryOperator::CreateAdd(Op0I->getOperand(0), C); } @@ -5327,7 +5328,7 @@ static bool AddWithOverflow(Constant *&Result, Constant *In1, if (const VectorType *VTy = dyn_cast(In1->getType())) { for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - Constant *Idx = Context->getConstantInt(Type::Int32Ty, i); + Constant *Idx = ConstantInt::get(Type::Int32Ty, i); if (HasAddOverflow(ExtractElement(Result, Idx, Context), ExtractElement(In1, Idx, Context), ExtractElement(In2, Idx, Context), @@ -5363,7 +5364,7 @@ static bool SubWithOverflow(Constant *&Result, Constant *In1, if (const VectorType *VTy = dyn_cast(In1->getType())) { for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { - Constant *Idx = Context->getConstantInt(Type::Int32Ty, i); + Constant *Idx = ConstantInt::get(Type::Int32Ty, i); if (HasSubOverflow(ExtractElement(Result, Idx, Context), ExtractElement(In1, Idx, Context), ExtractElement(In2, Idx, Context), @@ -5405,16 +5406,17 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) { if (ConstantInt *RC = dyn_cast(Result)) Result = - Context->getConstantInt(RC->getValue() + APInt(IntPtrWidth, Size)); + ConstantInt::get(*Context, + RC->getValue() + APInt(IntPtrWidth, Size)); else Result = IC.InsertNewInstBefore( BinaryOperator::CreateAdd(Result, - Context->getConstantInt(IntPtrTy, Size), + ConstantInt::get(IntPtrTy, Size), GEP->getName()+".offs"), I); continue; } - Constant *Scale = Context->getConstantInt(IntPtrTy, Size); + Constant *Scale = ConstantInt::get(IntPtrTy, Size); Constant *OC = Context->getConstantExprIntegerCast(OpC, IntPtrTy, true /*SExt*/); Scale = Context->getConstantExprMul(OC, Scale); @@ -5438,7 +5440,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) { Op->getName()+".c"), I); } if (Size != 1) { - Constant *Scale = Context->getConstantInt(IntPtrTy, Size); + Constant *Scale = ConstantInt::get(IntPtrTy, Size); if (Constant *OpC = dyn_cast(Op)) Op = Context->getConstantExprMul(OpC, Scale); else // We'll let instcombine(mul) convert this to a shl if possible. @@ -5559,7 +5561,7 @@ static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I, VariableIdx = CastInst::CreateIntegerCast(VariableIdx, IntPtrTy, true /*SExt*/, VariableIdx->getNameStart(), &I); - Constant *OffsetVal = IC.getContext()->getConstantInt(IntPtrTy, NewOffs); + Constant *OffsetVal = ConstantInt::get(IntPtrTy, NewOffs); return BinaryOperator::CreateAdd(VariableIdx, OffsetVal, "offset", &I); } @@ -5653,7 +5655,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS, if (NumDifferences == 0) // SAME GEP? return ReplaceInstUsesWith(I, // No comparison is needed here. - Context->getConstantInt(Type::Int1Ty, + ConstantInt::get(Type::Int1Ty, ICmpInst::isTrueWhenEqual(Cond))); else if (NumDifferences == 1) { @@ -5985,7 +5987,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // icmp X, X if (Op0 == Op1) - return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, I.isTrueWhenEqual())); if (isa(Op1)) // X icmp undef -> undef @@ -5997,7 +5999,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { isa(Op0)) && (isa(Op1) || isa(Op1) || isa(Op1))) - return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, !I.isTrueWhenEqual())); // icmp's with boolean values can always be turned into bitwise operations @@ -6141,10 +6143,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // that code below can assume that Min != Max. if (!isa(Op0) && Op0Min == Op0Max) return new ICmpInst(*Context, I.getPredicate(), - Context->getConstantInt(Op0Min), Op1); + ConstantInt::get(*Context, Op0Min), Op1); if (!isa(Op1) && Op1Min == Op1Max) return new ICmpInst(*Context, I.getPredicate(), Op0, - Context->getConstantInt(Op1Min)); + ConstantInt::get(*Context, Op1Min)); // Based on the range information we know about the LHS, see if we can // simplify this comparison. For example, (x&4) < 8 is always true. @@ -6344,7 +6346,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // can assume it is successful and remove the malloc. if (LHSI->hasOneUse() && isa(RHSC)) { AddToWorkList(LHSI); - return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty, + return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty, !I.isTrueWhenEqual())); } break; @@ -6442,7 +6444,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // Mask = -1 >> count-trailing-zeros(Cst). if (!CI->isZero() && !CI->isOne()) { const APInt &AP = CI->getValue(); - ConstantInt *Mask = Context->getConstantInt( + ConstantInt *Mask = ConstantInt::get(*Context, APInt::getLowBitsSet(AP.getBitWidth(), AP.getBitWidth() - AP.countTrailingZeros())); @@ -6489,7 +6491,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { if (match(B, m_ConstantInt(C1), *Context) && match(D, m_ConstantInt(C2), *Context) && Op1->hasOneUse()) { Constant *NC = - Context->getConstantInt(C1->getValue() ^ C2->getValue()); + ConstantInt::get(*Context, C1->getValue() ^ C2->getValue()); Instruction *Xor = BinaryOperator::CreateXor(C, NC, "tmp"); return new ICmpInst(*Context, I.getPredicate(), A, InsertNewInstBefore(Xor, I)); @@ -6727,7 +6729,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, NewRHS.zext(SrcBits); NewRHS |= KnownOne; return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0), - Context->getConstantInt(NewRHS)); + ConstantInt::get(*Context, NewRHS)); } } break; @@ -6770,7 +6772,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, ? ICI.getUnsignedPredicate() : ICI.getSignedPredicate(); return new ICmpInst(*Context, Pred, LHSI->getOperand(0), - Context->getConstantInt(RHSV ^ SignBit)); + ConstantInt::get(*Context, RHSV ^ SignBit)); } // (icmp u/s (xor A ~SignBit), C) -> (icmp s/u (xor C ~SignBit), A) @@ -6781,7 +6783,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, : ICI.getSignedPredicate(); Pred = ICI.getSwappedPredicate(Pred); return new ICmpInst(*Context, Pred, LHSI->getOperand(0), - Context->getConstantInt(RHSV ^ NotSignBit)); + ConstantInt::get(*Context, RHSV ^ NotSignBit)); } } } @@ -6810,10 +6812,10 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, NewCI.zext(BitWidth); Instruction *NewAnd = BinaryOperator::CreateAnd(Cast->getOperand(0), - Context->getConstantInt(NewCST),LHSI->getName()); + ConstantInt::get(*Context, NewCST), LHSI->getName()); InsertNewInstBefore(NewAnd, ICI); return new ICmpInst(*Context, ICI.getPredicate(), NewAnd, - Context->getConstantInt(NewCI)); + ConstantInt::get(*Context, NewCI)); } } @@ -6930,7 +6932,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, ShAmt); if (Comp != RHS) {// Comparing against a bit that we know is zero. bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; - Constant *Cst = Context->getConstantInt(Type::Int1Ty, IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); return ReplaceInstUsesWith(ICI, Cst); } @@ -6938,7 +6940,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, // Otherwise strength reduce the shift into an and. uint32_t ShAmtVal = (uint32_t)ShAmt->getLimitedValue(TypeBits); Constant *Mask = - Context->getConstantInt(APInt::getLowBitsSet(TypeBits, + ConstantInt::get(*Context, APInt::getLowBitsSet(TypeBits, TypeBits-ShAmtVal)); Instruction *AndI = @@ -6946,7 +6948,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Mask, LHSI->getName()+".mask"); Value *And = InsertNewInstBefore(AndI, ICI); return new ICmpInst(*Context, ICI.getPredicate(), And, - Context->getConstantInt(RHSV.lshr(ShAmtVal))); + ConstantInt::get(*Context, RHSV.lshr(ShAmtVal))); } } @@ -6955,7 +6957,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (LHSI->hasOneUse() && isSignBitCheck(ICI.getPredicate(), RHS, TrueIfSigned)) { // (X << 31) (X&1) != 0 - Constant *Mask = Context->getConstantInt(APInt(TypeBits, 1) << + Constant *Mask = ConstantInt::get(*Context, APInt(TypeBits, 1) << (TypeBits-ShAmt->getZExtValue()-1)); Instruction *AndI = BinaryOperator::CreateAnd(LHSI->getOperand(0), @@ -6994,7 +6996,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (Comp != RHSV) { // Comparing against a bit that we know is zero. bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE; - Constant *Cst = Context->getConstantInt(Type::Int1Ty, IsICMP_NE); + Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE); return ReplaceInstUsesWith(ICI, Cst); } @@ -7011,7 +7013,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (LHSI->hasOneUse()) { // Otherwise strength reduce the shift into an and. APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal)); - Constant *Mask = Context->getConstantInt(Val); + Constant *Mask = ConstantInt::get(*Context, Val); Instruction *AndI = BinaryOperator::CreateAnd(LHSI->getOperand(0), @@ -7051,18 +7053,18 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (ICI.isSignedPredicate()) { if (CR.getLower().isSignBit()) { return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHSI->getOperand(0), - Context->getConstantInt(CR.getUpper())); + ConstantInt::get(*Context, CR.getUpper())); } else if (CR.getUpper().isSignBit()) { return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHSI->getOperand(0), - Context->getConstantInt(CR.getLower())); + ConstantInt::get(*Context, CR.getLower())); } } else { if (CR.getLower().isMinValue()) { return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHSI->getOperand(0), - Context->getConstantInt(CR.getUpper())); + ConstantInt::get(*Context, CR.getUpper())); } else if (CR.getUpper().isMinValue()) { return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHSI->getOperand(0), - Context->getConstantInt(CR.getLower())); + ConstantInt::get(*Context, CR.getLower())); } } } @@ -7136,7 +7138,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Constant *NotCI = Context->getConstantExprNot(RHS); if (!Context->getConstantExprAnd(BOC, NotCI)->isNullValue()) return ReplaceInstUsesWith(ICI, - Context->getConstantInt(Type::Int1Ty, + ConstantInt::get(Type::Int1Ty, isICMP_NE)); } break; @@ -7147,7 +7149,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, // comparison can never succeed! if ((RHSV & ~BOC->getValue()) != 0) return ReplaceInstUsesWith(ICI, - Context->getConstantInt(Type::Int1Ty, + ConstantInt::get(Type::Int1Ty, isICMP_NE)); // If we have ((X & C) == C), turn it into ((X & C) != 0). @@ -7181,7 +7183,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, if (II->getIntrinsicID() == Intrinsic::bswap) { AddToWorkList(II); ICI.setOperand(0, II->getOperand(1)); - ICI.setOperand(1, Context->getConstantInt(RHSV.byteSwap())); + ICI.setOperand(1, ConstantInt::get(*Context, RHSV.byteSwap())); return &ICI; } } @@ -7411,7 +7413,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, if (I.getOpcode() != Instruction::AShr) return ReplaceInstUsesWith(I, Context->getNullValue(Op0->getType())); else { - I.setOperand(1, Context->getConstantInt(I.getType(), TypeBits-1)); + I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1)); return &I; } } @@ -7467,7 +7469,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, } Instruction *And = - BinaryOperator::CreateAnd(NSh, Context->getConstantInt(MaskV), + BinaryOperator::CreateAnd(NSh, ConstantInt::get(*Context, MaskV), TI->getName()); InsertNewInstBefore(And, I); // shift1 & 0x00FF @@ -7501,7 +7503,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, Op0BO->getOperand(1)->getName()); InsertNewInstBefore(X, I); // (X + (Y << C)) uint32_t Op1Val = Op1->getLimitedValue(TypeBits); - return BinaryOperator::CreateAnd(X, Context->getConstantInt( + return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val))); } @@ -7541,7 +7543,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, Op0BO->getOperand(0)->getName()); InsertNewInstBefore(X, I); // (X + (Y << C)) uint32_t Op1Val = Op1->getLimitedValue(TypeBits); - return BinaryOperator::CreateAnd(X, Context->getConstantInt( + return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val))); } @@ -7642,14 +7644,14 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, } return BinaryOperator::Create(I.getOpcode(), X, - Context->getConstantInt(Ty, AmtSum)); + ConstantInt::get(Ty, AmtSum)); } else if (ShiftOp->getOpcode() == Instruction::LShr && I.getOpcode() == Instruction::AShr) { if (AmtSum >= TypeBits) return ReplaceInstUsesWith(I, Context->getNullValue(I.getType())); // ((X >>u C1) >>s C2) -> (X >>u (C1+C2)) since C1 != 0. - return BinaryOperator::CreateLShr(X, Context->getConstantInt(Ty, AmtSum)); + return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum)); } else if (ShiftOp->getOpcode() == Instruction::AShr && I.getOpcode() == Instruction::LShr) { // ((X >>s C1) >>u C2) -> ((X >>s (C1+C2)) & mask) since C1 != 0. @@ -7657,11 +7659,11 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, AmtSum = TypeBits-1; Instruction *Shift = - BinaryOperator::CreateAShr(X, Context->getConstantInt(Ty, AmtSum)); + BinaryOperator::CreateAShr(X, ConstantInt::get(Ty, AmtSum)); InsertNewInstBefore(Shift, I); APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2)); - return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(Shift, ConstantInt::get(*Context, Mask)); } // Okay, if we get here, one shift must be left, and the other shift must be @@ -7670,12 +7672,12 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, // If we have ((X >>? C) << C), turn this into X & (-1 << C). if (I.getOpcode() == Instruction::Shl) { APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt1)); - return BinaryOperator::CreateAnd(X, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, Mask)); } // If we have ((X << C) >>u C), turn this into X & (-1 >>u C). if (I.getOpcode() == Instruction::LShr) { APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt1)); - return BinaryOperator::CreateAnd(X, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, Mask)); } // We can simplify ((X << C) >>s C) into a trunc + sext. // NOTE: we could do this for any C, but that would make 'unusual' integer @@ -7707,22 +7709,24 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, assert(ShiftOp->getOpcode() == Instruction::LShr || ShiftOp->getOpcode() == Instruction::AShr); Instruction *Shift = - BinaryOperator::CreateShl(X, Context->getConstantInt(Ty, ShiftDiff)); + BinaryOperator::CreateShl(X, ConstantInt::get(Ty, ShiftDiff)); InsertNewInstBefore(Shift, I); APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2)); - return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(Shift, + ConstantInt::get(*Context, Mask)); } // (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2) if (I.getOpcode() == Instruction::LShr) { assert(ShiftOp->getOpcode() == Instruction::Shl); Instruction *Shift = - BinaryOperator::CreateLShr(X, Context->getConstantInt(Ty, ShiftDiff)); + BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, ShiftDiff)); InsertNewInstBefore(Shift, I); APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2)); - return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(Shift, + ConstantInt::get(*Context, Mask)); } // We can't handle (X << C1) >>s C2, it shifts arbitrary bits in. @@ -7736,22 +7740,24 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1, ShiftOp->getOpcode() == Instruction::AShr); Instruction *Shift = BinaryOperator::Create(ShiftOp->getOpcode(), X, - Context->getConstantInt(Ty, ShiftDiff)); + ConstantInt::get(Ty, ShiftDiff)); InsertNewInstBefore(Shift, I); APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2)); - return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(Shift, + ConstantInt::get(*Context, Mask)); } // (X << C1) >>u C2 --> X << (C1-C2) & (-1 >> C2) if (I.getOpcode() == Instruction::LShr) { assert(ShiftOp->getOpcode() == Instruction::Shl); Instruction *Shift = - BinaryOperator::CreateShl(X, Context->getConstantInt(Ty, ShiftDiff)); + BinaryOperator::CreateShl(X, ConstantInt::get(Ty, ShiftDiff)); InsertNewInstBefore(Shift, I); APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2)); - return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask)); + return BinaryOperator::CreateAnd(Shift, + ConstantInt::get(*Context, Mask)); } // We can't handle (X << C1) >>a C2, it shifts arbitrary bits in. @@ -7771,7 +7777,7 @@ static Value *DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, if (ConstantInt *CI = dyn_cast(Val)) { Offset = CI->getZExtValue(); Scale = 0; - return Context->getConstantInt(Type::Int32Ty, 0); + return ConstantInt::get(Type::Int32Ty, 0); } else if (BinaryOperator *I = dyn_cast(Val)) { if (ConstantInt *RHS = dyn_cast(I->getOperand(1))) { if (I->getOpcode() == Instruction::Shl) { @@ -7868,7 +7874,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, Amt = NumElements; } else { // If the allocation size is constant, form a constant mul expression - Amt = Context->getConstantInt(Type::Int32Ty, Scale); + Amt = ConstantInt::get(Type::Int32Ty, Scale); if (isa(NumElements)) Amt = Context->getConstantExprMul(cast(NumElements), cast(Amt)); @@ -7880,7 +7886,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, } if (int Offset = (AllocElTySize*ArrayOffset)/CastElTySize) { - Value *Off = Context->getConstantInt(Type::Int32Ty, Offset, true); + Value *Off = ConstantInt::get(Type::Int32Ty, Offset, true); Instruction *Tmp = BinaryOperator::CreateAdd(Amt, Off, "tmp"); Amt = InsertNewInstBefore(Tmp, AI); } @@ -8181,7 +8187,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset"); } - NewIndices.push_back(Context->getConstantInt(IntPtrTy, FirstIdx)); + NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx)); // Index into the types. If we fail, set OrigBase to null. while (Offset) { @@ -8195,14 +8201,14 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, "Offset must stay within the indexed type"); unsigned Elt = SL->getElementContainingOffset(Offset); - NewIndices.push_back(Context->getConstantInt(Type::Int32Ty, Elt)); + NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt)); Offset -= SL->getElementOffset(Elt); Ty = STy->getElementType(Elt); } else if (const ArrayType *AT = dyn_cast(Ty)) { uint64_t EltSize = TD->getTypeAllocSize(AT->getElementType()); assert(EltSize && "Cannot index into a zero-sized array"); - NewIndices.push_back(Context->getConstantInt(IntPtrTy,Offset/EltSize)); + NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize)); Offset %= EltSize; Ty = AT->getElementType(); } else { @@ -8399,8 +8405,8 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) { return ReplaceInstUsesWith(CI, Res); // We need to emit an AND to clear the high bits. - Constant *C = Context->getConstantInt(APInt::getLowBitsSet(DestBitSize, - SrcBitSize)); + Constant *C = ConstantInt::get(*Context, + APInt::getLowBitsSet(DestBitSize, SrcBitSize)); return BinaryOperator::CreateAnd(Res, C); } case Instruction::SExt: { @@ -8447,7 +8453,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) { (!Op0->hasOneUse() || !isa(Op0))) { Value *New = InsertCastBefore(Instruction::ZExt, Op0, DestTy, CI); return BinaryOperator::CreateXor(New, - Context->getConstantInt(CI.getType(), 1)); + ConstantInt::get(CI.getType(), 1)); } break; @@ -8477,7 +8483,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) { // Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0) if (DestBitWidth == 1) { - Constant *One = Context->getConstantInt(Src->getType(), 1); + Constant *One = ConstantInt::get(Src->getType(), 1); Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI); Value *Zero = Context->getNullValue(Src->getType()); return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero); @@ -8524,7 +8530,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI, if (!DoXform) return ICI; Value *In = ICI->getOperand(0); - Value *Sh = Context->getConstantInt(In->getType(), + Value *Sh = ConstantInt::get(In->getType(), In->getType()->getScalarSizeInBits()-1); In = InsertNewInstBefore(BinaryOperator::CreateLShr(In, Sh, In->getName()+".lobit"), @@ -8534,7 +8540,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI, false/*ZExt*/, "tmp", &CI); if (ICI->getPredicate() == ICmpInst::ICMP_SGT) { - Constant *One = Context->getConstantInt(In->getType(), 1); + Constant *One = ConstantInt::get(In->getType(), 1); In = InsertNewInstBefore(BinaryOperator::CreateXor(In, One, In->getName()+".not"), CI); @@ -8570,7 +8576,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI, if (Op1CV != 0 && (Op1CV != KnownZeroMask)) { // (X&4) == 2 --> false // (X&4) != 2 --> true - Constant *Res = Context->getConstantInt(Type::Int1Ty, isNE); + Constant *Res = ConstantInt::get(Type::Int1Ty, isNE); Res = Context->getConstantExprZExt(Res, CI.getType()); return ReplaceInstUsesWith(CI, Res); } @@ -8581,12 +8587,12 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI, // Perform a logical shr by shiftamt. // Insert the shift to put the result in the low bit. In = InsertNewInstBefore(BinaryOperator::CreateLShr(In, - Context->getConstantInt(In->getType(), ShiftAmt), + ConstantInt::get(In->getType(), ShiftAmt), In->getName()+".lobit"), CI); } if ((Op1CV != 0) == isNE) { // Toggle the low bit. - Constant *One = Context->getConstantInt(In->getType(), 1); + Constant *One = ConstantInt::get(In->getType(), 1); In = BinaryOperator::CreateXor(In, One, "tmp"); InsertNewInstBefore(cast(In), CI); } @@ -8625,21 +8631,21 @@ Instruction *InstCombiner::visitZExt(ZExtInst &CI) { // SrcSize > DstSize: trunc(a) & mask if (SrcSize < DstSize) { APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); - Constant *AndConst = Context->getConstantInt(A->getType(), AndValue); + Constant *AndConst = ConstantInt::get(A->getType(), AndValue); Instruction *And = BinaryOperator::CreateAnd(A, AndConst, CSrc->getName()+".mask"); InsertNewInstBefore(And, CI); return new ZExtInst(And, CI.getType()); } else if (SrcSize == DstSize) { APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize)); - return BinaryOperator::CreateAnd(A, Context->getConstantInt(A->getType(), + return BinaryOperator::CreateAnd(A, ConstantInt::get(A->getType(), AndValue)); } else if (SrcSize > DstSize) { Instruction *Trunc = new TruncInst(A, CI.getType(), "tmp"); InsertNewInstBefore(Trunc, CI); APInt AndValue(APInt::getLowBitsSet(DstSize, MidSize)); return BinaryOperator::CreateAnd(Trunc, - Context->getConstantInt(Trunc->getType(), + ConstantInt::get(Trunc->getType(), AndValue)); } } @@ -8754,7 +8760,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { unsigned MidSize = Src->getType()->getScalarSizeInBits(); unsigned SrcDstSize = CI.getType()->getScalarSizeInBits(); unsigned ShAmt = CA->getZExtValue()+SrcDstSize-MidSize; - Constant *ShAmtV = Context->getConstantInt(CI.getType(), ShAmt); + Constant *ShAmtV = ConstantInt::get(CI.getType(), ShAmt); I = InsertNewInstBefore(BinaryOperator::CreateShl(I, ShAmtV, CI.getName()), CI); return BinaryOperator::CreateAShr(I, ShAmtV); @@ -9089,7 +9095,7 @@ static Constant *GetSelectFoldableConstant(Instruction *I, case Instruction::And: return Context->getAllOnesValue(I->getType()); case Instruction::Mul: - return Context->getConstantInt(I->getType(), 1); + return ConstantInt::get(I->getType(), 1); } } @@ -9322,7 +9328,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI, if ((Pred == ICmpInst::ICMP_SLT && Op1CV == 0) || (Pred == ICmpInst::ICMP_SGT && Op1CV.isAllOnesValue())) { Value *In = ICI->getOperand(0); - Value *Sh = Context->getConstantInt(In->getType(), + Value *Sh = ConstantInt::get(In->getType(), In->getType()->getScalarSizeInBits()-1); In = InsertNewInstBefore(BinaryOperator::CreateAShr(In, Sh, In->getName()+".lobit"), @@ -9674,7 +9680,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) { unsigned CopyAlign = MI->getAlignment(); if (CopyAlign < MinAlign) { - MI->setAlignment(Context->getConstantInt(MI->getAlignmentType(), + MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), MinAlign, false)); return MI; } @@ -9749,7 +9755,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) { Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { unsigned Alignment = GetOrEnforceKnownAlignment(MI->getDest()); if (MI->getAlignment() < Alignment) { - MI->setAlignment(Context->getConstantInt(MI->getAlignmentType(), + MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), Alignment, false)); return MI; } @@ -9777,7 +9783,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { // Extract the fill value and store. uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL; - InsertNewInstBefore(new StoreInst(Context->getConstantInt(ITy, Fill), + InsertNewInstBefore(new StoreInst(ConstantInt::get(ITy, Fill), Dest, false, Alignment), *MI); // Set the size of the copy to 0, it will be deleted on the next iteration. @@ -9950,14 +9956,14 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (ExtractedElts[Idx] == 0) { Instruction *Elt = new ExtractElementInst(Idx < 16 ? Op0 : Op1, - Context->getConstantInt(Type::Int32Ty, Idx&15, false), "tmp"); + ConstantInt::get(Type::Int32Ty, Idx&15, false), "tmp"); InsertNewInstBefore(Elt, CI); ExtractedElts[Idx] = Elt; } // Insert this value into the result vector. Result = InsertElementInst::Create(Result, ExtractedElts[Idx], - Context->getConstantInt(Type::Int32Ty, i, false), + ConstantInt::get(Type::Int32Ty, i, false), "tmp"); InsertNewInstBefore(cast(Result), CI); } @@ -11230,16 +11236,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (ArrayEltSize == 1) { NewIdx = GEP.getOperand(1); Scale = - Context->getConstantInt(cast(NewIdx->getType()), 1); + ConstantInt::get(cast(NewIdx->getType()), 1); } else if (ConstantInt *CI = dyn_cast(GEP.getOperand(1))) { - NewIdx = Context->getConstantInt(CI->getType(), 1); + NewIdx = ConstantInt::get(CI->getType(), 1); Scale = CI; } else if (Instruction *Inst =dyn_cast(GEP.getOperand(1))){ if (Inst->getOpcode() == Instruction::Shl && isa(Inst->getOperand(1))) { ConstantInt *ShAmt = cast(Inst->getOperand(1)); uint32_t ShAmtVal = ShAmt->getLimitedValue(64); - Scale = Context->getConstantInt(cast(Inst->getType()), + Scale = ConstantInt::get(cast(Inst->getType()), 1ULL << ShAmtVal); NewIdx = Inst->getOperand(0); } else if (Inst->getOpcode() == Instruction::Mul && @@ -11255,7 +11261,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // operation after making sure Scale doesn't have the sign bit set. if (ArrayEltSize && Scale && Scale->getSExtValue() >= 0LL && Scale->getZExtValue() % ArrayEltSize == 0) { - Scale = Context->getConstantInt(Scale->getType(), + Scale = ConstantInt::get(Scale->getType(), Scale->getZExtValue() / ArrayEltSize); if (Scale->getZExtValue() != 1) { Constant *C = @@ -11466,7 +11472,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, SingleChar = 0; StrVal = (StrVal << 8) | SingleChar; } - Value *NL = Context->getConstantInt(StrVal); + Value *NL = ConstantInt::get(*Context, StrVal); return IC.ReplaceInstUsesWith(LI, NL); } } @@ -12462,7 +12468,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType())); } return new ExtractElementInst(Src, - Context->getConstantInt(Type::Int32Ty, SrcIdx, false)); + ConstantInt::get(Type::Int32Ty, SrcIdx, false)); } } // FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement) @@ -12485,11 +12491,11 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, return true; } else if (V == LHS) { for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(Context->getConstantInt(Type::Int32Ty, i)); + Mask.push_back(ConstantInt::get(Type::Int32Ty, i)); return true; } else if (V == RHS) { for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(Context->getConstantInt(Type::Int32Ty, i+NumElts)); + Mask.push_back(ConstantInt::get(Type::Int32Ty, i+NumElts)); return true; } else if (InsertElementInst *IEI = dyn_cast(V)) { // If this is an insert of an extract from some other vector, include it. @@ -12523,11 +12529,11 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS, // If so, update the mask to reflect the inserted value. if (EI->getOperand(0) == LHS) { Mask[InsertedIdx % NumElts] = - Context->getConstantInt(Type::Int32Ty, ExtractedIdx); + ConstantInt::get(Type::Int32Ty, ExtractedIdx); } else { assert(EI->getOperand(0) == RHS); Mask[InsertedIdx % NumElts] = - Context->getConstantInt(Type::Int32Ty, ExtractedIdx+NumElts); + ConstantInt::get(Type::Int32Ty, ExtractedIdx+NumElts); } return true; @@ -12555,7 +12561,7 @@ static Value *CollectShuffleElements(Value *V, std::vector &Mask, Mask.assign(NumElts, Context->getUndef(Type::Int32Ty)); return V; } else if (isa(V)) { - Mask.assign(NumElts, Context->getConstantInt(Type::Int32Ty, 0)); + Mask.assign(NumElts, ConstantInt::get(Type::Int32Ty, 0)); return V; } else if (InsertElementInst *IEI = dyn_cast(V)) { // If this is an insert of an extract from some other vector, include it. @@ -12576,7 +12582,7 @@ static Value *CollectShuffleElements(Value *V, std::vector &Mask, RHS = EI->getOperand(0); Value *V = CollectShuffleElements(VecOp, Mask, RHS, Context); Mask[InsertedIdx % NumElts] = - Context->getConstantInt(Type::Int32Ty, NumElts+ExtractedIdx); + ConstantInt::get(Type::Int32Ty, NumElts+ExtractedIdx); return V; } @@ -12586,7 +12592,7 @@ static Value *CollectShuffleElements(Value *V, std::vector &Mask, // Everything but the extracted element is replaced with the RHS. for (unsigned i = 0; i != NumElts; ++i) { if (i != InsertedIdx) - Mask[i] = Context->getConstantInt(Type::Int32Ty, NumElts+i); + Mask[i] = ConstantInt::get(Type::Int32Ty, NumElts+i); } return V; } @@ -12604,7 +12610,7 @@ static Value *CollectShuffleElements(Value *V, std::vector &Mask, // Otherwise, can't do anything fancy. Return an identity vector. for (unsigned i = 0; i != NumElts; ++i) - Mask.push_back(Context->getConstantInt(Type::Int32Ty, i)); + Mask.push_back(ConstantInt::get(Type::Int32Ty, i)); return V; } @@ -12651,11 +12657,11 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) { Mask.assign(NumVectorElts, Context->getUndef(Type::Int32Ty)); else { assert(isa(VecOp) && "Unknown thing"); - Mask.assign(NumVectorElts, Context->getConstantInt(Type::Int32Ty, + Mask.assign(NumVectorElts, ConstantInt::get(Type::Int32Ty, NumVectorElts)); } Mask[InsertedIdx] = - Context->getConstantInt(Type::Int32Ty, ExtractedIdx); + ConstantInt::get(Type::Int32Ty, ExtractedIdx); return new ShuffleVectorInst(EI->getOperand(0), VecOp, Context->getConstantVector(Mask)); } @@ -12728,7 +12734,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { Elts.push_back(Context->getUndef(Type::Int32Ty)); } else { Mask[i] = Mask[i] % e; // Force to LHS. - Elts.push_back(Context->getConstantInt(Type::Int32Ty, Mask[i])); + Elts.push_back(ConstantInt::get(Type::Int32Ty, Mask[i])); } } } @@ -12786,7 +12792,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (NewMask[i] >= LHSInNElts*2) { Elts.push_back(Context->getUndef(Type::Int32Ty)); } else { - Elts.push_back(Context->getConstantInt(Type::Int32Ty, NewMask[i])); + Elts.push_back(ConstantInt::get(Type::Int32Ty, NewMask[i])); } } return new ShuffleVectorInst(LHSSVI->getOperand(0), diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 25ab011749..1e43e2eb79 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -434,8 +434,7 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB, << "' folding condition to '" << BranchDir << "': " << *BB->getTerminator(); ++NumFolds; - DestBI->setCondition(BB->getContext().getConstantInt(Type::Int1Ty, - BranchDir)); + DestBI->setCondition(ConstantInt::get(Type::Int1Ty, BranchDir)); ConstantFoldTerminator(BB); return true; } @@ -757,7 +756,7 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB, // We can only do the simplification for phi nodes of 'false' with AND or // 'true' with OR. See if we have any entries in the phi for this. unsigned PredNo = ~0U; - ConstantInt *PredCst = V->getContext().getConstantInt(Type::Int1Ty, !isAnd); + ConstantInt *PredCst = ConstantInt::get(Type::Int1Ty, !isAnd); for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { if (PN->getIncomingValue(i) == PredCst) { PredNo = i; diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index f20511ea28..f5e5d350de 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -295,14 +295,14 @@ static bool isUsedOutsideLoop(Value *V, Loop *L) { // Return V+1 static Value *getPlusOne(Value *V, bool Sign, Instruction *InsertPt, LLVMContext &Context) { - Constant *One = Context.getConstantInt(V->getType(), 1, Sign); + Constant *One = ConstantInt::get(V->getType(), 1, Sign); return BinaryOperator::CreateAdd(V, One, "lsp", InsertPt); } // Return V-1 static Value *getMinusOne(Value *V, bool Sign, Instruction *InsertPt, LLVMContext &Context) { - Constant *One = Context.getConstantInt(V->getType(), 1, Sign); + Constant *One = ConstantInt::get(V->getType(), 1, Sign); return BinaryOperator::CreateSub(V, One, "lsp", InsertPt); } diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 22717c21d4..4a6fe575f3 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1991,9 +1991,9 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond, NewStride = &IU->StrideOrder[i]; if (!isa(NewCmpTy)) - NewCmpRHS = Context.getConstantInt(NewCmpTy, NewCmpVal); + NewCmpRHS = ConstantInt::get(NewCmpTy, NewCmpVal); else { - Constant *CI = Context.getConstantInt(NewCmpIntTy, NewCmpVal); + Constant *CI = ConstantInt::get(NewCmpIntTy, NewCmpVal); NewCmpRHS = Context.getConstantExprIntToPtr(CI, NewCmpTy); } NewOffset = TyBits == NewTyBits @@ -2432,8 +2432,6 @@ void LoopStrengthReduce::OptimizeLoopCountIV(Loop *L) { if (!ExitingBlock) return; // More than one block exiting! - LLVMContext &Context = ExitingBlock->getContext(); - // Okay, we've computed the exiting block. See what condition causes us to // exit. // @@ -2506,7 +2504,7 @@ void LoopStrengthReduce::OptimizeLoopCountIV(Loop *L) { Value *startVal = phi->getIncomingValue(inBlock); Value *endVal = Cond->getOperand(1); // FIXME check for case where both are constant - Constant* Zero = Context.getConstantInt(Cond->getOperand(1)->getType(), 0); + Constant* Zero = ConstantInt::get(Cond->getOperand(1)->getType(), 0); BinaryOperator *NewStartVal = BinaryOperator::Create(Instruction::Sub, endVal, startVal, "tmp", PreInsertPt); diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 100b8c7cfb..efe246ef5d 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -911,7 +911,7 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, if (IsEqual) Replacement = Val; else - Replacement = Context.getConstantInt(Type::Int1Ty, + Replacement = ConstantInt::get(Type::Int1Ty, !cast(Val)->getZExtValue()); for (unsigned i = 0, e = Users.size(); i != e; ++i) diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 8937e1c863..d93aaa262a 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -69,7 +69,7 @@ static Value *isBytewiseValue(Value *V, LLVMContext& Context) { if (Val != Val2) return 0; } - return Context.getConstantInt(Val); + return ConstantInt::get(Context, Val); } } @@ -448,9 +448,9 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) { Value *Ops[] = { StartPtr, ByteVal, // Start, value // size - SI->getContext().getConstantInt(Type::Int64Ty, Range.End-Range.Start), + ConstantInt::get(Type::Int64Ty, Range.End-Range.Start), // align - SI->getContext().getConstantInt(Type::Int32Ty, Range.Alignment) + ConstantInt::get(Type::Int32Ty, Range.Alignment) }; Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt); DEBUG(cerr << "Replace stores:\n"; diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index 4ee19f76c9..3c648a887e 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -1169,7 +1169,8 @@ namespace { Value *V = VN.value(n); // XXX: redesign worklist. const Type *Ty = V->getType(); if (Ty->isInteger()) { - addToWorklist(V, Context->getConstantInt(*I), ICmpInst::ICMP_EQ, VRP); + addToWorklist(V, ConstantInt::get(*Context, *I), + ICmpInst::ICMP_EQ, VRP); return; } else if (const PointerType *PTy = dyn_cast(Ty)) { assert(*I == 0 && "Pointer is null but not zero?"); @@ -1783,7 +1784,7 @@ namespace { if (ConstantInt *CI = dyn_cast(Canonical)) { if (ConstantInt *Arg = dyn_cast(LHS)) { add(RHS, - Context->getConstantInt(CI->getValue() ^ Arg->getValue()), + ConstantInt::get(*Context, CI->getValue() ^ Arg->getValue()), ICmpInst::ICMP_EQ, NewContext); } } @@ -1895,7 +1896,7 @@ namespace { assert(!Ty->isFPOrFPVector() && "Float in work queue!"); Constant *Zero = Context->getNullValue(Ty); - Constant *One = Context->getConstantInt(Ty, 1); + Constant *One = ConstantInt::get(Ty, 1); ConstantInt *AllOnes = cast(Context->getAllOnesValue(Ty)); switch (Opcode) { @@ -2535,23 +2536,23 @@ namespace { void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) { VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI); - LLVMContext *Context = &SI.getContext(); + LLVMContext &Context = SI.getContext(); uint32_t SrcBitWidth = cast(SI.getSrcTy())->getBitWidth(); uint32_t DstBitWidth = cast(SI.getDestTy())->getBitWidth(); APInt Min(APInt::getHighBitsSet(DstBitWidth, DstBitWidth-SrcBitWidth+1)); APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth-1)); - VRP.add(Context->getConstantInt(Min), &SI, ICmpInst::ICMP_SLE); - VRP.add(Context->getConstantInt(Max), &SI, ICmpInst::ICMP_SGE); + VRP.add(ConstantInt::get(Context, Min), &SI, ICmpInst::ICMP_SLE); + VRP.add(ConstantInt::get(Context, Max), &SI, ICmpInst::ICMP_SGE); VRP.solve(); } void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) { VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &ZI); - LLVMContext *Context = &ZI.getContext(); + LLVMContext &Context = ZI.getContext(); uint32_t SrcBitWidth = cast(ZI.getSrcTy())->getBitWidth(); uint32_t DstBitWidth = cast(ZI.getDestTy())->getBitWidth(); APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth)); - VRP.add(Context->getConstantInt(Max), &ZI, ICmpInst::ICMP_UGE); + VRP.add(ConstantInt::get(Context, Max), &ZI, ICmpInst::ICMP_UGE); VRP.solve(); } @@ -2640,7 +2641,7 @@ namespace { Pred = IC.getPredicate(); - LLVMContext *Context = &IC.getContext(); + LLVMContext &Context = IC.getContext(); if (ConstantInt *Op1 = dyn_cast(IC.getOperand(1))) { ConstantInt *NextVal = 0; @@ -2649,12 +2650,12 @@ namespace { case ICmpInst::ICMP_SLT: case ICmpInst::ICMP_ULT: if (Op1->getValue() != 0) - NextVal = Context->getConstantInt(Op1->getValue()-1); + NextVal = ConstantInt::get(Context, Op1->getValue()-1); break; case ICmpInst::ICMP_SGT: case ICmpInst::ICMP_UGT: if (!Op1->getValue().isAllOnesValue()) - NextVal = Context->getConstantInt(Op1->getValue()+1); + NextVal = ConstantInt::get(Context, Op1->getValue()+1); break; } diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 9456940809..5ea590ea65 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -466,7 +466,7 @@ static Instruction *ConvertShiftToMul(Instruction *Shl, (Shl->hasOneUse() && (isReassociableOp(Shl->use_back(), Instruction::Mul) || isReassociableOp(Shl->use_back(), Instruction::Add)))) { - Constant *MulCst = Context.getConstantInt(Shl->getType(), 1); + Constant *MulCst = ConstantInt::get(Shl->getType(), 1); MulCst = Context.getConstantExprShl(MulCst, cast(Shl->getOperand(1))); diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index b9044d13b8..3376e86756 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -776,7 +776,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, unsigned OtherEltAlign = MemAlignment; if (OtherPtr) { - Value *Idx[2] = { Zero, Context.getConstantInt(Type::Int32Ty, i) }; + Value *Idx[2] = { Zero, ConstantInt::get(Type::Int32Ty, i) }; OtherElt = GetElementPtrInst::Create(OtherPtr, Idx, Idx + 2, OtherPtr->getNameStr()+"."+utostr(i), MI); @@ -839,7 +839,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, } // Convert the integer value to the appropriate type. - StoreVal = Context.getConstantInt(TotalVal); + StoreVal = ConstantInt::get(Context, TotalVal); if (isa(ValTy)) StoreVal = Context.getConstantExprIntToPtr(StoreVal, ValTy); else if (ValTy->isFloatingPoint()) @@ -876,15 +876,15 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst, Value *Ops[] = { SROADest ? EltPtr : OtherElt, // Dest ptr SROADest ? OtherElt : EltPtr, // Src ptr - Context.getConstantInt(MI->getOperand(3)->getType(), EltSize), // Size - Context.getConstantInt(Type::Int32Ty, OtherEltAlign) // Align + ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size + ConstantInt::get(Type::Int32Ty, OtherEltAlign) // Align }; CallInst::Create(TheFn, Ops, Ops + 4, "", MI); } else { assert(isa(MI)); Value *Ops[] = { EltPtr, MI->getOperand(2), // Dest, Value, - Context.getConstantInt(MI->getOperand(3)->getType(), EltSize), // Size + ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size Zero // Align }; CallInst::Create(TheFn, Ops, Ops + 4, "", MI); @@ -934,7 +934,7 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, Value *EltVal = SrcVal; if (Shift) { - Value *ShiftVal = Context.getConstantInt(EltVal->getType(), Shift); + Value *ShiftVal = ConstantInt::get(EltVal->getType(), Shift); EltVal = BinaryOperator::CreateLShr(EltVal, ShiftVal, "sroa.store.elt", SI); } @@ -982,7 +982,7 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI, Value *EltVal = SrcVal; if (Shift) { - Value *ShiftVal = Context.getConstantInt(EltVal->getType(), Shift); + Value *ShiftVal = ConstantInt::get(EltVal->getType(), Shift); EltVal = BinaryOperator::CreateLShr(EltVal, ShiftVal, "sroa.store.elt", SI); } @@ -1089,7 +1089,7 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI, Shift = AllocaSizeBits-Shift-FieldIntTy->getBitWidth(); if (Shift) { - Value *ShiftVal = Context.getConstantInt(SrcField->getType(), Shift); + Value *ShiftVal = ConstantInt::get(SrcField->getType(), Shift); SrcField = BinaryOperator::CreateShl(SrcField, ShiftVal, "", LI); } @@ -1212,7 +1212,7 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) { Indices.begin(), Indices.end(), GEPI->getName()+".0", GEPI); - Indices[1] = Context.getConstantInt(Type::Int32Ty, 1); + Indices[1] = ConstantInt::get(Type::Int32Ty, 1); Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0), Indices.begin(), Indices.end(), @@ -1469,7 +1469,7 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset) { Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str()); Value *New = ConvertScalar_InsertValue( - User->getContext().getConstantInt(APVal), + ConstantInt::get(User->getContext(), APVal), Old, Offset, Builder); Builder.CreateStore(New, NewAI); } @@ -1558,7 +1558,7 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, } // Return the element extracted out of it. Value *V = Builder.CreateExtractElement(FromVal, - Context.getConstantInt(Type::Int32Ty,Elt), + ConstantInt::get(Type::Int32Ty,Elt), "tmp"); if (V->getType() != ToType) V = Builder.CreateBitCast(V, ToType, "tmp"); @@ -1611,11 +1611,11 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, // only some bits are used. if (ShAmt > 0 && (unsigned)ShAmt < NTy->getBitWidth()) FromVal = Builder.CreateLShr(FromVal, - Context.getConstantInt(FromVal->getType(), + ConstantInt::get(FromVal->getType(), ShAmt), "tmp"); else if (ShAmt < 0 && (unsigned)-ShAmt < NTy->getBitWidth()) FromVal = Builder.CreateShl(FromVal, - Context.getConstantInt(FromVal->getType(), + ConstantInt::get(FromVal->getType(), -ShAmt), "tmp"); // Finally, unconditionally truncate the integer to the right width. @@ -1677,7 +1677,7 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp"); SV = Builder.CreateInsertElement(Old, SV, - Context.getConstantInt(Type::Int32Ty, Elt), + ConstantInt::get(Type::Int32Ty, Elt), "tmp"); return SV; } @@ -1745,11 +1745,11 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, // only some bits in the structure are set. APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth)); if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) { - SV = Builder.CreateShl(SV, Context.getConstantInt(SV->getType(), + SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(), ShAmt), "tmp"); Mask <<= ShAmt; } else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) { - SV = Builder.CreateLShr(SV, Context.getConstantInt(SV->getType(), + SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(), -ShAmt), "tmp"); Mask = Mask.lshr(-ShAmt); } @@ -1758,7 +1758,7 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old, // in the new bits. if (SrcWidth != DestWidth) { assert(DestWidth > SrcWidth); - Old = Builder.CreateAnd(Old, Context.getConstantInt(~Mask), "mask"); + Old = Builder.CreateAnd(Old, ConstantInt::get(Context, ~Mask), "mask"); SV = Builder.CreateOr(Old, SV, "ins"); } return SV; diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 3656ef013f..6f1898a2e0 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -157,7 +157,7 @@ Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len, Tys[0] = Len->getType(); Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1); return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, - Context->getConstantInt(Type::Int32Ty, Align)); + ConstantInt::get(Type::Int32Ty, Align)); } /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is @@ -213,7 +213,7 @@ Value *LibCallOptimization::EmitMemSet(Value *Dst, Value *Val, const Type *Tys[1]; Tys[0] = Len->getType(); Value *MemSet = Intrinsic::getDeclaration(M, IID, Tys, 1); - Value *Align = Context->getConstantInt(Type::Int32Ty, 1); + Value *Align = ConstantInt::get(Type::Int32Ty, 1); return B.CreateCall4(MemSet, CastToCStr(Dst, B), Val, Len, Align); } @@ -346,7 +346,7 @@ void LibCallOptimization::EmitFWrite(Value *Ptr, Value *Size, Value *File, TD->getIntPtrType(), TD->getIntPtrType(), File->getType(), NULL); CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size, - Context->getConstantInt(TD->getIntPtrType(), 1), File); + ConstantInt::get(TD->getIntPtrType(), 1), File); if (const Function *Fn = dyn_cast(F->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); @@ -580,7 +580,7 @@ struct VISIBILITY_HIDDEN StrCatOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // concatenation for us. Make a memcpy to copy the nul byte with align = 1. EmitMemCpy(CpyDst, Src, - Context->getConstantInt(TD->getIntPtrType(), Len+1), 1, B); + ConstantInt::get(TD->getIntPtrType(), Len+1), 1, B); } }; @@ -652,7 +652,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { return 0; return EmitMemChr(SrcStr, CI->getOperand(2), // include nul. - Context->getConstantInt(TD->getIntPtrType(), Len), B); + ConstantInt::get(TD->getIntPtrType(), Len), B); } // Otherwise, the character is a constant, see if the first argument is @@ -677,7 +677,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { } // strchr(s+n,c) -> gep(s+n+i,c) - Value *Idx = Context->getConstantInt(Type::Int64Ty, i); + Value *Idx = ConstantInt::get(Type::Int64Ty, i); return B.CreateGEP(SrcStr, Idx, "strchr"); } }; @@ -696,7 +696,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2); if (Str1P == Str2P) // strcmp(x,x) -> 0 - return Context->getConstantInt(CI->getType(), 0); + return ConstantInt::get(CI->getType(), 0); std::string Str1, Str2; bool HasStr1 = GetConstantStringInfo(Str1P, Str1); @@ -710,7 +710,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { // strcmp(x, y) -> cnst (if both x and y are constant strings) if (HasStr1 && HasStr2) - return Context->getConstantInt(CI->getType(), + return ConstantInt::get(CI->getType(), strcmp(Str1.c_str(),Str2.c_str())); // strcmp(P, "x") -> memcmp(P, "x", 2) @@ -718,7 +718,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { uint64_t Len2 = GetStringLength(Str2P); if (Len1 && Len2) { return EmitMemCmp(Str1P, Str2P, - Context->getConstantInt(TD->getIntPtrType(), + ConstantInt::get(TD->getIntPtrType(), std::min(Len1, Len2)), B); } @@ -741,7 +741,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization { Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2); if (Str1P == Str2P) // strncmp(x,x,n) -> 0 - return Context->getConstantInt(CI->getType(), 0); + return ConstantInt::get(CI->getType(), 0); // Get the length argument if it is constant. uint64_t Length; @@ -751,7 +751,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization { return 0; if (Length == 0) // strncmp(x,y,0) -> 0 - return Context->getConstantInt(CI->getType(), 0); + return ConstantInt::get(CI->getType(), 0); std::string Str1, Str2; bool HasStr1 = GetConstantStringInfo(Str1P, Str1); @@ -765,7 +765,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization { // strncmp(x, y) -> cnst (if both x and y are constant strings) if (HasStr1 && HasStr2) - return Context->getConstantInt(CI->getType(), + return ConstantInt::get(CI->getType(), strncmp(Str1.c_str(), Str2.c_str(), Length)); return 0; } @@ -795,7 +795,7 @@ struct VISIBILITY_HIDDEN StrCpyOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // concatenation for us. Make a memcpy to copy the nul byte with align = 1. EmitMemCpy(Dst, Src, - Context->getConstantInt(TD->getIntPtrType(), Len), 1, B); + ConstantInt::get(TD->getIntPtrType(), Len), 1, B); return Dst; } }; @@ -823,7 +823,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization { if (SrcLen == 0) { // strncpy(x, "", y) -> memset(x, '\0', y, 1) - EmitMemSet(Dst, Context->getConstantInt(Type::Int8Ty, '\0'), LenOp, B); + EmitMemSet(Dst, ConstantInt::get(Type::Int8Ty, '\0'), LenOp, B); return Dst; } @@ -840,7 +840,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization { // strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant] EmitMemCpy(Dst, Src, - Context->getConstantInt(TD->getIntPtrType(), Len), 1, B); + ConstantInt::get(TD->getIntPtrType(), Len), 1, B); return Dst; } @@ -861,7 +861,7 @@ struct VISIBILITY_HIDDEN StrLenOpt : public LibCallOptimization { // Constant folding: strlen("xyz") -> 3 if (uint64_t Len = GetStringLength(Src)) - return Context->getConstantInt(CI->getType(), Len-1); + return ConstantInt::get(CI->getType(), Len-1); // Handle strlen(p) != 0. if (!IsOnlyUsedInZeroEqualityComparison(CI)) return 0; @@ -980,7 +980,7 @@ struct VISIBILITY_HIDDEN MemMoveOpt : public LibCallOptimization { Value *Dst = CastToCStr(CI->getOperand(1), B); Value *Src = CastToCStr(CI->getOperand(2), B); Value *Size = CI->getOperand(3); - Value *Align = Context->getConstantInt(Type::Int32Ty, 1); + Value *Align = ConstantInt::get(Type::Int32Ty, 1); B.CreateCall4(MemMove, Dst, Src, Size, Align); return CI->getOperand(1); } @@ -1154,7 +1154,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { if (ConstantInt *CI = dyn_cast(Op)) { if (CI->getValue() == 0) // ffs(0) -> 0. return Context->getNullValue(CI->getType()); - return Context->getConstantInt(Type::Int32Ty, // ffs(c) -> cttz(c)+1 + return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1 CI->getValue().countTrailingZeros()+1); } @@ -1163,11 +1163,11 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization { Value *F = Intrinsic::getDeclaration(Callee->getParent(), Intrinsic::cttz, &ArgType, 1); Value *V = B.CreateCall(F, Op, "cttz"); - V = B.CreateAdd(V, Context->getConstantInt(V->getType(), 1), "tmp"); + 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"); - return B.CreateSelect(Cond, V, Context->getConstantInt(Type::Int32Ty, 0)); + return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0)); } }; @@ -1184,9 +1184,9 @@ struct VISIBILITY_HIDDEN IsDigitOpt : public LibCallOptimization { // isdigit(c) -> (c-'0') getOperand(1); - Op = B.CreateSub(Op, Context->getConstantInt(Type::Int32Ty, '0'), + Op = B.CreateSub(Op, ConstantInt::get(Type::Int32Ty, '0'), "isdigittmp"); - Op = B.CreateICmpULT(Op, Context->getConstantInt(Type::Int32Ty, 10), + Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 10), "isdigit"); return B.CreateZExt(Op, CI->getType()); } @@ -1205,7 +1205,7 @@ struct VISIBILITY_HIDDEN IsAsciiOpt : public LibCallOptimization { // isascii(c) -> c getOperand(1); - Op = B.CreateICmpULT(Op, Context->getConstantInt(Type::Int32Ty, 128), + Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 128), "isascii"); return B.CreateZExt(Op, CI->getType()); } @@ -1246,7 +1246,7 @@ struct VISIBILITY_HIDDEN ToAsciiOpt : public LibCallOptimization { // isascii(c) -> c & 0x7f return B.CreateAnd(CI->getOperand(1), - Context->getConstantInt(CI->getType(),0x7F)); + ConstantInt::get(CI->getType(),0x7F)); } }; @@ -1274,13 +1274,13 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { // Empty format string -> noop. if (FormatStr.empty()) // Tolerate printf's declared void. return CI->use_empty() ? (Value*)CI : - Context->getConstantInt(CI->getType(), 0); + ConstantInt::get(CI->getType(), 0); // printf("x") -> putchar('x'), even for '%'. if (FormatStr.size() == 1) { - EmitPutChar(Context->getConstantInt(Type::Int32Ty, FormatStr[0]), B); + EmitPutChar(ConstantInt::get(Type::Int32Ty, FormatStr[0]), B); return CI->use_empty() ? (Value*)CI : - Context->getConstantInt(CI->getType(), 1); + ConstantInt::get(CI->getType(), 1); } // printf("foo\n") --> puts("foo") @@ -1294,7 +1294,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { GlobalVariable::InternalLinkage, C, "str"); EmitPutS(C, B); return CI->use_empty() ? (Value*)CI : - Context->getConstantInt(CI->getType(), FormatStr.size()+1); + ConstantInt::get(CI->getType(), FormatStr.size()+1); } // Optimize specific format strings. @@ -1303,7 +1303,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { isa(CI->getOperand(2)->getType())) { EmitPutChar(CI->getOperand(2), B); return CI->use_empty() ? (Value*)CI : - Context->getConstantInt(CI->getType(), 1); + ConstantInt::get(CI->getType(), 1); } // printf("%s\n", str) --> puts(str) @@ -1344,8 +1344,8 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { // sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1) EmitMemCpy(CI->getOperand(1), CI->getOperand(2), // Copy the nul byte. - Context->getConstantInt(TD->getIntPtrType(), FormatStr.size()+1),1,B); - return Context->getConstantInt(CI->getType(), FormatStr.size()); + ConstantInt::get(TD->getIntPtrType(), FormatStr.size()+1),1,B); + return ConstantInt::get(CI->getType(), FormatStr.size()); } // The remaining optimizations require the format string to be "%s" or "%c" @@ -1360,10 +1360,10 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { Value *V = B.CreateTrunc(CI->getOperand(3), Type::Int8Ty, "char"); Value *Ptr = CastToCStr(CI->getOperand(1), B); B.CreateStore(V, Ptr); - Ptr = B.CreateGEP(Ptr, Context->getConstantInt(Type::Int32Ty, 1), "nul"); + Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul"); B.CreateStore(Context->getNullValue(Type::Int8Ty), Ptr); - return Context->getConstantInt(CI->getType(), 1); + return ConstantInt::get(CI->getType(), 1); } if (FormatStr[1] == 's') { @@ -1372,7 +1372,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { Value *Len = EmitStrLen(CI->getOperand(3), B); Value *IncLen = B.CreateAdd(Len, - Context->getConstantInt(Len->getType(), 1), + ConstantInt::get(Len->getType(), 1), "leninc"); EmitMemCpy(CI->getOperand(1), CI->getOperand(3), IncLen, 1, B); @@ -1405,13 +1405,13 @@ struct VISIBILITY_HIDDEN FWriteOpt : public LibCallOptimization { // If this is writing zero records, remove the call (it's a noop). if (Bytes == 0) - return Context->getConstantInt(CI->getType(), 0); + return ConstantInt::get(CI->getType(), 0); // If this is writing one byte, turn it into fputc. if (Bytes == 1) { // fwrite(S,1,1,F) -> fputc(S[0],F) Value *Char = B.CreateLoad(CastToCStr(CI->getOperand(1), B), "char"); EmitFPutC(Char, CI->getOperand(4), B); - return Context->getConstantInt(CI->getType(), 1); + return ConstantInt::get(CI->getType(), 1); } return 0; @@ -1434,7 +1434,7 @@ struct VISIBILITY_HIDDEN FPutsOpt : public LibCallOptimization { uint64_t Len = GetStringLength(CI->getOperand(1)); if (!Len) return 0; EmitFWrite(CI->getOperand(1), - Context->getConstantInt(TD->getIntPtrType(), Len-1), + ConstantInt::get(TD->getIntPtrType(), Len-1), CI->getOperand(2), B); return CI; // Known to have no uses (see above). } @@ -1463,10 +1463,10 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization { if (FormatStr[i] == '%') // Could handle %% -> % if we cared. return 0; // We found a format specifier. - EmitFWrite(CI->getOperand(2), Context->getConstantInt(TD->getIntPtrType(), + EmitFWrite(CI->getOperand(2), ConstantInt::get(TD->getIntPtrType(), FormatStr.size()), CI->getOperand(1), B); - return Context->getConstantInt(CI->getType(), FormatStr.size()); + return ConstantInt::get(CI->getType(), FormatStr.size()); } // The remaining optimizations require the format string to be "%s" or "%c" @@ -1479,7 +1479,7 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization { // fprintf(F, "%c", chr) --> *(i8*)dst = chr if (!isa(CI->getOperand(3)->getType())) return 0; EmitFPutC(CI->getOperand(3), CI->getOperand(1), B); - return Context->getConstantInt(CI->getType(), 1); + return ConstantInt::get(CI->getType(), 1); } if (FormatStr[1] == 's') { diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 2a91b0e80d..ab10baa772 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -306,7 +306,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs, if (AggregateArgs) { Value *Idx[2]; Idx[0] = Context.getNullValue(Type::Int32Ty); - Idx[1] = Context.getConstantInt(Type::Int32Ty, i); + Idx[1] = ConstantInt::get(Type::Int32Ty, i); TerminatorInst *TI = newFunction->begin()->getTerminator(); GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2, @@ -396,7 +396,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[1] = Context.getConstantInt(Type::Int32Ty, i); + Idx[1] = ConstantInt::get(Type::Int32Ty, i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, "gep_" + StructValues[i]->getName()); @@ -422,7 +422,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (AggregateArgs) { Value *Idx[2]; Idx[0] = Context.getNullValue(Type::Int32Ty); - Idx[1] = Context.getConstantInt(Type::Int32Ty, FirstOut + i); + Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i); GetElementPtrInst *GEP = GetElementPtrInst::Create(Struct, Idx, Idx + 2, "gep_reload_" + outputs[i]->getName()); @@ -474,17 +474,17 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, case 0: case 1: break; // No value needed. case 2: // Conditional branch, return a bool - brVal = Context.getConstantInt(Type::Int1Ty, !SuccNum); + brVal = ConstantInt::get(Type::Int1Ty, !SuccNum); break; default: - brVal = Context.getConstantInt(Type::Int16Ty, SuccNum); + brVal = ConstantInt::get(Type::Int16Ty, SuccNum); break; } ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget); // Update the switch instruction. - TheSwitch->addCase(Context.getConstantInt(Type::Int16Ty, SuccNum), + TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum), OldTarget); // Restore values just before we exit @@ -523,7 +523,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (AggregateArgs) { Value *Idx[2]; Idx[0] = Context.getNullValue(Type::Int32Ty); - Idx[1] = Context.getConstantInt(Type::Int32Ty,FirstOut+out); + Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out); GetElementPtrInst *GEP = GetElementPtrInst::Create(OAI, Idx, Idx + 2, "gep_" + outputs[out]->getName(), diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index ae0b5ee84b..16d8879436 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -324,14 +324,14 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { if (TD == 0) Size = Context.getConstantExprSizeOf(AggTy); else - Size = Context.getConstantInt(Type::Int64Ty, + Size = ConstantInt::get(Type::Int64Ty, TD->getTypeStoreSize(AggTy)); // Always generate a memcpy of alignment 1 here because we don't know // the alignment of the src pointer. Other optimizations can infer // better alignment. Value *CallArgs[] = { - DestCast, SrcCast, Size, Context.getConstantInt(Type::Int32Ty, 1) + DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1) }; CallInst *TheMemCpy = CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall); diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 8f61d88089..68108fa0f2 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -118,7 +118,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { // malloc(type) becomes i8 *malloc(size) Value *MallocArg; if (LowerMallocArgToInteger) - MallocArg = Context.getConstantInt(Type::Int64Ty, + MallocArg = ConstantInt::get(Type::Int64Ty, TD.getTypeAllocSize(AllocTy)); else MallocArg = Context.getConstantExprSizeOf(AllocTy); diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index 9f20f3954d..6a56bbe973 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -272,7 +272,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, AllocaInst *InvokeNum, SwitchInst *CatchSwitch) { LLVMContext &Context = II->getContext(); - ConstantInt *InvokeNoC = Context.getConstantInt(Type::Int32Ty, InvokeNo); + ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo); // If the unwind edge has phi nodes, split the edge. if (isa(II->getUnwindDest()->begin())) { @@ -483,7 +483,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { std::vector Idx; Idx.push_back(Context.getNullValue(Type::Int32Ty)); - Idx.push_back(Context.getConstantInt(Type::Int32Ty, 1)); + Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), "OldBuf", EntryBB->getTerminator()); @@ -504,7 +504,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // executing. For normal calls it contains zero. AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0, "invokenum",EntryBB->begin()); - new StoreInst(Context.getConstantInt(Type::Int32Ty, 0), InvokeNum, true, + new StoreInst(ConstantInt::get(Type::Int32Ty, 0), InvokeNum, true, EntryBB->getTerminator()); // Insert a load in the Catch block, and a switch on its value. By default, @@ -523,7 +523,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(), "setjmp.cont"); - Idx[1] = Context.getConstantInt(Type::Int32Ty, 0); + Idx[1] = ConstantInt::get(Type::Int32Ty, 0); Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), "TheJmpBuf", EntryBB->getTerminator()); @@ -577,12 +577,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Get a pointer to the jmpbuf and longjmp. std::vector Idx; Idx.push_back(Context.getNullValue(Type::Int32Ty)); - Idx.push_back(Context.getConstantInt(Type::Int32Ty, 0)); + Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", UnwindBlock); Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty), "tmp", UnwindBlock); - Idx[1] = Context.getConstantInt(Type::Int32Ty, 1); + Idx[1] = ConstantInt::get(Type::Int32Ty, 1); CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock); new UnreachableInst(UnwindBlock); diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index e155c295e0..f63c4fdb71 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1611,7 +1611,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { if (BB->getSinglePredecessor()) { // Turn this into a branch on constant. bool CondIsTrue = PBI->getSuccessor(0) == BB; - BI->setCondition(Context.getConstantInt(Type::Int1Ty, CondIsTrue)); + BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue)); return true; // Nuke the branch on constant. } @@ -1631,7 +1631,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) { PBI->getCondition() == BI->getCondition() && PBI->getSuccessor(0) != PBI->getSuccessor(1)) { bool CondIsTrue = PBI->getSuccessor(0) == BB; - NewPN->addIncoming(Context.getConstantInt(Type::Int1Ty, + NewPN->addIncoming(ConstantInt::get(Type::Int1Ty, CondIsTrue), *PI); } else { NewPN->addIncoming(BI->getCondition(), *PI); diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index 016a3395d9..ca2e57d4b7 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -271,20 +271,20 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Context.getPointerTypeUnqual(Type::DoubleTy), "upgraded.", CI); Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI); - Value *Idx = Context.getConstantInt(Type::Int32Ty, 0); + Value *Idx = ConstantInt::get(Type::Int32Ty, 0); Op1 = InsertElementInst::Create(Op1, Load, Idx, "upgraded.", CI); if (isLoadH) { - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 0)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); } else { - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); } Value *Mask = Context.getConstantVector(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); } else if (isMovL) { - Constant *Zero = Context.getConstantInt(Type::Int32Ty, 0); + Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); Idxs.push_back(Zero); Idxs.push_back(Zero); Idxs.push_back(Zero); @@ -292,32 +292,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) { Value *ZeroV = Context.getConstantVector(Idxs); Idxs.clear(); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 4)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 5)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 3)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3)); Value *Mask = Context.getConstantVector(Idxs); SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI); } else if (isMovSD || isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) { Value *Op1 = CI->getOperand(2); if (isMovSD) { - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); } else if (isUnpckhPD || isPunpckhQPD) { - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 3)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3)); } else { - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 0)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2)); } Value *Mask = Context.getConstantVector(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); } else if (isShufPD) { Value *Op1 = CI->getOperand(2); unsigned MaskVal = cast(CI->getOperand(3))->getZExtValue(); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, MaskVal & 1)); - Idxs.push_back(Context.getConstantInt(Type::Int32Ty, + Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1)); + Idxs.push_back(ConstantInt::get(Type::Int32Ty, ((MaskVal >> 1) & 1)+2)); Value *Mask = Context.getConstantVector(Idxs); SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI); diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 0e4bf6c7bf..a26bee8f95 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -171,7 +171,7 @@ static Constant *FoldBitCast(LLVMContext &Context, // Handle ConstantFP input. if (const ConstantFP *FP = dyn_cast(V)) // FP -> Integral. - return Context.getConstantInt(FP->getValueAPF().bitcastToAPInt()); + return ConstantInt::get(Context, FP->getValueAPF().bitcastToAPInt()); return 0; } @@ -258,7 +258,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, (void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI, APFloat::rmTowardZero, &ignored); APInt Val(DestBitWidth, 2, x); - return Context.getConstantInt(Val); + return ConstantInt::get(Context, Val); } return 0; // Can't fold. case Instruction::IntToPtr: //always treated as unsigned @@ -267,7 +267,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, return 0; // Other pointer types cannot be casted case Instruction::PtrToInt: // always treated as unsigned if (V->isNullValue()) // is it a null pointer value? - return Context.getConstantInt(DestTy, 0); + return ConstantInt::get(DestTy, 0); return 0; // Other pointer types cannot be casted case Instruction::UIToFP: case Instruction::SIToFP: @@ -287,7 +287,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, uint32_t BitWidth = cast(DestTy)->getBitWidth(); APInt Result(CI->getValue()); Result.zext(BitWidth); - return Context.getConstantInt(Result); + return ConstantInt::get(Context, Result); } return 0; case Instruction::SExt: @@ -295,7 +295,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, uint32_t BitWidth = cast(DestTy)->getBitWidth(); APInt Result(CI->getValue()); Result.sext(BitWidth); - return Context.getConstantInt(Result); + return ConstantInt::get(Context, Result); } return 0; case Instruction::Trunc: @@ -303,7 +303,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context, uint32_t BitWidth = cast(DestTy)->getBitWidth(); APInt Result(CI->getValue()); Result.trunc(BitWidth); - return Context.getConstantInt(Result); + return ConstantInt::get(Context, Result); } return 0; case Instruction::BitCast: @@ -721,51 +721,51 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, default: break; case Instruction::Add: - return Context.getConstantInt(C1V + C2V); + return ConstantInt::get(Context, C1V + C2V); case Instruction::Sub: - return Context.getConstantInt(C1V - C2V); + return ConstantInt::get(Context, C1V - C2V); case Instruction::Mul: - return Context.getConstantInt(C1V * C2V); + return ConstantInt::get(Context, C1V * C2V); case Instruction::UDiv: assert(!CI2->isNullValue() && "Div by zero handled above"); - return Context.getConstantInt(C1V.udiv(C2V)); + return ConstantInt::get(Context, C1V.udiv(C2V)); case Instruction::SDiv: assert(!CI2->isNullValue() && "Div by zero handled above"); if (C2V.isAllOnesValue() && C1V.isMinSignedValue()) return Context.getUndef(CI1->getType()); // MIN_INT / -1 -> undef - return Context.getConstantInt(C1V.sdiv(C2V)); + return ConstantInt::get(Context, C1V.sdiv(C2V)); case Instruction::URem: assert(!CI2->isNullValue() && "Div by zero handled above"); - return Context.getConstantInt(C1V.urem(C2V)); + return ConstantInt::get(Context, C1V.urem(C2V)); case Instruction::SRem: assert(!CI2->isNullValue() && "Div by zero handled above"); if (C2V.isAllOnesValue() && C1V.isMinSignedValue()) return Context.getUndef(CI1->getType()); // MIN_INT % -1 -> undef - return Context.getConstantInt(C1V.srem(C2V)); + return ConstantInt::get(Context, C1V.srem(C2V)); case Instruction::And: - return Context.getConstantInt(C1V & C2V); + return ConstantInt::get(Context, C1V & C2V); case Instruction::Or: - return Context.getConstantInt(C1V | C2V); + return ConstantInt::get(Context, C1V | C2V); case Instruction::Xor: - return Context.getConstantInt(C1V ^ C2V); + return ConstantInt::get(Context, C1V ^ C2V); case Instruction::Shl: { uint32_t shiftAmt = C2V.getZExtValue(); if (shiftAmt < C1V.getBitWidth()) - return Context.getConstantInt(C1V.shl(shiftAmt)); + return ConstantInt::get(Context, C1V.shl(shiftAmt)); else return Context.getUndef(C1->getType()); // too big shift is undef } case Instruction::LShr: { uint32_t shiftAmt = C2V.getZExtValue(); if (shiftAmt < C1V.getBitWidth()) - return Context.getConstantInt(C1V.lshr(shiftAmt)); + return ConstantInt::get(Context, C1V.lshr(shiftAmt)); else return Context.getUndef(C1->getType()); // too big shift is undef } case Instruction::AShr: { uint32_t shiftAmt = C2V.getZExtValue(); if (shiftAmt < C1V.getBitWidth()) - return Context.getConstantInt(C1V.ashr(shiftAmt)); + return ConstantInt::get(Context, C1V.ashr(shiftAmt)); else return Context.getUndef(C1->getType()); // too big shift is undef } @@ -1420,25 +1420,25 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, switch (pred) { default: llvm_unreachable("Invalid ICmp Predicate"); return 0; case ICmpInst::ICMP_EQ: - return Context.getConstantInt(Type::Int1Ty, V1 == V2); + return ConstantInt::get(Type::Int1Ty, V1 == V2); case ICmpInst::ICMP_NE: - return Context.getConstantInt(Type::Int1Ty, V1 != V2); + return ConstantInt::get(Type::Int1Ty, V1 != V2); case ICmpInst::ICMP_SLT: - return Context.getConstantInt(Type::Int1Ty, V1.slt(V2)); + return ConstantInt::get(Type::Int1Ty, V1.slt(V2)); case ICmpInst::ICMP_SGT: - return Context.getConstantInt(Type::Int1Ty, V1.sgt(V2)); + return ConstantInt::get(Type::Int1Ty, V1.sgt(V2)); case ICmpInst::ICMP_SLE: - return Context.getConstantInt(Type::Int1Ty, V1.sle(V2)); + return ConstantInt::get(Type::Int1Ty, V1.sle(V2)); case ICmpInst::ICMP_SGE: - return Context.getConstantInt(Type::Int1Ty, V1.sge(V2)); + return ConstantInt::get(Type::Int1Ty, V1.sge(V2)); case ICmpInst::ICMP_ULT: - return Context.getConstantInt(Type::Int1Ty, V1.ult(V2)); + return ConstantInt::get(Type::Int1Ty, V1.ult(V2)); case ICmpInst::ICMP_UGT: - return Context.getConstantInt(Type::Int1Ty, V1.ugt(V2)); + return ConstantInt::get(Type::Int1Ty, V1.ugt(V2)); case ICmpInst::ICMP_ULE: - return Context.getConstantInt(Type::Int1Ty, V1.ule(V2)); + return ConstantInt::get(Type::Int1Ty, V1.ule(V2)); case ICmpInst::ICMP_UGE: - return Context.getConstantInt(Type::Int1Ty, V1.uge(V2)); + return ConstantInt::get(Type::Int1Ty, V1.uge(V2)); } } else if (isa(C1) && isa(C2)) { APFloat C1V = cast(C1)->getValueAPF(); @@ -1449,38 +1449,38 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, case FCmpInst::FCMP_FALSE: return Context.getFalse(); case FCmpInst::FCMP_TRUE: return Context.getTrue(); case FCmpInst::FCMP_UNO: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered); + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered); case FCmpInst::FCMP_ORD: - return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpUnordered); + return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpUnordered); case FCmpInst::FCMP_UEQ: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || R==APFloat::cmpEqual); case FCmpInst::FCMP_OEQ: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpEqual); + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpEqual); case FCmpInst::FCMP_UNE: - return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpEqual); + return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpEqual); case FCmpInst::FCMP_ONE: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan || R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_ULT: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || R==APFloat::cmpLessThan); case FCmpInst::FCMP_OLT: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan); + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan); case FCmpInst::FCMP_UGT: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered || R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_OGT: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpGreaterThan); + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan); case FCmpInst::FCMP_ULE: - return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpGreaterThan); + return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpGreaterThan); case FCmpInst::FCMP_OLE: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan || R==APFloat::cmpEqual); case FCmpInst::FCMP_UGE: - return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpLessThan); + return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpLessThan); case FCmpInst::FCMP_OGE: - return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpGreaterThan || + return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan || R==APFloat::cmpEqual); } } else if (isa(C1->getType())) { @@ -1555,7 +1555,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // If we evaluated the result, return it now. if (Result != -1) - return Context.getConstantInt(Type::Int1Ty, Result); + return ConstantInt::get(Type::Int1Ty, Result); } else { // Evaluate the relation between the two constants, per the predicate. @@ -1632,7 +1632,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, // If we evaluated the result, return it now. if (Result != -1) - return Context.getConstantInt(Type::Int1Ty, Result); + return ConstantInt::get(Type::Int1Ty, Result); if (!isa(C1) && isa(C2)) { // If C2 is a constant expr and C1 isn't, flip them around and fold the diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index f94cd9e25f..96f729a7e6 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "LLVMContextImpl.h" #include "llvm/Constants.h" #include "ConstantFold.h" #include "llvm/DerivedTypes.h" @@ -171,6 +172,72 @@ ConstantInt::ConstantInt(const IntegerType *Ty, const APInt& V) assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type"); } +// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap +// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the +// operator== and operator!= to ensure that the DenseMap doesn't attempt to +// compare APInt's of different widths, which would violate an APInt class +// invariant which generates an assertion. +ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) { + // Get the corresponding integer type for the bit width of the value. + const IntegerType *ITy = Context.getIntegerType(V.getBitWidth()); + // get an existing value or the insertion position + DenseMapAPIntKeyInfo::KeyTy Key(V, ITy); + + Context.pImpl->ConstantsLock.reader_acquire(); + ConstantInt *&Slot = Context.pImpl->IntConstants[Key]; + Context.pImpl->ConstantsLock.reader_release(); + + if (!Slot) { + sys::SmartScopedWriter Writer(Context.pImpl->ConstantsLock); + ConstantInt *&NewSlot = Context.pImpl->IntConstants[Key]; + if (!Slot) { + NewSlot = new ConstantInt(ITy, V); + } + + return NewSlot; + } else { + return Slot; + } +} + +Constant* ConstantInt::get(const Type* Ty, uint64_t V, bool isSigned) { + Constant *C = get(cast(Ty->getScalarType()), + V, isSigned); + + // For vectors, broadcast the value. + if (const VectorType *VTy = dyn_cast(Ty)) + return Ty->getContext().getConstantVector( + std::vector(VTy->getNumElements(), C)); + + return C; +} + +ConstantInt* ConstantInt::get(const IntegerType* Ty, uint64_t V, + bool isSigned) { + return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned)); +} + +ConstantInt* ConstantInt::getSigned(const IntegerType* Ty, int64_t V) { + return get(Ty, V, true); +} + +Constant *ConstantInt::getSigned(const Type *Ty, int64_t V) { + return get(Ty, V, true); +} + +Constant* ConstantInt::get(const Type* Ty, const APInt& V) { + ConstantInt *C = get(Ty->getContext(), V); + assert(C->getType() == Ty->getScalarType() && + "ConstantInt type doesn't match the type implied by its value!"); + + // For vectors, broadcast the value. + if (const VectorType *VTy = dyn_cast(Ty)) + return Ty->getContext().getConstantVector( + std::vector(VTy->getNumElements(), C)); + + return C; +} + //===----------------------------------------------------------------------===// // ConstantFP //===----------------------------------------------------------------------===// @@ -758,275 +825,6 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) { //===----------------------------------------------------------------------===// // Factory Function Implementation - -// The number of operands for each ConstantCreator::create method is -// determined by the ConstantTraits template. -// ConstantCreator - A class that is used to create constants by -// ValueMap*. This class should be partially specialized if there is -// something strange that needs to be done to interface to the ctor for the -// constant. -// -namespace llvm { - template - struct ConstantTraits; - - template - struct VISIBILITY_HIDDEN ConstantTraits< std::vector > { - static unsigned uses(const std::vector& v) { - return v.size(); - } - }; - - template - struct VISIBILITY_HIDDEN ConstantCreator { - static ConstantClass *create(const TypeClass *Ty, const ValType &V) { - return new(ConstantTraits::uses(V)) ConstantClass(Ty, V); - } - }; - - template - struct VISIBILITY_HIDDEN ConvertConstantType { - static void convert(ConstantClass *OldC, const TypeClass *NewTy) { - llvm_unreachable("This type cannot be converted!"); - } - }; - - template - class VISIBILITY_HIDDEN ValueMap : public AbstractTypeUser { - public: - typedef std::pair MapKey; - typedef std::map MapTy; - typedef std::map InverseMapTy; - typedef std::map AbstractTypeMapTy; - private: - /// Map - This is the main map from the element descriptor to the Constants. - /// This is the primary way we avoid creating two of the same shape - /// constant. - MapTy Map; - - /// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping - /// from the constants to their element in Map. This is important for - /// removal of constants from the array, which would otherwise have to scan - /// through the map with very large keys. - InverseMapTy InverseMap; - - /// AbstractTypeMap - Map for abstract type constants. - /// - AbstractTypeMapTy AbstractTypeMap; - - /// ValueMapLock - Mutex for this map. - sys::SmartMutex ValueMapLock; - - public: - // NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. - typename MapTy::iterator map_end() { return Map.end(); } - - /// InsertOrGetItem - Return an iterator for the specified element. - /// If the element exists in the map, the returned iterator points to the - /// entry and Exists=true. If not, the iterator points to the newly - /// inserted entry and returns Exists=false. Newly inserted entries have - /// I->second == 0, and should be filled in. - /// NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. - typename MapTy::iterator InsertOrGetItem(std::pair - &InsertVal, - bool &Exists) { - std::pair IP = Map.insert(InsertVal); - Exists = !IP.second; - return IP.first; - } - -private: - typename MapTy::iterator FindExistingElement(ConstantClass *CP) { - if (HasLargeKey) { - typename InverseMapTy::iterator IMI = InverseMap.find(CP); - assert(IMI != InverseMap.end() && IMI->second != Map.end() && - IMI->second->second == CP && - "InverseMap corrupt!"); - return IMI->second; - } - - typename MapTy::iterator I = - Map.find(MapKey(static_cast(CP->getRawType()), - getValType(CP))); - if (I == Map.end() || I->second != CP) { - // FIXME: This should not use a linear scan. If this gets to be a - // performance problem, someone should look at this. - for (I = Map.begin(); I != Map.end() && I->second != CP; ++I) - /* empty */; - } - return I; - } - - ConstantClass* Create(const TypeClass *Ty, const ValType &V, - typename MapTy::iterator I) { - ConstantClass* Result = - ConstantCreator::create(Ty, V); - - assert(Result->getType() == Ty && "Type specified is not correct!"); - I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result)); - - if (HasLargeKey) // Remember the reverse mapping if needed. - InverseMap.insert(std::make_pair(Result, I)); - - // If the type of the constant is abstract, make sure that an entry - // exists for it in the AbstractTypeMap. - if (Ty->isAbstract()) { - typename AbstractTypeMapTy::iterator TI = - AbstractTypeMap.find(Ty); - - if (TI == AbstractTypeMap.end()) { - // Add ourselves to the ATU list of the type. - cast(Ty)->addAbstractTypeUser(this); - - AbstractTypeMap.insert(TI, std::make_pair(Ty, I)); - } - } - - return Result; - } -public: - - /// getOrCreate - Return the specified constant from the map, creating it if - /// necessary. - ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { - sys::SmartScopedLock Lock(ValueMapLock); - MapKey Lookup(Ty, V); - ConstantClass* Result = 0; - - typename MapTy::iterator I = Map.find(Lookup); - // Is it in the map? - if (I != Map.end()) - Result = static_cast(I->second); - - if (!Result) { - // If no preexisting value, create one now... - Result = Create(Ty, V, I); - } - - return Result; - } - - void remove(ConstantClass *CP) { - sys::SmartScopedLock Lock(ValueMapLock); - typename MapTy::iterator I = FindExistingElement(CP); - assert(I != Map.end() && "Constant not found in constant table!"); - assert(I->second == CP && "Didn't find correct element?"); - - if (HasLargeKey) // Remember the reverse mapping if needed. - InverseMap.erase(CP); - - // Now that we found the entry, make sure this isn't the entry that - // the AbstractTypeMap points to. - const TypeClass *Ty = static_cast(I->first.first); - if (Ty->isAbstract()) { - assert(AbstractTypeMap.count(Ty) && - "Abstract type not in AbstractTypeMap?"); - typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty]; - if (ATMEntryIt == I) { - // Yes, we are removing the representative entry for this type. - // See if there are any other entries of the same type. - typename MapTy::iterator TmpIt = ATMEntryIt; - - // First check the entry before this one... - if (TmpIt != Map.begin()) { - --TmpIt; - if (TmpIt->first.first != Ty) // Not the same type, move back... - ++TmpIt; - } - - // If we didn't find the same type, try to move forward... - if (TmpIt == ATMEntryIt) { - ++TmpIt; - if (TmpIt == Map.end() || TmpIt->first.first != Ty) - --TmpIt; // No entry afterwards with the same type - } - - // If there is another entry in the map of the same abstract type, - // update the AbstractTypeMap entry now. - if (TmpIt != ATMEntryIt) { - ATMEntryIt = TmpIt; - } else { - // Otherwise, we are removing the last instance of this type - // from the table. Remove from the ATM, and from user list. - cast(Ty)->removeAbstractTypeUser(this); - AbstractTypeMap.erase(Ty); - } - } - } - - Map.erase(I); - } - - - /// MoveConstantToNewSlot - If we are about to change C to be the element - /// specified by I, update our internal data structures to reflect this - /// fact. - /// NOTE: This function is not locked. It is the responsibility of the - /// caller to enforce proper synchronization if using this method. - void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) { - // First, remove the old location of the specified constant in the map. - typename MapTy::iterator OldI = FindExistingElement(C); - assert(OldI != Map.end() && "Constant not found in constant table!"); - assert(OldI->second == C && "Didn't find correct element?"); - - // If this constant is the representative element for its abstract type, - // update the AbstractTypeMap so that the representative element is I. - if (C->getType()->isAbstract()) { - typename AbstractTypeMapTy::iterator ATI = - AbstractTypeMap.find(C->getType()); - assert(ATI != AbstractTypeMap.end() && - "Abstract type not in AbstractTypeMap?"); - if (ATI->second == OldI) - ATI->second = I; - } - - // Remove the old entry from the map. - Map.erase(OldI); - - // Update the inverse map so that we know that this constant is now - // located at descriptor I. - if (HasLargeKey) { - assert(I->second == C && "Bad inversemap entry!"); - InverseMap[C] = I; - } - } - - void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { - sys::SmartScopedLock Lock(ValueMapLock); - typename AbstractTypeMapTy::iterator I = - AbstractTypeMap.find(cast(OldTy)); - - assert(I != AbstractTypeMap.end() && - "Abstract type not in AbstractTypeMap?"); - - // Convert a constant at a time until the last one is gone. The last one - // leaving will remove() itself, causing the AbstractTypeMapEntry to be - // eliminated eventually. - do { - ConvertConstantType::convert( - static_cast(I->second->second), - cast(NewTy)); - - I = AbstractTypeMap.find(cast(OldTy)); - } while (I != AbstractTypeMap.end()); - } - - // If the type became concrete without being refined to any other existing - // type, we just remove ourselves from the ATU list. - void typeBecameConcrete(const DerivedType *AbsTy) { - AbsTy->removeAbstractTypeUser(this); - } - - void dump() const { - DOUT << "Constant.cpp: ValueMap\n"; - } - }; -} - /// destroyConstant - Remove the constant from the constant table... /// void ConstantAggregateZero::destroyConstant() { diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 55707b029b..c35623e0ed 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -365,8 +365,7 @@ LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) { LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N, int SignExtend) { - return wrap(getGlobalContext().getConstantInt(unwrap(IntTy), N, - SignExtend != 0)); + return wrap(ConstantInt::get(unwrap(IntTy), N, SignExtend != 0)); } static const fltSemantics &SemanticsForType(Type *Ty) { diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 5e5ce64c1c..47cba012b8 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -704,7 +704,7 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) { static Value *getAISize(LLVMContext &Context, Value *Amt) { if (!Amt) - Amt = Context.getConstantInt(Type::Int32Ty, 1); + Amt = ConstantInt::get(Type::Int32Ty, 1); else { assert(!isa(Amt) && "Passed basic block into allocation size parameter! Use other ctor"); diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index d0f05eb414..db81c61ace 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -39,7 +39,7 @@ static const uint64_t zero[2] = {0, 0}; Constant* LLVMContext::getNullValue(const Type* Ty) { switch (Ty->getTypeID()) { case Type::IntegerTyID: - return getConstantInt(Ty, 0); + return ConstantInt::get(Ty, 0); case Type::FloatTyID: return getConstantFP(APFloat(APInt(32, 0))); case Type::DoubleTyID: @@ -65,7 +65,7 @@ Constant* LLVMContext::getNullValue(const Type* Ty) { Constant* LLVMContext::getAllOnesValue(const Type* Ty) { if (const IntegerType* ITy = dyn_cast(Ty)) - return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth())); + return ConstantInt::get(*this, APInt::getAllOnesValue(ITy->getBitWidth())); std::vector Elts; const VectorType* VTy = cast(Ty); @@ -92,51 +92,6 @@ ConstantInt* LLVMContext::getFalse() { return pImpl->getFalse(); } -Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V, - bool isSigned) { - Constant *C = getConstantInt(cast(Ty->getScalarType()), - V, isSigned); - - // For vectors, broadcast the value. - if (const VectorType *VTy = dyn_cast(Ty)) - return - getConstantVector(std::vector(VTy->getNumElements(), C)); - - return C; -} - - -ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V, - bool isSigned) { - return getConstantInt(APInt(Ty->getBitWidth(), V, isSigned)); -} - -ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty, - int64_t V) { - return getConstantInt(Ty, V, true); -} - -Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) { - return getConstantInt(Ty, V, true); -} - -ConstantInt* LLVMContext::getConstantInt(const APInt& V) { - return pImpl->getConstantInt(V); -} - -Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) { - ConstantInt *C = getConstantInt(V); - assert(C->getType() == Ty->getScalarType() && - "ConstantInt type doesn't match the type implied by its value!"); - - // For vectors, broadcast the value. - if (const VectorType *VTy = dyn_cast(Ty)) - return - getConstantVector(std::vector(VTy->getNumElements(), C)); - - return C; -} - // ConstantPointerNull accessors. ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) { return ConstantPointerNull::get(T); @@ -194,11 +149,11 @@ Constant* LLVMContext::getConstantArray(const std::string& Str, bool AddNull) { std::vector ElementVals; for (unsigned i = 0; i < Str.length(); ++i) - ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i])); + ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i])); // Add a null terminator to the string... if (AddNull) { - ElementVals.push_back(getConstantInt(Type::Int8Ty, 0)); + ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0)); } ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size()); @@ -302,8 +257,8 @@ Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) { // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1 const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL); Constant *NullPtr = getNullValue(AligningTy->getPointerTo()); - Constant *Zero = getConstantInt(Type::Int32Ty, 0); - Constant *One = getConstantInt(Type::Int32Ty, 1); + Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); + Constant *One = ConstantInt::get(Type::Int32Ty, 1); Constant *Indices[2] = { Zero, One }; Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2); return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty); @@ -463,7 +418,7 @@ Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val, Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) { // sizeof is implemented as: (i64) gep (Ty*)null, 1 - Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1); + Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1); Constant *GEP = getConstantExprGetElementPtr( getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1); return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty); diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 34fc6e52f8..8e6c7778b9 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -45,368 +45,10 @@ static std::vector getValType(ConstantVector *CP) { return Elements; } -namespace llvm { -template -struct VISIBILITY_HIDDEN ConstantTraits< std::vector > { - static unsigned uses(const std::vector& v) { - return v.size(); - } -}; - -template -struct VISIBILITY_HIDDEN ConstantCreator { - static ConstantClass *create(const TypeClass *Ty, const ValType &V) { - return new(ConstantTraits::uses(V)) ConstantClass(Ty, V); - } -}; - -template -struct VISIBILITY_HIDDEN ConvertConstantType { - static void convert(ConstantClass *OldC, const TypeClass *NewTy) { - llvm_unreachable("This type cannot be converted!"); - } -}; - -// ConstantAggregateZero does not take extra "value" argument... -template -struct ConstantCreator { - static ConstantAggregateZero *create(const Type *Ty, const ValType &V){ - return new ConstantAggregateZero(Ty); - } -}; - -template<> -struct ConvertConstantType { - static void convert(ConstantAggregateZero *OldC, const Type *NewTy) { - // Make everyone now use a constant of the new type... - Constant *New = NewTy->getContext().getConstantAggregateZero(NewTy); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; - -template<> -struct ConvertConstantType { - static void convert(ConstantArray *OldC, const ArrayType *NewTy) { - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = NewTy->getContext().getConstantArray(NewTy, C); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; - -template<> -struct ConvertConstantType { - static void convert(ConstantStruct *OldC, const StructType *NewTy) { - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = NewTy->getContext().getConstantStruct(NewTy, C); - assert(New != OldC && "Didn't replace constant??"); - - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; - -template<> -struct ConvertConstantType { - static void convert(ConstantVector *OldC, const VectorType *NewTy) { - // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = OldC->getContext().getConstantVector(NewTy, C); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } -}; -} - -template -class VISIBILITY_HIDDEN ValueMap : public AbstractTypeUser { -public: - typedef std::pair MapKey; - typedef std::map MapTy; - typedef std::map InverseMapTy; - typedef std::map AbstractTypeMapTy; -private: - /// Map - This is the main map from the element descriptor to the Constants. - /// This is the primary way we avoid creating two of the same shape - /// constant. - MapTy Map; - - /// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping - /// from the constants to their element in Map. This is important for - /// removal of constants from the array, which would otherwise have to scan - /// through the map with very large keys. - InverseMapTy InverseMap; - - /// AbstractTypeMap - Map for abstract type constants. - /// - AbstractTypeMapTy AbstractTypeMap; - - /// ValueMapLock - Mutex for this map. - sys::SmartMutex ValueMapLock; - -public: - // NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. - typename MapTy::iterator map_end() { return Map.end(); } - - /// InsertOrGetItem - Return an iterator for the specified element. - /// If the element exists in the map, the returned iterator points to the - /// entry and Exists=true. If not, the iterator points to the newly - /// inserted entry and returns Exists=false. Newly inserted entries have - /// I->second == 0, and should be filled in. - /// NOTE: This function is not locked. It is the caller's responsibility - // to enforce proper synchronization. - typename MapTy::iterator InsertOrGetItem(std::pair - &InsertVal, - bool &Exists) { - std::pair IP = Map.insert(InsertVal); - Exists = !IP.second; - return IP.first; - } - -private: - typename MapTy::iterator FindExistingElement(ConstantClass *CP) { - if (HasLargeKey) { - typename InverseMapTy::iterator IMI = InverseMap.find(CP); - assert(IMI != InverseMap.end() && IMI->second != Map.end() && - IMI->second->second == CP && - "InverseMap corrupt!"); - return IMI->second; - } - - typename MapTy::iterator I = - Map.find(MapKey(static_cast(CP->getRawType()), - getValType(CP))); - if (I == Map.end() || I->second != CP) { - // FIXME: This should not use a linear scan. If this gets to be a - // performance problem, someone should look at this. - for (I = Map.begin(); I != Map.end() && I->second != CP; ++I) - /* empty */; - } - return I; - } - - ConstantClass* Create(const TypeClass *Ty, const ValType &V, - typename MapTy::iterator I) { - ConstantClass* Result = - ConstantCreator::create(Ty, V); - - assert(Result->getType() == Ty && "Type specified is not correct!"); - I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result)); - - if (HasLargeKey) // Remember the reverse mapping if needed. - InverseMap.insert(std::make_pair(Result, I)); - - // If the type of the constant is abstract, make sure that an entry - // exists for it in the AbstractTypeMap. - if (Ty->isAbstract()) { - typename AbstractTypeMapTy::iterator TI = - AbstractTypeMap.find(Ty); - - if (TI == AbstractTypeMap.end()) { - // Add ourselves to the ATU list of the type. - cast(Ty)->addAbstractTypeUser(this); - - AbstractTypeMap.insert(TI, std::make_pair(Ty, I)); - } - } - - return Result; - } -public: - - /// getOrCreate - Return the specified constant from the map, creating it if - /// necessary. - ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { - sys::SmartScopedLock Lock(ValueMapLock); - MapKey Lookup(Ty, V); - ConstantClass* Result = 0; - - typename MapTy::iterator I = Map.find(Lookup); - // Is it in the map? - if (I != Map.end()) - Result = static_cast(I->second); - - if (!Result) { - // If no preexisting value, create one now... - Result = Create(Ty, V, I); - } - - return Result; - } - - void remove(ConstantClass *CP) { - sys::SmartScopedLock Lock(ValueMapLock); - typename MapTy::iterator I = FindExistingElement(CP); - assert(I != Map.end() && "Constant not found in constant table!"); - assert(I->second == CP && "Didn't find correct element?"); - - if (HasLargeKey) // Remember the reverse mapping if needed. - InverseMap.erase(CP); - - // Now that we found the entry, make sure this isn't the entry that - // the AbstractTypeMap points to. - const TypeClass *Ty = static_cast(I->first.first); - if (Ty->isAbstract()) { - assert(AbstractTypeMap.count(Ty) && - "Abstract type not in AbstractTypeMap?"); - typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty]; - if (ATMEntryIt == I) { - // Yes, we are removing the representative entry for this type. - // See if there are any other entries of the same type. - typename MapTy::iterator TmpIt = ATMEntryIt; - - // First check the entry before this one... - if (TmpIt != Map.begin()) { - --TmpIt; - if (TmpIt->first.first != Ty) // Not the same type, move back... - ++TmpIt; - } - - // If we didn't find the same type, try to move forward... - if (TmpIt == ATMEntryIt) { - ++TmpIt; - if (TmpIt == Map.end() || TmpIt->first.first != Ty) - --TmpIt; // No entry afterwards with the same type - } - - // If there is another entry in the map of the same abstract type, - // update the AbstractTypeMap entry now. - if (TmpIt != ATMEntryIt) { - ATMEntryIt = TmpIt; - } else { - // Otherwise, we are removing the last instance of this type - // from the table. Remove from the ATM, and from user list. - cast(Ty)->removeAbstractTypeUser(this); - AbstractTypeMap.erase(Ty); - } - } - } - - Map.erase(I); - } - - - /// MoveConstantToNewSlot - If we are about to change C to be the element - /// specified by I, update our internal data structures to reflect this - /// fact. - /// NOTE: This function is not locked. It is the responsibility of the - /// caller to enforce proper synchronization if using this method. - void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) { - // First, remove the old location of the specified constant in the map. - typename MapTy::iterator OldI = FindExistingElement(C); - assert(OldI != Map.end() && "Constant not found in constant table!"); - assert(OldI->second == C && "Didn't find correct element?"); - - // If this constant is the representative element for its abstract type, - // update the AbstractTypeMap so that the representative element is I. - if (C->getType()->isAbstract()) { - typename AbstractTypeMapTy::iterator ATI = - AbstractTypeMap.find(C->getType()); - assert(ATI != AbstractTypeMap.end() && - "Abstract type not in AbstractTypeMap?"); - if (ATI->second == OldI) - ATI->second = I; - } - - // Remove the old entry from the map. - Map.erase(OldI); - - // Update the inverse map so that we know that this constant is now - // located at descriptor I. - if (HasLargeKey) { - assert(I->second == C && "Bad inversemap entry!"); - InverseMap[C] = I; - } - } - - void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { - sys::SmartScopedLock Lock(ValueMapLock); - typename AbstractTypeMapTy::iterator I = - AbstractTypeMap.find(cast(OldTy)); - - assert(I != AbstractTypeMap.end() && - "Abstract type not in AbstractTypeMap?"); - - // Convert a constant at a time until the last one is gone. The last one - // leaving will remove() itself, causing the AbstractTypeMapEntry to be - // eliminated eventually. - do { - ConvertConstantType::convert( - static_cast(I->second->second), - cast(NewTy)); - - I = AbstractTypeMap.find(cast(OldTy)); - } while (I != AbstractTypeMap.end()); - } - - // If the type became concrete without being refined to any other existing - // type, we just remove ourselves from the ATU list. - void typeBecameConcrete(const DerivedType *AbsTy) { - AbsTy->removeAbstractTypeUser(this); - } - - void dump() const { - DOUT << "Constant.cpp: ValueMap\n"; - } -}; LLVMContextImpl::LLVMContextImpl(LLVMContext &C) : - Context(C), TheTrueVal(0), TheFalseVal(0) { - AggZeroConstants = new ValueMap(); - ArrayConstants = new ArrayConstantsTy(); - StructConstants = new StructConstantsTy(); - VectorConstants = new VectorConstantsTy(); -} + Context(C), TheTrueVal(0), TheFalseVal(0) { } -LLVMContextImpl::~LLVMContextImpl() { - delete AggZeroConstants; - delete ArrayConstants; - delete StructConstants; - delete VectorConstants; -} - -// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap -// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the -// operator== and operator!= to ensure that the DenseMap doesn't attempt to -// compare APInt's of different widths, which would violate an APInt class -// invariant which generates an assertion. -ConstantInt *LLVMContextImpl::getConstantInt(const APInt& V) { - // Get the corresponding integer type for the bit width of the value. - const IntegerType *ITy = Context.getIntegerType(V.getBitWidth()); - // get an existing value or the insertion position - DenseMapAPIntKeyInfo::KeyTy Key(V, ITy); - - ConstantsLock.reader_acquire(); - ConstantInt *&Slot = IntConstants[Key]; - ConstantsLock.reader_release(); - - if (!Slot) { - sys::SmartScopedWriter Writer(ConstantsLock); - ConstantInt *&NewSlot = IntConstants[Key]; - if (!Slot) { - NewSlot = new ConstantInt(ITy, V); - } - - return NewSlot; - } else { - return Slot; - } -} ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) { DenseMapAPFloatKeyInfo::KeyTy Key(V); @@ -483,7 +125,7 @@ LLVMContextImpl::getConstantAggregateZero(const Type *Ty) { "Cannot create an aggregate zero of non-aggregate type!"); // Implicitly locked. - return AggZeroConstants->getOrCreate(Ty, 0); + return AggZeroConstants.getOrCreate(Ty, 0); } Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty, @@ -493,12 +135,12 @@ Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty, Constant *C = V[0]; if (!C->isNullValue()) { // Implicitly locked. - return ArrayConstants->getOrCreate(Ty, V); + return ArrayConstants.getOrCreate(Ty, V); } for (unsigned i = 1, e = V.size(); i != e; ++i) if (V[i] != C) { // Implicitly locked. - return ArrayConstants->getOrCreate(Ty, V); + return ArrayConstants.getOrCreate(Ty, V); } } @@ -511,7 +153,7 @@ Constant *LLVMContextImpl::getConstantStruct(const StructType *Ty, for (unsigned i = 0, e = V.size(); i != e; ++i) if (!V[i]->isNullValue()) // Implicitly locked. - return StructConstants->getOrCreate(Ty, V); + return StructConstants.getOrCreate(Ty, V); return Context.getConstantAggregateZero(Ty); } @@ -539,7 +181,7 @@ Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty, return Context.getUndef(Ty); // Implicitly locked. - return VectorConstants->getOrCreate(Ty, V); + return VectorConstants.getOrCreate(Ty, V); } // *** erase methods *** @@ -556,19 +198,19 @@ void LLVMContextImpl::erase(MDNode *M) { } void LLVMContextImpl::erase(ConstantAggregateZero *Z) { - AggZeroConstants->remove(Z); + AggZeroConstants.remove(Z); } void LLVMContextImpl::erase(ConstantArray *C) { - ArrayConstants->remove(C); + ArrayConstants.remove(C); } void LLVMContextImpl::erase(ConstantStruct *S) { - StructConstants->remove(S); + StructConstants.remove(S); } void LLVMContextImpl::erase(ConstantVector *V) { - VectorConstants->remove(V); + VectorConstants.remove(V); } // *** RAUW helpers *** @@ -621,7 +263,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA, sys::SmartScopedWriter Writer(ConstantsLock); bool Exists; ArrayConstantsTy::MapTy::iterator I = - ArrayConstants->InsertOrGetItem(Lookup, Exists); + ArrayConstants.InsertOrGetItem(Lookup, Exists); if (Exists) { Replacement = I->second; @@ -630,7 +272,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA, // creating a new constant array, inserting it, replaceallusesof'ing the // old with the new, then deleting the old... just update the current one // in place! - ArrayConstants->MoveConstantToNewSlot(CA, I); + ArrayConstants.MoveConstantToNewSlot(CA, I); // Update to the new value. Optimize for the case when we have a single // operand that we're changing, but handle bulk updates efficiently. @@ -693,7 +335,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS, sys::SmartScopedWriter Writer(ConstantsLock); bool Exists; StructConstantsTy::MapTy::iterator I = - StructConstants->InsertOrGetItem(Lookup, Exists); + StructConstants.InsertOrGetItem(Lookup, Exists); if (Exists) { Replacement = I->second; @@ -702,7 +344,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS, // creating a new constant struct, inserting it, replaceallusesof'ing the // old with the new, then deleting the old... just update the current one // in place! - StructConstants->MoveConstantToNewSlot(CS, I); + StructConstants.MoveConstantToNewSlot(CS, I); // Update to the new value. CS->setOperand(OperandToUpdate, ToC); diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 73516245f5..96ac0f80fc 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -16,6 +16,7 @@ #define LLVM_LLVMCONTEXT_IMPL_H #include "llvm/LLVMContext.h" +#include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -29,14 +30,336 @@ #include #include -template -class ValueMap; - namespace llvm { template struct ConstantTraits; +// The number of operands for each ConstantCreator::create method is +// determined by the ConstantTraits template. +// ConstantCreator - A class that is used to create constants by +// ValueMap*. This class should be partially specialized if there is +// something strange that needs to be done to interface to the ctor for the +// constant. +// +template +struct VISIBILITY_HIDDEN ConstantTraits< std::vector > { + static unsigned uses(const std::vector& v) { + return v.size(); + } +}; + +template +struct VISIBILITY_HIDDEN ConstantCreator { + static ConstantClass *create(const TypeClass *Ty, const ValType &V) { + return new(ConstantTraits::uses(V)) ConstantClass(Ty, V); + } +}; + +template +struct VISIBILITY_HIDDEN ConvertConstantType { + static void convert(ConstantClass *OldC, const TypeClass *NewTy) { + llvm_unreachable("This type cannot be converted!"); + } +}; + +// ConstantAggregateZero does not take extra "value" argument... +template +struct ConstantCreator { + static ConstantAggregateZero *create(const Type *Ty, const ValType &V){ + return new ConstantAggregateZero(Ty); + } +}; + +template<> +struct ConvertConstantType { + static void convert(ConstantAggregateZero *OldC, const Type *NewTy) { + // Make everyone now use a constant of the new type... + Constant *New = NewTy->getContext().getConstantAggregateZero(NewTy); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; + +template<> +struct ConvertConstantType { + static void convert(ConstantArray *OldC, const ArrayType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + Constant *New = NewTy->getContext().getConstantArray(NewTy, C); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; + +template<> +struct ConvertConstantType { + static void convert(ConstantStruct *OldC, const StructType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + Constant *New = NewTy->getContext().getConstantStruct(NewTy, C); + assert(New != OldC && "Didn't replace constant??"); + + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; + +template<> +struct ConvertConstantType { + static void convert(ConstantVector *OldC, const VectorType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + Constant *New = OldC->getContext().getConstantVector(NewTy, C); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; + +template +class ValueMap : public AbstractTypeUser { +public: + typedef std::pair MapKey; + typedef std::map MapTy; + typedef std::map InverseMapTy; + typedef std::map AbstractTypeMapTy; +private: + /// Map - This is the main map from the element descriptor to the Constants. + /// This is the primary way we avoid creating two of the same shape + /// constant. + MapTy Map; + + /// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping + /// from the constants to their element in Map. This is important for + /// removal of constants from the array, which would otherwise have to scan + /// through the map with very large keys. + InverseMapTy InverseMap; + + /// AbstractTypeMap - Map for abstract type constants. + /// + AbstractTypeMapTy AbstractTypeMap; + + /// ValueMapLock - Mutex for this map. + sys::SmartMutex ValueMapLock; + +public: + // NOTE: This function is not locked. It is the caller's responsibility + // to enforce proper synchronization. + typename MapTy::iterator map_end() { return Map.end(); } + + /// InsertOrGetItem - Return an iterator for the specified element. + /// If the element exists in the map, the returned iterator points to the + /// entry and Exists=true. If not, the iterator points to the newly + /// inserted entry and returns Exists=false. Newly inserted entries have + /// I->second == 0, and should be filled in. + /// NOTE: This function is not locked. It is the caller's responsibility + // to enforce proper synchronization. + typename MapTy::iterator InsertOrGetItem(std::pair + &InsertVal, + bool &Exists) { + std::pair IP = Map.insert(InsertVal); + Exists = !IP.second; + return IP.first; + } + +private: + typename MapTy::iterator FindExistingElement(ConstantClass *CP) { + if (HasLargeKey) { + typename InverseMapTy::iterator IMI = InverseMap.find(CP); + assert(IMI != InverseMap.end() && IMI->second != Map.end() && + IMI->second->second == CP && + "InverseMap corrupt!"); + return IMI->second; + } + + typename MapTy::iterator I = + Map.find(MapKey(static_cast(CP->getRawType()), + getValType(CP))); + if (I == Map.end() || I->second != CP) { + // FIXME: This should not use a linear scan. If this gets to be a + // performance problem, someone should look at this. + for (I = Map.begin(); I != Map.end() && I->second != CP; ++I) + /* empty */; + } + return I; + } + + ConstantClass* Create(const TypeClass *Ty, const ValType &V, + typename MapTy::iterator I) { + ConstantClass* Result = + ConstantCreator::create(Ty, V); + + assert(Result->getType() == Ty && "Type specified is not correct!"); + I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result)); + + if (HasLargeKey) // Remember the reverse mapping if needed. + InverseMap.insert(std::make_pair(Result, I)); + + // If the type of the constant is abstract, make sure that an entry + // exists for it in the AbstractTypeMap. + if (Ty->isAbstract()) { + typename AbstractTypeMapTy::iterator TI = + AbstractTypeMap.find(Ty); + + if (TI == AbstractTypeMap.end()) { + // Add ourselves to the ATU list of the type. + cast(Ty)->addAbstractTypeUser(this); + + AbstractTypeMap.insert(TI, std::make_pair(Ty, I)); + } + } + + return Result; + } +public: + + /// getOrCreate - Return the specified constant from the map, creating it if + /// necessary. + ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { + sys::SmartScopedLock Lock(ValueMapLock); + MapKey Lookup(Ty, V); + ConstantClass* Result = 0; + + typename MapTy::iterator I = Map.find(Lookup); + // Is it in the map? + if (I != Map.end()) + Result = static_cast(I->second); + + if (!Result) { + // If no preexisting value, create one now... + Result = Create(Ty, V, I); + } + + return Result; + } + + void remove(ConstantClass *CP) { + sys::SmartScopedLock Lock(ValueMapLock); + typename MapTy::iterator I = FindExistingElement(CP); + assert(I != Map.end() && "Constant not found in constant table!"); + assert(I->second == CP && "Didn't find correct element?"); + + if (HasLargeKey) // Remember the reverse mapping if needed. + InverseMap.erase(CP); + + // Now that we found the entry, make sure this isn't the entry that + // the AbstractTypeMap points to. + const TypeClass *Ty = static_cast(I->first.first); + if (Ty->isAbstract()) { + assert(AbstractTypeMap.count(Ty) && + "Abstract type not in AbstractTypeMap?"); + typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty]; + if (ATMEntryIt == I) { + // Yes, we are removing the representative entry for this type. + // See if there are any other entries of the same type. + typename MapTy::iterator TmpIt = ATMEntryIt; + + // First check the entry before this one... + if (TmpIt != Map.begin()) { + --TmpIt; + if (TmpIt->first.first != Ty) // Not the same type, move back... + ++TmpIt; + } + + // If we didn't find the same type, try to move forward... + if (TmpIt == ATMEntryIt) { + ++TmpIt; + if (TmpIt == Map.end() || TmpIt->first.first != Ty) + --TmpIt; // No entry afterwards with the same type + } + + // If there is another entry in the map of the same abstract type, + // update the AbstractTypeMap entry now. + if (TmpIt != ATMEntryIt) { + ATMEntryIt = TmpIt; + } else { + // Otherwise, we are removing the last instance of this type + // from the table. Remove from the ATM, and from user list. + cast(Ty)->removeAbstractTypeUser(this); + AbstractTypeMap.erase(Ty); + } + } + } + + Map.erase(I); + } + + + /// MoveConstantToNewSlot - If we are about to change C to be the element + /// specified by I, update our internal data structures to reflect this + /// fact. + /// NOTE: This function is not locked. It is the responsibility of the + /// caller to enforce proper synchronization if using this method. + void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) { + // First, remove the old location of the specified constant in the map. + typename MapTy::iterator OldI = FindExistingElement(C); + assert(OldI != Map.end() && "Constant not found in constant table!"); + assert(OldI->second == C && "Didn't find correct element?"); + + // If this constant is the representative element for its abstract type, + // update the AbstractTypeMap so that the representative element is I. + if (C->getType()->isAbstract()) { + typename AbstractTypeMapTy::iterator ATI = + AbstractTypeMap.find(C->getType()); + assert(ATI != AbstractTypeMap.end() && + "Abstract type not in AbstractTypeMap?"); + if (ATI->second == OldI) + ATI->second = I; + } + + // Remove the old entry from the map. + Map.erase(OldI); + + // Update the inverse map so that we know that this constant is now + // located at descriptor I. + if (HasLargeKey) { + assert(I->second == C && "Bad inversemap entry!"); + InverseMap[C] = I; + } + } + + void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { + sys::SmartScopedLock Lock(ValueMapLock); + typename AbstractTypeMapTy::iterator I = + AbstractTypeMap.find(cast(OldTy)); + + assert(I != AbstractTypeMap.end() && + "Abstract type not in AbstractTypeMap?"); + + // Convert a constant at a time until the last one is gone. The last one + // leaving will remove() itself, causing the AbstractTypeMapEntry to be + // eliminated eventually. + do { + ConvertConstantType::convert( + static_cast(I->second->second), + cast(NewTy)); + + I = AbstractTypeMap.find(cast(OldTy)); + } while (I != AbstractTypeMap.end()); + } + + // If the type became concrete without being refined to any other existing + // type, we just remove ourselves from the ATU list. + void typeBecameConcrete(const DerivedType *AbsTy) { + AbsTy->removeAbstractTypeUser(this); + } + + void dump() const { + DOUT << "Constant.cpp: ValueMap\n"; + } +}; + + class ConstantInt; class ConstantFP; class MDString; @@ -112,19 +435,19 @@ class LLVMContextImpl { FoldingSet MDNodeSet; - ValueMap *AggZeroConstants; + ValueMap AggZeroConstants; typedef ValueMap, ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy; - ArrayConstantsTy *ArrayConstants; + ArrayConstantsTy ArrayConstants; typedef ValueMap, StructType, ConstantStruct, true /*largekey*/> StructConstantsTy; - StructConstantsTy *StructConstants; + StructConstantsTy StructConstants; typedef ValueMap, VectorType, ConstantVector> VectorConstantsTy; - VectorConstantsTy *VectorConstants; + VectorConstantsTy VectorConstants; LLVMContext &Context; ConstantInt *TheTrueVal; @@ -132,13 +455,10 @@ class LLVMContextImpl { LLVMContextImpl(); LLVMContextImpl(const LLVMContextImpl&); + + friend class ConstantInt; public: LLVMContextImpl(LLVMContext &C); - ~LLVMContextImpl(); - - /// Return a ConstantInt with the specified value and an implied Type. The - /// type is the integer type that corresponds to the bit width of the value. - ConstantInt *getConstantInt(const APInt &V); ConstantFP *getConstantFP(const APFloat &V); @@ -161,14 +481,14 @@ public: if (TheTrueVal) return TheTrueVal; else - return (TheTrueVal = Context.getConstantInt(IntegerType::get(1), 1)); + return (TheTrueVal = ConstantInt::get(IntegerType::get(1), 1)); } ConstantInt *getFalse() { if (TheFalseVal) return TheFalseVal; else - return (TheFalseVal = Context.getConstantInt(IntegerType::get(1), 0)); + return (TheFalseVal = ConstantInt::get(IntegerType::get(1), 0)); } void erase(MDString *M); -- cgit v1.2.3