|
15 | 15 | #define LLVM_IR_RUNTIME_LIBCALLS_H |
16 | 16 |
|
17 | 17 | #include "llvm/ADT/ArrayRef.h" |
| 18 | +#include "llvm/ADT/Bitset.h" |
18 | 19 | #include "llvm/ADT/Sequence.h" |
19 | 20 | #include "llvm/ADT/StringTable.h" |
20 | 21 | #include "llvm/IR/CallingConv.h" |
@@ -55,54 +56,12 @@ static inline auto libcall_impls() { |
55 | 56 | } |
56 | 57 |
|
57 | 58 | /// 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> { |
82 | 60 | public: |
83 | 61 | 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) {} |
106 | 65 | }; |
107 | 66 |
|
108 | 67 | /// A simple container for information about the supported runtime calls. |
|
0 commit comments