[llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp

Jim Laskey jlaskey at apple.com
Wed Aug 17 12:30:56 PDT 2005



Changes in directory llvm/lib/Target/CBackend:

Writer.cpp updated: 1.242 -> 1.243
---
Log message:

Culling out use of unions for converting FP to bits and vice versa.


 


---
Diffs of the changes:  (+5 -20)

 Writer.cpp |   25 +++++--------------------
 1 files changed, 5 insertions(+), 20 deletions(-)


Index: llvm/lib/Target/CBackend/Writer.cpp
diff -u llvm/lib/Target/CBackend/Writer.cpp:1.242 llvm/lib/Target/CBackend/Writer.cpp:1.243
--- llvm/lib/Target/CBackend/Writer.cpp:1.242	Thu Jul 14 14:41:16 2005
+++ llvm/lib/Target/CBackend/Writer.cpp	Wed Aug 17 14:30:44 2005
@@ -32,6 +32,7 @@
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/Support/Mangler.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h"
@@ -585,14 +586,10 @@
         const unsigned long SignalNaN = 0x7ff4UL;
 
         // We need to grab the first part of the FP #
-        union {
-          double   d;
-          uint64_t ll;
-        } DHex;
         char Buffer[100];
 
-        DHex.d = FPC->getValue();
-        sprintf(Buffer, "0x%llx", (unsigned long long)DHex.ll);
+        uint64_t ll = DoubleToBits(FPC->getValue());
+        sprintf(Buffer, "0x%llx", (unsigned long long)ll);
 
         std::string Num(&Buffer[0], &Buffer[6]);
         unsigned long Val = strtoul(Num.c_str(), 0, 16);
@@ -953,16 +950,6 @@
 
 /// Output all floating point constants that cannot be printed accurately...
 void CWriter::printFloatingPointConstants(Function &F) {
-  union {
-    double D;
-    uint64_t U;
-  } DBLUnion;
-
-  union {
-    float F;
-    unsigned U;
-  } FLTUnion;
-
   // Scan the module for floating point constants.  If any FP constant is used
   // in the function, we want to redirect it here so that we do not depend on
   // the precision of the printed form, unless the printed form preserves
@@ -979,14 +966,12 @@
         FPConstantMap[FPC] = FPCounter;  // Number the FP constants
 
         if (FPC->getType() == Type::DoubleTy) {
-          DBLUnion.D = Val;
           Out << "static const ConstantDoubleTy FPConstant" << FPCounter++
-              << " = 0x" << std::hex << DBLUnion.U << std::dec
+              << " = 0x" << std::hex << DoubleToBits(Val) << std::dec
               << "ULL;    /* " << Val << " */\n";
         } else if (FPC->getType() == Type::FloatTy) {
-          FLTUnion.F = Val;
           Out << "static const ConstantFloatTy FPConstant" << FPCounter++
-              << " = 0x" << std::hex << FLTUnion.U << std::dec
+              << " = 0x" << std::hex << FloatToBits(Val) << std::dec
               << "U;    /* " << Val << " */\n";
         } else
           assert(0 && "Unknown float type!");






More information about the llvm-commits mailing list