From: River Riddle Date: Sat, 4 May 2019 22:00:27 +0000 (-0700) Subject: Add a static utility to FloatAttr for converting an APFloat to double. X-Git-Tag: llvmorg-11-init~1466^2~1822 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3f27c6068896e0f85b727455a527f15fb842f5b1;p=platform%2Fupstream%2Fllvm.git Add a static utility to FloatAttr for converting an APFloat to double. -- PiperOrigin-RevId: 246671765 --- diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h index 2de33d3..2ff4937 100644 --- a/mlir/include/mlir/IR/Attributes.h +++ b/mlir/include/mlir/IR/Attributes.h @@ -223,6 +223,7 @@ public: /// This function is used to convert the value to a double, even if it loses /// precision. double getValueAsDouble() const; + static double getValueAsDouble(APFloat val); /// Methods for support type inquiry through isa, cast, and dyn_cast. static bool kindof(Kind kind) { return kind == Kind::Float; } diff --git a/mlir/lib/IR/Attributes.cpp b/mlir/lib/IR/Attributes.cpp index c69cb2b..ab15699 100644 --- a/mlir/lib/IR/Attributes.cpp +++ b/mlir/lib/IR/Attributes.cpp @@ -195,10 +195,11 @@ APFloat FloatAttr::getValue() const { } double FloatAttr::getValueAsDouble() const { - const auto &semantics = getType().cast().getFloatSemantics(); - auto value = getValue(); - bool losesInfo = false; // ignored - if (&semantics != &APFloat::IEEEdouble()) { + return getValueAsDouble(getValue()); +} +double FloatAttr::getValueAsDouble(APFloat value) { + if (&value.getSemantics() != &APFloat::IEEEdouble()) { + bool losesInfo = false; value.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &losesInfo); }