[llvm-commits] [llvm] r40974 - in /llvm/trunk/lib: Bitcode/Reader/BitcodeReader.cpp Bitcode/Writer/BitcodeWriter.cpp VMCore/Constants.cpp

Dale Johannesen dalej at apple.com
Thu Aug 9 15:51:36 PDT 2007


Author: johannes
Date: Thu Aug  9 17:51:36 2007
New Revision: 40974

URL: http://llvm.org/viewvc/llvm-project?rev=40974&view=rev
Log:
Patch 10 for long double.  Doing constants right needs expanding ConstantFP
to handle values bigger than double.  If we assume host==target and host
long double works correctly, this is not too bad, but we don't want to
have that limitation longterm.  I could implement accepting double
constants as long double or something like that, which would lead to
incorrect codegen with no errors; the more I think about that the worse
it seems.  Rather than do such a hack that would be backed out later,
I'm settling for giving reasonable error messages, for now.


Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=40974&r1=40973&r2=40974&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Aug  9 17:51:36 2007
@@ -629,6 +629,10 @@
         V = ConstantFP::get(CurTy, BitsToFloat(Record[0]));
       else if (CurTy == Type::DoubleTy)
         V = ConstantFP::get(CurTy, BitsToDouble(Record[0]));
+      // FIXME: Make long double constants work.
+      else if (CurTy == Type::X86_FP80Ty ||
+               CurTy == Type::FP128Ty || CurTy == Type::PPC_FP128Ty)
+        assert(0 && "Long double constants not handled yet.");
       else
         V = UndefValue::get(CurTy);
       break;

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=40974&r1=40973&r2=40974&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Thu Aug  9 17:51:36 2007
@@ -525,11 +525,17 @@
       }
     } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
       Code = bitc::CST_CODE_FLOAT;
-      if (CFP->getType() == Type::FloatTy) {
+      const Type *Ty = CFP->getType();
+      if (Ty == Type::FloatTy) {
         Record.push_back(FloatToBits((float)CFP->getValue()));
-      } else {
-        assert (CFP->getType() == Type::DoubleTy && "Unknown FP type!");
+      } else if (Ty == Type::DoubleTy) {
         Record.push_back(DoubleToBits((double)CFP->getValue()));
+      // FIXME: make long double constants work.
+      } else if (Ty == Type::X86_FP80Ty ||
+                 Ty == Type::FP128Ty || Ty == Type::PPC_FP128Ty) {
+        assert (0 && "Long double constants not handled yet.");
+      } else {
+        assert (0 && "Unknown FP type!");
       }
     } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
       // Emit constant strings specially.

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=40974&r1=40973&r2=40974&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Aug  9 17:51:36 2007
@@ -108,6 +108,9 @@
     return ConstantInt::get(Ty, 0);
   case Type::FloatTyID:
   case Type::DoubleTyID:
+  case Type::X86_FP80TyID:
+  case Type::PPC_FP128TyID:
+  case Type::FP128TyID:
     return ConstantFP::get(Ty, 0.0);
   case Type::PointerTyID:
     return ConstantPointerNull::get(cast<PointerType>(Ty));
@@ -288,12 +291,17 @@
     ConstantFP *&Slot = (*FloatConstants)[std::make_pair(IntVal, Ty)];
     if (Slot) return Slot;
     return Slot = new ConstantFP(Ty, (float)V);
-  } else {
-    assert(Ty == Type::DoubleTy);
+  } else if (Ty == Type::DoubleTy) { 
     uint64_t IntVal = DoubleToBits(V);
     ConstantFP *&Slot = (*DoubleConstants)[std::make_pair(IntVal, Ty)];
     if (Slot) return Slot;
     return Slot = new ConstantFP(Ty, V);
+  // FIXME:  Make long double constants work.
+  } else if (Ty == Type::X86_FP80Ty ||
+             Ty == Type::PPC_FP128Ty || Ty == Type::FP128Ty) {
+    assert(0 && "Long double constants not handled yet.");
+  } else {
+    assert(0 && "Unknown FP Type!");
   }
 }
 
@@ -696,10 +704,13 @@
   default:
     return false;         // These can't be represented as floating point!
 
-    // TODO: Figure out how to test if a double can be cast to a float!
+    // TODO: Figure out how to test if we can use a shorter type instead!
   case Type::FloatTyID:
   case Type::DoubleTyID:
-    return true;          // This is the largest type...
+  case Type::X86_FP80TyID:
+  case Type::PPC_FP128TyID:
+  case Type::FP128TyID:
+    return true;
   }
 }
 





More information about the llvm-commits mailing list