[llvm] [TableGen] Eliminate use of `convertInitializerTo` in SearchableTable (PR #109206)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 04:26:51 PDT 2024
https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/109206
>From 9ef5d3f67d8b9b10ae54d3a05ff517d154c2b259 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 | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 37534fe4ca6afe..a200ef92795480 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -31,17 +31,19 @@ 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) {
+ if (const BitsInit *BI = dyn_cast<BitsInit>(B))
+ return *BI->convertInitializerToInt();
+ 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