1 // RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
3 include "llvm/TableGen/SearchableTable.td"
5 class SysReg<string name, bits<12> op> {
7 bits<12> Encoding = op;
8 code FeaturesRequired = [{ {} }];
11 def List1 : GenericTable {
12 let FilterClass = "SysReg";
14 "Name", "Encoding", "FeaturesRequired",
17 let PrimaryKey = [ "Encoding" ];
18 let PrimaryKeyName = "lookupSysRegByEncoding";
19 let PrimaryKeyReturnRange = true;
22 let FeaturesRequired = [{ {Feature1} }] in {
23 def : SysReg<"csr1", 0x7C0>;
26 let FeaturesRequired = [{ {Feature2} }] in {
27 def : SysReg<"csr2", 0x7C0>;
30 // CHECK: #ifdef GET_List1_DECL
31 // CHECK-NEXT: llvm::iterator_range<const SysReg *> lookupSysRegByEncoding(uint16_t Encoding);
34 // CHECK: #ifdef GET_List1_IMPL
35 // CHECK-NEXT: constexpr SysReg List1[] = {
36 // CHECK-NEXT: { "csr1", 0x7C0, {Feature1} }, // 0
37 // CHECK-NEXT: { "csr2", 0x7C0, {Feature2} }, // 1
40 // CHECK: llvm::iterator_range<const SysReg *> lookupSysRegByEncoding(uint16_t Encoding) {
41 // CHECK-NEXT: struct KeyType {
42 // CHECK-NEXT: uint16_t Encoding;
44 // CHECK-NEXT: KeyType Key = {Encoding};
45 // CHECK-NEXT: struct Comp {
46 // CHECK-NEXT: bool operator()(const SysReg &LHS, const KeyType &RHS) const {
47 // CHECK-NEXT: if (LHS.Encoding < RHS.Encoding)
48 // CHECK-NEXT: return true;
49 // CHECK-NEXT: if (LHS.Encoding > RHS.Encoding)
50 // CHECK-NEXT: return false;
51 // CHECK-NEXT: return false;
53 // CHECK-NEXT: bool operator()(const KeyType &LHS, const SysReg &RHS) const {
54 // CHECK-NEXT: if (LHS.Encoding < RHS.Encoding)
55 // CHECK-NEXT: return true;
56 // CHECK-NEXT: if (LHS.Encoding > RHS.Encoding)
57 // CHECK-NEXT: return false;
58 // CHECK-NEXT: return false;
61 // CHECK-NEXT: auto Table = ArrayRef(List1);
62 // CHECK-NEXT: auto It = std::equal_range(Table.begin(), Table.end(), Key, Comp());
63 // CHECK-NEXT: return llvm::make_range(It.first, It.second);