[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293255 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tim Shen
2017-01-27 02:11:07 +00:00
parent a7e6bc8a63
commit e581db178d
2 changed files with 49 additions and 167 deletions
+12 -5
View File
@@ -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