diff options
author | Jim Laskey <jlaskey@mac.com> | 2005-08-17 19:34:49 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2005-08-17 19:34:49 +0000 |
commit | cb6682fa44e13262bdef7dd22b4ba90f8c2e7b97 (patch) | |
tree | 7007ebf49e8bf80c2f04c0df03980f65ddd88077 /lib/Target/CBackend/CBackend.cpp | |
parent | 8482dd894d7d64134f999d8e62bc9adf5cb239a9 (diff) |
Culling out use of unions for converting FP to bits and vice versa.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22838 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CBackend/CBackend.cpp')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index b29187b154..fc87afd206 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -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 @@ void CWriter::printConstant(Constant *CPV) { 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 @@ bool CWriter::doInitialization(Module &M) { /// 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 @@ void CWriter::printFloatingPointConstants(Function &F) { 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!"); |