Revise previous patch per review comments.
authorDale Johannesen <dalej@apple.com>
Wed, 12 Sep 2007 03:30:33 +0000 (03:30 +0000)
committerDale Johannesen <dalej@apple.com>
Wed, 12 Sep 2007 03:30:33 +0000 (03:30 +0000)
Next round of x87 long double stuff.
Getting close now, basically works.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41875 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
lib/AsmParser/Lexer.l
lib/AsmParser/llvmAsmParser.y
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/CodeGen/AsmPrinter.cpp
lib/CodeGen/MachOWriter.cpp
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/MSIL/MSILWriter.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
tools/llvm2cpp/CppWriter.cpp

index 5acbbacf60fdb7ce2b69edbcb0d1b45890c5bc4d..73e9c5477127f9d287e7f83e977ddfcdf3ed695d 100644 (file)
@@ -284,8 +284,8 @@ void            { RET_TY(Type::VoidTy,  VOID);  }
 float           { RET_TY(Type::FloatTy, FLOAT); }
 double          { RET_TY(Type::DoubleTy,DOUBLE);}
 x86_fp80        { RET_TY(Type::X86_FP80Ty, X86_FP80);}
-fp128            { RET_TY(Type::FP128Ty, FP128);}
-ppc_fp128         { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
+fp128           { RET_TY(Type::FP128Ty, FP128);}
+ppc_fp128       { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
 label           { RET_TY(Type::LabelTy, LABEL); }
 type            { return TYPE;   }
 opaque          { return OPAQUE; }
@@ -477,21 +477,21 @@ shufflevector   { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
                 }
 
 {FPConstant}    { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
-{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext)); 
+{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext+2)); 
                   return FPVAL; 
                 }
 {HexFP80Constant} { uint64_t Pair[2];
-                    HexToIntPair(yytext, Pair);
+                    HexToIntPair(yytext+3, Pair);
                     llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
                     return FPVAL;
                 }
 {HexFP128Constant} { uint64_t Pair[2];
-                    HexToIntPair(yytext, Pair);
+                    HexToIntPair(yytext+3, Pair);
                     llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
                     return FPVAL;
                 }
 {HexPPC128Constant} { uint64_t Pair[2];
-                    HexToIntPair(yytext, Pair);
+                    HexToIntPair(yytext+3, Pair);
                     llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
                     return FPVAL;
                 }
index c0374daf3f1c02d236266f7e2ab2e101ff907383..d2e5256de8870995c436a48fba858008ad608d12 100644 (file)
@@ -1866,7 +1866,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     $$ = ConstantInt::getFalse();
     CHECK_FOR_ERROR
   }
