summaryrefslogtreecommitdiff
path: root/mlir/lib/IR/AsmPrinter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/IR/AsmPrinter.cpp')
-rw-r--r--mlir/lib/IR/AsmPrinter.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 29e36210f127..6a362afc52f2 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -2061,7 +2061,8 @@ void AsmPrinter::Impl::printLocationInternal(LocationAttr loc, bool pretty,
/// Print a floating point value in a way that the parser will be able to
/// round-trip losslessly.
-static void printFloatValue(const APFloat &apValue, raw_ostream &os) {
+static void printFloatValue(const APFloat &apValue, raw_ostream &os,
+ bool *printedHex = nullptr) {
// We would like to output the FP constant value in exponential notation,
// but we cannot do this if doing so will lose precision. Check here to
// make sure that we only output it in exponential format if we can parse
@@ -2102,6 +2103,8 @@ static void printFloatValue(const APFloat &apValue, raw_ostream &os) {
// Print special values in hexadecimal format. The sign bit should be included
// in the literal.
+ if (printedHex)
+ *printedHex = true;
SmallVector<char, 16> str;
APInt apInt = apValue.bitcastToAPInt();
apInt.toString(str, /*Radix=*/16, /*Signed=*/false,
@@ -2275,10 +2278,12 @@ void AsmPrinter::Impl::printAttributeImpl(Attribute attr,
return;
} else if (auto floatAttr = llvm::dyn_cast<FloatAttr>(attr)) {
- printFloatValue(floatAttr.getValue(), os);
+ bool printedHex = false;
+ printFloatValue(floatAttr.getValue(), os, &printedHex);
// FloatAttr elides the type if F64.
- if (typeElision == AttrTypeElision::May && floatAttr.getType().isF64())
+ if (typeElision == AttrTypeElision::May && floatAttr.getType().isF64() &&
+ !printedHex)
return;
} else if (auto strAttr = llvm::dyn_cast<StringAttr>(attr)) {