diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-12-03 23:28:35 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-12-03 23:28:35 +0000 |
commit | 8d6f4e36e8251f083ad76117581f5c90d2423966 (patch) | |
tree | 10da9d6f047c3cf44166e1bfaa27b2a2f497da36 | |
parent | 2b2a17675243c6f9283d353984d882792805803f (diff) | |
download | bcm5719-llvm-8d6f4e36e8251f083ad76117581f5c90d2423966.tar.gz bcm5719-llvm-8d6f4e36e8251f083ad76117581f5c90d2423966.zip |
AsmPrinter: Simplify emitting FP elements in sequential data. NFC
Use APFloat APIs here Rather than manually type-punning through
unions.
llvm-svn: 254664
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 9ffd830a9f5..2cfea650872 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/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); } } |