-  | FPType FPVAL {                   // Float & Double constants
+  | FPType FPVAL {                   // Floating point constants
     if (!ConstantFP::isValueValidForType($1, *$2))
       GEN_ERROR("Floating point constant invalid for type");
     // Lexer has no type info, so builds all float and double FP constants 
index 06429931dbdf33353618afb016aa4a1d3d44a97e..9e4a3dee60f3f0636567d1cb8fe88452c105bace 100644 (file)
@@ -629,7 +629,6 @@ bool BitcodeReader::ParseConstants() {
         V = ConstantFP::get(CurTy, APFloat(APInt(32, (uint32_t)Record[0])));
       else if (CurTy == Type::DoubleTy)
         V = ConstantFP::get(CurTy, APFloat(APInt(64, Record[0])));
-      // FIXME: Make long double constants work.  BitsToDouble does not make it.
       else if (CurTy == Type::X86_FP80Ty)
         V = ConstantFP::get(CurTy, APFloat(APInt(80, 2, &Record[0])));
       else if (CurTy == Type::FP128Ty)
index 78a16d8f627378af4b495caad04dc90fc52bec9a..fdaa9be5bb615b5b586c463387a32d4759e0502c 100644 (file)
@@ -526,11 +526,8 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
     } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
       Code = bitc::CST_CODE_FLOAT;
       const Type *Ty = CFP->getType();
-      if (Ty == Type::FloatTy)
-        Record.push_back((uint32_t)*CFP->getValueAPF().convertToAPInt().
-                                      getRawData());
-      else if (Ty == Type::DoubleTy) {
-        Record.push_back(*CFP->getValueAPF().convertToAPInt().getRawData());
+      if (Ty == Type::FloatTy || Ty == Type::DoubleTy) {
+        Record.push_back(CFP->getValueAPF().convertToAPInt().getZExtValue());
       } else if (Ty == Type::X86_FP80Ty) {
         const uint64_t *p = CFP->getValueAPF().convertToAPInt().getRawData();
         Record.push_back(p[0]);
index 49bcba7814182a1d38cbe707a1929df9c02ca495..b55310661e605c825898eca66b6b2683a56512b6 100644 (file)
@@ -831,7 +831,7 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
     // precision...
     if (CFP->getType() == Type::DoubleTy) {
       double Val = CFP->getValueAPF().convertToDouble();  // for comment only
-      uint64_t i = *CFP->getValueAPF().convertToAPInt().getRawData();
+      uint64_t i = CFP->getValueAPF().convertToAPInt().getZExtValue();
       if (TAI->getData64bitsDirective())
         O << TAI->getData64bitsDirective() << i << "\t"
           << TAI->getCommentString() << " double value: " << Val << "\n";
@@ -851,13 +851,50 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
           << " double most significant word " << Val << "\n";
       }
       return;
-    } else {
+    } else if (CFP->getType() == Type::FloatTy) {
       float Val = CFP->getValueAPF().convertToFloat();  // for comment only
       O << TAI->getData32bitsDirective()
-        << (uint32_t)*CFP->getValueAPF().convertToAPInt().getRawData()
+        << CFP->getValueAPF().convertToAPInt().getZExtValue()
         << "\t" << TAI->getCommentString() << " float " << Val << "\n";
       return;
-    }
+    } else if (CFP->getType() == Type::X86_FP80Ty) {
+      // all long double variants are printed as hex
+      const uint64_t *p = CFP->getValueAPF().convertToAPInt().getRawData();
+      if (TD->isBigEndian()) {
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+          << "\t" << TAI->getCommentString()
+          << " long double most significant halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0])
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[1])
+          << "\t" << TAI->getCommentString()
+          << " long double least significant halfword\n";
+       } else {
+        O << TAI->getData16bitsDirective() << uint16_t(p[1])
+          << "\t" << TAI->getCommentString()
+          << " long double least significant halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0])
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 16)
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
+          << "\t" << TAI->getCommentString()
+          << " long double next halfword\n";
+        O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
+          << "\t" << TAI->getCommentString()
+          << " long double most significant halfword\n";
+      }
+      return;
+    } else assert(0 && "Floating point constant type not handled");
   } else if (CV->getType() == Type::Int64Ty) {
     if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
       uint64_t Val = CI->getZExtValue();
index 1c9b0feff54e34ef8af29fa997c697bf45250727..0c743759da6c0aef0a4e80fc01edba2e1f9c514e 100644 (file)
@@ -861,8 +861,8 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
         break;
       }
       case Type::FloatTyID: {
-        uint32_t val = (uint32_t)*cast<ConstantFP>(PC)->
-                                  getValueAPF().convertToAPInt().getRawData();
+        uint32_t val = cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
+                        getZExtValue();
         if (TD->isBigEndian())
           val = ByteSwap_32(val);
         ptr[0] = val;
@@ -872,8 +872,8 @@ void MachOWriter::InitMem(const Constant *C, void *Addr, intptr_t Offset,
         break;
       }
       case Type::DoubleTyID: {
-        uint64_t val = *cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
-                         getRawData();
+        uint64_t val = cast<ConstantFP>(PC)->getValueAPF().convertToAPInt().
+                         getZExtValue();
         if (TD->isBigEndian())
           val = ByteSwap_64(val);
         ptr[0] = val;
index 2050d23ad72b6c21504bb356f31171ec823f9c34..68158be167051005eba4812f1eea5f759ddeff22 100644 (file)
@@ -3800,8 +3800,8 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
       default: assert(0 && "Unknown FP type");
       case MVT::f32:
         if (!AfterLegalize || TLI.isTypeLegal(MVT::i32)) {
-          Tmp = DAG.getConstant((uint32_t)*CFP->getValueAPF().
-                              convertToAPInt().getRawData(), MVT::i32);
+          Tmp = DAG.getConstant((uint32_t)CFP->getValueAPF().
+                              convertToAPInt().getZExtValue(), MVT::i32);
           return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
                               ST->getSrcValueOffset(), ST->isVolatile(),
                               ST->getAlignment());
@@ -3809,8 +3809,8 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
         break;
       case MVT::f64:
         if (!AfterLegalize || TLI.isTypeLegal(MVT::i64)) {
-          Tmp = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
-                                  getRawData(), MVT::i64);
+          Tmp = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
+                                  getZExtValue(), MVT::i64);
           return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
                               ST->getSrcValueOffset(), ST->isVolatile(),
                               ST->getAlignment());
