[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp

Jim Laskey jlaskey at apple.com
Wed Aug 17 12:35:00 PDT 2005



Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.126 -> 1.127
---
Log message:

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


 
 


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

 Constants.cpp |   29 +++++------------------------
 1 files changed, 5 insertions(+), 24 deletions(-)


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.126 llvm/lib/VMCore/Constants.cpp:1.127
--- llvm/lib/VMCore/Constants.cpp:1.126	Thu Apr 21 18:46:51 2005
+++ llvm/lib/VMCore/Constants.cpp	Wed Aug 17 14:34:49 2005
@@ -19,6 +19,7 @@
 #include "llvm/SymbolTable.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/MathExtras.h"
 #include <algorithm>
 #include <iostream>
 using namespace llvm;
@@ -796,24 +797,14 @@
   struct ConstantCreator<ConstantFP, Type, uint64_t> {
     static ConstantFP *create(const Type *Ty, uint64_t V) {
       assert(Ty == Type::DoubleTy);
-      union {
-        double F;
-        uint64_t I;
-      } T;
-      T.I = V;
-      return new ConstantFP(Ty, T.F);
+      return new ConstantFP(Ty, BitsToDouble(V));
     }
   };
   template<>
   struct ConstantCreator<ConstantFP, Type, uint32_t> {
     static ConstantFP *create(const Type *Ty, uint32_t V) {
       assert(Ty == Type::FloatTy);
-      union {
-        float F;
-        uint32_t I;
-      } T;
-      T.I = V;
-      return new ConstantFP(Ty, T.F);
+      return new ConstantFP(Ty, BitsToFloat(V));
     }
   };
 }
@@ -824,20 +815,10 @@
 ConstantFP *ConstantFP::get(const Type *Ty, double V) {
   if (Ty == Type::FloatTy) {
     // Force the value through memory to normalize it.
-    union {
-      float F;
-      uint32_t I;
-    } T;
-    T.F = (float)V;
-    return FloatConstants.getOrCreate(Ty, T.I);
+    return FloatConstants.getOrCreate(Ty, FloatToBits(V));
   } else {
     assert(Ty == Type::DoubleTy);
-    union {
-      double F;
-      uint64_t I;
-    } T;
-    T.F = V;
-    return DoubleConstants.getOrCreate(Ty, T.I);
+    return DoubleConstants.getOrCreate(Ty, DoubleToBits(V));
   }
 }
 






More information about the llvm-commits mailing list