Switch to using Simplified ConstantFP::get API.
authorChris Lattner <sabre@nondot.org>
Sun, 20 Apr 2008 00:41:09 +0000 (00:41 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 20 Apr 2008 00:41:09 +0000 (00:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49977 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ConstantFolding.cpp
lib/Analysis/ScalarEvolution.cpp
lib/AsmParser/llvmAsmParser.y
lib/Bitcode/Reader/BitcodeReader.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/ExecutionEngine/JIT/JIT.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Transforms/Scalar/InstructionCombining.cpp

index 0e8435fcaca68f46d1fde237844d8bef058c8fb6..d58d78f07734257322e2b58933214a3770faf69e 100644 (file)
@@ -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<ConstantInt>(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())));
         }
       }
     }
index 0508bb76c1ec83ab3a4982103b0f04df6d1ed3c6..32e9e96a6d8acc275590f791631ae8b973a94764 100644 (file)
@@ -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);
index beafcd2735750dc3f44616a048ca7b53f62a3ac6..a1abae3a6252a7214873b158d73b06538d51ee17 100644 (file)
@@ -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<PointerType>(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
   };
index 141d5e15f5f64774494f72c8c4dedab0aadb5bd7..ec099a7852a9a437c2e6136be41e41f3f369e5a9 100644 (file)
@@ -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;
index 18d1d1853e0fd7363623d93b22dca82ce107adab..5f260ece552a0c42c4b6504e1884a646762e803f 100644 (file)
@@ -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<Constant*> CV;
     for (unsigned i = 0, e = NumElems; i != e; ++i) {
       if (ConstantFPSDNode *V = 
           dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) {
-        CV.push_back(ConstantFP::get(OpNTy, V->getValueAPF()));
+        CV.push_back(ConstantFP::get(V->getValueAPF()));
       } else if (ConstantSDNode *V = 
-                 dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
-        CV.push_back(ConstantInt::get(OpNTy, V->getValue()));
+                   dyn_cast<ConstantSDNode>(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));
       }
     }
index 3cdd727ae81948a8d2b4b30a78ea60c4f186b4c1..b4958d6d946813e57a0c016920c10599975991cd 100644 (file)
@@ -601,8 +601,7 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
   } else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
     MI->addOperand(MachineOperand::CreateImm(C->getValue()));
   } else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(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<RegisterSDNode>(Op)) {
     MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));
index 776129e6b20db92bb0178e716a1cc66ad181b136..281869ad1bfedb2db6c4ab50f096a3057043d20a 100644 (file)
@@ -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;
     }
index 0e27c00e4af3bbfc157a1e38fc2ae3400519260d..3a4dc23b9a57ead5741baf8a5676484453623313 100644 (file)
@@ -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<Constant*> 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<Constant*> 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<Constant*> 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);
index 7b974731b1b05a6d013aa20024f15d1d63d66b29..d1e66ba9165f7e546f6868dbc525188dfa84c4a0 100644 (file)
@@ -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.
   }