brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.3 KiB · 8638740 Raw
240 lines · plain
1// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s2// RUN: not llvm-tblgen -gen-searchable-tables -I %p/../../include -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s3// XFAIL: vg_leak4 5include "llvm/TableGen/SearchableTable.td"6 7// CHECK-LABEL: GET_BValues_DECL8// CHECK: enum BValues {9// CHECK:   BAlice = 172,10// CHECK:   BBob = 20,11// CHECK:   BCharlie = 128,12// CHECK:   BEve = 76,13// CHECK: }14 15// CHECK-LABEL: GET_CEnum_DECL16// CHECK: enum CEnum {17// CHECK:   CBar18// CHECK:   CBaz19// CHECK:   CFoo20// CHECK: }21 22// CHECK-LABEL: GET_ATable_DECL23// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);24 25// CHECK-LABEL: GET_ATable_IMPL26// CHECK: constexpr AEntry ATable[] = {27// CHECK-NOT:   { "aaa"28// CHECK:       { "baz", 0x2, 0x6, 0xFFFFFFFF00000000 },29// CHECK:       { "foo", 0x4, 0x4, 0x100000000 },30// CHECK:       { "foobar", 0x4, 0x5, 0x100000000 },31// CHECK:       { "bar", 0x5, 0x3, 0x100000000 },32// CHECK: };33 34// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {35// CHECK:   return &*Idx;36// CHECK: }37 38class AEntry<string str, int val1, int val2, bits<64> val3> {39  string Str = str;40  bits<8> Val1 = val1;41  bits<10> Val2 = val2;42  bits<64> Val3 = val3;43  bit IsNeeded = 1;44}45 46def : AEntry<"aaa", 0, 0, 0> { let IsNeeded = 0; }47def : AEntry<"bar",    5, 3, 0x100000000>;48def : AEntry<"baz",    2, 6, 0xFFFFFFFF00000000>;49def : AEntry<"foo",    4, 4, 0b0000000000000000000000000000000100000000000000000000000000000000>;50def : AEntry<"foobar", 4, 5, 4294967296>;51 52def ATable : GenericTable {53  let FilterClass = "AEntry";54  let FilterClassField = "IsNeeded";55  let Fields = ["Str", "Val1", "Val2", "Val3"];56 57  let PrimaryKey = ["Val1", "Val2"];58  let PrimaryKeyName = "lookupATableByValues";59}60 61 62// CHECK-LABEL: GET_BTable_IMPL63// CHECK: constexpr BTypeName BTable[] = {64// CHECK:   { "BAlice", 0xAC, false,  },65// CHECK:   { "BBob", 0x14, false, Bob == 13 },66// CHECK:   { "BCharlie", 0x80, true, Charlie == 42 },67// CHECK:   { "BEve", 0x4C, true, Eve == 108 },68// CHECK:  };69// CHECK: const BTypeName *lookupBTableByName(StringRef Name) {70// CHECK:   return &BTable[Idx->_index];71// CHECK: }72// CHECK: const BTypeName *lookupBTableByNameAndFlag(StringRef Name, bool Flag) {73// CHECK:   return &BTable[Idx->_index];74// CHECK: }75 76class BEntry<bits<16> enc, bit flag = 0, code test = [{}]> {77  string Name = NAME;78  bits<16> Encoding = enc;79  bit Flag = flag;80  code Test = test;81}82 83def BAlice   : BEntry<0xac>;84def BBob     : BEntry<0x14, 0, [{Bob == 13}]>;85def BCharlie : BEntry<0x80, 1, "Charlie == 42">;86def BEve     : BEntry<0x4c, 1, [{Eve == }] # 108>;87 88def BValues : GenericEnum {89  let FilterClass = "BEntry";90  let NameField = "Name";91  let ValueField = "Encoding";92}93 94def BTable : GenericTable {95  let FilterClass = "BEntry";96  string CppTypeName = "BTypeName";97  let Fields = ["Name", "Encoding", "Flag", "Test"];98  string TypeOf_Test = "code";99}100 101def lookupBTableByName : SearchIndex {102  let Table = BTable;103  let Key = ["Name"];104}105 106def lookupBTableByNameAndFlag : SearchIndex {107  let Table = BTable;108  let Key = ["Name", "Flag"];109}110 111// CHECK-LABEL: GET_CTable_DECL112// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding);113// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind);114// CHECK-LABEL: GET_CTable_IMPL115// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {116// CHECK:   if ((uint16_t)Encoding != std::clamp((uint16_t)Encoding, (uint16_t)0xA, (uint16_t)0xF))117// CHECK:     return nullptr;118 119// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {120// CHECK: Index[] = {121// CHECK:   { "ALICE", CBar, 1 },122// CHECK:   { "ALICE", CFoo, 0 },123// CHECK:   { "BOB", CBaz, 2 },124 125class CEnum;126 127def CFoo : CEnum;128def CBar : CEnum;129def CBaz : CEnum;130 131def CEnum : GenericEnum {132  let FilterClass = "CEnum";133}134 135class CEntry<string name, CEnum kind, int enc> {136  string Name = name;137  CEnum Kind = kind;138  bits<16> Encoding = enc;139}140 141def : CEntry<"alice", CFoo, 10>;142def : CEntry<"alice", CBar, 13>;143def : CEntry<"bob",   CBaz, 15>;144 145def CTable : GenericTable {146  let FilterClass = "CEntry";147  let Fields = ["Name", "Kind", "Encoding"];148 149  string TypeOf_Kind = "CEnum";150 151  let PrimaryKey = ["Encoding"];152  let PrimaryKeyName = "lookupCEntryByEncoding";153  let PrimaryKeyEarlyOut = 1;154}155 156def lookupCEntry : SearchIndex {157  let Table = CTable;158  let Key = ["Name", "Kind"];159}160 161#ifdef ERROR1162 163class DEntry<string str, int val1> {164  string Str = str;165  bits<8> Val1 = val1;166}167 168def DFoo : DEntry<"foo", 1>;169// ERROR1: [[@LINE+1]]:5: error: Record 'DBar' for table 'DTable' is missing field 'Val1'170def DBar : DEntry<"bar", ?>;171 172def DTable : GenericTable {173  let FilterClass = "DEntry";174  let Fields = ["Str", "Val1"];175}176 177#endif // ERROR1178 179// CHECK-LABEL: GET_EEntryEvenTable_DECL180// CHECK: const EEntry *lookupEEntryEvenTableByValue(uint8_t Value);181 182// CHECK-LABEL: GET_EEntryEvenTable_IMPL183// CHECK: constexpr EEntry EEntryEvenTable[] = {184// CHECK:   { 0x2185// CHECK:   { 0x4186// CHECK:   { 0x6187// CHECK:   { 0x8188// CHECK:   { 0xA189// CHECK: };190 191// CHECK: const EEntry *lookupEEntryEvenTableByValue(uint8_t Value) {192// CHECK:   return &*Idx;193// CHECK: }194 195// CHECK-LABEL: GET_EEntryOddTable_DECL196// CHECK: const EEntry *lookupEEntryOddTableByValue(uint8_t Value);197 198// CHECK-LABEL: GET_EEntryOddTable_IMPL199// CHECK: constexpr EEntry EEntryOddTable[] = {200// CHECK:   { 0x1201// CHECK:   { 0x3202// CHECK:   { 0x5203// CHECK:   { 0x7204// CHECK:   { 0x9205// CHECK: };206 207// CHECK: const EEntry *lookupEEntryOddTableByValue(uint8_t Value) {208// CHECK:   return &*Idx;209// CHECK: }210 211// We can construct two GenericTables with the same FilterClass, so that they212// select from the same overall set of records, but assign them with different213// FilterClassField values so that they include different subsets of the records214// of that class.215class EEntry<bits<8> value> {216  bits<8> Value = value;217  bit IsEven = !eq(!and(value, 1), 0);218  bit IsOdd = !not(IsEven);219}220 221foreach i = {1-10} in {222  def : EEntry<i>;223}224 225def EEntryEvenTable : GenericTable {226  let FilterClass = "EEntry";227  let FilterClassField = "IsEven";228  let Fields = ["Value"];229  let PrimaryKey = ["Value"];230  let PrimaryKeyName = "lookupEEntryEvenTableByValue";231}232 233def EEntryOddTable : GenericTable {234  let FilterClass = "EEntry";235  let FilterClassField = "IsOdd";236  let Fields = ["Value"];237  let PrimaryKey = ["Value"];238  let PrimaryKeyName = "lookupEEntryOddTableByValue";239}240