Skip to content

Commit

Permalink
[X86] Remove FeatureBitset from X86TargetParser.cpp. NFC
Browse files Browse the repository at this point in the history
Use the templated Bitset added in D158576.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D158682
  • Loading branch information
topperc committed Aug 24, 2023
1 parent 2ad50f3 commit 4f12c0b
Showing 1 changed file with 2 additions and 70 deletions.
72 changes: 2 additions & 70 deletions llvm/lib/TargetParser/X86TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "llvm/TargetParser/X86TargetParser.h"
#include "llvm/ADT/Bitset.h"
#include "llvm/ADT/StringSwitch.h"
#include <numeric>

Expand All @@ -19,76 +20,7 @@ using namespace llvm::X86;

namespace {

/// Container class for CPU features.
/// This is a constexpr reimplementation of a subset of std::bitset. It would be
/// nice to use std::bitset directly, but it doesn't support constant
/// initialization.
class FeatureBitset {
static constexpr unsigned NUM_FEATURE_WORDS =
(X86::CPU_FEATURE_MAX + 31) / 32;

// This cannot be a std::array, operator[] is not constexpr until C++17.
uint32_t Bits[NUM_FEATURE_WORDS] = {};

public:
constexpr FeatureBitset() = default;
constexpr FeatureBitset(std::initializer_list<unsigned> Init) {
for (auto I : Init)
set(I);
}

bool any() const {
return llvm::any_of(Bits, [](uint64_t V) { return V != 0; });
}

constexpr FeatureBitset &set(unsigned I) {
Bits[I / 32] |= uint32_t(1) << (I % 32);
return *this;
}

constexpr bool operator[](unsigned I) const {
uint32_t Mask = uint32_t(1) << (I % 32);
return (Bits[I / 32] & Mask) != 0;
}

constexpr FeatureBitset &operator&=(const FeatureBitset &RHS) {
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
Bits[I] &= RHS.Bits[I];
return *this;
}

constexpr FeatureBitset &operator|=(const FeatureBitset &RHS) {
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
Bits[I] |= RHS.Bits[I];
return *this;
}

constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {
FeatureBitset Result = *this;
Result &= RHS;
return Result;
}

constexpr FeatureBitset operator|(const FeatureBitset &RHS) const {
FeatureBitset Result = *this;
Result |= RHS;
return Result;
}

constexpr FeatureBitset operator~() const {
FeatureBitset Result;
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
Result.Bits[I] = ~Bits[I];
return Result;
}

constexpr bool operator!=(const FeatureBitset &RHS) const {
for (unsigned I = 0, E = std::size(Bits); I != E; ++I)
if (Bits[I] != RHS.Bits[I])
return true;
return false;
}
};
using FeatureBitset = Bitset<X86::CPU_FEATURE_MAX>;

struct ProcInfo {
StringLiteral Name;
Expand Down

0 comments on commit 4f12c0b

Please sign in to comment.