mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
f2f87b751f
Summary: This is essentially a rewrite of the backend which introduces TableGen base classes GenericEnum, GenericTable, and SearchIndex. They allow generating custom enums and tables with lookup functions using separately defined records as the underlying database. Also added as part of this change: - Lookup functions may use indices composed of multiple fields. - Instruction fields are supported similar to Intrinsic fields. - When the lookup key has contiguous numeric values, the lookup function will directly index into the table instead of using a binary search. The existing SearchableTable functionality is internally mapped to the new primitives. Change-Id: I444f3490fa1dbfb262d7286a1660a2c4308e9932 Reviewers: arsenm, tra, t.p.northover Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D48013 llvm-svn: 335225
139 lines
3.1 KiB
TableGen
139 lines
3.1 KiB
TableGen
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
|
|
// XFAIL: vg_leak
|
|
|
|
include "llvm/TableGen/SearchableTable.td"
|
|
|
|
// CHECK-LABEL: GET_BValues_DECL
|
|
// CHECK: enum BValues {
|
|
// CHECK: BAlice = 172,
|
|
// CHECK: BBob = 20,
|
|
// CHECK: BCharlie = 128,
|
|
// CHECK: BEve = 76,
|
|
// CHECK: }
|
|
|
|
// CHECK-LABEL: GET_CEnum_DECL
|
|
// CHECK: enum CEnum {
|
|
// CHECK: CBar
|
|
// CHECK: CBaz
|
|
// CHECK: CFoo
|
|
// CHECK: }
|
|
|
|
// CHECK-LABEL: GET_ATable_DECL
|
|
// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);
|
|
|
|
// CHECK-LABEL: GET_ATable_IMPL
|
|
// CHECK: const AEntry ATable[] = {
|
|
// CHECK: { "baz"
|
|
// CHECK: { "foo"
|
|
// CHECK: { "foobar"
|
|
// CHECK: { "bar"
|
|
// CHECK: };
|
|
|
|
// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
|
|
// CHECK: return &*Idx;
|
|
// CHECK: }
|
|
|
|
class AEntry<string str, int val1, int val2> {
|
|
string Str = str;
|
|
bits<8> Val1 = val1;
|
|
bits<10> Val2 = val2;
|
|
}
|
|
|
|
def : AEntry<"bar", 5, 3>;
|
|
def : AEntry<"baz", 2, 6>;
|
|
def : AEntry<"foo", 4, 4>;
|
|
def : AEntry<"foobar", 4, 5>;
|
|
|
|
def ATable : GenericTable {
|
|
let FilterClass = "AEntry";
|
|
let Fields = ["Str", "Val1", "Val2"];
|
|
|
|
let PrimaryKey = ["Val1", "Val2"];
|
|
let PrimaryKeyName = "lookupATableByValues";
|
|
}
|
|
|
|
|
|
// CHECK-LABEL: GET_BTable_IMPL
|
|
// CHECK: const BTypeName *lookupBTableByName(StringRef Name) {
|
|
// CHECK: return &BTable[Idx->_index];
|
|
// CHECK: }
|
|
|
|
class BEntry<bits<16> enc> {
|
|
string Name = NAME;
|
|
bits<16> Encoding = enc;
|
|
}
|
|
|
|
def BAlice : BEntry<0xac>;
|
|
def BBob : BEntry<0x14>;
|
|
def BCharlie : BEntry<0x80>;
|
|
def BEve : BEntry<0x4c>;
|
|
|
|
def BValues : GenericEnum {
|
|
let FilterClass = "BEntry";
|
|
let NameField = "Name";
|
|
let ValueField = "Encoding";
|
|
}
|
|
|
|
def BTable : GenericTable {
|
|
let FilterClass = "BEntry";
|
|
string CppTypeName = "BTypeName";
|
|
let Fields = ["Name", "Encoding"];
|
|
}
|
|
|
|
def lookupBTableByName : SearchIndex {
|
|
let Table = BTable;
|
|
let Key = ["Name"];
|
|
}
|
|
|
|
|
|
// CHECK-LABEL: GET_CTable_DECL
|
|
// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding);
|
|
// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind);
|
|
// CHECK-LABEL: GET_CTable_IMPL
|
|
// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {
|
|
// CHECK: if ((Encoding < 0xA) ||
|
|
// CHECK: (Encoding > 0xF))
|
|
// CHECK: return nullptr;
|
|
|
|
// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {
|
|
// CHECK: Index[] = {
|
|
// CHECK: { "ALICE", CBar, 1 },
|
|
// CHECK: { "ALICE", CFoo, 0 },
|
|
// CHECK: { "BOB", CBaz, 2 },
|
|
|
|
class CEnum;
|
|
|
|
def CFoo : CEnum;
|
|
def CBar : CEnum;
|
|
def CBaz : CEnum;
|
|
|
|
def CEnum : GenericEnum {
|
|
let FilterClass = "CEnum";
|
|
}
|
|
|
|
class CEntry<string name, CEnum kind, int enc> {
|
|
string Name = name;
|
|
CEnum Kind = kind;
|
|
bits<16> Encoding = enc;
|
|
}
|
|
|
|
def : CEntry<"alice", CFoo, 10>;
|
|
def : CEntry<"alice", CBar, 13>;
|
|
def : CEntry<"bob", CBaz, 15>;
|
|
|
|
def CTable : GenericTable {
|
|
let FilterClass = "CEntry";
|
|
let Fields = ["Name", "Kind", "Encoding"];
|
|
|
|
GenericEnum TypeOf_Kind = CEnum;
|
|
|
|
let PrimaryKey = ["Encoding"];
|
|
let PrimaryKeyName = "lookupCEntryByEncoding";
|
|
let PrimaryKeyEarlyOut = 1;
|
|
}
|
|
|
|
def lookupCEntry : SearchIndex {
|
|
let Table = CTable;
|
|
let Key = ["Name", "Kind"];
|
|
}
|