From c5aa4e71ff52b61762ef2dfdab5ccba6a49fffe5 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 3 Dec 2015 23:28:35 +0000 Subject: [PATCH] AsmPrinter: Simplify emitting FP elements in sequential data. NFC Use APFloat APIs here Rather than manually type-punning through unions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254664 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 41 ++++++++++----------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 9ffd830a9f5..2cfea650872 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1945,33 +1945,22 @@ static void emitGlobalConstantDataSequential(const DataLayout &DL, AP.OutStreamer->EmitIntValue(CDS->getElementAsInteger(i), ElementByteSize); } - } else if (ElementByteSize == 4) { - // FP Constants are printed as integer constants to avoid losing - // precision. - assert(CDS->getElementType()->isFloatTy()); - for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { - union { - float F; - uint32_t I; - }; - - F = CDS->getElementAsFloat(i); - if (AP.isVerbose()) - AP.OutStreamer->GetCommentOS() << "float " << F << '\n'; - AP.OutStreamer->EmitIntValue(I, 4); - } } else { - assert(CDS->getElementType()->isDoubleTy()); - for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { - union { - double F; - uint64_t I; - }; - - F = CDS->getElementAsDouble(i); - if (AP.isVerbose()) - AP.OutStreamer->GetCommentOS() << "double " << F << '\n'; - AP.OutStreamer->EmitIntValue(I, 8); + // FP Constants are printed as integer constants to avoid losing precision. + for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) { + APFloat Num = CDS->getElementAsAPFloat(I); + if (AP.isVerbose()) { + if (ElementByteSize == 4) + AP.OutStreamer->GetCommentOS() << "float " << Num.convertToFloat() + << '\n'; + else if (ElementByteSize == 8) + AP.OutStreamer->GetCommentOS() << "double " << Num.convertToDouble() + << '\n'; + else + llvm_unreachable("Unexpected float width"); + } + AP.OutStreamer->EmitIntValue(Num.bitcastToAPInt().getLimitedValue(), + ElementByteSize); } } -- 2.34.1