[llvm] [TableGen] Eliminate use of `convertInitializerTo` in SearchableTable (PR #109206)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 04:27:25 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
Eliminate use of `convertInitializerTo` as that needs a non-const RecordKeeper (which we want to make const).
---
Full diff: https://github.com/llvm/llvm-project/pull/109206.diff
1 Files Affected:
- (modified) llvm/utils/TableGen/SearchableTableEmitter.cpp (+9-7)
``````````diff
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>;
``````````
</details>
https://github.com/llvm/llvm-project/pull/109206
More information about the llvm-commits
mailing list