Skip to content

Commit 7b13ce5

Browse files
committed
Use Bitset
1 parent 592679c commit 7b13ce5

File tree

3 files changed

+20
-54
lines changed

3 files changed

+20
-54
lines changed

llvm/include/llvm/ADT/Bitset.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ class Bitset {
3535
static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
3636
"Unsupported word size");
3737

38-
static constexpr unsigned NumWords = (NumBits + BITWORD_SIZE-1) / BITWORD_SIZE;
39-
std::array<BitWord, NumWords> Bits{};
38+
static constexpr unsigned NumWords =
39+
(NumBits + BITWORD_SIZE - 1) / BITWORD_SIZE;
4040

4141
protected:
42-
constexpr Bitset(const std::array<BitWord, NumWords> &B)
43-
: Bits{B} {}
42+
using StorageType = std::array<BitWord, NumWords>;
43+
44+
private:
45+
StorageType Bits{};
46+
47+
protected:
48+
constexpr Bitset(const StorageType &B) : Bits{B} {}
4449

4550
public:
4651
constexpr Bitset() = default;

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define LLVM_IR_RUNTIME_LIBCALLS_H
1616

1717
#include "llvm/ADT/ArrayRef.h"
18+
#include "llvm/ADT/Bitset.h"
1819
#include "llvm/ADT/Sequence.h"
1920
#include "llvm/ADT/StringTable.h"
2021
#include "llvm/IR/CallingConv.h"
@@ -54,54 +55,12 @@ static inline auto libcall_impls() {
5455
}
5556

5657
/// Manage a bitset representing the list of available libcalls for a module.
57-
///
58-
/// Most of this exists because std::bitset cannot be statically constructed in
59-
/// a size large enough before c++23
60-
class LibcallImplBitset {
61-
private:
62-
using BitWord = uint64_t;
63-
static constexpr unsigned BitWordSize = sizeof(BitWord) * CHAR_BIT;
64-
static constexpr size_t NumArrayElts =
65-
divideCeil(RTLIB::NumLibcallImpls, BitWordSize);
66-
using Storage = BitWord[NumArrayElts];
67-
68-
Storage Bits = {};
69-
70-
/// Get bitmask for \p Impl in its Bits element.
71-
static constexpr BitWord getBitmask(RTLIB::LibcallImpl Impl) {
72-
unsigned Idx = static_cast<unsigned>(Impl);
73-
return BitWord(1) << (Idx % BitWordSize);
74-
}
75-
76-
/// Get index of array element of Bits for \p Impl
77-
static constexpr unsigned getArrayIdx(RTLIB::LibcallImpl Impl) {
78-
return static_cast<unsigned>(Impl) / BitWordSize;
79-
}
80-
58+
class LibcallImplBitset : public Bitset<RTLIB::NumLibcallImpls> {
8159
public:
8260
constexpr LibcallImplBitset() = default;
83-
constexpr LibcallImplBitset(const Storage &Src) {
84-
for (size_t I = 0; I != NumArrayElts; ++I)
85-
Bits[I] = Src[I];
86-
}
87-
88-
/// Check if a LibcallImpl is available.
89-
constexpr bool test(RTLIB::LibcallImpl Impl) const {
90-
BitWord Mask = getBitmask(Impl);
91-
return (Bits[getArrayIdx(Impl)] & Mask) != 0;
92-
}
93-
94-
/// Mark a LibcallImpl as available
95-
void set(RTLIB::LibcallImpl Impl) {
96-
assert(Impl != RTLIB::Unsupported && "cannot enable unsupported libcall");
97-
Bits[getArrayIdx(Impl)] |= getBitmask(Impl);
98-
}
99-
100-
/// Mark a LibcallImpl as unavailable
101-
void unset(RTLIB::LibcallImpl Impl) {
102-
assert(Impl != RTLIB::Unsupported && "cannot enable unsupported libcall");
103-
Bits[getArrayIdx(Impl)] &= ~getBitmask(Impl);
104-
}
61+
constexpr LibcallImplBitset(
62+
const Bitset<RTLIB::NumLibcallImpls>::StorageType &Src)
63+
: Bitset(Src) {}
10564
};
10665

10766
/// A simple container for information about the supported runtime calls.

llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,12 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
402402
PredicateSorter.insert(
403403
PredicateWithCC()); // No predicate or CC override first.
404404

405+
constexpr unsigned BitsPerStorageElt = sizeof(uintptr_t) * CHAR_BIT;
406+
405407
DenseMap<PredicateWithCC, LibcallsWithCC> Pred2Funcs;
406408

407-
SmallVector<uint64_t, 32> BitsetValues(
408-
divideCeil(RuntimeLibcallImplDefList.size(), 64));
409+
SmallVector<uintptr_t, 32> BitsetValues(
410+
divideCeil(RuntimeLibcallImplDefList.size(), BitsPerStorageElt));
409411

410412
for (const Record *Elt : *Elements) {
411413
const RuntimeLibcallImpl *LibCallImpl = getRuntimeLibcallImpl(Elt);
@@ -416,8 +418,8 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
416418
}
417419

418420
size_t BitIdx = LibCallImpl->getEnumVal();
419-
uint64_t BitmaskVal = uint64_t(1) << (BitIdx % 64);
420-
size_t BitsetIdx = BitIdx / 64;
421+
uintptr_t BitmaskVal = uintptr_t(1) << (BitIdx % BitsPerStorageElt);
422+
size_t BitsetIdx = BitIdx / BitsPerStorageElt;
421423

422424
auto It = Func2Preds.find(LibCallImpl);
423425
if (It == Func2Preds.end()) {

0 commit comments

Comments
 (0)