[llvm] 9a75033 - [MC] Leverage constexpr `std::array` in `SubtargetFeature.h`
Joe Loser via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 13 11:55:58 PDT 2022
Author: Joe Loser
Date: 2022-08-13T12:54:32-06:00
New Revision: 9a750334022a4ab33808555b685b5f35714fe254
URL: https://github.com/llvm/llvm-project/commit/9a750334022a4ab33808555b685b5f35714fe254
DIFF: https://github.com/llvm/llvm-project/commit/9a750334022a4ab33808555b685b5f35714fe254.diff
LOG: [MC] Leverage constexpr `std::array` in `SubtargetFeature.h`
Replace C-style array with `std::array` since `std::array<T, N>::operator[]` is
`constexpr` in C++17. This also allows us to replace `array_lengthof` calls with
member `size()` function.
Differential Revision: https://reviews.llvm.org/D131826
Added:
Modified:
llvm/include/llvm/MC/SubtargetFeature.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/SubtargetFeature.h b/llvm/include/llvm/MC/SubtargetFeature.h
index 799912d4bacbf..c952070f9a43e 100644
--- a/llvm/include/llvm/MC/SubtargetFeature.h
+++ b/llvm/include/llvm/MC/SubtargetFeature.h
@@ -40,14 +40,11 @@ const unsigned MAX_SUBTARGET_FEATURES = MAX_SUBTARGET_WORDS * 64;
class FeatureBitset {
static_assert((MAX_SUBTARGET_FEATURES % 64) == 0,
"Should be a multiple of 64!");
- // This cannot be a std::array, operator[] is not constexpr until C++17.
- uint64_t Bits[MAX_SUBTARGET_WORDS] = {};
+ std::array<uint64_t, MAX_SUBTARGET_WORDS> Bits{};
protected:
- constexpr FeatureBitset(const std::array<uint64_t, MAX_SUBTARGET_WORDS> &B) {
- for (unsigned I = 0; I != B.size(); ++I)
- Bits[I] = B[I];
- }
+ constexpr FeatureBitset(const std::array<uint64_t, MAX_SUBTARGET_WORDS> &B)
+ : Bits{B} {}
public:
constexpr FeatureBitset() = default;
@@ -103,7 +100,7 @@ class FeatureBitset {
}
constexpr FeatureBitset &operator^=(const FeatureBitset &RHS) {
- for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) {
+ for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
Bits[I] ^= RHS.Bits[I];
}
return *this;
@@ -115,7 +112,7 @@ class FeatureBitset {
}
constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
- for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) {
+ for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
Bits[I] &= RHS.Bits[I];
}
return *this;
@@ -127,7 +124,7 @@ class FeatureBitset {
}
constexpr FeatureBitset &operator|=(const FeatureBitset &RHS) {
- for (unsigned I = 0, E = array_lengthof(Bits); I != E; ++I) {
+ for (unsigned I = 0, E = Bits.size(); I != E; ++I) {
Bits[I] |= RHS.Bits[I];
}
return *this;
More information about the llvm-commits
mailing list