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 | |
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')
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 25 | ||||
-rw-r--r-- | lib/Target/CBackend/Writer.cpp | 25 | ||||
-rw-r--r-- | lib/Target/Sparc/SparcAsmPrinter.cpp | 16 | ||||
-rw-r--r-- | lib/Target/SparcV8/SparcV8AsmPrinter.cpp | 16 |
4 files changed, 16 insertions, 66 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!"); diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index b29187b154..fc87afd206 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.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!"); diff --git a/lib/Target/Sparc/SparcAsmPrinter.cpp b/lib/Target/Sparc/SparcAsmPrinter.cpp index c8852cca99..4e908a1b95 100644 --- a/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -247,22 +247,12 @@ void V8Printer::emitGlobalConstant(const Constant *CV) { switch (CFP->getType()->getTypeID()) { default: assert(0 && "Unknown floating point type!"); case Type::FloatTyID: { - union FU { // Abide by C TBAA rules - float FVal; - unsigned UVal; - } U; - U.FVal = Val; - O << ".long\t" << U.UVal << "\t! float " << Val << "\n"; + O << ".long\t" << FloatToBits(Val) << "\t! float " << Val << "\n"; return; } case Type::DoubleTyID: { - union DU { // Abide by C TBAA rules - double FVal; - uint64_t UVal; - } U; - U.FVal = Val; - O << ".word\t0x" << std::hex << (U.UVal >> 32) << std::dec << "\t! double " << Val << "\n"; - O << ".word\t0x" << std::hex << (U.UVal & 0xffffffffUL) << std::dec << "\t! double " << Val << "\n"; + O << ".word\t0x" << std::hex << (DoubleToBits(Val) >> 32) << std::dec << "\t! double " << Val << "\n"; + O << ".word\t0x" << std::hex << (DoubleToBits(Val) & 0xffffffffUL) << std::dec << "\t! double " << Val << "\n"; return; } } diff --git a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp index c8852cca99..4e908a1b95 100644 --- a/lib/Target/SparcV8/SparcV8AsmPrinter.cpp +++ b/lib/Target/SparcV8/SparcV8AsmPrinter.cpp @@ -247,22 +247,12 @@ void V8Printer::emitGlobalConstant(const Constant *CV) { switch (CFP->getType()->getTypeID()) { default: assert(0 && "Unknown floating point type!"); case Type::FloatTyID: { - union FU { // Abide by C TBAA rules - float FVal; - unsigned UVal; - } U; - U.FVal = Val; - O << ".long\t" << U.UVal << "\t! float " << Val << "\n"; + O << ".long\t" << FloatToBits(Val) << "\t! float " << Val << "\n"; return; } case Type::DoubleTyID: { - union DU { // Abide by C TBAA rules - double FVal; - uint64_t UVal; - } U; - U.FVal = Val; - O << ".word\t0x" << std::hex << (U.UVal >> 32) << std::dec << "\t! double " << Val << "\n"; - O << ".word\t0x" << std::hex << (U.UVal & 0xffffffffUL) << std::dec << "\t! double " << Val << "\n"; + O << ".word\t0x" << std::hex << (DoubleToBits(Val) >> 32) << std::dec << "\t! double " << Val << "\n"; + O << ".word\t0x" << std::hex << (DoubleToBits(Val) & 0xffffffffUL) << std::dec << "\t! double " << Val << "\n"; return; } } |