[clang] 32aac7b - [NFC] Switch FloatModeKind enum class to use bitmask enums
Jolanta Jensen via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 03:02:31 PDT 2022
Author: Jolanta Jensen
Date: 2022-06-29T11:02:02+01:00
New Revision: 32aac7babfdd2a7e6d40cb186d676bef93bfc6bb
URL: https://github.com/llvm/llvm-project/commit/32aac7babfdd2a7e6d40cb186d676bef93bfc6bb
DIFF: https://github.com/llvm/llvm-project/commit/32aac7babfdd2a7e6d40cb186d676bef93bfc6bb.diff
LOG: [NFC] Switch FloatModeKind enum class to use bitmask enums
Using bitmask enums simplifies and clarifies the code.
Differential Revision: https://reviews.llvm.org/D128182
Added:
Modified:
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Targets/X86.h
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 3ed47559ab4d0..0ab3e9b67dfe8 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -15,6 +15,7 @@
#define LLVM_CLANG_BASIC_TARGETINFO_H
#include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/BitmaskEnum.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
@@ -52,14 +53,14 @@ class MacroBuilder;
namespace Builtin { struct Info; }
enum class FloatModeKind {
- NoFloat = 255,
- Half = 0,
- Float,
- Double,
- LongDouble,
- Float128,
- Ibm128,
- Last = Ibm128
+ NoFloat = 0,
+ Half = 1 << 0,
+ Float = 1 << 1,
+ Double = 1 << 2,
+ LongDouble = 1 << 3,
+ Float128 = 1 << 4,
+ Ibm128 = 1 << 5,
+ LLVM_MARK_AS_BITMASK_ENUM(Ibm128)
};
/// Fields controlling how types are laid out in memory; these may need to
@@ -221,7 +222,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
mutable VersionTuple PlatformMinVersion;
unsigned HasAlignMac68kSupport : 1;
- unsigned RealTypeUsesObjCFPRetMask : (int)FloatModeKind::Last + 1;
+ unsigned RealTypeUsesObjCFPRetMask
+ : llvm::BitmaskEnumDetail::bitWidth(
+ (int)FloatModeKind::LLVM_BITMASK_LARGEST_ENUMERATOR);
unsigned ComplexLongDoubleUsesFP2Ret : 1;
unsigned HasBuiltinMSVaList : 1;
@@ -890,9 +893,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
/// Check whether the given real type should use the "fpret" flavor of
/// Objective-C message passing on this target.
bool useObjCFPRetForRealType(FloatModeKind T) const {
- assert(T <= FloatModeKind::Last &&
- "T value is larger than RealTypeUsesObjCFPRetMask can handle");
- return RealTypeUsesObjCFPRetMask & (1 << (int)T);
+ return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
}
/// Check whether _Complex long double should use the "fp2ret" flavor
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 007d5c23ec4c7..78e444f4e4eb0 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -14,6 +14,7 @@
#define LLVM_CLANG_LIB_BASIC_TARGETS_X86_H
#include "OSTargets.h"
+#include "clang/Basic/BitmaskEnum.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/Triple.h"
@@ -419,8 +420,8 @@ class LLVM_LIBRARY_VISIBILITY X86_32TargetInfo : public X86TargetInfo {
// Use fpret for all types.
RealTypeUsesObjCFPRetMask =
- ((1 << (int)FloatModeKind::Float) | (1 << (int)FloatModeKind::Double) |
- (1 << (int)FloatModeKind::LongDouble));
+ (int)(FloatModeKind::Float | FloatModeKind::Double |
+ FloatModeKind::LongDouble);
// x86-32 has atomics up to 8 bytes
MaxAtomicPromoteWidth = 64;
@@ -699,7 +700,7 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo {
"64-i64:64-f80:128-n8:16:32:64-S128");
// Use fpret only for long double.
- RealTypeUsesObjCFPRetMask = (1 << (int)FloatModeKind::LongDouble);
+ RealTypeUsesObjCFPRetMask = (int)FloatModeKind::LongDouble;
// Use fp2ret for _Complex long double.
ComplexLongDoubleUsesFP2Ret = true;
More information about the cfe-commits
mailing list