Skip to content

Commit f8da969

Browse files
committed
Use Bitset
1 parent b76bc42 commit f8da969

File tree

2 files changed

+11
-50
lines changed

2 files changed

+11
-50
lines changed

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"
@@ -55,54 +56,12 @@ static inline auto libcall_impls() {
5556
}
5657

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

10867
/// 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
@@ -588,10 +588,12 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
588588
PredicateSorter.insert(
589589
PredicateWithCC()); // No predicate or CC override first.
590590

591+
constexpr unsigned BitsPerStorageElt = sizeof(uintptr_t) * CHAR_BIT;
592+
591593
DenseMap<PredicateWithCC, LibcallsWithCC> Pred2Funcs;
592594

593-
SmallVector<uint64_t, 32> BitsetValues(
594-
divideCeil(RuntimeLibcallImplDefList.size(), 64));
595+
SmallVector<uintptr_t, 32> BitsetValues(
596+
divideCeil(RuntimeLibcallImplDefList.size(), BitsPerStorageElt));
595597

596598
for (const Record *Elt : *Elements) {
597599
const RuntimeLibcallImpl *LibCallImpl = getRuntimeLibcallImpl(Elt);
@@ -602,8 +604,8 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
602604
}
603605

604606
size_t BitIdx = LibCallImpl->getEnumVal();
605-
uint64_t BitmaskVal = uint64_t(1) << (BitIdx % 64);
606-
size_t BitsetIdx = BitIdx / 64;
607+
uintptr_t BitmaskVal = uintptr_t(1) << (BitIdx % BitsPerStorageElt);
608+
size_t BitsetIdx = BitIdx / BitsPerStorageElt;
607609

608610
auto It = Func2Preds.find(LibCallImpl);
609611
if (It == Func2Preds.end()) {

0 commit comments

Comments
 (0)