Next round of APFloat changes.
Use APFloat in UpgradeParser and AsmParser.
Change all references to ConstantFP to use the
APFloat interface rather than double.  Remove
the ConstantFP double interfaces.
Use APFloat functions for constant folding arithmetic
and comparisons.
(There are still way too many places APFloat is
just a wrapper around host float/double, but we're
getting there.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41747 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/Lexer.cpp.cvs b/lib/AsmParser/Lexer.cpp.cvs
index 30ddb8f..326bdf0 100644
--- a/lib/AsmParser/Lexer.cpp.cvs
+++ b/lib/AsmParser/Lexer.cpp.cvs
@@ -2129,15 +2129,17 @@
 case 145:
 YY_RULE_SETUP
 #line 440 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
-{ llvmAsmlval.FPVal = atof(yytext); return FPVAL; }
+{ llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
 	YY_BREAK
 case 146:
 YY_RULE_SETUP
 #line 441 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
-{ llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; }
+{ llvmAsmlval.FPVal = new APFloat(HexToFP(yytext)); 
+                  return FPVAL; 
+                }
 	YY_BREAK
 case YY_STATE_EOF(INITIAL):
-#line 443 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
+#line 445 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
 {
                   /* Make sure to free the internal buffers for flex when we are
                    * done reading our input!
@@ -2148,20 +2150,20 @@
 	YY_BREAK
 case 147:
 YY_RULE_SETUP
-#line 451 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
+#line 453 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
 { /* Ignore whitespace */ }
 	YY_BREAK
 case 148:
 YY_RULE_SETUP
-#line 452 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
+#line 454 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
 { return yytext[0]; }
 	YY_BREAK
 case 149:
 YY_RULE_SETUP
-#line 454 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
+#line 456 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 2165 "Lexer.cpp"
+#line 2167 "Lexer.cpp"
 
 	case YY_END_OF_BUFFER:
 		{
@@ -3043,5 +3045,5 @@
 	return 0;
 	}
 #endif
-#line 454 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
+#line 456 "/Volumes/MacOS9/gcc/llvm/lib/AsmParser/Lexer.l"
 
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 64e6d16..390544d 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -437,8 +437,10 @@
                   return GLOBALVAL_ID;
                 }
 
-{FPConstant}    { llvmAsmlval.FPVal = atof(yytext); return FPVAL; }
-{HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; }
+{FPConstant}    { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
+{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext)); 
+                  return FPVAL; 
+                }
 
 <<EOF>>         {
                   /* Make sure to free the internal buffers for flex when we are
diff --git a/lib/AsmParser/Lexer.l.cvs b/lib/AsmParser/Lexer.l.cvs
index 64e6d16..390544d 100644
--- a/lib/AsmParser/Lexer.l.cvs
+++ b/lib/AsmParser/Lexer.l.cvs
@@ -437,8 +437,10 @@
                   return GLOBALVAL_ID;
                 }
 
-{FPConstant}    { llvmAsmlval.FPVal = atof(yytext); return FPVAL; }
-{HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; }
+{FPConstant}    { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
+{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext)); 
+                  return FPVAL; 
+                }
 
 <<EOF>>         {
                   /* Make sure to free the internal buffers for flex when we are
diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h
index e315902..61de652 100644
--- a/lib/AsmParser/ParserInternals.h
+++ b/lib/AsmParser/ParserInternals.h
@@ -22,7 +22,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Assembly/Parser.h"
 #include "llvm/ADT/StringExtras.h"
-
+#include "llvm/ADT/APFloat.h"
 
 // Global variables exported from the lexer...
 
@@ -93,10 +93,10 @@
     std::string *Name;    // If it's a named reference.  Memory must be deleted.
     int64_t  ConstPool64; // Constant pool reference.  This is the value
     uint64_t UConstPool64;// Unsigned constant pool reference.
-    double   ConstPoolFP; // Floating point constant pool reference
+    APFloat *ConstPoolFP; // Floating point constant pool reference
     Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
     InlineAsmDescriptor *IAD;
-  };
+ };
 
   static ValID createLocalID(unsigned Num) {
     ValID D; D.Type = LocalID; D.Num = Num; return D;
@@ -119,7 +119,7 @@
     ValID D; D.Type = ConstUIntVal; D.UConstPool64 = Val; return D;
   }
 
-  static ValID create(double Val) {
+  static ValID create(APFloat *Val) {
     ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val; return D;
   }
 
@@ -168,7 +168,7 @@
     case GlobalID      : return '@' + utostr(Num);
     case LocalName     : return *Name;
     case GlobalName    : return *Name;
-    case ConstFPVal    : return ftostr(ConstPoolFP);
+    case ConstFPVal    : return ftostr(*ConstPoolFP);
     case ConstNullVal  : return "null";
     case ConstUndefVal : return "undef";
     case ConstZeroVal  : return "zeroinitializer";
@@ -194,7 +194,8 @@
     case GlobalName:    return *Name < *V.Name;
     case ConstSIntVal:  return ConstPool64  < V.ConstPool64;
     case ConstUIntVal:  return UConstPool64 < V.UConstPool64;
-    case ConstFPVal:    return ConstPoolFP  < V.ConstPoolFP;
+    case ConstFPVal:    return ConstPoolFP->compare(*V.ConstPoolFP) ==
+                               APFloat::cmpLessThan;
     case ConstNullVal:  return false;
     case ConstUndefVal: return false;
     case ConstZeroVal: return false;
@@ -212,7 +213,8 @@
         case GlobalName: return *Name == *(V.Name);
         case ConstSIntVal:  return ConstPool64  == V.ConstPool64;
         case ConstUIntVal:  return UConstPool64 == V.UConstPool64;
-        case ConstFPVal:    return ConstPoolFP  == V.ConstPoolFP;
+        case ConstFPVal:    return ConstPoolFP->compare(*V.ConstPoolFP) == 
+                                   APFloat::cmpEqual;
         case ConstantVal:   return ConstantValue == V.ConstantValue;
         case ConstNullVal:  return true;
         case ConstUndefVal: return true;
diff --git a/lib/AsmParser/llvmAsmParser.h.cvs b/lib/AsmParser/llvmAsmParser.h.cvs
index 353388b..feb3ff6 100644
--- a/lib/AsmParser/llvmAsmParser.h.cvs
+++ b/lib/AsmParser/llvmAsmParser.h.cvs
@@ -355,7 +355,7 @@
   uint64_t                          UInt64Val;
   int                               SIntVal;
   unsigned                          UIntVal;
-  double                            FPVal;
+  llvm::APFloat                    *FPVal;
   bool                              BoolVal;
 
   std::string                      *StrVal;   // This memory must be deleted
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 93f7a08..83dfa31 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -412,11 +412,15 @@
     }
 
   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
-    if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP)) {
+    if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
       GenerateError("FP constant invalid for type");
       return 0;
     }
-    return ConstantFP::get(Ty, D.ConstPoolFP);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if (Ty==Type::FloatTy)
+      D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    return ConstantFP::get(Ty, *D.ConstPoolFP);
 
   case ValID::ConstNullVal:      // Is it a null value?
     if (!isa<PointerType>(Ty)) {
@@ -992,7 +996,7 @@
   uint64_t                          UInt64Val;
   int                               SIntVal;
   unsigned                          UIntVal;
-  double                            FPVal;
+  llvm::APFloat                    *FPVal;
   bool                              BoolVal;
 
   std::string                      *StrVal;   // This memory must be deleted
@@ -1862,9 +1866,13 @@
     CHECK_FOR_ERROR
   }
   | FPType FPVAL {                   // Float & Double constants
-    if (!ConstantFP::isValueValidForType($1, $2))
+    if (!ConstantFP::isValueValidForType($1, *$2))
       GEN_ERROR("Floating point constant invalid for type");
-    $$ = ConstantFP::get($1, $2);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if ($1==Type::FloatTy)
+      $2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    $$ = ConstantFP::get($1, *$2);
     CHECK_FOR_ERROR
   };
 
diff --git a/lib/AsmParser/llvmAsmParser.y.cvs b/lib/AsmParser/llvmAsmParser.y.cvs
index 93f7a08..83dfa31 100644
--- a/lib/AsmParser/llvmAsmParser.y.cvs
+++ b/lib/AsmParser/llvmAsmParser.y.cvs
@@ -412,11 +412,15 @@
     }
 
   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
-    if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP)) {
+    if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
       GenerateError("FP constant invalid for type");
       return 0;
     }
-    return ConstantFP::get(Ty, D.ConstPoolFP);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if (Ty==Type::FloatTy)
+      D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    return ConstantFP::get(Ty, *D.ConstPoolFP);
 
   case ValID::ConstNullVal:      // Is it a null value?
     if (!isa<PointerType>(Ty)) {
@@ -992,7 +996,7 @@
   uint64_t                          UInt64Val;
   int                               SIntVal;
   unsigned                          UIntVal;
-  double                            FPVal;
+  llvm::APFloat                    *FPVal;
   bool                              BoolVal;
 
   std::string                      *StrVal;   // This memory must be deleted
@@ -1862,9 +1866,13 @@
     CHECK_FOR_ERROR
   }
   | FPType FPVAL {                   // Float & Double constants
-    if (!ConstantFP::isValueValidForType($1, $2))
+    if (!ConstantFP::isValueValidForType($1, *$2))
       GEN_ERROR("Floating point constant invalid for type");
-    $$ = ConstantFP::get($1, $2);
+    // Lexer has no type info, so builds all FP constants as double.
+    // Fix this here.
+    if ($1==Type::FloatTy)
+      $2->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
+    $$ = ConstantFP::get($1, *$2);
     CHECK_FOR_ERROR
   };