[llvm] a15eb89 - [TableGen] Allow bit fields in SearchableTables.
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 2 13:50:10 PDT 2023
Author: Stanislav Mekhanoshin
Date: 2023-06-02T13:49:07-07:00
New Revision: a15eb89abae33f4e42e655cd09932927cf58dc8b
URL: https://github.com/llvm/llvm-project/commit/a15eb89abae33f4e42e655cd09932927cf58dc8b
DIFF: https://github.com/llvm/llvm-project/commit/a15eb89abae33f4e42e655cd09932927cf58dc8b.diff
LOG: [TableGen] Allow bit fields in SearchableTables.
Differential Revision: https://reviews.llvm.org/D151756
Added:
Modified:
llvm/test/TableGen/generic-tables.td
llvm/utils/TableGen/SearchableTableEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/generic-tables.td b/llvm/test/TableGen/generic-tables.td
index 4bf3918c01a11..dc9debf152cef 100644
--- a/llvm/test/TableGen/generic-tables.td
+++ b/llvm/test/TableGen/generic-tables.td
@@ -56,25 +56,29 @@ def ATable : GenericTable {
// CHECK-LABEL: GET_BTable_IMPL
// CHECK: constexpr BTypeName BTable[] = {
-// CHECK: { "BAlice", 0xAC, },
-// CHECK: { "BBob", 0x14, Bob == 13 },
-// CHECK: { "BCharlie", 0x80, Charlie == 42 },
-// CHECK: { "BEve", 0x4C, Eve == 108 },
+// CHECK: { "BAlice", 0xAC, false, },
+// CHECK: { "BBob", 0x14, false, Bob == 13 },
+// CHECK: { "BCharlie", 0x80, true, Charlie == 42 },
+// CHECK: { "BEve", 0x4C, true, Eve == 108 },
// CHECK: };
// CHECK: const BTypeName *lookupBTableByName(StringRef Name) {
// CHECK: return &BTable[Idx->_index];
// CHECK: }
+// CHECK: const BTypeName *lookupBTableByNameAndFlag(StringRef Name, bool Flag) {
+// CHECK: return &BTable[Idx->_index];
+// CHECK: }
-class BEntry<bits<16> enc, code test = [{}]> {
+class BEntry<bits<16> enc, bit flag = 0, code test = [{}]> {
string Name = NAME;
bits<16> Encoding = enc;
+ bit Flag = flag;
code Test = test;
}
def BAlice : BEntry<0xac>;
-def BBob : BEntry<0x14, [{Bob == 13}]>;
-def BCharlie : BEntry<0x80, "Charlie == 42">;
-def BEve : BEntry<0x4c, [{Eve == }] # 108>;
+def BBob : BEntry<0x14, 0, [{Bob == 13}]>;
+def BCharlie : BEntry<0x80, 1, "Charlie == 42">;
+def BEve : BEntry<0x4c, 1, [{Eve == }] # 108>;
def BValues : GenericEnum {
let FilterClass = "BEntry";
@@ -85,7 +89,7 @@ def BValues : GenericEnum {
def BTable : GenericTable {
let FilterClass = "BEntry";
string CppTypeName = "BTypeName";
- let Fields = ["Name", "Encoding", "Test"];
+ let Fields = ["Name", "Encoding", "Flag", "Test"];
string TypeOf_Test = "code";
}
@@ -94,6 +98,10 @@ def lookupBTableByName : SearchIndex {
let Key = ["Name"];
}
+def lookupBTableByNameAndFlag : SearchIndex {
+ let Table = BTable;
+ let Key = ["Name", "Flag"];
+}
// CHECK-LABEL: GET_CTable_DECL
// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding);
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 2fc291708db7e..4d547c54c4705 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -174,6 +174,8 @@ class SearchableTableEmitter {
"' lookup method '" + Index.Name +
"', key field '" + Field.Name +
"' of type bits is too large");
+ } else if (BitRecTy *BI = dyn_cast<BitRecTy>(Field.RecType)) {
+ return "bool";
} else if (Field.Enum || Field.IsIntrinsic || Field.IsInstruction)
return "unsigned";
PrintFatalError(Index.Loc,
More information about the llvm-commits
mailing list