From 02a260aa11a2e1b2c14335274d3c42ca3f3eabc0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Apr 2008 00:41:09 +0000 Subject: [PATCH] Switch to using Simplified ConstantFP::get API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49977 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 20 +++++----- lib/Analysis/ScalarEvolution.cpp | 4 +- lib/AsmParser/llvmAsmParser.y | 6 +-- lib/Bitcode/Reader/BitcodeReader.cpp | 10 ++--- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 13 +++---- lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 3 +- lib/ExecutionEngine/JIT/JIT.cpp | 24 +++++++----- lib/Target/X86/X86ISelLowering.cpp | 37 ++++++++----------- .../Scalar/InstructionCombining.cpp | 9 ++--- 9 files changed, 60 insertions(+), 66 deletions(-) diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 0e8435fcaca..d58d78f0773 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -593,10 +593,9 @@ static Constant *ConstantFoldFP(double (*NativeFP)(double), double V, } if (Ty == Type::FloatTy) - return ConstantFP::get(Ty, APFloat((float)V)); - + return ConstantFP::get(APFloat((float)V)); if (Ty == Type::DoubleTy) - return ConstantFP::get(Ty, APFloat(V)); + return ConstantFP::get(APFloat(V)); assert(0 && "Can only constant fold float/double"); } @@ -611,9 +610,9 @@ static Constant *ConstantFoldBinaryFP(double (*NativeFP)(double, double), } if (Ty == Type::FloatTy) - return ConstantFP::get(Ty, APFloat((float)V)); + return ConstantFP::get(APFloat((float)V)); if (Ty == Type::DoubleTy) - return ConstantFP::get(Ty, APFloat(V)); + return ConstantFP::get(APFloat(V)); assert(0 && "Can only constant fold float/double"); } @@ -678,8 +677,7 @@ llvm::ConstantFoldCall(Function *F, if (V >= -0.0) return ConstantFoldFP(sqrt, V, Ty); else // Undefined - return ConstantFP::get(Ty, Ty==Type::FloatTy ? APFloat(0.0f) : - APFloat(0.0)); + return Constant::getNullValue(Ty); } break; case 's': @@ -734,11 +732,11 @@ llvm::ConstantFoldCall(Function *F, } } else if (ConstantInt *Op2C = dyn_cast(Operands[1])) { if (!strcmp(Str, "llvm.powi.f32")) { - return ConstantFP::get(Ty, APFloat((float)std::pow((float)Op1V, - (int)Op2C->getZExtValue()))); + return ConstantFP::get(APFloat((float)std::pow((float)Op1V, + (int)Op2C->getZExtValue()))); } else if (!strcmp(Str, "llvm.powi.f64")) { - return ConstantFP::get(Ty, APFloat((double)std::pow((double)Op1V, - (int)Op2C->getZExtValue()))); + return ConstantFP::get(APFloat((double)std::pow((double)Op1V, + (int)Op2C->getZExtValue()))); } } } diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 0508bb76c1e..32e9e96a6d8 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -494,8 +494,8 @@ SCEVHandle ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) { if (Val == 0) C = Constant::getNullValue(Ty); else if (Ty->isFloatingPoint()) - C = ConstantFP::get(Ty, APFloat(Ty==Type::FloatTy ? APFloat::IEEEsingle : - APFloat::IEEEdouble, Val)); + C = ConstantFP::get(APFloat(Ty==Type::FloatTy ? APFloat::IEEEsingle : + APFloat::IEEEdouble, Val)); else C = ConstantInt::get(Ty, Val); return getUnknown(C); diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index beafcd27357..a1abae3a625 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -408,12 +408,12 @@ static Value *getExistingVal(const Type *Ty, const ValID &D) { GenerateError("FP constant invalid for type"); return 0; } - // Lexer has no type info, so builds all float and double FP constants + // Lexer has no type info, so builds all float and double FP constants // as double. Fix this here. Long double does not need this. if (&D.ConstPoolFP->getSemantics() == &APFloat::IEEEdouble && Ty==Type::FloatTy) D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven); - return ConstantFP::get(Ty, *D.ConstPoolFP); + return ConstantFP::get(*D.ConstPoolFP); case ValID::ConstNullVal: // Is it a null value? if (!isa(Ty)) { @@ -1867,7 +1867,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr // as double. Fix this here. Long double is done right. if (&$2->getSemantics()==&APFloat::IEEEdouble && $1==Type::FloatTy) $2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven); - $$ = ConstantFP::get($1, *$2); + $$ = ConstantFP::get(*$2); delete $2; CHECK_FOR_ERROR }; diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 141d5e15f5f..ec099a7852a 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -636,15 +636,15 @@ bool BitcodeReader::ParseConstants() { if (Record.empty()) return Error("Invalid FLOAT record"); if (CurTy == Type::FloatTy) - V = ConstantFP::get(CurTy, APFloat(APInt(32, (uint32_t)Record[0]))); + V = ConstantFP::get(APFloat(APInt(32, (uint32_t)Record[0]))); else if (CurTy == Type::DoubleTy) - V = ConstantFP::get(CurTy, APFloat(APInt(64, Record[0]))); + V = ConstantFP::get(APFloat(APInt(64, Record[0]))); else if (CurTy == Type::X86_FP80Ty) - V = ConstantFP::get(CurTy, APFloat(APInt(80, 2, &Record[0]))); + V = ConstantFP::get(APFloat(APInt(80, 2, &Record[0]))); else if (CurTy == Type::FP128Ty) - V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0]), true)); + V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]), true)); else if (CurTy == Type::PPC_FP128Ty) - V = ConstantFP::get(CurTy, APFloat(APInt(128, 2, &Record[0]))); + V = ConstantFP::get(APFloat(APInt(128, 2, &Record[0]))); else V = UndefValue::get(CurTy); break; diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 18d1d1853e0..5f260ece552 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -491,8 +491,7 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, // an FP extending load is the same cost as a normal load (such as on the x87 // fp stack or PPC FP unit). MVT::ValueType VT = CFP->getValueType(0); - ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT), - CFP->getValueAPF()); + ConstantFP *LLVMC = ConstantFP::get(CFP->getValueAPF()); if (!UseCP) { if (VT!=MVT::f64 && VT!=MVT::f32) assert(0 && "Invalid type expansion"); @@ -4901,18 +4900,18 @@ SDOperand SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { // If all elements are constants, create a load from the constant pool. if (isConstant) { MVT::ValueType VT = Node->getValueType(0); - const Type *OpNTy = - MVT::getTypeForValueType(Node->getOperand(0).getValueType()); std::vector CV; for (unsigned i = 0, e = NumElems; i != e; ++i) { if (ConstantFPSDNode *V = dyn_cast(Node->getOperand(i))) { - CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF())); + CV.push_back(ConstantFP::get(V->getValueAPF())); } else if (ConstantSDNode *V = - dyn_cast(Node->getOperand(i))) { - CV.push_back(ConstantInt::get(OpNTy, V->getValue())); + dyn_cast(Node->getOperand(i))) { + CV.push_back(ConstantInt::get(V->getAPIntValue())); } else { assert(Node->getOperand(i).getOpcode() == ISD::UNDEF); + const Type *OpNTy = + MVT::getTypeForValueType(Node->getOperand(0).getValueType()); CV.push_back(UndefValue::get(OpNTy)); } } diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index 3cdd727ae81..b4958d6d946 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -601,8 +601,7 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op, } else if (ConstantSDNode *C = dyn_cast(Op)) { MI->addOperand(MachineOperand::CreateImm(C->getValue())); } else if (ConstantFPSDNode *F = dyn_cast(Op)) { - const Type *FType = MVT::getTypeForValueType(Op.getValueType()); - ConstantFP *CFP = ConstantFP::get(FType, F->getValueAPF()); + ConstantFP *CFP = ConstantFP::get(F->getValueAPF()); MI->addOperand(MachineOperand::CreateFPImm(CFP)); } else if (RegisterSDNode *R = dyn_cast(Op)) { MI->addOperand(MachineOperand::CreateReg(R->getReg(), false)); diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 776129e6b20..281869ad1bf 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -235,22 +235,26 @@ GenericValue JIT::runFunction(Function *F, const GenericValue &AV = ArgValues[i]; switch (ArgTy->getTypeID()) { default: assert(0 && "Unknown argument type for function call!"); - case Type::IntegerTyID: C = ConstantInt::get(AV.IntVal); break; - case Type::FloatTyID: C = ConstantFP ::get(ArgTy, APFloat(AV.FloatVal)); - break; - case Type::DoubleTyID: C = ConstantFP ::get(ArgTy, APFloat(AV.DoubleVal)); - break; + case Type::IntegerTyID: + C = ConstantInt::get(AV.IntVal); + break; + case Type::FloatTyID: + C = ConstantFP::get(APFloat(AV.FloatVal)); + break; + case Type::DoubleTyID: + C = ConstantFP::get(APFloat(AV.DoubleVal)); + break; case Type::PPC_FP128TyID: case Type::X86_FP80TyID: - case Type::FP128TyID: C = ConstantFP ::get(ArgTy, APFloat(AV.IntVal)); - break; + case Type::FP128TyID: + C = ConstantFP::get(APFloat(AV.IntVal)); + break; case Type::PointerTyID: void *ArgPtr = GVTOP(AV); - if (sizeof(void*) == 4) { + if (sizeof(void*) == 4) C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr); - } else { + else C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr); - } C = ConstantExpr::getIntToPtr(C, ArgTy); // Cast the integer to pointer break; } diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 0e27c00e4af..3a4dc23b9a5 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4368,14 +4368,13 @@ SDOperand X86TargetLowering::LowerFABS(SDOperand Op, SelectionDAG &DAG) { MVT::ValueType EltVT = VT; if (MVT::isVector(VT)) EltVT = MVT::getVectorElementType(VT); - const Type *OpNTy = MVT::getTypeForValueType(EltVT); std::vector CV; if (EltVT == MVT::f64) { - Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, ~(1ULL << 63)))); + Constant *C = ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63)))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, ~(1U << 31)))); + Constant *C = ConstantFP::get(APFloat(APInt(32, ~(1U << 31)))); CV.push_back(C); CV.push_back(C); CV.push_back(C); @@ -4397,14 +4396,13 @@ SDOperand X86TargetLowering::LowerFNEG(SDOperand Op, SelectionDAG &DAG) { EltVT = MVT::getVectorElementType(VT); EltNum = MVT::getVectorNumElements(VT); } - const Type *OpNTy = MVT::getTypeForValueType(EltVT); std::vector CV; if (EltVT == MVT::f64) { - Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(64, 1ULL << 63))); + Constant *C = ConstantFP::get(APFloat(APInt(64, 1ULL << 63))); CV.push_back(C); CV.push_back(C); } else { - Constant *C = ConstantFP::get(OpNTy, APFloat(APInt(32, 1U << 31))); + Constant *C = ConstantFP::get(APFloat(APInt(32, 1U << 31))); CV.push_back(C); CV.push_back(C); CV.push_back(C); @@ -4430,19 +4428,16 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) { SDOperand Op1 = Op.getOperand(1); MVT::ValueType VT = Op.getValueType(); MVT::ValueType SrcVT = Op1.getValueType(); - const Type *SrcTy = MVT::getTypeForValueType(SrcVT); // If second operand is smaller, extend it first. if (MVT::getSizeInBits(SrcVT) < MVT::getSizeInBits(VT)) { Op1 = DAG.getNode(ISD::FP_EXTEND, VT, Op1); SrcVT = VT; - SrcTy = MVT::getTypeForValueType(SrcVT); } // And if it is bigger, shrink it first. if (MVT::getSizeInBits(SrcVT) > MVT::getSizeInBits(VT)) { Op1 = DAG.getNode(ISD::FP_ROUND, VT, Op1, DAG.getIntPtrConstant(1)); SrcVT = VT; - SrcTy = MVT::getTypeForValueType(SrcVT); } // At this point the operands and the result should have the same @@ -4451,13 +4446,13 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) { // First get the sign bit of second operand. std::vector CV; if (SrcVT == MVT::f64) { - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 1ULL << 63)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(64, 1ULL << 63)))); + CV.push_back(ConstantFP::get(APFloat(APInt(64, 0)))); } else { - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 1U << 31)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 1U << 31)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); } Constant *C = ConstantVector::get(CV); SDOperand CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); @@ -4480,13 +4475,13 @@ SDOperand X86TargetLowering::LowerFCOPYSIGN(SDOperand Op, SelectionDAG &DAG) { // Clear first operand sign bit. CV.clear(); if (VT == MVT::f64) { - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, ~(1ULL << 63))))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(64, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(64, ~(1ULL << 63))))); + CV.push_back(ConstantFP::get(APFloat(APInt(64, 0)))); } else { - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, ~(1U << 31))))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); - CV.push_back(ConstantFP::get(SrcTy, APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, ~(1U << 31))))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); + CV.push_back(ConstantFP::get(APFloat(APInt(32, 0)))); } C = ConstantVector::get(CV); CPIdx = DAG.getConstantPool(C, getPointerTy(), 4); diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 7b974731b1b..d1e66ba9165 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7560,11 +7560,10 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { /// FitsInFPType - Return a Constant* for the specified FP constant if it fits /// in the specified FP type without changing its value. -static Constant *FitsInFPType(ConstantFP *CFP, const Type *FPTy, - const fltSemantics &Sem) { +static Constant *FitsInFPType(ConstantFP *CFP, const fltSemantics &Sem) { APFloat F = CFP->getValueAPF(); if (F.convert(Sem, APFloat::rmNearestTiesToEven) == APFloat::opOK) - return ConstantFP::get(FPTy, F); + return ConstantFP::get(F); return 0; } @@ -7582,11 +7581,11 @@ static Value *LookThroughFPExtensions(Value *V) { if (CFP->getType() == Type::PPC_FP128Ty) return V; // No constant folding of this. // See if the value can be truncated to float and then reextended. - if (Value *V = FitsInFPType(CFP, Type::FloatTy, APFloat::IEEEsingle)) + if (Value *V = FitsInFPType(CFP, APFloat::IEEEsingle)) return V; if (CFP->getType() == Type::DoubleTy) return V; // Won't shrink. - if (Value *V = FitsInFPType(CFP, Type::DoubleTy, APFloat::IEEEdouble)) + if (Value *V = FitsInFPType(CFP, APFloat::IEEEdouble)) return V; // Don't try to shrink to various long double types. }