summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APFloat.cpp
diff options
context:
space:
mode:
authorTim Shen <timshen91@gmail.com>2017-01-27 02:11:07 +0000
committerTim Shen <timshen91@gmail.com>2017-01-27 02:11:07 +0000
commit601ba8c58362dc09c3ff36d88478a2fa098b88fe (patch)
tree827a336eecc420af975f4f6031ab26c8a7272ea7 /llvm/lib/Support/APFloat.cpp
parentc5b2e00d0675df6cc0415442b0ff2c5ebb09d28d (diff)
downloadbcm5719-llvm-601ba8c58362dc09c3ff36d88478a2fa098b88fe.tar.gz
bcm5719-llvm-601ba8c58362dc09c3ff36d88478a2fa098b88fe.zip
[APFloat] Reduce some dispatch boilerplates. NFC.
Summary: This is an attempt to reduce the verbose manual dispatching code in APFloat. This doesn't handle multiple dispatch on single discriminator (e.g. APFloat::add(const APFloat&)), nor handles multiple dispatch on multiple discriminators (e.g. APFloat::convert()). Reviewers: hfinkel, echristo, jlebar Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D29161 llvm-svn: 293255
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r--llvm/lib/Support/APFloat.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 1349eb6ac0b..2fe3b070023 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -26,6 +26,15 @@
#include <cstring>
#include <limits.h>
+#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
+ do { \
+ if (usesLayout<IEEEFloat>(getSemantics())) \
+ return U.IEEE.METHOD_CALL; \
+ if (usesLayout<DoubleAPFloat>(getSemantics())) \
+ return U.Double.METHOD_CALL; \
+ llvm_unreachable("Unexpected semantics"); \
+ } while (false)
+
using namespace llvm;
/// A macro used to combine two fcCategory enums into one key which can be used
@@ -4418,11 +4427,7 @@ APFloat::Storage::Storage(IEEEFloat F, const fltSemantics &Semantics) {
}
APFloat::opStatus APFloat::convertFromString(StringRef Str, roundingMode RM) {
- if (usesLayout<IEEEFloat>(getSemantics()))
- return U.IEEE.convertFromString(Str, RM);
- if (usesLayout<DoubleAPFloat>(getSemantics()))
- return U.Double.convertFromString(Str, RM);
- llvm_unreachable("Unexpected semantics");
+ APFLOAT_DISPATCH_ON_SEMANTICS(convertFromString(Str, RM));
}
hash_code hash_value(const APFloat &Arg) {
@@ -4512,3 +4517,5 @@ APFloat::opStatus APFloat::convertToInteger(APSInt &result,
}
} // End llvm namespace
+
+#undef APFLOAT_DISPATCH_ON_SEMANTICS
OpenPOWER on IntegriCloud