SearchableTable.td 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //===- SearchableTable.td ----------------------------------*- tablegen -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the key top-level classes needed to produce a reasonably
  10. // generic table that can be binary-searched. Three types of objects can be
  11. // defined using the classes in this file:
  12. //
  13. // 1. (Generic) Enums. By instantiating the GenericEnum class once, an enum with
  14. // the name of the def is generated. It is guarded by the preprocessor define
  15. // GET_name_DECL, where name is the name of the def.
  16. //
  17. // 2. (Generic) Tables and search indices. By instantiating the GenericTable
  18. // class once, a table with the name of the instantiating def is generated and
  19. // guarded by the GET_name_IMPL preprocessor guard.
  20. //
  21. // Both a primary key and additional secondary keys / search indices can also
  22. // be defined, which result in the generation of lookup functions. Their
  23. // declarations and definitions are all guarded by GET_name_DECL and
  24. // GET_name_IMPL, respectively, where name is the name of the underlying table.
  25. //
  26. // See AArch64SystemOperands.td and its generated header for example uses.
  27. //
  28. //===----------------------------------------------------------------------===//
  29. // Define a record derived from this class to generate a generic enum.
  30. //
  31. // The name of the record is used as the type name of the C++ enum.
  32. class GenericEnum {
  33. // Name of a TableGen class. The enum will have one entry for each record
  34. // that derives from that class.
  35. string FilterClass;
  36. // (Optional) Name of a field that is present in all collected records and
  37. // contains the name of enum entries.
  38. //
  39. // If NameField is not set, the record names will be used instead.
  40. string NameField;
  41. // (Optional) Name of a field that is present in all collected records and
  42. // contains the numerical value of enum entries.
  43. //
  44. // If ValueField is not set, enum values will be assigned automatically,
  45. // starting at 0, according to a lexicographical sort of the entry names.
  46. string ValueField;
  47. }
  48. // Define a record derived from this class to generate a generic table. This
  49. // table can have a searchable primary key, and it can also be referenced by
  50. // external search indices.
  51. //
  52. // The name of the record is used as the name of the global primary array of
  53. // entries of the table in C++.
  54. class GenericTable {
  55. // Name of a class. The table will have one entry for each record that
  56. // derives from that class.
  57. string FilterClass;
  58. // Name of the C++ struct/class type that holds table entries. The
  59. // declaration of this type is not generated automatically.
  60. string CppTypeName = FilterClass;
  61. // List of the names of fields of collected records that contain the data for
  62. // table entries, in the order that is used for initialization in C++.
  63. //
  64. // TableGen needs to know the type of the fields so that it can format
  65. // the initializers correctly. It can infer the type of bit, bits, string,
  66. // Intrinsic, and Instruction values.
  67. //
  68. // For each field of the table named xxx, TableGen will look for a field
  69. // named TypeOf_xxx and use that as a more detailed description of the
  70. // type of the field. This is required for fields whose type
  71. // cannot be deduced automatically, such as enum fields. For example:
  72. //
  73. // def MyEnum : GenericEnum {
  74. // let FilterClass = "MyEnum";
  75. // ...
  76. // }
  77. //
  78. // class MyTableEntry {
  79. // MyEnum V;
  80. // ...
  81. // }
  82. //
  83. // def MyTable : GenericTable {
  84. // let FilterClass = "MyTableEntry";
  85. // let Fields = ["V", ...];
  86. // string TypeOf_V = "MyEnum";
  87. // }
  88. //
  89. // If a string field was initialized with a code literal, TableGen will
  90. // emit the code verbatim. However, if a string field was initialized
  91. // in some other way, but should be interpreted as code, then a TypeOf_xxx
  92. // field is necessary, with a value of "code":
  93. //
  94. // string TypeOf_Predicate = "code";
  95. list<string> Fields;
  96. // (Optional) List of fields that make up the primary key.
  97. list<string> PrimaryKey;
  98. // (Optional) Name of the primary key search function.
  99. string PrimaryKeyName;
  100. // See SearchIndex.EarlyOut
  101. bit PrimaryKeyEarlyOut = false;
  102. }
  103. // Define a record derived from this class to generate an additional search
  104. // index for a generic table that has been defined earlier.
  105. //
  106. // The name of the record will be used as the name of the C++ lookup function.
  107. class SearchIndex {
  108. // Table that this search index refers to.
  109. GenericTable Table;
  110. // List of fields that make up the key.
  111. list<string> Key;
  112. // If true, the lookup function will check the first field of the key against
  113. // the minimum and maximum values in the index before entering the binary
  114. // search. This is convenient for tables that add extended data for a subset
  115. // of a larger enum-based space, e.g. extended data about a subset of
  116. // instructions.
  117. //
  118. // Can only be used when the first field is an integral (non-string) type.
  119. bit EarlyOut = false;
  120. }
  121. // Legacy table type with integrated enum.
  122. class SearchableTable {
  123. list<string> SearchableFields;
  124. string EnumNameField = "Name";
  125. string EnumValueField;
  126. }