diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-27 20:59:43 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-27 20:59:43 +0000 |
commit | 6f83c9c6ef0e7f79825a0a8f22941815e4b684c7 (patch) | |
tree | a6b206cab778933e7ebb35788fc3b41e47b57c7c | |
parent | 9a31254d0e51cfe08bc0e0c63ea04780cbc776f4 (diff) |
Move ConstantFP construction back to the 2.5-ish API.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77247 91177308-0d34-0410-b5e6-96231b3b80d8
26 files changed, 188 insertions, 207 deletions
diff --git a/docs/tutorial/LangImpl3.html b/docs/tutorial/LangImpl3.html index 5031427a7b..c56b1edac6 100644 --- a/docs/tutorial/LangImpl3.html +++ b/docs/tutorial/LangImpl3.html @@ -159,7 +159,7 @@ we'll do numeric literals:</p> <div class="doc_code"> <pre> Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } </pre> </div> @@ -1034,7 +1034,7 @@ static std::map<std::string, Value*> NamedValues; Value *ErrorV(const char *Str) { Error(Str); return 0; } Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { diff --git a/docs/tutorial/LangImpl4.html b/docs/tutorial/LangImpl4.html index 41f3a2cd85..45002d29ea 100644 --- a/docs/tutorial/LangImpl4.html +++ b/docs/tutorial/LangImpl4.html @@ -869,7 +869,7 @@ static FunctionPassManager *TheFPM; Value *ErrorV(const char *Str) { Error(Str); return 0; } Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index a783c4abbd..62a0dd9739 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -364,7 +364,7 @@ Value *IfExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. CondV = Builder.CreateFCmpONE(CondV, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond"); </pre> </div> @@ -796,7 +796,7 @@ references to it will naturally find it in the symbol table.</p> if (StepVal == 0) return 0; } else { // If not specified, use 1.0. - StepVal = getGlobalContext().getConstantFP(APFloat(1.0)); + StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); } Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar"); @@ -815,7 +815,7 @@ will be the value of the loop variable on the next iteration of the loop.</p> // Convert condition to a bool by comparing equal to 0.0. EndCond = Builder.CreateFCmpONE(EndCond, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond"); </pre> </div> @@ -1360,7 +1360,7 @@ static FunctionPassManager *TheFPM; Value *ErrorV(const char *Str) { Error(Str); return 0; } Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { @@ -1411,7 +1411,7 @@ Value *IfExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. CondV = Builder.CreateFCmpONE(CondV, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond"); Function *TheFunction = Builder.GetInsertBlock()->getParent(); @@ -1510,7 +1510,7 @@ Value *ForExprAST::Codegen() { if (StepVal == 0) return 0; } else { // If not specified, use 1.0. - StepVal = getGlobalContext().getConstantFP(APFloat(1.0)); + StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); } Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar"); @@ -1521,7 +1521,7 @@ Value *ForExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. EndCond = Builder.CreateFCmpONE(EndCond, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond"); // Create the "after loop" block and insert it. diff --git a/docs/tutorial/LangImpl6.html b/docs/tutorial/LangImpl6.html index 1933d71c06..5a553b7b8a 100644 --- a/docs/tutorial/LangImpl6.html +++ b/docs/tutorial/LangImpl6.html @@ -1365,7 +1365,7 @@ static FunctionPassManager *TheFPM; Value *ErrorV(const char *Str) { Error(Str); return 0; } Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { @@ -1436,7 +1436,7 @@ Value *IfExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. CondV = Builder.CreateFCmpONE(CondV, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond"); Function *TheFunction = Builder.GetInsertBlock()->getParent(); @@ -1535,7 +1535,7 @@ Value *ForExprAST::Codegen() { if (StepVal == 0) return 0; } else { // If not specified, use 1.0. - StepVal = getGlobalContext().getConstantFP(APFloat(1.0)); + StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); } Value *NextVar = Builder.CreateAdd(Variable, StepVal, "nextvar"); @@ -1546,7 +1546,7 @@ Value *ForExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. EndCond = Builder.CreateFCmpONE(EndCond, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond"); // Create the "after loop" block and insert it. diff --git a/docs/tutorial/LangImpl7.html b/docs/tutorial/LangImpl7.html index 07c8da653c..d3ebd962c5 100644 --- a/docs/tutorial/LangImpl7.html +++ b/docs/tutorial/LangImpl7.html @@ -923,7 +923,7 @@ that we replace in OldBindings.</p> InitVal = Init->Codegen(); if (InitVal == 0) return 0; } else { // If not specified, use 0.0. - InitVal = getGlobalContext().getConstantFP(APFloat(0.0)); + InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0)); } AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName); @@ -1623,7 +1623,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { @@ -1716,7 +1716,7 @@ Value *IfExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. CondV = Builder.CreateFCmpONE(CondV, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond"); Function *TheFunction = Builder.GetInsertBlock()->getParent(); @@ -1822,7 +1822,7 @@ Value *ForExprAST::Codegen() { if (StepVal == 0) return 0; } else { // If not specified, use 1.0. - StepVal = getGlobalContext().getConstantFP(APFloat(1.0)); + StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); } // Compute the end condition. @@ -1837,7 +1837,7 @@ Value *ForExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. EndCond = Builder.CreateFCmpONE(EndCond, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond"); // Create the "after loop" block and insert it. @@ -1881,7 +1881,7 @@ Value *VarExprAST::Codegen() { InitVal = Init->Codegen(); if (InitVal == 0) return 0; } else { // If not specified, use 0.0. - InitVal = getGlobalContext().getConstantFP(APFloat(0.0)); + InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0)); } AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName); diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp index 1aa9965fa4..6f7f0ee206 100644 --- a/examples/Kaleidoscope/toy.cpp +++ b/examples/Kaleidoscope/toy.cpp @@ -623,7 +623,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, Value *NumberExprAST::Codegen() { - return getGlobalContext().getConstantFP(APFloat(Val)); + return ConstantFP::get(getGlobalContext(), APFloat(Val)); } Value *VariableExprAST::Codegen() { @@ -716,7 +716,7 @@ Value *IfExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. CondV = Builder.CreateFCmpONE(CondV, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "ifcond"); Function *TheFunction = Builder.GetInsertBlock()->getParent(); @@ -821,7 +821,7 @@ Value *ForExprAST::Codegen() { if (StepVal == 0) return 0; } else { // If not specified, use 1.0. - StepVal = getGlobalContext().getConstantFP(APFloat(1.0)); + StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0)); } // Compute the end condition. @@ -836,7 +836,7 @@ Value *ForExprAST::Codegen() { // Convert condition to a bool by comparing equal to 0.0. EndCond = Builder.CreateFCmpONE(EndCond, - getGlobalContext().getConstantFP(APFloat(0.0)), + ConstantFP::get(getGlobalContext(), APFloat(0.0)), "loopcond"); // Create the "after loop" block and insert it. @@ -879,7 +879,7 @@ Value *VarExprAST::Codegen() { InitVal = Init->Codegen(); if (InitVal == 0) return 0; } else { // If not specified, use 0.0. - InitVal = getGlobalContext().getConstantFP(APFloat(0.0)); + InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0)); } AllocaInst *Alloca = CreateEntryBlockAlloca(TheFunction, VarName); diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index d59621a453..f7b785aff3 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -50,7 +50,6 @@ class ConstantInt : public Constant { ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT ConstantInt(const IntegerType *Ty, const APInt& V); APInt Val; - friend class LLVMContextImpl; protected: // allocate space for exactly zero operands void *operator new(size_t s) { @@ -238,6 +237,19 @@ protected: return User::operator new(s, 0); } public: + /// 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* getZeroValueForNegation(const Type* Ty); + + /// get() - This returns a ConstantFP, or a vector containing a splat of a + /// ConstantFP, for the specified value in the specified type. This should + /// only be used for simple constant values like 2.0/1.0 etc, that are + /// known-valid both as host double and as the target format. + static Constant* get(const Type* Ty, double V); + static ConstantFP* get(LLVMContext &Context, const APFloat& V); + static ConstantFP* getNegativeZero(const Type* Ty); + /// isValueValidForType - return true if Ty is big enough to represent V. static bool isValueValidForType(const Type *Ty, const APFloat& V); inline const APFloat& getValueAPF() const { return Val; } diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index ab81595722..37f0cd1a44 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -56,6 +56,7 @@ class LLVMContext { LLVMContextImpl* pImpl; friend class ConstantInt; + friend class ConstantFP; public: LLVMContext(); ~LLVMContext(); @@ -180,21 +181,6 @@ public: /// 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 - ConstantFP* getConstantFP(const APFloat& V); - - /// get() - This returns a ConstantFP, or a vector containing a splat of a - /// ConstantFP, for the specified value in the specified type. This should - /// only be used for simple constant values like 2.0/1.0 etc, that are - /// known-valid both as host double and as the target format. - Constant* getConstantFP(const Type* Ty, double V); - ConstantFP* getConstantFPNegativeZero(const Type* Ty); - // ConstantVector accessors Constant* getConstantVector(const VectorType* T, const std::vector<Constant*>& V); diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index fb8e387d3d..7a93b7665f 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -506,7 +506,7 @@ struct neg_match { } private: bool matchIfNeg(Value *LHS, Value *RHS, LLVMContext &Context) { - return LHS == Context.getZeroValueForNegation(LHS->getType()) && + return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) && L.match(RHS, Context); } }; @@ -535,7 +535,7 @@ struct fneg_match { } private: bool matchIfFNeg(Value *LHS, Value *RHS, LLVMContext &Context) { - return LHS == Context.getZeroValueForNegation(LHS->getType()) && + return LHS == ConstantFP::getZeroValueForNegation(LHS->getType()) && L.match(RHS, Context); } }; diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 173326e2bb..31d4f8230b 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -655,9 +655,9 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, } if (Ty == Type::FloatTy) - return Context.getConstantFP(APFloat((float)V)); + return ConstantFP::get(Context, APFloat((float)V)); if (Ty == Type::DoubleTy) - return Context.getConstantFP(APFloat(V)); + return ConstantFP::get(Context, APFloat(V)); llvm_unreachable("Can only constant fold float/double"); return 0; // dummy return to suppress warning } @@ -674,9 +674,9 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double), } if (Ty == Type::FloatTy) - return Context.getConstantFP(APFloat((float)V)); + return ConstantFP::get(Context, APFloat((float)V)); if (Ty == Type::DoubleTy) - return Context.getConstantFP(APFloat(V)); + return ConstantFP::get(Context, APFloat(V)); llvm_unreachable("Can only constant fold float/double"); return 0; // dummy return to suppress warning } @@ -796,10 +796,10 @@ llvm::ConstantFoldCall(Function *F, } } else if (ConstantInt *Op2C = dyn_cast<ConstantInt>(Operands[1])) { if (Name == "llvm.powi.f32") { - return Context.getConstantFP(APFloat((float)std::pow((float)Op1V, + return ConstantFP::get(Context, APFloat((float)std::pow((float)Op1V, (int)Op2C->getZExtValue()))); } else if (Name == "llvm.powi.f64") { - return Context.getConstantFP(APFloat((double)std::pow((double)Op1V, + return ConstantFP::get(Context, APFloat((double)std::pow((double)Op1V, (int)Op2C->getZExtValue()))); } } diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index c6f1b257bd..f9db40915a 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2143,7 +2143,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID, ID.APFloatVal.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven, &Ignored); } - V = Context.getConstantFP(ID.APFloatVal); + V = ConstantFP::get(Context, ID.APFloatVal); if (V->getType() != Ty) return Error(ID.Loc, "floating point constant does not have type '" + diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 0c6162ccff..687cae9ecf 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -896,19 +896,19 @@ bool BitcodeReader::ParseConstants() { if (Record.empty()) return Error("Invalid FLOAT record"); if (CurTy == Type::FloatTy) - V = Context.getConstantFP(APFloat(APInt(32, (uint32_t)Record[0]))); + V = ConstantFP::get(Context, APFloat(APInt(32, (uint32_t)Record[0]))); else if (CurTy == Type::DoubleTy) - V = Context.getConstantFP(APFloat(APInt(64, Record[0]))); + V = ConstantFP::get(Context, APFloat(APInt(64, Record[0]))); else if (CurTy == Type::X86_FP80Ty) { // Bits are not stored the same way as a normal i80 APInt, compensate. uint64_t Rearrange[2]; Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16); Rearrange[1] = Record[0] >> 48; - V = Context.getConstantFP(APFloat(APInt(80, 2, Rearrange))); + V = ConstantFP::get(Context, APFloat(APInt(80, 2, Rearrange))); } else if (CurTy == Type::FP128Ty) - V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]), true)); + V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]), true)); else if (CurTy == Type::PPC_FP128Ty) - V = Context.getConstantFP(APFloat(APInt(128, 2, &Record[0]))); + V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0]))); else V = Context.getUndef(CurTy); break; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 5a46288e58..a8398243c7 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -916,7 +916,7 @@ SDValue SelectionDAG::getIntPtrConstant(uint64_t Val, bool isTarget) { SDValue SelectionDAG::getConstantFP(const APFloat& V, MVT VT, bool isTarget) { - return getConstantFP(*Context->getConstantFP(V), VT, isTarget); + return getConstantFP(*ConstantFP::get(*getContext(), V), VT, isTarget); } SDValue SelectionDAG::getConstantFP(const ConstantFP& V, MVT VT, bool isTarget){ diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index 8685c85b58..3a8b782564 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -2148,8 +2148,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, - DAG.getContext()->getConstantFPNegativeZero(ElTy)); + std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy)); Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size()); if (CV == CNZ) { SDValue Op2 = getValue(I.getOperand(1)); @@ -2160,8 +2159,7 @@ void SelectionDAGLowering::visitFSub(User &I) { } } if (ConstantFP *CFP = dyn_cast<ConstantFP>(I.getOperand(0))) - if (CFP->isExactlyValue( - DAG.getContext()->getConstantFPNegativeZero(Ty)->getValueAPF())) { + if (CFP->isExactlyValue(ConstantFP::getNegativeZero(Ty)->getValueAPF())) { SDValue Op2 = getValue(I.getOperand(1)); setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(), Op2.getValueType(), Op2)); diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index a9b062d85e..444ef3c3ce 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -490,15 +490,15 @@ GenericValue JIT::runFunction(Function *F, C = ConstantInt::get(F->getContext(), AV.IntVal); break; case Type::FloatTyID: - C = Context.getConstantFP(APFloat(AV.FloatVal)); + C = ConstantFP::get(F->getContext(), APFloat(AV.FloatVal)); break; case Type::DoubleTyID: - C = Context.getConstantFP(APFloat(AV.DoubleVal)); + C = ConstantFP::get(F->getContext(), APFloat(AV.DoubleVal)); break; case Type::PPC_FP128TyID: case Type::X86_FP80TyID: case Type::FP128TyID: - C = Context.getConstantFP(APFloat(AV.IntVal)); + C = ConstantFP::get(F->getContext(), APFloat(AV.IntVal)); break; case Type::PointerTyID: void *ArgPtr = GVTOP(AV); diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 15c6dfead4..42bd7dc983 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4898,9 +4898,9 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) { std::vector<Constant*> CV1; CV1.push_back( - Context->getConstantFP(APFloat(APInt(64, 0x4530000000000000ULL)))); + ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL)))); CV1.push_back( - Context->getConstantFP(APFloat(APInt(64, 0x4330000000000000ULL)))); + ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL)))); Constant *C1 = Context->getConstantVector(CV1); SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16); @@ -5113,11 +5113,11 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) { EltVT = VT.getVectorElementType(); std::vector<Constant*> CV; if (EltVT == MVT::f64) { - Constant *C = Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63)))); + Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63)))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = Context->getConstantFP(APFloat(APInt(32, ~(1U << 31)))); + Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31)))); CV.push_back(C); CV.push_back(C); CV.push_back(C); @@ -5143,11 +5143,11 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) { } std::vector<Constant*> CV; if (EltVT == MVT::f64) { - Constant *C = Context->getConstantFP(APFloat(APInt(64, 1ULL << 63))); + Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = Context->getConstantFP(APFloat(APInt(32, 1U << 31))); + Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31))); CV.push_back(C); CV.push_back(C); CV.push_back(C); @@ -5194,13 +5194,13 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { // First get the sign bit of second operand. std::vector<Constant*> CV; if (SrcVT == MVT::f64) { - CV.push_back(Context->getConstantFP(APFloat(APInt(64, 1ULL << 63)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0)))); } else { - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 1U << 31)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); } Constant *C = Context->getConstantVector(CV); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); @@ -5223,13 +5223,13 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) { // Clear first operand sign bit. CV.clear(); if (VT == MVT::f64) { - CV.push_back(Context->getConstantFP(APFloat(APInt(64, ~(1ULL << 63))))); - CV.push_back(Context->getConstantFP(APFloat(APInt(64, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63))))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(64, 0)))); } else { - CV.push_back(Context->getConstantFP(APFloat(APInt(32, ~(1U << 31))))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); - CV.push_back(Context->getConstantFP(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31))))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0)))); } C = Context->getConstantVector(CV); CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 15daf3efb4..a6538dcaa2 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2354,7 +2354,7 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) { if (Constant *RHSC = dyn_cast<Constant>(RHS)) { // X + 0 --> X if (ConstantFP *CFP = dyn_cast<ConstantFP>(RHSC)) { - if (CFP->isExactlyValue(Context->getConstantFPNegativeZero + if (CFP->isExactlyValue(ConstantFP::getNegativeZero (I.getType())->getValueAPF())) return ReplaceInstUsesWith(I, LHS); } @@ -8779,7 +8779,7 @@ static Constant *FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem, APFloat F = CFP->getValueAPF(); (void)F.convert(Sem, APFloat::rmNearestTiesToEven, &losesInfo); if (!losesInfo) - return Context->getConstantFP(F); + return ConstantFP::get(*Context, F); return 0; } diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 82ca81acc4..9829c8d7df 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2177,8 +2177,6 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) { if (isa<SCEVCouldNotCompute>(BackedgeTakenCount)) return; - LLVMContext &Context = L->getHeader()->getContext(); - for (unsigned Stride = 0, e = IU->StrideOrder.size(); Stride != e; ++Stride) { std::map<const SCEV *, IVUsersOfOneStride *>::iterator SI = @@ -2240,7 +2238,7 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) { ConstantInt *Init = dyn_cast<ConstantInt>(PH->getIncomingValue(Entry)); if (!Init) continue; - Constant *NewInit = Context.getConstantFP(DestTy, Init->getZExtValue()); + Constant *NewInit = ConstantFP::get(DestTy, Init->getZExtValue()); BinaryOperator *Incr = dyn_cast<BinaryOperator>(PH->getIncomingValue(Latch)); @@ -2264,7 +2262,7 @@ void LoopStrengthReduce::OptimizeShadowIV(Loop *L) { PHINode *NewPH = PHINode::Create(DestTy, "IV.S.", PH); /* create new increment. '++d' in above example. */ - Constant *CFP = Context.getConstantFP(DestTy, C->getZExtValue()); + Constant *CFP = ConstantFP::get(DestTy, C->getZExtValue()); BinaryOperator *NewIncr = BinaryOperator::Create(Incr->getOpcode() == Instruction::Add ? Instruction::FAdd : Instruction::FSub, diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index e48b14c2cd..0bf583a52a 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -1035,7 +1035,7 @@ struct VISIBILITY_HIDDEN PowOpt : public LibCallOptimization { if (Op2C == 0) return 0; if (Op2C->getValueAPF().isZero()) // pow(x, 0.0) -> 1.0 - return Context->getConstantFP(CI->getType(), 1.0); + return ConstantFP::get(CI->getType(), 1.0); if (Op2C->isExactlyValue(0.5)) { // FIXME: This is not safe for -0.0 and -inf. This can only be done when @@ -1055,7 +1055,7 @@ struct VISIBILITY_HIDDEN PowOpt : public LibCallOptimization { if (Op2C->isExactlyValue(2.0)) // pow(x, 2.0) -> x*x return B.CreateFMul(Op1, Op1, "pow2"); if (Op2C->isExactlyValue(-1.0)) // pow(x, -1.0) -> 1.0/x - return B.CreateFDiv(Context->getConstantFP(CI->getType(), 1.0), + return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0), Op1, "powrecip"); return 0; } @@ -10 |