[PATCH] D151756: [TableGen] Allow bit fileds in SearchableTables.

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 30 14:59:50 PDT 2023


rampitec updated this revision to Diff 526806.
rampitec marked an inline comment as done.
rampitec retitled this revision from "[TableGen] Allow bit fileds in SearchableTables. NFC." to "[TableGen] Allow bit fileds in SearchableTables.".
rampitec added a comment.

This is NFC in terms that there is no in-tree backend code to use it yet. Removed NFC from the description anyway.

Fixed indent.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151756/new/

https://reviews.llvm.org/D151756

Files:
  llvm/test/TableGen/generic-tables.td
  llvm/utils/TableGen/SearchableTableEmitter.cpp


Index: llvm/utils/TableGen/SearchableTableEmitter.cpp
===================================================================
--- llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -174,6 +174,8 @@
                                      "' 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,
Index: llvm/test/TableGen/generic-tables.td
===================================================================
--- llvm/test/TableGen/generic-tables.td
+++ llvm/test/TableGen/generic-tables.td
@@ -56,25 +56,29 @@
 
 // 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 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 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151756.526806.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230530/87e4f15e/attachment.bin>


More information about the llvm-commits mailing list