[llvm] [TableGen] Eliminate use of `convertInitializerTo` in SearchableTable (PR #109206)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 05:15:56 PDT 2024


https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/109206

>From c6ec64dd2b5a110cf78d59ed44c24e01e0112e13 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..b5bf621b057383 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>(B))
+    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