@@ -3818,7 +3818,7 @@ SDOperand DAGCombiner::visitSTORE(SDNode *N) {
           // Many FP stores are not make apparent until after legalize, e.g. for
           // argument passing.  Since this is so common, custom legalize the
           // 64-bit integer store into two 32-bit stores.
-          uint64_t Val = *CFP->getValueAPF().convertToAPInt().getRawData();
+          uint64_t Val = CFP->getValueAPF().convertToAPInt().getZExtValue();
           SDOperand Lo = DAG.getConstant(Val & 0xFFFFFFFF, MVT::i32);
           SDOperand Hi = DAG.getConstant(Val >> 32, MVT::i32);
           if (!TLI.isLittleEndian()) std::swap(Lo, Hi);
index d7eb85bd8fb06208fdebeb8ea1bc9badf59565c9..da55eafdb28a2b72d6e91089680a131e961e50ad 100644 (file)
@@ -489,11 +489,8 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP,
   ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy :
                                       Type::FloatTy, CFP->getValueAPF());
   if (!UseCP) {
-    const APFloat& Val = LLVMC->getValueAPF();
-    return isDouble
-      ? DAG.getConstant(*Val.convertToAPInt().getRawData(), MVT::i64)
-      : DAG.getConstant((uint32_t )*Val.convertToAPInt().getRawData(), 
-                        MVT::i32);
+    return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(),
+                           isDouble ? MVT::i64 : MVT::i32);
   }
 
   if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) &&
@@ -1981,13 +1978,13 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
       // together.
       if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(ST->getValue())) {
         if (CFP->getValueType(0) == MVT::f32) {
-          Tmp3 = DAG.getConstant((uint32_t)*CFP->getValueAPF().
-                                          convertToAPInt().getRawData(),
+          Tmp3 = DAG.getConstant((uint32_t)CFP->getValueAPF().
+                                          convertToAPInt().getZExtValue(),
                                   MVT::i32);
         } else {
           assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!");
-          Tmp3 = DAG.getConstant(*CFP->getValueAPF().convertToAPInt().
-                                   getRawData(), MVT::i64);
+          Tmp3 = DAG.getConstant(CFP->getValueAPF().convertToAPInt().
+                                   getZExtValue(), MVT::i64);
         }
         Result = DAG.getStore(Tmp1, Tmp3, Tmp2, ST->getSrcValue(),
                               SVOffset, isVolatile, Alignment);
index 85a76f436b1b421393e2d076b1c9696227effde6..ed1777e34ad29bac7f8fef8c55138bccf6c9367c 100644 (file)
@@ -109,12 +109,12 @@ bool ISD::isBuildVectorAllOnes(const SDNode *N) {
   } else if (isa<ConstantFPSDNode>(NotZero)) {
     MVT::ValueType VT = NotZero.getValueType();
     if (VT== MVT::f64) {
-      if (*((cast<ConstantFPSDNode>(NotZero)->getValueAPF().
-                  convertToAPInt().getRawData())) != (uint64_t)-1)
+      if (((cast<ConstantFPSDNode>(NotZero)->getValueAPF().
+                  convertToAPInt().getZExtValue())) != (uint64_t)-1)
         return false;
     } else {
-      if ((uint32_t)*cast<ConstantFPSDNode>(NotZero)->
-                      getValueAPF().convertToAPInt().getRawData() != 
+      if ((uint32_t)cast<ConstantFPSDNode>(NotZero)->
+                      getValueAPF().convertToAPInt().getZExtValue() != 
           (uint32_t)-1)
         return false;
     }
@@ -1697,9 +1697,9 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
     }
     case ISD::BIT_CONVERT:
       if (VT == MVT::i32 && C->getValueType(0) == MVT::f32)
-        return getConstant((uint32_t)*V.convertToAPInt().getRawData(), VT);
+        return getConstant((uint32_t)V.convertToAPInt().getZExtValue(), VT);
       else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64)
-        return getConstant(*V.convertToAPInt().getRawData(), VT);
+        return getConstant(V.convertToAPInt().getZExtValue(), VT);
       break;
     }
   }
