aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-13 04:09:18 +0000
committerOwen Anderson <resistor@mac.com>2009-07-13 04:09:18 +0000
commit0a5372ed3e8cda10d724feda3c1a1c998db05ca0 (patch)
tree89dc39f73d938c223b4e192bc6fd918490a60218
parentf1db120d0494ec55d9265cea7dab22e80dcae10c (diff)
Begin the painful process of tearing apart the rat'ss nest that is Constants.cpp and ConstantFold.cpp.
This involves temporarily hard wiring some parts to use the global context. This isn't ideal, but it's the only way I could figure out to make this process vaguely incremental. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75445 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/tutorial/LangImpl5.html2
-rw-r--r--docs/tutorial/LangImpl6.html2
-rw-r--r--docs/tutorial/LangImpl7.html2
-rw-r--r--examples/BrainF/BrainF.cpp2
-rw-r--r--examples/Kaleidoscope/toy.cpp2
-rw-r--r--include/llvm/CodeGen/FastISel.h1
-rw-r--r--include/llvm/Constant.h8
-rw-r--r--include/llvm/Constants.h23
-rw-r--r--include/llvm/InstrTypes.h16
-rw-r--r--include/llvm/LLVMContext.h14
-rw-r--r--include/llvm/Support/IRBuilder.h4
-rw-r--r--lib/Analysis/DebugInfo.cpp2
-rw-r--r--lib/Analysis/IPA/Andersens.cpp2
-rw-r--r--lib/Analysis/ScalarEvolution.cpp11
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp7
-rw-r--r--lib/CodeGen/MachOWriter.cpp2
-rw-r--r--lib/CodeGen/SelectionDAG/FastISel.cpp7
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp7
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuild.h6
-rw-r--r--lib/CodeGen/ShadowStackGC.cpp4
-rw-r--r--lib/CodeGen/UnreachableBlockElim.cpp2
-rw-r--r--lib/Target/CBackend/CBackend.cpp12
-rw-r--r--lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp2
-rw-r--r--lib/Target/Mips/MipsISelLowering.cpp2
-rw-r--r--lib/Target/TargetAsmInfo.cpp6
-rw-r--r--lib/Target/X86/X86FastISel.cpp4
-rw-r--r--lib/Target/X86/X86InstrInfo.cpp3
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp45
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp33
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp30
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp12
-rw-r--r--lib/VMCore/ConstantFold.cpp445
-rw-r--r--lib/VMCore/ConstantFold.h28
-rw-r--r--lib/VMCore/Constants.cpp132
-rw-r--r--lib/VMCore/Instructions.cpp30
-rw-r--r--lib/VMCore/LLVMContext.cpp86
-rw-r--r--tools/bugpoint/CrashDebugger.cpp3
-rw-r--r--tools/bugpoint/ExtractFunction.cpp2
-rw-r--r--tools/bugpoint/Miscompilation.cpp3
-rw-r--r--tools/bugpoint/TestPasses.cpp2
-rw-r--r--tools/lto/LTOModule.cpp2
-rw-r--r--unittests/ExecutionEngine/JIT/JITTest.cpp2
-rw-r--r--unittests/Support/ValueHandleTest.cpp17
43 files changed, 547 insertions, 480 deletions
diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html
index bb4b4075b8..f3630d06ac 100644
--- a/docs/tutorial/LangImpl5.html
+++ b/docs/tutorial/LangImpl5.html
@@ -856,7 +856,7 @@ the loop again and exiting the loop. Any future code is emitted in the
NamedValues.erase(VarName);
// for expr always returns 0.0.
- return Constant::getNullValue(Type::DoubleTy);
+ return TheFunction->getContext()->getNullValue(Type::DoubleTy);
}
</pre>
</div>
diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html
index c6d9ce1847..c0c396b8a3 100644
--- a/docs/tutorial/LangImpl6.html
+++ b/docs/tutorial/LangImpl6.html
@@ -1570,7 +1570,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::DoubleTy);
+ return TheFunction->getContext()->getNullValue(Type::DoubleTy);
}
Function *PrototypeAST::Codegen() {
diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html
index 71bb397b49..157b7dda45 100644
--- a/docs/tutorial/LangImpl7.html
+++ b/docs/tutorial/LangImpl7.html
@@ -1858,7 +1858,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::DoubleTy);
+ return TheFunction->getContext()->getNullValue(Type::DoubleTy);
}
Value *VarExprAST::Codegen() {
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index cd9e850728..38914688ec 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -145,7 +145,7 @@ void BrainF::header(LLVMContext& C) {
//call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
{
- Constant *zero_32 = Constant::getNullValue(IntegerType::Int32Ty);
+ Constant *zero_32 = C.getNullValue(IntegerType::Int32Ty);
Constant *gep_params[] = {
zero_32,
diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp
index 3893aeac59..134742516d 100644
--- a/examples/Kaleidoscope/toy.cpp
+++ b/examples/Kaleidoscope/toy.cpp
@@ -854,7 +854,7 @@ Value *ForExprAST::Codegen() {
// for expr always returns 0.0.
- return Constant::getNullValue(Type::DoubleTy);
+ return TheFunction->getContext()->getNullValue(Type::DoubleTy);
}
Value *VarExprAST::Codegen() {
diff --git a/include/llvm/CodeGen/FastISel.h b/include/llvm/CodeGen/FastISel.h
index c7b1a42d06..857267c011 100644
--- a/include/llvm/CodeGen/FastISel.h
+++ b/include/llvm/CodeGen/FastISel.h
@@ -60,6 +60,7 @@ protected:
const TargetData &TD;
const TargetInstrInfo &TII;
const TargetLowering &TLI;
+ LLVMContext *Context;
public:
/// startNewBlock - Set the current block to which generated machine
diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h
index d4949d1a0f..05a6623200 100644
--- a/include/llvm/Constant.h
+++ b/include/llvm/Constant.h
@@ -18,6 +18,7 @@
namespace llvm {
template<typename T> class SmallVectorImpl;
+ class LLVMContext;
/// If object contains references to other objects, then relocations are
/// usually required for emission of such object (especially in PIC mode). One
@@ -59,10 +60,6 @@ protected:
void destroyConstantImpl();
public:
- /// Static constructor to get a '0' constant of arbitrary type...
- ///
- static Constant *getNullValue(const Type *Ty);
-
/// Static constructor to get a '-1' constant. This supports integers and
/// vectors.
///
@@ -98,7 +95,8 @@ public:
/// type, returns the elements of the vector in the specified smallvector.
/// This handles breaking down a vector undef into undef elements, etc. For
/// constant exprs and other cases we can't handle, we return an empty vector.
- void getVectorElements(SmallVectorImpl<Constant*> &Elts) const;
+ void getVectorElements(LLVMContext &Context,
+ SmallVectorImpl<Constant*> &Elts) const;
/// destroyConstant - Called if some element of this constant is no longer
/// valid. At this point only other constants may be on the use_list for this
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 09750668a1..77124d8974 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -276,9 +276,6 @@ public:
/// considers -0.0 to be null as well as 0.0. :(
virtual bool isNullValue() const;
- // Get a negative zero.
- static ConstantFP *getNegativeZero(const Type* Ty);
-
/// isExactlyValue - We don't rely on operator== working on double values, as
/// it returns true for things that are clearly not equal, like -0.0 and 0.0.
/// As such, this method can be used to do an exact bit-for-bit comparison of
@@ -383,7 +380,7 @@ public:
/// isString) and it ends in a null byte \0 and does not contains any other
/// @endverbatim
/// null bytes except its terminator.
- bool isCString() const;
+ bool isCString(LLVMContext &Context) const;
/// getAsString - If this array is isString(), then this method converts the
/// array to an std::string and returns it. Otherwise, it asserts out.
@@ -694,17 +691,6 @@ public:
return getSelectTy(V1->getType(), C, V1, V2);
}
- /// getAlignOf constant expr - computes the alignment of a type in a target
- /// independent way (Note: the return type is an i32; Note: assumes that i8
- /// is byte aligned).
- ///
- static Constant *getAlignOf(const Type *Ty);
-
- /// getSizeOf constant expr - computes the size of a type in a target
- /// independent way (Note: the return type is an i64).
- ///
- static Constant *getSizeOf(const Type *Ty);
-
/// ConstantExpr::get - Return a binary or shift operator constant expression,
/// folding if possible.
///
@@ -716,8 +702,6 @@ public:
/// ConstantExpr::get* - Return some common constants without having to
/// specify the full Instruction::OPCODE identifier.
///
- static Constant *getNeg(Constant *C);
- static Constant *getFNeg(Constant *C);
static Constant *getNot(Constant *C);
static Constant *getAdd(Constant *C1, Constant *C2);
static Constant *getFAdd(Constant *C1, Constant *C2);
@@ -756,11 +740,6 @@ public:
static Constant *getInsertValue(Constant *Agg, Constant *Val,
const unsigned *IdxList, unsigned NumIdx);
- /// Floating point negation must be implemented with f(x) = -0.0 - x. This
- /// method returns the negative zero constant for floating point or vector
- /// floating point types; for all other types, it returns the null value.
- static Constant *getZeroValueForNegationExpr(const Type *Ty);
-
/// isNullValue - Return true if this is the value that would be returned by
/// getNullValue.
virtual bool isNullValue() const { return false; }
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index 76827191f1..9c1f8fc804 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -202,13 +202,17 @@ public:
/// CreateNeg, CreateNot - Create the NEG and NOT
/// instructions out of SUB and XOR instructions.
///
- static BinaryOperator *CreateNeg(Value *Op, const std::string &Name = "",
+ static BinaryOperator *CreateNeg(LLVMContext &Context,
+ Value *Op, const std::string &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateNeg(Value *Op, const std::string &Name,
+ static BinaryOperator *CreateNeg(LLVMContext &Context,
+ Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd);
- static BinaryOperator *CreateFNeg(Value *Op, const std::string &Name = "",
+ static BinaryOperator *CreateFNeg(LLVMContext &Context,
+ Value *Op, const std::string &Name = "",
Instruction *InsertBefore = 0);
- static BinaryOperator *CreateFNeg(Value *Op, const std::string &Name,
+ static BinaryOperator *CreateFNeg(LLVMContext &Context,
+ Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd);
static BinaryOperator *CreateNot(Value *Op, const std::string &Name = "",
Instruction *InsertBefore = 0);
@@ -218,8 +222,8 @@ public:
/// isNeg, isFNeg, isNot - Check if the given Value is a
/// NEG, FNeg, or NOT instruction.
///
- static bool isNeg(const Value *V);
- static bool isFNeg(const Value *V);
+ static bool isNeg(LLVMContext &Context, const Value *V);
+ static bool isFNeg(LLVMContext &Context, const Value *V);
static bool isNot(const Value *V);
/// getNegArgument, getNotArgument - Helper functions to extract the
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h
index 75b7e59ceb..e441d189c2 100644
--- a/include/llvm/LLVMContext.h
+++ b/include/llvm/LLVMContext.h
@@ -120,6 +120,11 @@ public:
bool isSigned);
Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
+
+ /// getAlignOf constant expr - computes the alignment of a type in a target
+ /// independent way (Note: the return type is an i32; Note: assumes that i8
+ /// is byte aligned).
+ ///
Constant* getConstantExprAlignOf(const Type* Ty);
Constant* getConstantExprCompare(unsigned short pred,
Constant* C1, Constant* C2);
@@ -162,7 +167,15 @@ public:
Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
const unsigned* IdxList,
unsigned NumIdx);
+
+ /// getSizeOf constant expr - computes the size of a type in a target
+ /// independent way (Note: the return type is an i64).
+ ///
Constant* getConstantExprSizeOf(const Type* Ty);
+
+ /// Floating point negation must be implemented with f(x) = -0.0 - x. This
+ /// method returns the negative zero constant for floating point or vector
+ /// floating point types; for all other types, it returns the null value.
Constant* getZeroValueForNegation(const Type* Ty);
// ConstantFP accessors
@@ -200,6 +213,7 @@ public:
StructType* getStructType(bool isPacked=false);
StructType* getStructType(const std::vector<const Type*>& Params,
bool isPacked = false);
+ StructType* getStructType(const Type* type, ...);
// ArrayType accessors
ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 9fc29ef44e..5de33eb2cb 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -311,12 +311,12 @@ public:
Value *CreateNeg(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
return Folder.CreateNeg(VC);
- return Insert(BinaryOperator::CreateNeg(V), Name);
+ return Insert(BinaryOperator::CreateNeg(getGlobalContext(), V), Name);
}
Value *CreateFNeg(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
return Folder.CreateFNeg(VC);
- return Insert(BinaryOperator::CreateFNeg(V), Name);
+ return Insert(BinaryOperator::CreateFNeg(getGlobalContext(), V), Name);
}
Value *CreateNot(Value *V, const char *Name = "") {
if (Constant *VC = dyn_cast<Constant>(V))
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 << ", ";
<