diff options
Diffstat (limited to 'lib')
25 files changed, 492 insertions, 428 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 491cc3f202..437ff03b32 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -463,7 +463,7 @@ DIFactory::DIFactory(Module &m) /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. /// This is only valid when the descriptor is non-null. Constant *DIFactory::getCastToEmpty(DIDescriptor D) { - if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); + if (D.isNull()) return VMContext.getNullValue(EmptyStructPtr); return VMContext.getConstantExprBitCast(D.getGV(), EmptyStructPtr); } diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp index 3f1dcb75b1..91aaf0670a 100644 --- a/lib/Analysis/IPA/Andersens.cpp +++ b/lib/Analysis/IPA/Andersens.cpp @@ -693,7 +693,7 @@ void Andersens::getMustAliases(Value *P, std::vector<Value*> &RetVals) { // If the object in the points-to set is the null object, then the null // pointer is a must alias. if (Pointee == &GraphNodes[NullObject]) - RetVals.push_back(Constant::getNullValue(P->getType())); + RetVals.push_back(Context->getNullValue(P->getType())); } } AliasAnalysis::getMustAliases(P, RetVals); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index a167792024..fc7d286aaf 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2084,7 +2084,8 @@ const SCEV *ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { /// const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) { if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V)) - return getConstant(cast<ConstantInt>(ConstantExpr::getNeg(VC->getValue()))); + return getConstant( + cast<ConstantInt>(Context->getConstantExprNeg(VC->getValue()))); const Type *Ty = V->getType(); Ty = getEffectiveSCEVType(Ty); @@ -3284,7 +3285,7 @@ EvaluateConstantChrecAtConstant(const SCEVAddRecExpr *AddRec, ConstantInt *C, /// the addressed element of the initializer or null if the index expression is /// invalid. static Constant * -GetAddressedElementFromGlobal(GlobalVariable *GV, +GetAddressedElementFromGlobal(LLVMContext *Context, GlobalVariable *GV, const std::vector<ConstantInt*> &Indices) { Constant *Init = GV->getInitializer(); for (unsigned i = 0, e = Indices.size(); i != e; ++i) { @@ -3298,10 +3299,10 @@ GetAddressedElementFromGlobal(GlobalVariable *GV, } else if (isa<ConstantAggregateZero>(Init)) { if (const StructType *STy = dyn_cast<StructType>(Init->getType())) { assert(Idx < STy->getNumElements() && "Bad struct index!"); - Init = Constant::getNullValue(STy->getElementType(Idx)); + Init = Context->getNullValue(STy->getElementType(Idx)); } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Init->getType())) { if (Idx >= ATy->getNumElements()) return 0; // Bogus program - Init = Constant::getNullValue(ATy->getElementType()); + Init = Context->getNullValue(ATy->getElementType()); } else { LLVM_UNREACHABLE("Unknown constant aggregate type!"); } @@ -3372,7 +3373,7 @@ ScalarEvolution::ComputeLoadConstantCompareBackedgeTakenCount( // Form the GEP offset. Indexes[VarIdxNum] = Val; - Constant *Result = GetAddressedElementFromGlobal(GV, Indexes); + Constant *Result = GetAddressedElementFromGlobal(Context, GV, Indexes); if (Result == 0) break; // Cannot compute! // Evaluate the condition for this iteration. diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 914d703e85..9e6bcd83f3 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -315,6 +315,7 @@ static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { IRBuilder<> Builder(CI->getParent(), CI); + LLVMContext *Context = CI->getParent()->getContext(); Function *Callee = CI->getCalledFunction(); assert(Callee && "Cannot lower an indirect call!"); @@ -340,7 +341,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { } case Intrinsic::sigsetjmp: if (CI->getType() != Type::VoidTy) - CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); + CI->replaceAllUsesWith(Context->getNullValue(CI->getType())); break; case Intrinsic::longjmp: { @@ -387,7 +388,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { "save" : "restore") << " intrinsic.\n"; Warned = true; if (Callee->getIntrinsicID() == Intrinsic::stacksave) - CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); + CI->replaceAllUsesWith(Context->getNullValue(CI->getType())); break; } @@ -422,7 +423,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { case Intrinsic::eh_exception: case Intrinsic::eh_selector_i32: case Intrinsic::eh_selector_i64: - CI->replaceAllUsesWith(Constant::getNullValue(CI->getType())); + CI->replaceAllUsesWith(Context->getNullValue(CI->getType())); break; case Intrinsic::eh_typeid_for_i32: diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp index 7542d9ed10..35f71075cc 100644 --- a/lib/CodeGen/MachOWriter.cpp +++ b/lib/CodeGen/MachOWriter.cpp @@ -123,7 +123,7 @@ bool MachOWriter::doFinalization(Module &M) { // getConstSection - Get constant section for Constant 'C' MachOSection *MachOWriter::getConstSection(Constant *C) { const ConstantArray *CVA = dyn_cast<ConstantArray>(C); - if (CVA && CVA->isCString()) + if (CVA && CVA->isCString(*Context)) return getSection("__TEXT", "__cstring", MachOSection::S_CSTRING_LITERALS); diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index cd2d5ac8ec..adb4d729e6 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -92,7 +92,7 @@ unsigned FastISel::getRegForValue(Value *V) { } else if (isa<ConstantPointerNull>(V)) { // Translate this as an integer zero so that it can be // local-CSE'd with actual integer zeros. - Reg = getRegForValue(Constant::getNullValue(TD.getIntPtrType())); + Reg = getRegForValue(Context->getNullValue(TD.getIntPtrType())); } else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) { Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF); @@ -480,7 +480,7 @@ bool FastISel::SelectCall(User *I) { UpdateValueMap(I, ResultReg); } else { unsigned ResultReg = - getRegForValue(Constant::getNullValue(I->getType())); + getRegForValue(Context->getNullValue(I->getType())); UpdateValueMap(I, ResultReg); } return true; @@ -753,7 +753,8 @@ FastISel::FastISel(MachineFunction &mf, TM(MF.getTarget()), TD(*TM.getTargetData()), TII(*TM.getInstrInfo()), - TLI(*TM.getTargetLowering()) { + TLI(*TM.getTargetLowering()), + Context(mf.getFunction()->getContext()) { } FastISel::~FastISel() {} diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 63aa7cfe7c..ef71a62f14 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -2139,7 +2139,7 @@ void SelectionDAGLowering::visitFSub(User &I) { const VectorType *DestTy = cast<VectorType>(I.getType()); const Type *ElTy = DestTy->getElementType(); unsigned VL = DestTy->getNumElements(); - std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy)); + std::vector<Constant*> NZ(VL, Context->getConstantFPNegativeZero(ElTy)); Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size()); if (CV == CNZ) { SDValue Op2 = getValue(I.getOperand(1)); @@ -2150,7 +2150,8 @@ void SelectionDAGLowering::visitFSub(User &I) { } } if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0))) - if (CFP->isExactlyValue(ConstantFP::getNegativeZero(Ty)->getValueAPF())) { + if (CFP->isExactlyValue( + Context->getConstantFPNegativeZero(Ty)->getValueAPF())) { SDValue Op2 = getValue(I.getOperand(1)); setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), Op2.getValueType(), Op2)); @@ -2398,7 +2399,7 @@ void SelectionDAGLowering::visitShuffleVector(User &I) { // Convert the ConstantVector mask operand into an array of ints, with -1 // representing undef values. SmallVector<Constant*, 8> MaskElts; - cast<Constant>(I.getOperand(2))->getVectorElements(MaskElts); + cast<Constant>(I.getOperand(2))->getVectorElements(*Context, MaskElts); unsigned MaskNumElts = MaskElts.size(); for (unsigned i = 0; i != MaskNumElts; ++i) { if (isa<UndefValue>(MaskElts[i])) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h index 6039ef56f2..deb8855690 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.h @@ -15,6 +15,7 @@ #define SELECTIONDAGBUILD_H #include "llvm/Constants.h" +#include "llvm/CodeGen/SelectionDAG.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" #ifndef NDEBUG @@ -362,11 +363,14 @@ public: /// GFI - Garbage collection metadata for the function. GCFunctionInfo *GFI; + LLVMContext *Context; + SelectionDAGLowering(SelectionDAG &dag, TargetLowering &tli, FunctionLoweringInfo &funcinfo, CodeGenOpt::Level ol) : CurDebugLoc(DebugLoc::getUnknownLoc()), - TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol) { + TLI(tli), DAG(dag), FuncInfo(funcinfo), OptLevel(ol), + Context(dag.getContext()) { } void init(GCFunctionInfo *gfi, AliasAnalysis &aa); diff --git a/lib/CodeGen/ShadowStackGC.cpp b/lib/CodeGen/ShadowStackGC.cpp index 6ba1243ce1..13fa758c24 100644 --- a/lib/CodeGen/ShadowStackGC.cpp +++ b/lib/CodeGen/ShadowStackGC.cpp @@ -293,10 +293,10 @@ bool ShadowStackGC::initializeCustomLowering(Module &M) { // linkage! Head = new GlobalVariable(M, StackEntryPtrTy, false, GlobalValue::LinkOnceAnyLinkage, - Constant::getNullValue(StackEntryPtrTy), + M.getContext().getNullValue(StackEntryPtrTy), "llvm_gc_root_chain"); } else if (Head->hasExternalLinkage() && Head->isDeclaration()) { - Head->setInitializer(Constant::getNullValue(StackEntryPtrTy)); + Head->setInitializer(M.getContext().getNullValue(StackEntryPtrTy)); Head->setLinkage(GlobalValue::LinkOnceAnyLinkage); } diff --git a/lib/CodeGen/UnreachableBlockElim.cpp b/lib/CodeGen/UnreachableBlockElim.cpp index c3b213cebe..003470d954 100644 --- a/lib/CodeGen/UnreachableBlockElim.cpp +++ b/lib/CodeGen/UnreachableBlockElim.cpp @@ -68,7 +68,7 @@ bool UnreachableBlockElim::runOnFunction(Function &F) { BasicBlock *BB = I; DeadBlocks.push_back(BB); while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) { - PN->replaceAllUsesWith(Constant::getNullValue(PN->getType())); + PN->replaceAllUsesWith(Context->getNullValue(PN->getType())); BB->getInstList().pop_front(); } for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index f922146cd0..a403f2e9f1 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -1239,7 +1239,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) { Out << '{'; if (AT->getNumElements()) { Out << ' '; - Constant *CZ = Constant::getNullValue(AT->getElementType()); + Constant *CZ = Context->getNullValue(AT->getElementType()); printConstant(CZ, Static); for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { Out << ", "; @@ -1264,7 +1264,7 @@ void CWriter::printConstant(Constant *CPV, bool Static) { assert(isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV)); const VectorType *VT = cast<VectorType>(CPV->getType()); Out << "{ "; - Constant *CZ = Constant::getNullValue(VT->getElementType()); + Constant *CZ = Context->getNullValue(VT->getElementType()); printConstant(CZ, Static); for (unsigned i = 1, e = VT->getNumElements(); i != e; ++i) { Out << ", "; @@ -1286,10 +1286,10 @@ void CWriter::printConstant(Constant *CPV, bool Static) { Out << '{'; if (ST->getNumElements()) { Out << ' '; - printConstant(Constant::getNullValue(ST->getElementType(0)), Static); + printConstant(Context->getNullValue(ST->getElementType(0)), Static); for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) { Out << ", "; - printConstant(Constant::getNullValue(ST->getElementType(i)), Static); + printConstant(Context->getNullValue(ST->getElementType(i)), Static); } } Out << " }"; @@ -2621,11 +2621,11 @@ void CWriter::visitBinaryOperator(Instruction &I) { // If this is a negation operation, print it out as such. For FP, we don't // want to print "-0.0 - X". - if (BinaryOperator::isNeg(&I)) { + if (BinaryOperator::isNeg(*Context, &I)) { Out << "-("; writeOperand(BinaryOperator::getNegArgument(cast<BinaryOperator>(&I))); Out << ")"; - } else if (BinaryOperator::isFNeg(&I)) { + } else if (BinaryOperator::isFNeg(*Context, &I)) { Out << "-("; writeOperand(BinaryOperator::getFNegArgument(cast<BinaryOperator>(&I))); Out << ")"; diff --git a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp index 17c7640e36..89e9426f24 100644 --- a/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp +++ b/lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp @@ -541,7 +541,7 @@ printModuleLevelGV(const GlobalVariable* GVar) { // Fall Through case GlobalValue::PrivateLinkage: case GlobalValue::InternalLinkage: - if (CVA && CVA->isCString()) + if (CVA && CVA->isCString(GVar->getParent()->getContext())) printSizeAndType = false; break; case GlobalValue::GhostLinkage: diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp index f3fa17938b..3727918eac 100644 --- a/lib/Target/Mips/MipsISelLowering.cpp +++ b/lib/Target/Mips/MipsISelLowering.cpp @@ -227,7 +227,7 @@ bool MipsTargetLowering::IsGlobalInSmallSection(GlobalValue *GV) if (GVA->hasInitializer() && GV->hasLocalLinkage()) { Constant *C = GVA->getInitializer(); const ConstantArray *CVA = dyn_cast<ConstantArray>(C); - if (CVA && CVA->isCString()) + if (CVA && CVA->isCString(GV->getParent()->getContext())) return false; } diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 782e7b4d87..4fbe1ae55e 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -170,11 +170,11 @@ static bool isSuitableForBSS(const GlobalVariable *GV) { return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS); } -static bool isConstantString(const Constant *C) { +static bool isConstantString(LLVMContext &Context, const Constant *C) { // First check: is we have constant array of i8 terminated with zero const ConstantArray *CVA = dyn_cast<ConstantArray>(C); // Check, if initializer is a null-terminated string - if (CVA && CVA->isCString()) + if (CVA && CVA->isCString(Context)) return true; // Another possibility: [1 x i8] zeroinitializer @@ -229,7 +229,7 @@ TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { } } else { // Check, if initializer is a null-terminated string - if (isConstantString(C)) + if (isConstantString(GV->getParent()->getContext(), C)) return SectionKind::RODataMergeStr; else return SectionKind::RODataMergeConst; diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index feb3d4c72e..2b3304d19c 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -272,7 +272,7 @@ bool X86FastISel::X86FastEmitStore(MVT VT, Value *Val, const X86AddressMode &AM) { // Handle 'null' like i32/i64 0. if (isa<ConstantPointerNull>(Val)) - Val = Constant::getNullValue(TD.getIntPtrType()); + Val = Context->getNullValue(TD.getIntPtrType()); // If this is a store of a simple constant, fold the constant into the store. if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) { @@ -672,7 +672,7 @@ bool X86FastISel::X86FastEmitCompare(Value *Op0, Value *Op1, MVT VT) { // Handle 'null' like i32/i64 0. if (isa<ConstantPointerNull>(Op1)) - Op1 = Constant::getNullValue(TD.getIntPtrType()); + Op1 = Context->getNullValue(TD.getIntPtrType()); // We have two options: compare with register or immediate. If the RHS of // the compare is an immediate that we can fold into this compare, use diff --git a/lib/Target/X86/X86InstrInfo.cpp b/lib/Target/X86/X86InstrInfo.cpp index 572b71dbc0..cb98c057c4 100644 --- a/lib/Target/X86/X86InstrInfo.cpp +++ b/lib/Target/X86/X86InstrInfo.cpp @@ -20,6 +20,7 @@ #include "X86TargetMachine.h" #include "llvm/GlobalVariable.h" #include "llvm/DerivedTypes.h" +#include "llvm/LLVMContext.h" #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -2312,7 +2313,7 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF, MachineConstantPool &MCP = *MF.getConstantPool(); const VectorType *Ty = VectorType::get(Type::Int32Ty, 4); Constant *C = LoadMI->getOpcode() == X86::V_SET0 ? - ConstantVector::getNullValue(Ty) : + MF.getFunction()->getContext()->getNullValue(Ty) : ConstantVector::getAllOnesValue(Ty); unsigned CPI = MCP.getConstantPoolIndex(C, 16); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 2cf3fd7f2a..39ad04f53e 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -408,9 +408,10 @@ X("instcombine", "Combine redundant instructions"); // getComplexity: Assign a complexity or rank value to LLVM Values... // 0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst -static unsigned getComplexity(Value *V) { +static unsigned getComplexity(LLVMContext *Context, Value *V) { if (isa<Instruction>(V)) { - if (BinaryOperator::isNeg(V) || BinaryOperator::isFNeg(V) || + if (BinaryOperator::isNeg(*Context, V) || + BinaryOperator::isFNeg(*Context, V) || BinaryOperator::isNot(V)) return 3; return 4; @@ -521,7 +522,8 @@ static bool ValueRequiresCast(Instruction::CastOps opcode, const Value *V, // bool InstCombiner::SimplifyCommutative(BinaryOperator &I) { bool Changed = false; - if (getComplexity(I.getOperand(0)) < getComplexity(I.getOperand(1))) + if (getComplexity(Context, I.getOperand(0)) < + getComplexity(Context, I.getOperand(1))) Changed = !I.swapOperands(); if (!I.isAssociative()) return Changed; @@ -559,7 +561,8 @@ bool InstCombiner::SimplifyCommutative(BinaryOperator &I) { /// so that theyare listed from right (least complex) to left (most complex). /// This puts constants before unary operators before binary operators. bool InstCombiner::SimplifyCompare(CmpInst &I) { - if (getComplexity(I.getOperand(0)) >= getComplexity(I.getOperand(1))) + if (getComplexity(Context, I.getOperand(0)) >= + getComplexity(Context, I.getOperand(1))) return false; I.swapOperands(); // Compare instructions are not associative so there's nothing else we can do. @@ -570,7 +573,7 @@ bool InstCombiner::SimplifyCompare(CmpInst &I) { // if the LHS is a constant zero (which is the 'negate' form). // static inline Value *dyn_castNegVal(Value *V, LLVMContext *Context) { - if (BinaryOperator::isNeg(V)) + if (BinaryOperator::isNeg(*Context, V)) return BinaryOperator::getNegArgument(V); // Constants can be considered to be negated values if they can be folded. @@ -589,7 +592,7 @@ static inline Value *dyn_castNegVal(Value *V, LLVMContext *Context) { // form). // static inline Value *dyn_castFNegVal(Value *V, LLVMContext *Context) { - if (BinaryOperator::isFNeg(V)) + if (BinaryOperator::isFNeg(*Context, V)) return BinaryOperator::getFNegArgument(V); // Constants can be considered to be negated values if they can be folded. @@ -2185,7 +2188,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { if (Value *RHSV = dyn_castNegVal(RHS, Context)) { Instruction *NewAdd = BinaryOperator::CreateAdd(LHSV, RHSV, "sum"); InsertNewInstBefore(NewAdd, I); - return BinaryOperator::CreateNeg(NewAdd); + return BinaryOperator::CreateNeg(*Context, NewAdd); } } @@ -2530,9 +2533,11 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) { if (Op1I->getOpcode() == Instruction::Add) { if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y - return BinaryOperator::CreateNeg(Op1I->getOperand(1), I.getName()); + return BinaryOperator::CreateNeg(*Context, Op1I->getOperand(1), + I.getName()); else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y - return BinaryOperator::CreateNeg(Op1I->getOperand(0), I.getName()); + return BinaryOperator::CreateNeg(*Context, Op1I->getOperand(0), + I.getName()); else if (ConstantInt *CI1 = dyn_cast<ConstantInt>(I.getOperand(0))) { if (ConstantInt *CI2 = dyn_cast<ConstantInt>(Op1I->getOperand(1))) // C1-(X+C2) --> (C1-C2)-X @@ -2593,7 +2598,8 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { return ReplaceInstUsesWith(I, Op0I->getOperand(0)); } else if (Op0I->getOpcode() == Instruction::Sub) { if (Op0I->getOperand(0) == Op1) // (X-Y)-X == -Y - return BinaryOperator::CreateNeg(Op0I->getOperand(1), I.getName()); + return BinaryOperator::CreateNeg(*Context, Op0I->getOperand(1), + I.getName()); } } @@ -2619,9 +2625,11 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1)) { if (Op1I->getOpcode() == Instruction::FAdd) { if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y - return BinaryOperator::CreateFNeg(Op1I->getOperand(1), I.getName()); + return BinaryOperator::CreateFNeg(*Context, Op1I->getOperand(1), + I.getName()); else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y - return BinaryOperator::CreateFNeg(Op1I->getOperand(0), I.getName()); + return BinaryOperator::CreateFNeg(*Context, Op1I->getOperand(0), + I.getName()); } } @@ -2683,7 +2691,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (CI->equalsInt(1)) // X * 1 == X return ReplaceInstUsesWith(I, Op0); if (CI->isAllOnesValue()) // X * -1 == 0 - X - return BinaryOperator::CreateNeg(Op0, I.getName()); + return BinaryOperator::CreateNeg(*Context, Op0, I.getName()); const APInt& Val = cast<ConstantInt>(CI)->getValue(); if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C @@ -2695,7 +2703,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) { if (Op1V->isAllOnesValue()) // X * -1 == 0 - X - return BinaryOperator::CreateNeg(Op0, I.getName()); + return BinaryOperator::CreateNeg(*Context, Op0, I.getName()); // As above, vector X*splat(1.0) -> X in all defined cases. if (Constant *Splat = Op1V->getSplatValue()) { @@ -3108,7 +3116,7 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) { // sdiv X, -1 == -X if (RHS->isAllOnesValue()) - return BinaryOperator::CreateNeg(Op0); + return BinaryOperator::CreateNeg(*Context, Op0); } // If the sign bits of both operands are zero (i.e. we can prove they are @@ -4042,7 +4050,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { ConstantInt *A = dyn_cast<ConstantInt>(Op0LHS); if (!(A && A->isZero()) && // avoid infinite recursion. MaskedValueIsZero(Op0LHS, Mask)) { - Instruction *NewNeg = BinaryOperator::CreateNeg(Op0RHS); + Instruction *NewNeg = BinaryOperator::CreateNeg(*Context, Op0RHS); InsertNewInstBefore(NewNeg, I); return BinaryOperator::CreateAnd(NewNeg, AndRHS); } @@ -7094,7 +7102,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, else if (Value *NegVal = dyn_castNegVal(BOp0, Context)) return new ICmpInst(*Context, ICI.getPredicate(), NegVal, BOp1); else if (BO->hasOneUse()) { - Instruction *Neg = BinaryOperator::CreateNeg(BOp1); + Instruction *Neg = BinaryOperator::CreateNeg(*Context, BOp1); InsertNewInstBefore(Neg, ICI); Neg->takeName(BO); return new ICmpInst(*Context, ICI.getPredicate(), BOp0, Neg); @@ -9587,7 +9595,8 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { NegVal = Context->getConstantExprNeg(C); } else { NegVal = InsertNewInstBefore( - BinaryOperator::CreateNeg(SubOp->getOperand(1), "tmp"), SI); + BinaryOperator::CreateNeg(*Context, SubOp->getOperand(1), + "tmp"), SI); } Value *NewTrueOp = OtherAddOp; diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index c82c4ff3bf..24ac7bf30b 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -1341,6 +1341,7 @@ namespace { BasicBlock *TopBB; Instruction *TopInst; bool &modified; + LLVMContext *Context; typedef InequalityGraph::Node Node; @@ -1660,7 +1661,8 @@ namespace { Top(DTDFS->getNodeForBlock(TopBB)), TopBB(TopBB), TopInst(NULL), - modified(modified) + modified(modified), + Context(TopBB->getContext()) { assert(Top && "VRPSolver created for unreachable basic block."); } @@ -1760,7 +1762,7 @@ namespace { } break; case Instruction::Or: { // "or i32 %a, %b" EQ 0 then %a EQ 0 and %b EQ 0 - Constant *Zero = Constant::getNullValue(Ty); + Constant *Zero = Context->getNullValue(Ty); if (Canonical == Zero) { add(Zero, Op0, ICmpInst::ICMP_EQ, NewContext); add(Zero, Op1, ICmpInst::ICMP_EQ, NewContext); @@ -1783,10 +1785,10 @@ namespace { } if (Canonical == LHS) { if (isa<ConstantInt>(Canonical)) - add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ, + add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_EQ, NewContext); } else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) { - add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_NE, + add(RHS, Context->getNullValue(Ty), ICmpInst::ICMP_NE, NewContext); } } break; @@ -1831,10 +1833,10 @@ namespace { } // TODO: The GEPI indices are all zero. Copy from definition to operand, // jumping the type plane as needed. - if (isRelatedBy(GEPI, Constant::getNullValue(GEPI->getType()), + if (isRelatedBy(GEPI, Context->getNullValue(GEPI->getType()), ICmpInst::ICMP_NE)) { Value *Ptr = GEPI->getPointerOperand(); - add(Ptr, Constant::getNullValue(Ptr->getType()), ICmpInst::ICMP_NE, + add(Ptr, Context->getNullValue(Ptr->getType()), ICmpInst::ICMP_NE, NewContext); } } else if (CastInst *CI = dyn_cast<CastInst>(I)) { @@ -1888,7 +1890,7 @@ namespace { const Type *Ty = BO->getType(); assert(!Ty->isFPOrFPVector() && "Float in work queue!"); - Constant *Zero = Constant::getNullValue(Ty); + Constant *Zero = Context->getNullValue(Ty); Constant *One = ConstantInt::get(Ty, 1); ConstantInt *AllOnes = ConstantInt::getAllOnesValue(Ty); @@ -2110,9 +2112,9 @@ namespace { // TODO: The GEPI indices are all zero. Copy from operand to definition, // jumping the type plane as needed. |