]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/include/llvm/Target/TargetSchedule.td
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / include / llvm / Target / TargetSchedule.td
1 //===- TargetSchedule.td - Target Independent Scheduling ---*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the target-independent scheduling interfaces which should
11 // be implemented by each target which is using TableGen based scheduling.
12 //
13 // The SchedMachineModel is defined by subtargets for three categories of data:
14 // 1. Basic properties for coarse grained instruction cost model.
15 // 2. Scheduler Read/Write resources for simple per-opcode cost model.
16 // 3. Instruction itineraties for detailed reservation tables.
17 //
18 // (1) Basic properties are defined by the SchedMachineModel
19 // class. Target hooks allow subtargets to associate opcodes with
20 // those properties.
21 //
22 // (2) A per-operand machine model can be implemented in any
23 // combination of the following ways:
24 //
25 // A. Associate per-operand SchedReadWrite types with Instructions by
26 // modifying the Instruction definition to inherit from Sched. For
27 // each subtarget, define WriteRes and ReadAdvance to associate
28 // processor resources and latency with each SchedReadWrite type.
29 //
30 // B. In each instruction definition, name an ItineraryClass. For each
31 // subtarget, define ItinRW entries to map ItineraryClass to
32 // per-operand SchedReadWrite types. Unlike method A, these types may
33 // be subtarget specific and can be directly associated with resources
34 // by defining SchedWriteRes and SchedReadAdvance.
35 //
36 // C. In the subtarget, map SchedReadWrite types to specific
37 // opcodes. This overrides any SchedReadWrite types or
38 // ItineraryClasses defined by the Instruction. As in method B, the
39 // subtarget can directly associate resources with SchedReadWrite
40 // types by defining SchedWriteRes and SchedReadAdvance.
41 //
42 // D. In either the target or subtarget, define SchedWriteVariant or
43 // SchedReadVariant to map one SchedReadWrite type onto another
44 // sequence of SchedReadWrite types. This allows dynamic selection of
45 // an instruction's machine model via custom C++ code. It also allows
46 // a machine-independent SchedReadWrite type to map to a sequence of
47 // machine-dependent types.
48 //
49 // (3) A per-pipeline-stage machine model can be implemented by providing
50 // Itineraries in addition to mapping instructions to ItineraryClasses.
51 //===----------------------------------------------------------------------===//
52
53 // Include legacy support for instruction itineraries.
54 include "llvm/Target/TargetItinerary.td"
55
56 class Instruction; // Forward def
57
58 // DAG operator that interprets the DAG args as Instruction defs.
59 def instrs;
60
61 // DAG operator that interprets each DAG arg as a regex pattern for
62 // matching Instruction opcode names.
63 // The regex must match the beginning of the opcode (as in Python re.match).
64 // To avoid matching prefixes, append '$' to the pattern.
65 def instregex;
66
67 // Define the SchedMachineModel and provide basic properties for
68 // coarse grained instruction cost model. Default values for the
69 // properties are defined in MCSchedModel. A value of "-1" in the
70 // target description's SchedMachineModel indicates that the property
71 // is not overriden by the target.
72 //
73 // Target hooks allow subtargets to associate LoadLatency and
74 // HighLatency with groups of opcodes.
75 class SchedMachineModel {
76   int IssueWidth = -1; // Max micro-ops that may be scheduled per cycle.
77   int MinLatency = -1; // Determines which instrucions are allowed in a group.
78                        // (-1) inorder (0) ooo, (1): inorder +var latencies.
79   int ILPWindow = -1;  // Cycles of latency likely hidden by hardware buffers.
80   int LoadLatency = -1; // Cycles for loads to access the cache.
81   int HighLatency = -1; // Approximation of cycles for "high latency" ops.
82   int MispredictPenalty = -1; // Extra cycles for a mispredicted branch.
83
84   // Per-cycle resources tables.
85   ProcessorItineraries Itineraries = NoItineraries;
86
87   bit NoModel = 0; // Special tag to indicate missing machine model.
88 }
89
90 def NoSchedModel : SchedMachineModel {
91   let NoModel = 1;
92 }
93
94 // Define a kind of processor resource that may be common across
95 // similar subtargets.
96 class ProcResourceKind;
97
98 // Define a number of interchangeable processor resources. NumUnits
99 // determines the throughput of instructions that require the resource.
100 //
101 // An optional Super resource may be given to model these resources as
102 // a subset of the more general super resources. Using one of these
103 // resources implies using one of the super resoruces.
104 //
105 // ProcResourceUnits normally model a few buffered resources within an
106 // out-of-order engine that the compiler attempts to conserve.
107 // Buffered resources may be held for multiple clock cycles, but the
108 // scheduler does not pin them to a particular clock cycle relative to
109 // instruction dispatch. Setting Buffered=0 changes this to an
110 // in-order resource. In this case, the scheduler counts down from the
111 // cycle that the instruction issues in-order, forcing an interlock
112 // with subsequent instructions that require the same resource until
113 // the number of ResourceCyles specified in WriteRes expire.
114 //
115 // SchedModel ties these units to a processor for any stand-alone defs
116 // of this class. Instances of subclass ProcResource will be automatically
117 // attached to a processor, so SchedModel is not needed.
118 class ProcResourceUnits<ProcResourceKind kind, int num> {
119   ProcResourceKind Kind = kind;
120   int NumUnits = num;
121   ProcResourceKind Super = ?;
122   bit Buffered = 1;
123   SchedMachineModel SchedModel = ?;
124 }
125
126 // EponymousProcResourceKind helps implement ProcResourceUnits by
127 // allowing a ProcResourceUnits definition to reference itself. It
128 // should not be referenced anywhere else.
129 def EponymousProcResourceKind : ProcResourceKind;
130
131 // Subtargets typically define processor resource kind and number of
132 // units in one place.
133 class ProcResource<int num> : ProcResourceKind,
134   ProcResourceUnits<EponymousProcResourceKind, num>;
135
136 class ProcResGroup<list<ProcResource> resources> : ProcResourceKind {
137   list<ProcResource> Resources = resources;
138   SchedMachineModel SchedModel = ?;
139 }
140
141 // A target architecture may define SchedReadWrite types and associate
142 // them with instruction operands.
143 class SchedReadWrite;
144
145 // List the per-operand types that map to the machine model of an
146 // instruction. One SchedWrite type must be listed for each explicit
147 // def operand in order. Additional SchedWrite types may optionally be
148 // listed for implicit def operands.  SchedRead types may optionally
149 // be listed for use operands in order. The order of defs relative to
150 // uses is insignificant. This way, the same SchedReadWrite list may
151 // be used for multiple forms of an operation. For example, a
152 // two-address instruction could have two tied operands or single
153 // operand that both reads and writes a reg. In both cases we have a
154 // single SchedWrite and single SchedRead in any order.
155 class Sched<list<SchedReadWrite> schedrw> {
156   list<SchedReadWrite> SchedRW = schedrw;
157 }
158
159 // Define a scheduler resource associated with a def operand.
160 class SchedWrite : SchedReadWrite;
161 def NoWrite : SchedWrite;
162
163 // Define a scheduler resource associated with a use operand.
164 class SchedRead  : SchedReadWrite;
165
166 // Define a SchedWrite that is modeled as a sequence of other
167 // SchedWrites with additive latency. This allows a single operand to
168 // be mapped the resources composed from a set of previously defined
169 // SchedWrites.
170 //
171 // If the final write in this sequence is a SchedWriteVariant marked
172 // Variadic, then the list of prior writes are distributed across all
173 // operands after resolving the predicate for the final write.
174 //
175 // SchedModel silences warnings but is ignored.
176 class WriteSequence<list<SchedWrite> writes, int rep = 1> : SchedWrite {
177   list<SchedWrite> Writes = writes;
178   int Repeat = rep;
179   SchedMachineModel SchedModel = ?;
180 }
181
182 // Define values common to WriteRes and SchedWriteRes.
183 //
184 // SchedModel ties these resources to a processor.
185 class ProcWriteResources<list<ProcResourceKind> resources> {
186   list<ProcResourceKind> ProcResources = resources;
187   list<int> ResourceCycles = [];
188   int Latency = 1;
189   int NumMicroOps = 1;
190   bit BeginGroup = 0;
191   bit EndGroup = 0;
192   // Allow a processor to mark some scheduling classes as unsupported
193   // for stronger verification.
194   bit Unsupported = 0;
195   SchedMachineModel SchedModel = ?;
196 }
197
198 // Define the resources and latency of a SchedWrite. This will be used
199 // directly by targets that have no itinerary classes. In this case,
200 // SchedWrite is defined by the target, while WriteResources is
201 // defined by the subtarget, and maps the SchedWrite to processor
202 // resources.
203 //
204 // If a target already has itinerary classes, SchedWriteResources can
205 // be used instead to define subtarget specific SchedWrites and map
206 // them to processor resources in one place. Then ItinRW can map
207 // itinerary classes to the subtarget's SchedWrites.
208 //
209 // ProcResources indicates the set of resources consumed by the write.
210 // Optionally, ResourceCycles indicates the number of cycles the
211 // resource is consumed. Each ResourceCycles item is paired with the
212 // ProcResource item at the same position in its list. Since
213 // ResourceCycles are rarely specialized, the list may be
214 // incomplete. By default, resources are consumed for a single cycle,
215 // regardless of latency, which models a fully pipelined processing
216 // unit. A value of 0 for ResourceCycles means that the resource must
217 // be available but is not consumed, which is only relevant for
218 // unbuffered resources.
219 //
220 // By default, each SchedWrite takes one micro-op, which is counted
221 // against the processor's IssueWidth limit. If an instruction can
222 // write multiple registers with a single micro-op, the subtarget
223 // should define one of the writes to be zero micro-ops. If a
224 // subtarget requires multiple micro-ops to write a single result, it
225 // should either override the write's NumMicroOps to be greater than 1
226 // or require additional writes. Extra writes can be required either
227 // by defining a WriteSequence, or simply listing extra writes in the
228 // instruction's list of writers beyond the number of "def"
229 // operands. The scheduler assumes that all micro-ops must be
230 // dispatched in the same cycle. These micro-ops may be required to
231 // begin or end the current dispatch group.
232 class WriteRes<SchedWrite write, list<ProcResourceKind> resources>
233   : ProcWriteResources<resources> {
234   SchedWrite WriteType = write;
235 }
236
237 // Directly name a set of WriteResources defining a new SchedWrite
238 // type at the same time. This class is unaware of its SchedModel so
239 // must be referenced by InstRW or ItinRW.
240 class SchedWriteRes<list<ProcResourceKind> resources> : SchedWrite,
241   ProcWriteResources<resources>;
242
243 // Define values common to ReadAdvance and SchedReadAdvance.
244 //
245 // SchedModel ties these resources to a processor.
246 class ProcReadAdvance<int cycles, list<SchedWrite> writes = []> {
247   int Cycles = cycles;
248   list<SchedWrite> ValidWrites = writes;
249   // Allow a processor to mark some scheduling classes as unsupported
250   // for stronger verification.
251   bit Unsupported = 0;
252   SchedMachineModel SchedModel = ?;
253 }
254
255 // A processor may define a ReadAdvance associated with a SchedRead
256 // to reduce latency of a prior write by N cycles. A negative advance
257 // effectively increases latency, which may be used for cross-domain
258 // stalls.
259 //
260 // A ReadAdvance may be associated with a list of SchedWrites
261 // to implement pipeline bypass. The Writes list may be empty to
262 // indicate operands that are always read this number of Cycles later
263 // than a normal register read, allowing the read's parent instruction
264 // to issue earlier relative to the writer.
265 class ReadAdvance<SchedRead read, int cycles, list<SchedWrite> writes = []>
266   : ProcReadAdvance<cycles, writes> {
267   SchedRead ReadType = read;
268 }
269
270 // Directly associate a new SchedRead type with a delay and optional
271 // pipeline bypess. For use with InstRW or ItinRW.
272 class SchedReadAdvance<int cycles, list<SchedWrite> writes = []> : SchedRead,
273   ProcReadAdvance<cycles, writes>;
274
275 // Define SchedRead defaults. Reads seldom need special treatment.
276 def ReadDefault : SchedRead;
277 def NoReadAdvance : SchedReadAdvance<0>;
278
279 // Define shared code that will be in the same scope as all
280 // SchedPredicates. Available variables are:
281 // (const MachineInstr *MI, const TargetSchedModel *SchedModel)
282 class PredicateProlog<code c> {
283   code Code = c;
284 }
285
286 // Define a predicate to determine which SchedVariant applies to a
287 // particular MachineInstr. The code snippet is used as an
288 // if-statement's expression. Available variables are MI, SchedModel,
289 // and anything defined in a PredicateProlog.
290 //
291 // SchedModel silences warnings but is ignored.
292 class SchedPredicate<code pred> {
293   SchedMachineModel SchedModel = ?;
294   code Predicate = pred;
295 }
296 def NoSchedPred : SchedPredicate<[{true}]>;
297
298 // Associate a predicate with a list of SchedReadWrites. By default,
299 // the selected SchedReadWrites are still associated with a single
300 // operand and assumed to execute sequentially with additive
301 // latency. However, if the parent SchedWriteVariant or
302 // SchedReadVariant is marked "Variadic", then each Selected
303 // SchedReadWrite is mapped in place to the instruction's variadic
304 // operands. In this case, latency is not additive. If the current Variant
305 // is already part of a Sequence, then that entire chain leading up to
306 // the Variant is distributed over the variadic operands.
307 class SchedVar<SchedPredicate pred, list<SchedReadWrite> selected> {
308   SchedPredicate Predicate = pred;
309   list<SchedReadWrite> Selected = selected;
310 }
311
312 // SchedModel silences warnings but is ignored.
313 class SchedVariant<list<SchedVar> variants> {
314   list<SchedVar> Variants = variants;
315   bit Variadic = 0;
316   SchedMachineModel SchedModel = ?;
317 }
318
319 // A SchedWriteVariant is a single SchedWrite type that maps to a list
320 // of SchedWrite types under the conditions defined by its predicates.
321 //
322 // A Variadic write is expanded to cover multiple "def" operands. The
323 // SchedVariant's Expansion list is then interpreted as one write
324 // per-operand instead of the usual sequential writes feeding a single
325 // operand.
326 class SchedWriteVariant<list<SchedVar> variants> : SchedWrite,
327   SchedVariant<variants> {
328 }
329
330 // A SchedReadVariant is a single SchedRead type that maps to a list
331 // of SchedRead types under the conditions defined by its predicates.
332 //
333 // A Variadic write is expanded to cover multiple "readsReg" operands as
334 // explained above.
335 class SchedReadVariant<list<SchedVar> variants> : SchedRead,
336   SchedVariant<variants> {
337 }
338
339 // Map a set of opcodes to a list of SchedReadWrite types. This allows
340 // the subtarget to easily override specific operations.
341 //
342 // SchedModel ties this opcode mapping to a processor.
343 class InstRW<list<SchedReadWrite> rw, dag instrlist> {
344   list<SchedReadWrite> OperandReadWrites = rw;
345   dag Instrs = instrlist;
346   SchedMachineModel SchedModel = ?;
347 }
348
349 // Map a set of itinerary classes to SchedReadWrite resources. This is
350 // used to bootstrap a target (e.g. ARM) when itineraries already
351 // exist and changing InstrInfo is undesirable.
352 //
353 // SchedModel ties this ItineraryClass mapping to a processor.
354 class ItinRW<list<SchedReadWrite> rw, list<InstrItinClass> iic> {
355   list<InstrItinClass> MatchedItinClasses = iic;
356   list<SchedReadWrite> OperandReadWrites = rw;
357   SchedMachineModel SchedModel = ?;
358 }
359
360 // Alias a target-defined SchedReadWrite to a processor specific
361 // SchedReadWrite. This allows a subtarget to easily map a
362 // SchedReadWrite type onto a WriteSequence, SchedWriteVariant, or
363 // SchedReadVariant.
364 //
365 // SchedModel will usually be provided by surrounding let statement
366 // and ties this SchedAlias mapping to a processor.
367 class SchedAlias<SchedReadWrite match, SchedReadWrite alias> {
368   SchedReadWrite MatchRW = match;
369   SchedReadWrite AliasRW = alias;
370   SchedMachineModel SchedModel = ?;
371 }