index f25b1133b24d5a2206669a06ba973b9b6d96c8c3..9fc30c45da1405e9d9e0e0e5632fa18c3bbd5e5a 100644 (file)
@@ -1715,14 +1715,14 @@ void CWriter::printFloatingPointConstants(Function &F) {
 
         if (FPC->getType() == Type::DoubleTy) {
           double Val = FPC->getValueAPF().convertToDouble();
-          uint64_t i = *FPC->getValueAPF().convertToAPInt().getRawData();
+          uint64_t i = FPC->getValueAPF().convertToAPInt().getZExtValue();
           Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
               << " = 0x" << std::hex << i << std::dec
               << "ULL;    /* " << Val << " */\n";
         } else if (FPC->getType() == Type::FloatTy) {
           float Val = FPC->getValueAPF().convertToFloat();
-          uint32_t i = (uint32_t)*FPC->getValueAPF().convertToAPInt().
-                                    getRawData();
+          uint32_t i = (uint32_t)FPC->getValueAPF().convertToAPInt().
+                                    getZExtValue();
           Out << "static const ConstantFloatTy FPConstant" << FPCounter++
               << " = 0x" << std::hex << i << std::dec
               << "U;    /* " << Val << " */\n";
index cd67df17a6fbae2b75e4c48cec901650f0cbcd31..5d6740bd1e8f2e7d39a1aedcefd084b3406b0bfe 100644 (file)
@@ -428,10 +428,10 @@ void MSILWriter::printConstLoad(const Constant* C) {
     uint64_t X;
     unsigned Size;
     if (FP->getType()->getTypeID()==Type::FloatTyID) {
-      X = (uint32_t)*FP->getValueAPF().convertToAPInt().getRawData();
+      X = (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue();
       Size = 4;  
     } else {
-      X = *FP->getValueAPF().convertToAPInt().getRawData();
+      X = FP->getValueAPF().convertToAPInt().getZExtValue();
       Size = 8;  
     }
     Out << "\tldc.r" << Size << "\t( " << utohexstr(X) << ')';
@@ -1473,10 +1473,10 @@ void MSILWriter::printStaticConstant(const Constant* C, uint64_t& Offset) {
     const ConstantFP* FP = cast<ConstantFP>(C);
     if (Ty->getTypeID() == Type::FloatTyID)
       Out << "int32 (" << 
-        (uint32_t)*FP->getValueAPF().convertToAPInt().getRawData() << ')';
+        (uint32_t)FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
     else
       Out << "int64 (" << 
-        *FP->getValueAPF().convertToAPInt().getRawData() << ')';
+        FP->getValueAPF().convertToAPInt().getZExtValue() << ')';
     break;
   }
   case Type::ArrayTyID:
index a7b1239bcf8653ba43bee590b3b190d33e0e2037..b96fbff88cdb67996a5f357d8f714f9f868d8798 100644 (file)
@@ -481,35 +481,64 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
     else 
       Out << CI->getValue().toStringSigned(10);
   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
-    // We would like to output the FP constant value in exponential notation,
-    // but we cannot do this if doing so will lose precision.  Check here to
-    // make sure that we only output it in exponential format if we can parse
-    // the value back and get the same value.
-    //
-    bool isDouble = &CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble;
-    double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() :
-                              CFP->getValueAPF().convertToFloat();
-    std::string StrVal = ftostr(CFP->getValueAPF());
-
-    // Check to make sure that the stringized number is not some string like
-    // "Inf" or NaN, that atof will accept, but the lexer will not.  Check that
-    // the string matches the "[-+]?[0-9]" regex.
-    //
-    if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
-        ((StrVal[0] == '-' || StrVal[0] == '+') &&
-         (StrVal[1] >= '0' && StrVal[1] <= '9')))
-      // Reparse stringized version!
-      if (atof(StrVal.c_str()) == Val) {
-        Out << StrVal;
-        return;
+    if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble ||
+        &CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) {
+      // We would like to output the FP constant value in exponential notation,
+      // but we cannot do this if doing so will lose precision.  Check here to
+      // make sure that we only output it in exponential format if we can parse
+      // the value back and get the same value.
+      //
+      bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble;
+      double Val = (isDouble) ? CFP->getValueAPF().convertToDouble() :
+                                CFP->getValueAPF().convertToFloat();
+      std::string StrVal = ftostr(CFP->getValueAPF());
+
+      // Check to make sure that the stringized number is not some string like
+      // "Inf" or NaN, that atof will accept, but the lexer will not.  Check
+      // that the string matches the "[-+]?[0-9]" regex.
+      //
+      if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
+          ((StrVal[0] == '-' || StrVal[0] == '+') &&
+           (StrVal[1] >= '0' && StrVal[1] <= '9'))) {
+        // Reparse stringized version!
+        if (atof(StrVal.c_str()) == Val) {
+          Out << StrVal;
+          return;
+        }
       }
-
-    // Otherwise we could not reparse it to exactly the same value, so we must
-    // output the string in hexadecimal format!
-    assert(sizeof(double) == sizeof(uint64_t) &&
-           "assuming that double is 64 bits!");
-    Out << "0x" << utohexstr(DoubleToBits(Val));
-
+      // Otherwise we could not reparse it to exactly the same value, so we must
+      // output the string in hexadecimal format!
+      assert(sizeof(double) == sizeof(uint64_t) &&
+             "assuming that double is 64 bits!");
+      Out << "0x" << utohexstr(DoubleToBits(Val));
+    } else {
+      // Some form of long double.  These appear as a magic letter identifying
+      // the type, then a fixed number of hex digits.
+      Out << "0x";
+      if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended)
+        Out << 'K';
+      else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad)
+        Out << 'L';
+      else
+        assert(0 && "Unsupported floating point type");
+      const uint64_t* p = CFP->getValueAPF().convertToAPInt().getRawData();
+      uint64_t word = *p;
+      int shiftcount=60;
+      int width = CFP->getValueAPF().convertToAPInt().getBitWidth();
+      for (int j=0; j<width; j+=4, shiftcount-=4) {
+        unsigned int nibble = (word>>shiftcount) & 15;
+        if (nibble < 10)
+          Out << (unsigned char)(nibble + '0');
+        else
+          Out << (unsigned char)(nibble - 10 + 'A');
+        if (shiftcount == 0) {
+          word = *(++p);
+          shiftcount = 60;
+          if (width-j-4 < 64)
+            shiftcount = width-j-4;
+        }
+      }
+    }
   } else if (isa<ConstantAggregateZero>(CV)) {
     Out << "zeroinitializer";
   } else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
