1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
// XFAIL: vg_leak
include "llvm/TableGen/SearchableTable.td"
include "llvm/Target/Target.td"
def ArchInstrInfo : InstrInfo { }
def Arch : Target { let InstructionSet = ArchInstrInfo; }
// CHECK-LABEL: GET_InstrTable_IMPL
// CHECK: constexpr MyInstr InstrTable[] = {
// CHECK: { B, 0xA },
// CHECK: { C, 0x0 },
// CHECK: { A, 0x5 },
// CHECK: { D, 0x8 },
// CHECK: };
// A contiguous primary (Instruction) key should get a direct lookup instead of
// binary search.
// CHECK: const MyInstr *getCustomEncodingHelper(unsigned Opcode) {
// CHECK: if ((unsigned)Opcode != std::clamp((unsigned)Opcode, (unsigned)B, (unsigned)D))
// CHECK: return nullptr;
// CHECK: auto Table = ArrayRef(InstrTable);
// CHECK: size_t Idx = Opcode - B;
// CHECK: return &Table[Idx];
class MyInstr<int op> : Instruction {
let OutOperandList = (outs);
let InOperandList = (ins);
Instruction Opcode = !cast<Instruction>(NAME);
bits<16> CustomEncoding = op;
}
def A : MyInstr<5>;
def D : MyInstr<8>;
let isPseudo = 1 in {
def C : MyInstr<0>;
def B : MyInstr<10>;
}
def InstrTable : GenericTable {
let FilterClass = "MyInstr";
let Fields = ["Opcode", "CustomEncoding"];
let PrimaryKey = ["Opcode"];
let PrimaryKeyName = "getCustomEncodingHelper";
}
// Non-contiguous instructions should get a binary search instead of direct
// lookup.
// CHECK: const MyInfoEntry *getTable2ByOpcode(unsigned Opcode) {
// CHECK: auto Idx = std::lower_bound(Table.begin(), Table.end(), Key,
//
// Verify contiguous check for SearchIndex.
// const MyInfoEntry *getTable2ByValue(uint8_t Value) {
// CHECK: if ((uint8_t)Value != std::clamp((uint8_t)Value, (uint8_t)0xB, (uint8_t)0xD))
// CHECK: return nullptr;
// CHECK: auto Table = ArrayRef(Index);
// CHECK: size_t Idx = Value - 0xB;
// CHECK: return &InstrTable2[Table[Idx]._index];
class MyInfoEntry<int V, string S> {
Instruction Opcode = !cast<Instruction>(NAME);
bits<4> Value = V;
string Name = S;
}
let OutOperandList = (outs), InOperandList = (ins) in {
def W : Instruction, MyInfoEntry<12, "IW">;
def X : Instruction;
def Y : Instruction, MyInfoEntry<13, "IY">;
def Z : Instruction, MyInfoEntry<11, "IZ">;
}
def InstrTable2 : GenericTable {
let FilterClass = "MyInfoEntry";
let Fields = ["Opcode", "Value", "Name"];
let PrimaryKey = ["Opcode"];
let PrimaryKeyName = "getTable2ByOpcode";
}
def getTable2ByValue : SearchIndex {
let Table = InstrTable2;
let Key = ["Value"];
}
|