[PATCH] D131826: [MC] Leverage constexpr `std::array` in `SubtargetFeature.h`
Joe Loser via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 12 21:18:31 PDT 2022
jloser created this revision.
jloser added a reviewer: craig.topper.
Herald added a subscriber: StephenFan.
Herald added a project: All.
jloser requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131826
Files:
llvm/include/llvm/MC/SubtargetFeature.h
Index: llvm/include/llvm/MC/SubtargetFeature.h
===================================================================
--- llvm/include/llvm/MC/SubtargetFeature.h
+++ llvm/include/llvm/MC/SubtargetFeature.h
@@ -40,14 +40,11 @@
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 @@
}
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 @@
}
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 @@
}
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131826.452371.patch
Type: text/x-patch
Size: 1668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220813/e7c78bc4/attachment.bin>
More information about the llvm-commits
mailing list