[llvm] [TableGen] Eliminate use of `convertInitializerTo` in SearchableTable (PR #109206)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 14:56:13 PDT 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/109206
Eliminate use of `convertInitializerTo` as that needs a non-const RecordKeeper (which we want to make const).
>From f94cd79dcc425c3a18e27e04e295dfd7bc35e53b Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 18 Sep 2024 14:53:46 -0700
Subject: [PATCH] [TableGen] Eliminate use of `convertInitializerTo` in
SearchableTable
Eliminate use of `convertInitializerTo` as that needs a non-const
RecordKeeper (which we want to make const).
---
llvm/utils/TableGen/SearchableTableEmitter.cpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 37534fe4ca6afe..c7ba5c96e42017 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -31,17 +31,20 @@ using namespace llvm;
#define DEBUG_TYPE "searchable-table-emitter"
-namespace {
-
-int64_t getAsInt(Init *B) {
- return cast<IntInit>(
- B->convertInitializerTo(IntRecTy::get(B->getRecordKeeper())))
- ->getValue();
+static int64_t getAsInt(const Init *B) {
+ errs() << "Kind = " << (int)B->getKind() << " : " << *B << "\n";
+ if (const BitsInit *BI = dyn_cast<BitsInit>(B))
+ return *BI->convertInitializerToInt();
+ else if (const IntInit *II = dyn_cast<IntInit>(BI))
+ return II->getValue();
+ llvm_unreachable("Unexpected initializer");
}
-int64_t getInt(Record *R, StringRef Field) {
+
+static int64_t getInt(const Record *R, StringRef Field) {
return getAsInt(R->getValueInit(Field));
}
+namespace {
struct GenericEnum {
using Entry = std::pair<StringRef, int64_t>;
More information about the llvm-commits
mailing list