Warning, /include/llvm/TableGen/SearchableTable.td is written in an unsupported language. File is not indexed.
0001 //===- SearchableTable.td ----------------------------------*- tablegen -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the key top-level classes needed to produce a reasonably
0010 // generic table that can be binary-searched. Three types of objects can be
0011 // defined using the classes in this file:
0012 //
0013 // 1. (Generic) Enums. By instantiating the GenericEnum class once, an enum with
0014 // the name of the def is generated. It is guarded by the preprocessor define
0015 // GET_name_DECL, where name is the name of the def.
0016 //
0017 // 2. (Generic) Tables and search indices. By instantiating the GenericTable
0018 // class once, a table with the name of the instantiating def is generated and
0019 // guarded by the GET_name_IMPL preprocessor guard.
0020 //
0021 // Both a primary key and additional secondary keys / search indices can also
0022 // be defined, which result in the generation of lookup functions. Their
0023 // declarations and definitions are all guarded by GET_name_DECL and
0024 // GET_name_IMPL, respectively, where name is the name of the underlying table.
0025 //
0026 // See AArch64SystemOperands.td and its generated header for example uses.
0027 //
0028 //===----------------------------------------------------------------------===//
0029
0030 // Define a record derived from this class to generate a generic enum.
0031 //
0032 // The name of the record is used as the type name of the C++ enum.
0033 class GenericEnum {
0034 // Name of a TableGen class. The enum will have one entry for each record
0035 // that derives from that class.
0036 string FilterClass;
0037
0038 // (Optional) Name of a field that is present in all collected records and
0039 // contains the name of enum entries.
0040 //
0041 // If NameField is not set, the record names will be used instead.
0042 string NameField;
0043
0044 // (Optional) Name of a field that is present in all collected records and
0045 // contains the numerical value of enum entries.
0046 //
0047 // If ValueField is not set, enum values will be assigned automatically,
0048 // starting at 0, according to a lexicographical sort of the entry names.
0049 string ValueField;
0050 }
0051
0052 // Define a record derived from this class to generate a generic table. This
0053 // table can have a searchable primary key, and it can also be referenced by
0054 // external search indices.
0055 //
0056 // The name of the record is used as the name of the global primary array of
0057 // entries of the table in C++.
0058 class GenericTable {
0059 // Name of a class. The table will have one entry for each record that
0060 // derives from that class.
0061 string FilterClass;
0062
0063 // A field of FilterClass to filter out entries. This is an optional field
0064 // of ``FilterClass`` which should be `bit` type. If specified, only those
0065 // records with this field being true will have corresponding entries in the
0066 // table.
0067 string FilterClassField = ?;
0068
0069 // Name of the C++ struct/class type that holds table entries. The
0070 // declaration of this type is not generated automatically.
0071 string CppTypeName = FilterClass;
0072
0073 // List of the names of fields of collected records that contain the data for
0074 // table entries, in the order that is used for initialization in C++.
0075 //
0076 // TableGen needs to know the type of the fields so that it can format
0077 // the initializers correctly. It can infer the type of bit, bits, string,
0078 // Intrinsic, and Instruction values.
0079 //
0080 // For each field of the table named xxx, TableGen will look for a field
0081 // named TypeOf_xxx and use that as a more detailed description of the
0082 // type of the field. This is required for fields whose type
0083 // cannot be deduced automatically, such as enum fields. For example:
0084 //
0085 // def MyEnum : GenericEnum {
0086 // let FilterClass = "MyEnum";
0087 // ...
0088 // }
0089 //
0090 // class MyTableEntry {
0091 // MyEnum V;
0092 // ...
0093 // }
0094 //
0095 // def MyTable : GenericTable {
0096 // let FilterClass = "MyTableEntry";
0097 // let Fields = ["V", ...];
0098 // string TypeOf_V = "MyEnum";
0099 // }
0100 //
0101 // If a string field was initialized with a code literal, TableGen will
0102 // emit the code verbatim. However, if a string field was initialized
0103 // in some other way, but should be interpreted as code, then a TypeOf_xxx
0104 // field is necessary, with a value of "code":
0105 //
0106 // string TypeOf_Predicate = "code";
0107 list<string> Fields;
0108
0109 // (Optional) List of fields that make up the primary key.
0110 list<string> PrimaryKey;
0111
0112 // (Optional) Name of the primary key search function.
0113 string PrimaryKeyName;
0114
0115 // See SearchIndex.EarlyOut
0116 bit PrimaryKeyEarlyOut = false;
0117
0118 // If true, will generate a different function signature which will return an
0119 // iterator range of pointers giving the starting and end value of the range.
0120 // e.g. lookupSysRegByEncoding returns multiple CSRs for same encoding.
0121 bit PrimaryKeyReturnRange = false;
0122 }
0123
0124 // Define a record derived from this class to generate an additional search
0125 // index for a generic table that has been defined earlier.
0126 //
0127 // The name of the record will be used as the name of the C++ lookup function.
0128 class SearchIndex {
0129 // Table that this search index refers to.
0130 GenericTable Table;
0131
0132 // List of fields that make up the key.
0133 list<string> Key;
0134
0135 // If true, the lookup function will check the first field of the key against
0136 // the minimum and maximum values in the index before entering the binary
0137 // search. This is convenient for tables that add extended data for a subset
0138 // of a larger enum-based space, e.g. extended data about a subset of
0139 // instructions.
0140 //
0141 // Can only be used when the first field is an integral (non-string) type.
0142 bit EarlyOut = false;
0143 }
0144
0145 // Legacy table type with integrated enum.
0146 class SearchableTable {
0147 list<string> SearchableFields;
0148 string EnumNameField = "Name";
0149 string EnumValueField;
0150 }