index e11b749f9be8f600f381077e224641cce8f474ed..5c80a377ba7b25fecfe65206309ab93b343c69b4 100644 (file)
@@ -87,8 +87,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
     
     if (SrcEltTy->getTypeID() == Type::DoubleTyID) {
       for (unsigned i = 0; i != SrcNumElts; ++i) {
-        uint64_t V = *cast<ConstantFP>(CV->getOperand(i))->
-                       getValueAPF().convertToAPInt().getRawData();
+        uint64_t V = cast<ConstantFP>(CV->getOperand(i))->
+                       getValueAPF().convertToAPInt().getZExtValue();
         Constant *C = ConstantInt::get(Type::Int64Ty, V);
         Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
       }
@@ -97,8 +97,8 @@ static Constant *CastConstantVector(ConstantVector *CV,
 
     assert(SrcEltTy->getTypeID() == Type::FloatTyID);
     for (unsigned i = 0; i != SrcNumElts; ++i) {
-      uint32_t V = (uint32_t)*cast<ConstantFP>(CV->getOperand(i))->
-                               getValueAPF().convertToAPInt().getRawData();
+      uint32_t V = (uint32_t)cast<ConstantFP>(CV->getOperand(i))->
+                               getValueAPF().convertToAPInt().getZExtValue();
       Constant *C = ConstantInt::get(Type::Int32Ty, V);
       Result.push_back(ConstantExpr::getBitCast(C, DstEltTy));
     }
@@ -331,9 +331,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
         return const_cast<Constant*>(V);
 
       if (DestTy->isFloatingPoint()) {
-        if (DestTy == Type::FloatTy)
-          return ConstantFP::get(DestTy, APFloat(CI->getValue()));
-        assert(DestTy == Type::DoubleTy && "Unknown FP type!");
+        assert((DestTy == Type::DoubleTy || DestTy == Type::FloatTy) && 
+               "Unknown FP type!");
         return ConstantFP::get(DestTy, APFloat(CI->getValue()));
       }
       // Otherwise, can't fold this (vector?)
index 1708e460795d2485a2e6499850026197dedf6b0e..c546045454218ebcd8bf6843f5f2b0703e627a1e 100644 (file)
@@ -245,8 +245,14 @@ ConstantFP::ConstantFP(const Type *Ty, const APFloat& V)
   // temporary
   if (Ty==Type::FloatTy)
     assert(&V.getSemantics()==&APFloat::IEEEsingle);
-  else
+  else if (Ty==Type::DoubleTy)
     assert(&V.getSemantics()==&APFloat::IEEEdouble);
+  else if (Ty==Type::X86_FP80Ty)
+    assert(&V.getSemantics()==&APFloat::x87DoubleExtended);
+  else if (Ty==Type::FP128Ty)
+    assert(&V.getSemantics()==&APFloat::IEEEquad);
+  else
+    assert(0);
 }
 
 bool ConstantFP::isNullValue() const {
@@ -294,8 +300,14 @@ ConstantFP *ConstantFP::get(const Type *Ty, const APFloat& V) {
   // temporary
   if (Ty==Type::FloatTy)
     assert(&V.getSemantics()==&APFloat::IEEEsingle);
-  else
+  else if (Ty==Type::DoubleTy)
     assert(&V.getSemantics()==&APFloat::IEEEdouble);
+  else if (Ty==Type::X86_FP80Ty)
+    assert(&V.getSemantics()==&APFloat::x87DoubleExtended);
+  else if (Ty==Type::FP128Ty)
+    assert(&V.getSemantics()==&APFloat::IEEEquad);
+  else
+    assert(0);
   
   DenseMapAPFloatKeyInfo::KeyTy Key(V);
   ConstantFP *&Slot = (*FPConstants)[Key];
@@ -713,11 +725,14 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) {
            &Val2.getSemantics() == &APFloat::IEEEdouble ||
            Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven) == 
              APFloat::opOK;
-  // TODO: Figure out how to test if we can use a shorter type instead!
   case Type::X86_FP80TyID:
-  case Type::PPC_FP128TyID:
+    return &Val2.getSemantics() == &APFloat::IEEEsingle || 
+           &Val2.getSemantics() == &APFloat::IEEEdouble ||
+           &Val2.getSemantics() == &APFloat::x87DoubleExtended;
   case Type::FP128TyID:
-    return true;
+    return &Val2.getSemantics() == &APFloat::IEEEsingle || 
+           &Val2.getSemantics() == &APFloat::IEEEdouble ||
+           &Val2.getSemantics() == &APFloat::IEEEquad;
   }
 }
 
index a56c7cdd41a8186ed487d9fa75839d45eb5be5a7..8fae51d10c752939fdba295d2818fcdd794b8bfc 100644 (file)
@@ -250,11 +250,11 @@ CppWriter::printCFP(const ConstantFP *CFP) {
       }
     else if (CFP->getType() == Type::DoubleTy)
       Out << "BitsToDouble(0x" << std::hex 
-          << *CFP->getValueAPF().convertToAPInt().getRawData()
+          << CFP->getValueAPF().convertToAPInt().getZExtValue()
           << std::dec << "ULL) /* " << StrVal << " */";
     else 
       Out << "BitsToFloat(0x" << std::hex 
-          << (uint32_t)*CFP->getValueAPF().convertToAPInt().getRawData()
+          << (uint32_t)CFP->getValueAPF().convertToAPInt().getZExtValue()
           << std::dec << "U) /* " << StrVal << " */";
     Out << ")";
 #if HAVE_PRINTF_A