annotate llvm/docs/TableGen/BackGuide.rst @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 ===================================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 TableGen Backend Developer's Guide
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 ===================================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 .. sectnum::
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 .. contents::
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 :local:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 Introduction
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 ============
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 The purpose of TableGen is to generate complex output files based on
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 information from source files that are significantly easier to code than the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 output files would be, and also easier to maintain and modify over time. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 information is coded in a declarative style involving classes and records,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 which are then processed by TableGen. The internalized records are passed on
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 to various backends, which extract information from a subset of the records
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 and generate an output file. These output files are typically ``.inc`` files
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 for C++, but may be any type of file that the backend developer needs.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 This document is a guide to writing a backend for TableGen. It is not a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 complete reference manual, but rather a guide to using the facilities
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 provided by TableGen for the backends. For a complete reference to the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 various data structures and functions involved, see the primary TableGen
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 header file (``record.h``) and/or the Doxygen documentation.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 This document assumes that you have read the :doc:`TableGen Programmer's
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 Reference <./ProgRef>`, which provides a detailed reference for coding
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 TableGen source files. For a description of the existing backends, see
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 :doc:`TableGen BackEnds <./BackEnds>`.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 Data Structures
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 ===============
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 The following sections describe the data structures that contain the classes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 and records that are collected from the TableGen source files by the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 TableGen parser. Note that the term *class* refers to an abstract record
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 class, while the term *record* refers to a concrete record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 Unless otherwise noted, functions associated with classes are instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ``RecordKeeper``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 ----------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 An instance of the ``RecordKeeper`` class acts as the container for all the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 classes and records parsed and collected by TableGen. The ``RecordKeeper``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 instance is passed to the backend when it is invoked by TableGen. This class
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 is usually abbreviated ``RK``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 There are two maps in the recordkeeper, one for classes and one for records
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 (the latter often referred to as *defs*). Each map maps the class or record
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 name to an instance of the ``Record`` class (see `Record`_), which contains
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 all the information about that class or record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 In addition to the two maps, the ``RecordKeeper`` instance contains:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 * A map that maps the names of global variables to their values.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 Global variables are defined in TableGen files with outer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 ``defvar`` statements.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 * A counter for naming anonymous records.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 The ``RecordKeeper`` class provides a few useful functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 * Functions to get the complete class and record maps.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 * Functions to get a subset of the records based on their parent classes.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 * Functions to get individual classes, records, and globals, by name.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 A ``RecordKeeper`` instance can be printed to an output stream with the ``<<``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 operator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ``Record``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 ----------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 Each class or record built by TableGen is represented by an instance of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 the ``Record`` class. The ``RecordKeeper`` instance contains one map for the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 classes and one for the records. The primary data members of a record are
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 the record name, the vector of field names and their values, and the vector of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 superclasses of the record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 The record name is stored as a pointer to an ``Init`` (see `Init`_), which
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 is a class whose instances hold TableGen values (sometimes referred to as
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 *initializers*). The field names and values are stored in a vector of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 ``RecordVal`` instances (see `RecordVal`_), each of which contains both the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 field name and its value. The superclass vector contains a sequence of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 pairs, with each pair including the superclass record and its source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 file location.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 In addition to those members, a ``Record`` instance contains:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 * A vector of source file locations that includes the record definition
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 itself, plus the locations of any multiclasses involved in its definition.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 * For a class record, a vector of the class's template arguments.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 * An instance of ``DefInit`` (see `DefInit`_) corresponding to this record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 * A unique record ID.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 * A boolean that specifies whether this is a class definition.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 * A boolean that specifies whether this is an anonymous record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 The ``Record`` class provides many useful functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 * Functions to get the record name, fields, source file locations,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 template arguments, and unique ID.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 * Functions to get all the record's superclasses or just its direct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 superclasses.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 * Functions to get a particular field value by specifying its name in various
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 forms, and returning its value in various forms
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 (see `Getting Record Names and Fields`_).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 * Boolean functions to check the various attributes of the record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 A ``Record`` instance can be printed to an output stream with the ``<<``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 operator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 ``RecordVal``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 -------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 Each field of a record is stored in an instance of the ``RecordVal`` class.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 The ``Record`` instance includes a vector of these value instances. A
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 ``RecordVal`` instance contains the name of the field, stored in an ``Init``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 instance. It also contains the value of the field, likewise stored in an
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 ``Init``. (A better name for this class might be ``RecordField``.)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 In addition to those primary members, the ``RecordVal`` has other data members.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 * The source file location of the field definition.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 * The type of the field, stored as an instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 of the ``RecTy`` class (see `RecTy`_).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 The ``RecordVal`` class provides some useful functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 * Functions to get the name of the field in various forms.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 * A function to get the type of the field.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 * A function to get the value of the field.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 * A function to get the source file location.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 Note that field values are more easily obtained directly from the ``Record``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 instance (see `Record`_).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 A ``RecordVal`` instance can be printed to an output stream with the ``<<``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 operator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 ``RecTy``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 ---------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 The ``RecTy`` class is used to represent the types of field values. It is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 the base class for a series of subclasses, one for each of the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 available field types. The ``RecTy`` class has one data member that is an
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 enumerated type specifying the specific type of field value. (A better
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 name for this class might be ``FieldTy``.)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 The ``RecTy`` class provides a few useful functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 * A virtual function to get the type name as a string.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 * A virtual function to check whether all the values of this type can
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 be converted to another given type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 * A virtual function to check whether this type is a subtype of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 another given type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 * A function to get the corresponding ``list``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 type for lists with elements of this type. For example, the function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 returns the ``list<int>`` type when called with the ``int`` type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 The subclasses that inherit from ``RecTy`` are
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 ``BitRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 ``BitsRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 ``CodeRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 ``DagRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 ``IntRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 ``ListRecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 ``RecordRecTy``, and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 ``StringRecTy``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 Some of these classes have additional members that
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 are described in the following subsections.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 *All* of the classes derived from ``RecTy`` provide the ``get()`` function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 It returns an instance of ``Recty`` corresponding to the derived class.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 Some of the ``get()`` functions require an argument to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 specify which particular variant of the type is desired. These arguments are
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 described in the following subsections.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 A ``RecTy`` instance can be printed to an output stream with the ``<<``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 operator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 .. warning::
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 It is not specified whether there is a single ``RecTy`` instance of a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 particular type or multiple instances.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 ``BitsRecTy``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 ~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 This class includes a data member with the size of the ``bits`` value and a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 function to get that size.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 The ``get()`` function takes the length of the sequence, *n*, and returns the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 ``BitsRecTy`` type corresponding to ``bits<``\ *n*\ ``>``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 ``ListRecTy``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 ~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 This class includes a data member that specifies the type of the list's
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 elements and a function to get that type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 The ``get()`` function takes the ``RecTy`` *type* of the list members and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 returns the ``ListRecTy`` type corresponding to ``list<``\ *type*\ ``>``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 ``RecordRecTy``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 ~~~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 This class includes data members that contain the list of parent classes of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 this record. It also provides a function to obtain the array of classes and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 two functions to get the iterator ``begin()`` and ``end()`` values. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 class defines a type for the return values of the latter two functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 using const_record_iterator = Record * const *;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 The ``get()`` function takes an ``ArrayRef`` of pointers to the ``Record``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 instances of the *direct* superclasses of the record and returns the ``RecordRecTy``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 corresponding to the record inheriting from those superclasses.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 ``Init``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 --------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 The ``Init`` class is used to represent TableGen values. The name derives
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 from *initialization value*. This class should not be confused with the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 ``RecordVal`` class, which represents record fields, both their names and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 values. The ``Init`` class is the base class for a series of subclasses, one
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 for each of the available value types. The primary data member of ``Init``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 is an enumerated type that represents the specific type of the value.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 The ``Init`` class provides a few useful functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 * A function to get the type enumerator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 * A boolean virtual function to determine whether a value is completely
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 specified; that is, has no uninitialized subvalues.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 * Virtual functions to get the value as a string.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 * Virtual functions to cast the value to other types, implement the bit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 range feature of TableGen, and implement the list slice feature.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 * A virtual function to get a particular bit of the value.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 The subclasses that inherit directly from ``Init`` are
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 ``UnsetInit`` and ``TypedInit``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 An ``Init`` instance can be printed to an output stream with the ``<<``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 operator.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 .. warning::
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 It is not specified whether two separate initialization values with
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 the same underlying type and value (e.g., two strings with the value
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 "Hello") are represented by two ``Init``\ s or share the same ``Init``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 ``UnsetInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 ~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 This class, a subclass of ``Init``, represents the unset (uninitialized)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 value. The static function ``get()`` can be used to obtain the singleton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 ``Init`` of this type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 ``TypedInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 ~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 This class, a subclass of ``Init``, acts as the parent class of the classes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 that represent specific value types (except for the unset value). These
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 classes include ``BitInit``, ``BitsInit``, ``DagInit``, ``DefInit``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 ``IntInit``, ``ListInit``, and ``StringInit``. (There are additional derived
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 types used by the TableGen parser.)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 This class includes a data member that specifies the ``RecTy`` type of the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 value. It provides a function to get that ``RecTy`` type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 ``BitInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 ~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 The ``BitInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 represent the possible values of a bit: 0 or 1. It includes a data member
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 that contains the bit.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 *All* of the classes derived from ``TypedInit`` provide the following functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 * A static function named ``get()`` that returns an ``Init`` representing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 the specified value(s). In the case of ``BitInit``, ``get(true)`` returns
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 an instance of ``BitInit`` representing true, while ``get(false)`` returns
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 an instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 representing false. As noted above, it is not specified whether there
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 is exactly one or more than one ``BitInit`` representing true (or false).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 * A function named ``GetValue()`` that returns the value of the instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 in a more direct form, in this case as a ``bool``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 ``BitsInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 ~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 The ``BitsInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 represent sequences of bits, from high-order to low-order. It includes a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 data member with the length of the sequence and a vector of pointers to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 ``Init`` instances, one per bit.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 The class provides the usual ``get()`` function. It does not provide the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 ``getValue()`` function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 The class provides the following additional functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 * A function to get the number of bits in the sequence.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 * A function that gets a bit specified by an integer index.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 ``DagInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 ~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 The ``DagInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 represent the possible direct acyclic graphs (``dag``).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 The class includes a pointer to an ``Init`` for the DAG operator and a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 pointer to a ``StringInit`` for the operator name. It includes the count of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 DAG operands and the count of operand names. Finally, it includes a vector of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 pointers to ``Init`` instances for the operands and another to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 ``StringInit`` instances for the operand names.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 (The DAG operands are also referred to as *arguments*.)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 The class provides two forms of the usual ``get()`` function. It does not
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 provide the usual ``getValue()`` function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 The class provides many additional functions:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 * Functions to get the operator in various forms and to get the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 operator name in various forms.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 * Functions to determine whether there are any operands and to get the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 number of operands.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 * Functions to the get the operands, both individually and together.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 * Functions to determine whether there are any names and to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 get the number of names
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 * Functions to the get the names, both individually and together.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 * Functions to get the operand iterator ``begin()`` and ``end()`` values.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 * Functions to get the name iterator ``begin()`` and ``end()`` values.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 The class defines two types for the return values of the operand and name
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 iterators.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 using const_arg_iterator = SmallVectorImpl<Init*>::const_iterator;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 using const_name_iterator = SmallVectorImpl<StringInit*>::const_iterator;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 ``DefInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 ~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 The ``DefInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 represent the records that were collected by TableGen. It includes a data
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 member that is a pointer to the record's ``Record`` instance.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 The class provides the usual ``get()`` function. It does not provide
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 ``getValue()``. Instead, it provides ``getDef()``, which returns the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 ``Record`` instance.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 ``IntInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 ~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 The ``IntInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 represent the possible values of a 64-bit integer. It includes a data member
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 that contains the integer.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 The class provides the usual ``get()`` and ``getValue()`` functions. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 latter function returns the integer as an ``int64_t``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 The class also provides a function, ``getBit()``, to obtain a specified bit
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 of the integer value.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 ``ListInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 ~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 The ``ListInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 represent lists of elements of some type. It includes a data member with the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 length of the list and a vector of pointers to ``Init`` instances, one per
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 element.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 The class provides the usual ``get()`` and ``getValues()`` functions. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 latter function returns an ``ArrayRef`` of the vector of pointers to ``Init``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 instances.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 The class provides these additional functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 * A function to get the element type.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 * Functions to get the length of the vector and to determine whether
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 it is empty.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 * Functions to get an element specified by an integer index and return
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 it in various forms.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 * Functions to get the iterator ``begin()`` and ``end()`` values. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 class defines a type for the return type of these two functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 using const_iterator = Init *const *;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 ``StringInit``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 ~~~~~~~~~~~~~~
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 The ``StringInit`` class is a subclass of ``TypedInit``. Its instances
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 represent arbitrary-length strings. It includes a data member
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 that contains a ``StringRef`` of the value.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 The class provides the usual ``get()`` and ``getValue()`` functions. The
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 latter function returns the ``StringRef``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 Creating a New Backend
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 ======================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 The following steps are required to create a new backend for TableGen.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 #. Invent a name for your backend C++ file, say ``GenAddressModes``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 #. Write the new backend, using the file ``TableGenBackendSkeleton.cpp``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 as a starting point.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 #. Determine which instance of TableGen requires the new backend. There is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 one instance for Clang and another for LLVM. Or you may be building
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 your own instance.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 #. Modify the selected ``tablegen.cpp`` to include your new backend.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 a. Add the name to the enumerated type ``ActionType``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 #. Add a keyword to the ``ActionType`` command option using the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 ``clEnumValN()`` function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 #. Add a case to the ``switch`` statement in the *xxx*\ ``TableGenMain()``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 function. It should invoke the "main function" of your backend, which
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 in this case, according to convention, is named ``EmitAddressModes``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 5. Add a declaration of your "main function" to the corresponding
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 ``TableGenBackends.h`` header file.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 #. Add your backend C++ file to the appropriate ``CMakeLists.txt`` file so
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 that it will be built.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 #. Add your C++ file to the system.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 The Backend Skeleton
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 ====================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 The file ``TableGenBackendSkeleton.cpp`` provides a skeleton C++ translation
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 unit for writing a new TableGen backend. Here are a few notes on the file.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 * The list of includes is the minimal list required by most backends.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 * As with all LLVM C++ files, it has a ``using namespace llvm;`` statement.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 It also has an anonymous namespace that contains all the file-specific
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 data structure definitions, along with the class embodying the emitter
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 data members and functions. Continuing with the ``GenAddressModes`` example,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 this class is named ``AddressModesEmitter``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 * The constructor for the emitter class accepts a ``RecordKeeper`` reference,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 typically named ``RK``. The ``RecordKeeper`` reference is saved in a data
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 member so that records can be obtained from it. This data member is usually
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 named ``Records``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 * One function is named ``run``. It is invoked by the backend's "main
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 function" to collect records and emit the output file. It accepts an instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 of the ``raw_ostream`` class, typically named ``OS``. The output file is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 emitted by writing to this stream.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 * The ``run`` function should use the ``emitSourceFileHeader`` helper function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 to include a standard header in the emitted file.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 * The only function in the ``llvm`` namespace is the backend "main function."
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 In this example, it is named ``EmitAddressModes``. It creates an instance
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 of the ``AddressModesEmitter`` class, passing the ``RecordKeeper``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 instance, then invokes the ``run`` function, passing the ``raw_ostream``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 instance.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 All the examples in the remainder of this document will assume the naming
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 conventions used in the skeleton file.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 Getting Classes
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 ===============
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 The ``RecordKeeper`` class provides two functions for getting the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 ``Record`` instances for classes defined in the TableGen files.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 * ``getClasses()`` returns a ``RecordMap`` reference for all the classes.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 * ``getClass(``\ *name*\ ``)`` returns a ``Record`` reference for the named
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 class.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 If you need to iterate over all the class records:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 for (auto ClassPair : Records.getClasses()) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 Record *ClassRec = ClassPair.second.get();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 ``ClassPair.second`` gets the class's ``unique_ptr``, then ``.get()`` gets the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 class ``Record`` itself.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 Getting Records
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 ===============
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 The ``RecordKeeper`` class provides four functions for getting the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 ``Record`` instances for concrete records defined in the TableGen files.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 * ``getDefs()`` returns a ``RecordMap`` reference for all the concrete
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 records.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 * ``getDef(``\ *name*\ ``)`` returns a ``Record`` reference for the named
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 concrete record.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 * ``getAllDerivedDefinitions(``\ *classname*\ ``)`` returns a vector of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 ``Record`` references for the concrete records that derive from the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 given class.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 * ``getAllDerivedDefinitions(``\ *classnames*\ ``)`` returns
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 a vector of ``Record`` references for the concrete records that derive from
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 *all* of the given classes.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
553
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 This statement obtains all the records that derive from the ``Attribute``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 class and iterates over them.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
556
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 auto AttrRecords = Records.getAllDerivedDefinitions("Attribute");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 for (Record *AttrRec : AttrRecords) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 Getting Record Names and Fields
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 ===============================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 As described above (see `Record`_), there are multiple functions that
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 return the name of a record. One particularly useful one is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 ``getNameInitAsString()``, which returns the name as a ``std::string``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
570
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 There are also multiple functions that return the fields of a record. To
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 obtain and iterate over all the fields:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
575
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 for (const RecordVal &Field : SomeRec->getValues()) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 You will recall that ``RecordVal`` is the class whose instances contain
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 information about the fields in records.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 The ``getValue()`` function returns the ``RecordVal`` instance for a field
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 specified by name. There are multiple overloaded functions, some taking a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 ``StringRef`` and others taking a ``const Init *``. Some functions return a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 ``RecordVal *`` and others return a ``const RecordVal *``. If the field does
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 not exist, a fatal error message is printed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 More often than not, you are interested in the value of the field, not all
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 the information in the ``RecordVal``. There is a large set of functions that
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 take a field name in some form and return its value. One function,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 ``getValueInit``, returns the value as an ``Init *``. Another function,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 ``isValueUnset``, returns a boolean specifying whether the value is unset
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 (uninitialized).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 Most of the functions return the value in some more useful form. For
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 example:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 std::vector<int64_t> RegCosts =
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 SomeRec->getValueAsListOfInts("RegCosts");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 The field ``RegCosts`` is assumed to be a list of integers. That list is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 returned as a ``std::vector`` of 64-bit integers. If the field is not a list
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 of integers, a fatal error message is printed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 Here is a function that returns a field value as a ``Record``, but returns
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 null if the field does not exist.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
612
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 if (Record *BaseRec = SomeRec->getValueAsOptionalDef(BaseFieldName)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 The field is assumed to have another record as its value. That record is returned
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 as a pointer to a ``Record``. If the field does not exist or is unset, the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 functions returns null.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
620
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 Getting Record Superclasses
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 ===========================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 The ``Record`` class provides a function to obtain the superclasses of a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 record. It is named ``getSuperClasses`` and returns an ``ArrayRef`` of an
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 array of ``std::pair`` pairs. The superclasses are in post-order: the order
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 in which the superclasses were visited while copying their fields into the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 record. Each pair consists of a pointer to the ``Record`` instance for a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 superclass record and an instance of the ``SMRange`` class. The range
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 indicates the source file locations of the beginning and end of the class
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 definition.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 This example obtains the superclasses of the ``Prototype`` record and then
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 iterates over the pairs in the returned array.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
637
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 ArrayRef<std::pair<Record *, SMRange>>
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 Superclasses = Prototype->getSuperClasses();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 for (const auto &SuperPair : Superclasses) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
643
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 The ``Record`` class also provides a function, ``getDirectSuperClasses``, to
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 append the *direct* superclasses of a record to a given vector of type
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 ``SmallVectorImpl<Record *>``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
647
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 Emitting Text to the Output Stream
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 ==================================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
650
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 The ``run`` function is passed a ``raw_ostream`` to which it prints the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 output file. By convention, this stream is saved in the emitter class member
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 named ``OS``, although some ``run`` functions are simple and just use the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 stream without saving it. The output can be produced by writing values
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 directly to the output stream, or by using the ``std::format()`` or
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 ``llvm::formatv()`` functions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
657
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
659
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 OS << "#ifndef " << NodeName << "\n";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
661
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 OS << format("0x%0*x, ", Digits, Value);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
663
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 Instances of the following classes can be printed using the ``<<`` operator:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 ``RecordKeeper``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 ``Record``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 ``RecTy``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 ``RecordVal``, and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 ``Init``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 The helper function ``emitSourceFileHeader()`` prints the header comment
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 that should be included at the top of every output file. A call to it is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 included in the skeleton backend file ``TableGenBackendSkeleton.cpp``.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
674
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 Printing Error Messages
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 =======================
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
677
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 TableGen records are often derived from multiple classes and also often
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 defined through a sequence of multiclasses. Because of this, it can be
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 difficult for backends to report clear error messages with accurate source
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 file locations. To make error reporting easier, five error reporting
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 functions are provided, each with four overloads.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
683
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 * ``PrintWarning`` prints a message tagged as a warning.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
685
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 * ``PrintError`` prints a message tagged as an error.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
687
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 * ``PrintFatalError`` prints a message tagged as an error and then terminates.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
689
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 * ``PrintNote`` prints a note. It is often used after one of the previous
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 functions to provide more information.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
692
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 * ``PrintFatalNote`` prints a note and then terminates.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
694
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 Each of these five functions is overloaded four times.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
696
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 * ``PrintError(const Twine &Msg)``:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 Prints the message with no source file location.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
699
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 * ``PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg)``:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 Prints the message followed by the specified source line,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 along with a pointer to the item in error. The array of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 source file locations is typically taken from a ``Record`` instance.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
704
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 * ``PrintError(const Record *Rec, const Twine &Msg)``:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 Prints the message followed by the source line associated with the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 specified record (see `Record`_).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 * ``PrintError(const RecordVal *RecVal, const Twine &Msg)``:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 Prints the message followed by the source line associated with the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 specified record field (see `RecordVal`_).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
712
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 Using these functions, the goal is to produce the most specific error report
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 possible.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
715
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 Debugging Tools
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 ===============
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
718
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 TableGen provides some tools to aid in debugging backends.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 The ``PrintRecords`` Backend
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 ----------------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
723
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 The TableGen command option ``--print-records`` invokes a simple backend
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 that prints all the classes and records defined in the source files. This is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 the default backend option. The format of the output is guaranteed to be
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 constant over time, so that the output can be compared in tests. The output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 looks like this:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
729
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
731
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 ------------- Classes -----------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 class XEntry<string XEntry:str = ?, int XEntry:val1 = ?> { // XBase
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 string Str = XEntry:str;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 bits<8> Val1 = { !cast<bits<8>>(XEntry:val1){7}, ... };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 bit Val3 = 1;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 ------------- Defs -----------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 def ATable { // GenericTable
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 string FilterClass = "AEntry";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 string CppTypeName = "AEntry";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 list<string> Fields = ["Str", "Val1", "Val2"];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 list<string> PrimaryKey = ["Val1", "Val2"];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 string PrimaryKeyName = "lookupATableByValues";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 bit PrimaryKeyEarlyOut = 0;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 def anonymous_0 { // AEntry
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 string Str = "Bob";
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 bits<8> Val1 = { 0, 0, 0, 0, 0, 1, 0, 1 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 bits<10> Val2 = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
755
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 Classes are shown with their template arguments, parent classes (following
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 ``//``), and fields. Records are shown with their parent classes and
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 fields. Note that anonymous records are named ``anonymous_0``,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 ``anonymous_1``, etc.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 The ``PrintDetailedRecords`` Backend
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 ------------------------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 The TableGen command option ``--print-detailed-records`` invokes a backend
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 that prints all the global variables, classes, and records defined in the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 source files. The format of the output is *not* guaranteed to be constant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 over time. The output looks like this.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
768
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
770
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 DETAILED RECORDS for file llvm-project\llvm\lib\target\arc\arc.td
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
772
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 -------------------- Global Variables (5) --------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
774
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 AMDGPUBufferIntrinsics = [int_amdgcn_buffer_load_format, ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 AMDGPUImageDimAtomicIntrinsics = [int_amdgcn_image_atomic_swap_1d, ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 -------------------- Classes (758) --------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
779
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 AMDGPUBufferLoad |IntrinsicsAMDGPU.td:879|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 Template args:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 LLVMType AMDGPUBufferLoad:data_ty = llvm_any_ty |IntrinsicsAMDGPU.td:879|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 Superclasses: (SDPatternOperator) Intrinsic AMDGPURsrcIntrinsic
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 Fields:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 list<SDNodeProperty> Properties = [SDNPMemOperand] |Intrinsics.td:348|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 string LLVMName = "" |Intrinsics.td:343|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 -------------------- Records (12303) --------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
789
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 AMDGPUSample_lz_o |IntrinsicsAMDGPU.td:560|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 Defm sequence: |IntrinsicsAMDGPU.td:584| |IntrinsicsAMDGPU.td:566|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 Superclasses: AMDGPUSampleVariant
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 Fields:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 string UpperCaseMod = "_LZ_O" |IntrinsicsAMDGPU.td:542|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 string LowerCaseMod = "_lz_o" |IntrinsicsAMDGPU.td:543|
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 ...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
797
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 * Global variables defined with outer ``defvar`` statements are shown with
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 their values.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
800
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 * The classes are shown with their source location, template arguments,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 superclasses, and fields.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
803
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 * The records are shown with their source location, ``defm`` sequence,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
805 superclasses, and fields.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
806
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 Superclasses are shown in the order processed, with indirect superclasses in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 parentheses. Each field is shown with its value and the source location at
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 which it was set.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 The ``defm`` sequence gives the locations of the ``defm`` statements that
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 were involved in generating the record, in the order they were invoked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
812
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 Timing TableGen Phases
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 ----------------------
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
815
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
816 TableGen provides a phase timing feature that produces a report of the time
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 used by the various phases of parsing the source files and running the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 selected backend. This feature is enabled with the ``--time-phases`` option
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 of the TableGen command.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
820
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 If the backend is *not* instrumented for timing, then a report such as the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 following is produced. This is the timing for the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 ``--print-detailed-records`` backend run on the AMDGPU target.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
824
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
826
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 ===-------------------------------------------------------------------------===
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 TableGen Phase Timing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
829 ===-------------------------------------------------------------------------===
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 Total Execution Time: 101.0106 seconds (102.4819 wall clock)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
831
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 85.5197 ( 84.9%) 0.1560 ( 50.0%) 85.6757 ( 84.8%) 85.7009 ( 83.6%) Backend overall
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 15.1789 ( 15.1%) 0.0000 ( 0.0%) 15.1789 ( 15.0%) 15.1829 ( 14.8%) Parse, build records
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 0.0000 ( 0.0%) 0.1560 ( 50.0%) 0.1560 ( 0.2%) 1.5981 ( 1.6%) Write output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 100.6986 (100.0%) 0.3120 (100.0%) 101.0106 (100.0%) 102.4819 (100.0%) Total
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
837
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 Note that all the time for the backend is lumped under "Backend overall".
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
839
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 If the backend is instrumented for timing, then its processing is
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 divided into phases and each one timed separately. This is the timing for
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 the ``--emit-dag-isel`` backend run on the AMDGPU target.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
843
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 .. code-block:: text
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
845
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 ===-------------------------------------------------------------------------===
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 TableGen Phase Timing
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 ===-------------------------------------------------------------------------===
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 Total Execution Time: 746.3868 seconds (747.1447 wall clock)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
850
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 ---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 657.7938 ( 88.1%) 0.1404 ( 90.0%) 657.9342 ( 88.1%) 658.6497 ( 88.2%) Emit matcher table
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 70.2317 ( 9.4%) 0.0000 ( 0.0%) 70.2317 ( 9.4%) 70.2700 ( 9.4%) Convert to matchers
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 14.8825 ( 2.0%) 0.0156 ( 10.0%) 14.8981 ( 2.0%) 14.9009 ( 2.0%) Parse, build records
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 2.1840 ( 0.3%) 0.0000 ( 0.0%) 2.1840 ( 0.3%) 2.1791 ( 0.3%) Sort patterns
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 1.1388 ( 0.2%) 0.0000 ( 0.0%) 1.1388 ( 0.2%) 1.1401 ( 0.2%) Optimize matchers
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 0.0000 ( 0.0%) 0.0000 ( 0.0%) 0.0000 ( 0.0%) 0.0050 ( 0.0%) Write output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 746.2308 (100.0%) 0.1560 (100.0%) 746.3868 (100.0%) 747.1447 (100.0%) Total
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
859
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 The backend has been divided into four phases and timed separately.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
861
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 If you want to instrument a backend, refer to the backend ``DAGISelEmitter.cpp``
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 and search for ``Records.startTimer``.