1 // RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
4 include "llvm/TableGen/SearchableTable.td"
5 include "llvm/Target/Target.td"
7 def ArchInstrInfo : InstrInfo { }
8 def Arch : Target { let InstructionSet = ArchInstrInfo; }
10 // CHECK-LABEL: GET_InstrTable_IMPL
11 // CHECK: constexpr MyInstr InstrTable[] = {
18 // A contiguous primary (Instruction) key should get a direct lookup instead of
20 // CHECK: const MyInstr *getCustomEncodingHelper(unsigned Opcode) {
21 // CHECK: if ((Opcode < B) ||
22 // CHECK: (Opcode > D))
23 // CHECK: return nullptr;
24 // CHECK: auto Table = ArrayRef(InstrTable);
25 // CHECK: size_t Idx = Opcode - B;
26 // CHECK: return &Table[Idx];
29 class MyInstr<int op> : Instruction {
30 let OutOperandList = (outs);
31 let InOperandList = (ins);
32 Instruction Opcode = !cast<Instruction>(NAME);
33 bits<16> CustomEncoding = op;
43 def InstrTable : GenericTable {
44 let FilterClass = "MyInstr";
45 let Fields = ["Opcode", "CustomEncoding"];
47 let PrimaryKey = ["Opcode"];
48 let PrimaryKeyName = "getCustomEncodingHelper";
52 // Non-contiguous instructions should get a binary search instead of direct
54 // CHECK: const MyInfoEntry *getTable2ByOpcode(unsigned Opcode) {
55 // CHECK: auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
57 // Verify contiguous check for SearchIndex.
58 // const MyInfoEntry *getTable2ByValue(uint8_t Value) {
59 // CHECK: if ((Value < 0xB) ||
60 // CHECK: (Value > 0xD))
61 // CHECK: return nullptr;
62 // CHECK: auto Table = ArrayRef(Index);
63 // CHECK: size_t Idx = Value - 0xB;
64 // CHECK: return &InstrTable2[Table[Idx]._index];
67 class MyInfoEntry<int V, string S> {
68 Instruction Opcode = !cast<Instruction>(NAME);
73 let OutOperandList = (outs), InOperandList = (ins) in {
74 def W : Instruction, MyInfoEntry<12, "IW">;
76 def Y : Instruction, MyInfoEntry<13, "IY">;
77 def Z : Instruction, MyInfoEntry<11, "IZ">;
80 def InstrTable2 : GenericTable {
81 let FilterClass = "MyInfoEntry";
82 let Fields = ["Opcode", "Value", "Name"];
84 let PrimaryKey = ["Opcode"];
85 let PrimaryKeyName = "getTable2ByOpcode";
88 def getTable2ByValue : SearchIndex {
89 let Table = InstrTable2;