[cfe-commits] r51578 - in /cfe/trunk: lib/CodeGen/CodeGenTypes.cpp test/CodeGen/long-double-x86.c

Eli Friedman eli.friedman at gmail.com
Mon May 26 21:20:05 PDT 2008


Author: efriedma
Date: Mon May 26 23:20:05 2008
New Revision: 51578

URL: http://llvm.org/viewvc/llvm-project?rev=51578&view=rev
Log:
Generalize the float type generation code, and specifically fix the 
codegen of X86 long double.


Added:
    cfe/trunk/test/CodeGen/long-double-x86.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=51578&r1=51577&r2=51578&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Mon May 26 23:20:05 2008
@@ -161,6 +161,21 @@
   }
 }
 
+static const llvm::Type* getTypeForFormat(const llvm::fltSemantics * format) {
+  if (format == &llvm::APFloat::IEEEsingle)
+    return llvm::Type::FloatTy;
+  if (format == &llvm::APFloat::IEEEdouble)
+    return llvm::Type::DoubleTy;
+  if (format == &llvm::APFloat::IEEEquad)
+    return llvm::Type::FP128Ty;
+  if (format == &llvm::APFloat::PPCDoubleDouble)
+    return llvm::Type::PPC_FP128Ty;
+  if (format == &llvm::APFloat::x87DoubleExtended)
+    return llvm::Type::X86_FP80Ty;
+  assert(9 && "Unknown float format!");
+  return 0;
+}
+
 const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
   const clang::Type &Ty = *T.getCanonicalType();
   
@@ -195,13 +210,12 @@
       return llvm::IntegerType::get(
         static_cast<unsigned>(Context.getTypeSize(T)));
       
-    case BuiltinType::Float:      return llvm::Type::FloatTy;
+    case BuiltinType::Float:
+      return getTypeForFormat(Context.Target.getFloatFormat());
     case BuiltinType::Double:
-      return (Context.Target.getDoubleFormat() == &llvm::APFloat::IEEEdouble) ? 
-        llvm::Type::DoubleTy : llvm::Type::FloatTy;
+      return getTypeForFormat(Context.Target.getDoubleFormat());
     case BuiltinType::LongDouble:
-      // FIXME: mapping long double onto double.
-      return llvm::Type::DoubleTy;
+      return getTypeForFormat(Context.Target.getLongDoubleFormat());
     }
     break;
   }

Added: cfe/trunk/test/CodeGen/long-double-x86.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/long-double-x86.c?rev=51578&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/long-double-x86.c (added)
+++ cfe/trunk/test/CodeGen/long-double-x86.c Mon May 26 23:20:05 2008
@@ -0,0 +1,4 @@
+// RUN: clang %s -emit-llvm -o - -triple=i686-apple-darwin9 | grep x86_fp80
+
+long double x = 0;
+int checksize[sizeof(x) == 12 ? 1 : -1];





More information about the cfe-commits mailing list