Skip to content

Commit 7365b1c

Browse files
authored
[TableGen] Eliminate use of convertInitializerTo in SearchableTable (#109206)
Eliminate use of `convertInitializerTo` as that needs a non-const RecordKeeper (which we want to make const).
1 parent 78768c5 commit 7365b1c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

llvm/utils/TableGen/SearchableTableEmitter.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,19 @@ using namespace llvm;
3131

3232
#define DEBUG_TYPE "searchable-table-emitter"
3333

34-
namespace {
35-
36-
int64_t getAsInt(Init *B) {
37-
return cast<IntInit>(
38-
B->convertInitializerTo(IntRecTy::get(B->getRecordKeeper())))
39-
->getValue();
34+
static int64_t getAsInt(const Init *B) {
35+
if (const BitsInit *BI = dyn_cast<BitsInit>(B))
36+
return *BI->convertInitializerToInt();
37+
if (const IntInit *II = dyn_cast<IntInit>(B))
38+
return II->getValue();
39+
llvm_unreachable("Unexpected initializer");
4040
}
41-
int64_t getInt(Record *R, StringRef Field) {
41+
42+
static int64_t getInt(const Record *R, StringRef Field) {
4243
return getAsInt(R->getValueInit(Field));
4344
}
4445

46+
namespace {
4547
struct GenericEnum {
4648
using Entry = std::pair<StringRef, int64_t>;
4749

0 commit comments

Comments
 (0)