Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- TargetSchedule.td - Target Independent Scheduling ---*- tablegen -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the target-independent scheduling interfaces which should |
| 10 | // be implemented by each target which is using TableGen based scheduling. |
| 11 | // |
| 12 | // The SchedMachineModel is defined by subtargets for three categories of data: |
| 13 | // 1. Basic properties for coarse grained instruction cost model. |
| 14 | // 2. Scheduler Read/Write resources for simple per-opcode cost model. |
| 15 | // 3. Instruction itineraries for detailed reservation tables. |
| 16 | // |
| 17 | // (1) Basic properties are defined by the SchedMachineModel |
| 18 | // class. Target hooks allow subtargets to associate opcodes with |
| 19 | // those properties. |
| 20 | // |
| 21 | // (2) A per-operand machine model can be implemented in any |
| 22 | // combination of the following ways: |
| 23 | // |
| 24 | // A. Associate per-operand SchedReadWrite types with Instructions by |
| 25 | // modifying the Instruction definition to inherit from Sched. For |
| 26 | // each subtarget, define WriteRes and ReadAdvance to associate |
| 27 | // processor resources and latency with each SchedReadWrite type. |
| 28 | // |
| 29 | // B. In each instruction definition, name an ItineraryClass. For each |
| 30 | // subtarget, define ItinRW entries to map ItineraryClass to |
| 31 | // per-operand SchedReadWrite types. Unlike method A, these types may |
| 32 | // be subtarget specific and can be directly associated with resources |
| 33 | // by defining SchedWriteRes and SchedReadAdvance. |
| 34 | // |
| 35 | // C. In the subtarget, map SchedReadWrite types to specific |
| 36 | // opcodes. This overrides any SchedReadWrite types or |
| 37 | // ItineraryClasses defined by the Instruction. As in method B, the |
| 38 | // subtarget can directly associate resources with SchedReadWrite |
| 39 | // types by defining SchedWriteRes and SchedReadAdvance. |
| 40 | // |
| 41 | // D. In either the target or subtarget, define SchedWriteVariant or |
| 42 | // SchedReadVariant to map one SchedReadWrite type onto another |
| 43 | // sequence of SchedReadWrite types. This allows dynamic selection of |
| 44 | // an instruction's machine model via custom C++ code. It also allows |
| 45 | // a machine-independent SchedReadWrite type to map to a sequence of |
| 46 | // machine-dependent types. |
| 47 | // |
| 48 | // (3) A per-pipeline-stage machine model can be implemented by providing |
| 49 | // Itineraries in addition to mapping instructions to ItineraryClasses. |
| 50 | //===----------------------------------------------------------------------===// |
| 51 | |
| 52 | // Include legacy support for instruction itineraries. |
| 53 | include "llvm/Target/TargetItinerary.td" |
| 54 | |
| 55 | class Instruction; // Forward def |
| 56 | |
| 57 | class Predicate; // Forward def |
| 58 | |
| 59 | // DAG operator that interprets the DAG args as Instruction defs. |
| 60 | def instrs; |
| 61 | |
| 62 | // DAG operator that interprets each DAG arg as a regex pattern for |
| 63 | // matching Instruction opcode names. |
| 64 | // The regex must match the beginning of the opcode (as in Python re.match). |
| 65 | // To avoid matching prefixes, append '$' to the pattern. |
| 66 | def instregex; |
| 67 | |
| 68 | // Define the SchedMachineModel and provide basic properties for |
| 69 | // coarse grained instruction cost model. Default values for the |
| 70 | // properties are defined in MCSchedModel. A value of "-1" in the |
| 71 | // target description's SchedMachineModel indicates that the property |
| 72 | // is not overriden by the target. |
| 73 | // |
| 74 | // Target hooks allow subtargets to associate LoadLatency and |
| 75 | // HighLatency with groups of opcodes. |
| 76 | // |
| 77 | // See MCSchedule.h for detailed comments. |
| 78 | class SchedMachineModel { |
| 79 | int IssueWidth = -1; // Max micro-ops that may be scheduled per cycle. |
| 80 | int MicroOpBufferSize = -1; // Max micro-ops that can be buffered. |
| 81 | int LoopMicroOpBufferSize = -1; // Max micro-ops that can be buffered for |
| 82 | // optimized loop dispatch/execution. |
| 83 | int LoadLatency = -1; // Cycles for loads to access the cache. |
| 84 | int HighLatency = -1; // Approximation of cycles for "high latency" ops. |
| 85 | int MispredictPenalty = -1; // Extra cycles for a mispredicted branch. |
| 86 | |
| 87 | // Per-cycle resources tables. |
| 88 | ProcessorItineraries Itineraries = NoItineraries; |
| 89 | |
| 90 | bit PostRAScheduler = 0; // Enable Post RegAlloc Scheduler pass. |
| 91 | |
| 92 | // Subtargets that define a model for only a subset of instructions |
| 93 | // that have a scheduling class (itinerary class or SchedRW list) |
| 94 | // and may actually be generated for that subtarget must clear this |
| 95 | // bit. Otherwise, the scheduler considers an unmodelled opcode to |
| 96 | // be an error. This should only be set during initial bringup, |
| 97 | // or there will be no way to catch simple errors in the model |
| 98 | // resulting from changes to the instruction definitions. |
| 99 | bit CompleteModel = 1; |
| 100 | |
| 101 | // Indicates that we should do full overlap checking for multiple InstrRWs |
| 102 | // definining the same instructions within the same SchedMachineModel. |
| 103 | // FIXME: Remove when all in tree targets are clean with the full check |
| 104 | // enabled. |
| 105 | bit FullInstRWOverlapCheck = 1; |
| 106 | |
| 107 | // A processor may only implement part of published ISA, due to either new ISA |
| 108 | // extensions, (e.g. Pentium 4 doesn't have AVX) or implementation |
| 109 | // (ARM/MIPS/PowerPC/SPARC soft float cores). |
| 110 | // |
| 111 | // For a processor which doesn't support some feature(s), the schedule model |
| 112 | // can use: |
| 113 | // |
| 114 | // let<Predicate> UnsupportedFeatures = [HaveA,..,HaveY]; |
| 115 | // |
| 116 | // to skip the checks for scheduling information when building LLVM for |
| 117 | // instructions which have any of the listed predicates in their Predicates |
| 118 | // field. |
| 119 | list<Predicate> UnsupportedFeatures = []; |
| 120 | |
| 121 | bit NoModel = 0; // Special tag to indicate missing machine model. |
| 122 | } |
| 123 | |
| 124 | def NoSchedModel : SchedMachineModel { |
| 125 | let NoModel = 1; |
| 126 | let CompleteModel = 0; |
| 127 | } |
| 128 | |
| 129 | // Define a kind of processor resource that may be common across |
| 130 | // similar subtargets. |
| 131 | class ProcResourceKind; |
| 132 | |
| 133 | // Define a number of interchangeable processor resources. NumUnits |
| 134 | // determines the throughput of instructions that require the resource. |
| 135 | // |
| 136 | // An optional Super resource may be given to model these resources as |
| 137 | // a subset of the more general super resources. Using one of these |
| 138 | // resources implies using one of the super resoruces. |
| 139 | // |
| 140 | // ProcResourceUnits normally model a few buffered resources within an |
| 141 | // out-of-order engine. Buffered resources may be held for multiple |
| 142 | // clock cycles, but the scheduler does not pin them to a particular |
| 143 | // clock cycle relative to instruction dispatch. Setting BufferSize=0 |
| 144 | // changes this to an in-order issue/dispatch resource. In this case, |
| 145 | // the scheduler counts down from the cycle that the instruction |
| 146 | // issues in-order, forcing a stall whenever a subsequent instruction |
| 147 | // requires the same resource until the number of ResourceCycles |
| 148 | // specified in WriteRes expire. Setting BufferSize=1 changes this to |
| 149 | // an in-order latency resource. In this case, the scheduler models |
| 150 | // producer/consumer stalls between instructions that use the |
| 151 | // resource. |
| 152 | // |
| 153 | // Examples (all assume an out-of-order engine): |
| 154 | // |
| 155 | // Use BufferSize = -1 for "issue ports" fed by a unified reservation |
| 156 | // station. Here the size of the reservation station is modeled by |
| 157 | // MicroOpBufferSize, which should be the minimum size of either the |
| 158 | // register rename pool, unified reservation station, or reorder |
| 159 | // buffer. |
| 160 | // |
| 161 | // Use BufferSize = 0 for resources that force "dispatch/issue |
| 162 | // groups". (Different processors define dispath/issue |
| 163 | // differently. Here we refer to stage between decoding into micro-ops |
| 164 | // and moving them into a reservation station.) Normally NumMicroOps |
| 165 | // is sufficient to limit dispatch/issue groups. However, some |
| 166 | // processors can form groups of with only certain combinitions of |
| 167 | // instruction types. e.g. POWER7. |
| 168 | // |
| 169 | // Use BufferSize = 1 for in-order execution units. This is used for |
| 170 | // an in-order pipeline within an out-of-order core where scheduling |
| 171 | // dependent operations back-to-back is guaranteed to cause a |
| 172 | // bubble. e.g. Cortex-a9 floating-point. |
| 173 | // |
| 174 | // Use BufferSize > 1 for out-of-order executions units with a |
| 175 | // separate reservation station. This simply models the size of the |
| 176 | // reservation station. |
| 177 | // |
| 178 | // To model both dispatch/issue groups and in-order execution units, |
| 179 | // create two types of units, one with BufferSize=0 and one with |
| 180 | // BufferSize=1. |
| 181 | // |
| 182 | // SchedModel ties these units to a processor for any stand-alone defs |
| 183 | // of this class. |
| 184 | class ProcResourceUnits<ProcResourceKind kind, int num> { |
| 185 | ProcResourceKind Kind = kind; |
| 186 | int NumUnits = num; |
| 187 | ProcResourceKind Super = ?; |
| 188 | int BufferSize = -1; |
| 189 | SchedMachineModel SchedModel = ?; |
| 190 | } |
| 191 | |
| 192 | // EponymousProcResourceKind helps implement ProcResourceUnits by |
| 193 | // allowing a ProcResourceUnits definition to reference itself. It |
| 194 | // should not be referenced anywhere else. |
| 195 | def EponymousProcResourceKind : ProcResourceKind; |
| 196 | |
| 197 | // Subtargets typically define processor resource kind and number of |
| 198 | // units in one place. |
| 199 | class ProcResource<int num> : ProcResourceKind, |
| 200 | ProcResourceUnits<EponymousProcResourceKind, num>; |
| 201 | |
| 202 | class ProcResGroup<list<ProcResource> resources> : ProcResourceKind { |
| 203 | list<ProcResource> Resources = resources; |
| 204 | SchedMachineModel SchedModel = ?; |
| 205 | int BufferSize = -1; |
| 206 | } |
| 207 | |
| 208 | // A target architecture may define SchedReadWrite types and associate |
| 209 | // them with instruction operands. |
| 210 | class SchedReadWrite; |
| 211 | |
| 212 | // List the per-operand types that map to the machine model of an |
| 213 | // instruction. One SchedWrite type must be listed for each explicit |
| 214 | // def operand in order. Additional SchedWrite types may optionally be |
| 215 | // listed for implicit def operands. SchedRead types may optionally |
| 216 | // be listed for use operands in order. The order of defs relative to |
| 217 | // uses is insignificant. This way, the same SchedReadWrite list may |
| 218 | // be used for multiple forms of an operation. For example, a |
| 219 | // two-address instruction could have two tied operands or single |
| 220 | // operand that both reads and writes a reg. In both cases we have a |
| 221 | // single SchedWrite and single SchedRead in any order. |
| 222 | class Sched<list<SchedReadWrite> schedrw> { |
| 223 | list<SchedReadWrite> SchedRW = schedrw; |
| 224 | } |
| 225 | |
| 226 | // Define a scheduler resource associated with a def operand. |
| 227 | class SchedWrite : SchedReadWrite; |
| 228 | def NoWrite : SchedWrite; |
| 229 | |
| 230 | // Define a scheduler resource associated with a use operand. |
| 231 | class SchedRead : SchedReadWrite; |
| 232 | |
| 233 | // Define a SchedWrite that is modeled as a sequence of other |
| 234 | // SchedWrites with additive latency. This allows a single operand to |
| 235 | // be mapped the resources composed from a set of previously defined |
| 236 | // SchedWrites. |
| 237 | // |
| 238 | // If the final write in this sequence is a SchedWriteVariant marked |
| 239 | // Variadic, then the list of prior writes are distributed across all |
| 240 | // operands after resolving the predicate for the final write. |
| 241 | // |
| 242 | // SchedModel silences warnings but is ignored. |
| 243 | class WriteSequence<list<SchedWrite> writes, int rep = 1> : SchedWrite { |
| 244 | list<SchedWrite> Writes = writes; |
| 245 | int Repeat = rep; |
| 246 | SchedMachineModel SchedModel = ?; |
| 247 | } |
| 248 | |
| 249 | // Define values common to WriteRes and SchedWriteRes. |
| 250 | // |
| 251 | // SchedModel ties these resources to a processor. |
| 252 | class ProcWriteResources<list<ProcResourceKind> resources> { |
| 253 | list<ProcResourceKind> ProcResources = resources; |
| 254 | list<int> ResourceCycles = []; |
| 255 | int Latency = 1; |
| 256 | int NumMicroOps = 1; |
| 257 | bit BeginGroup = 0; |
| 258 | bit EndGroup = 0; |
| 259 | // Allow a processor to mark some scheduling classes as unsupported |
| 260 | // for stronger verification. |
| 261 | bit Unsupported = 0; |
| 262 | // Allow a processor to mark some scheduling classes as single-issue. |
| 263 | // SingleIssue is an alias for Begin/End Group. |
| 264 | bit SingleIssue = 0; |
| 265 | SchedMachineModel SchedModel = ?; |
| 266 | } |
| 267 | |
| 268 | // Define the resources and latency of a SchedWrite. This will be used |
| 269 | // directly by targets that have no itinerary classes. In this case, |
| 270 | // SchedWrite is defined by the target, while WriteResources is |
| 271 | // defined by the subtarget, and maps the SchedWrite to processor |
| 272 | // resources. |
| 273 | // |
| 274 | // If a target already has itinerary classes, SchedWriteResources can |
| 275 | // be used instead to define subtarget specific SchedWrites and map |
| 276 | // them to processor resources in one place. Then ItinRW can map |
| 277 | // itinerary classes to the subtarget's SchedWrites. |
| 278 | // |
| 279 | // ProcResources indicates the set of resources consumed by the write. |
| 280 | // Optionally, ResourceCycles indicates the number of cycles the |
| 281 | // resource is consumed. Each ResourceCycles item is paired with the |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 282 | // ProcResource item at the same position in its list. ResourceCycles |
| 283 | // can be `[]`: in that case, all resources are consumed for a single |
| 284 | // cycle, regardless of latency, which models a fully pipelined processing |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 285 | // unit. A value of 0 for ResourceCycles means that the resource must |
| 286 | // be available but is not consumed, which is only relevant for |
| 287 | // unbuffered resources. |
| 288 | // |
| 289 | // By default, each SchedWrite takes one micro-op, which is counted |
| 290 | // against the processor's IssueWidth limit. If an instruction can |
| 291 | // write multiple registers with a single micro-op, the subtarget |
| 292 | // should define one of the writes to be zero micro-ops. If a |
| 293 | // subtarget requires multiple micro-ops to write a single result, it |
| 294 | // should either override the write's NumMicroOps to be greater than 1 |
| 295 | // or require additional writes. Extra writes can be required either |
| 296 | // by defining a WriteSequence, or simply listing extra writes in the |
| 297 | // instruction's list of writers beyond the number of "def" |
| 298 | // operands. The scheduler assumes that all micro-ops must be |
| 299 | // dispatched in the same cycle. These micro-ops may be required to |
| 300 | // begin or end the current dispatch group. |
| 301 | class WriteRes<SchedWrite write, list<ProcResourceKind> resources> |
| 302 | : ProcWriteResources<resources> { |
| 303 | SchedWrite WriteType = write; |
| 304 | } |
| 305 | |
| 306 | // Directly name a set of WriteResources defining a new SchedWrite |
| 307 | // type at the same time. This class is unaware of its SchedModel so |
| 308 | // must be referenced by InstRW or ItinRW. |
| 309 | class SchedWriteRes<list<ProcResourceKind> resources> : SchedWrite, |
| 310 | ProcWriteResources<resources>; |
| 311 | |
| 312 | // Define values common to ReadAdvance and SchedReadAdvance. |
| 313 | // |
| 314 | // SchedModel ties these resources to a processor. |
| 315 | class ProcReadAdvance<int cycles, list<SchedWrite> writes = []> { |
| 316 | int Cycles = cycles; |
| 317 | list<SchedWrite> ValidWrites = writes; |
| 318 | // Allow a processor to mark some scheduling classes as unsupported |
| 319 | // for stronger verification. |
| 320 | bit Unsupported = 0; |
| 321 | SchedMachineModel SchedModel = ?; |
| 322 | } |
| 323 | |
| 324 | // A processor may define a ReadAdvance associated with a SchedRead |
| 325 | // to reduce latency of a prior write by N cycles. A negative advance |
| 326 | // effectively increases latency, which may be used for cross-domain |
| 327 | // stalls. |
| 328 | // |
| 329 | // A ReadAdvance may be associated with a list of SchedWrites |
| 330 | // to implement pipeline bypass. The Writes list may be empty to |
| 331 | // indicate operands that are always read this number of Cycles later |
| 332 | // than a normal register read, allowing the read's parent instruction |
| 333 | // to issue earlier relative to the writer. |
| 334 | class ReadAdvance<SchedRead read, int cycles, list<SchedWrite> writes = []> |
| 335 | : ProcReadAdvance<cycles, writes> { |
| 336 | SchedRead ReadType = read; |
| 337 | } |
| 338 | |
| 339 | // Directly associate a new SchedRead type with a delay and optional |
| 340 | // pipeline bypass. For use with InstRW or ItinRW. |
| 341 | class SchedReadAdvance<int cycles, list<SchedWrite> writes = []> : SchedRead, |
| 342 | ProcReadAdvance<cycles, writes>; |
| 343 | |
| 344 | // Define SchedRead defaults. Reads seldom need special treatment. |
| 345 | def ReadDefault : SchedRead; |
| 346 | def NoReadAdvance : SchedReadAdvance<0>; |
| 347 | |
| 348 | // Define shared code that will be in the same scope as all |
| 349 | // SchedPredicates. Available variables are: |
| 350 | // (const MachineInstr *MI, const TargetSchedModel *SchedModel) |
| 351 | class PredicateProlog<code c> { |
| 352 | code Code = c; |
| 353 | } |
| 354 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 355 | // Base class for scheduling predicates. |
| 356 | class SchedPredicateBase; |
| 357 | |
| 358 | // A scheduling predicate whose logic is defined by a MCInstPredicate. |
| 359 | // This can directly be used by SchedWriteVariant definitions. |
| 360 | class MCSchedPredicate<MCInstPredicate P> : SchedPredicateBase { |
| 361 | MCInstPredicate Pred = P; |
| 362 | SchedMachineModel SchedModel = ?; |
| 363 | } |
| 364 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 365 | // Define a predicate to determine which SchedVariant applies to a |
| 366 | // particular MachineInstr. The code snippet is used as an |
| 367 | // if-statement's expression. Available variables are MI, SchedModel, |
| 368 | // and anything defined in a PredicateProlog. |
| 369 | // |
| 370 | // SchedModel silences warnings but is ignored. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 371 | class SchedPredicate<code pred> : SchedPredicateBase { |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 372 | SchedMachineModel SchedModel = ?; |
| 373 | code Predicate = pred; |
| 374 | } |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 375 | |
| 376 | // Define a predicate to be typically used as the default case in a |
| 377 | // SchedVariant. It the SchedVariant does not use any other predicate based on |
| 378 | // MCSchedPredicate, this is the default scheduling case used by llvm-mca. |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 379 | def NoSchedPred : MCSchedPredicate<TruePred>; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 380 | |
| 381 | // Associate a predicate with a list of SchedReadWrites. By default, |
| 382 | // the selected SchedReadWrites are still associated with a single |
| 383 | // operand and assumed to execute sequentially with additive |
| 384 | // latency. However, if the parent SchedWriteVariant or |
| 385 | // SchedReadVariant is marked "Variadic", then each Selected |
| 386 | // SchedReadWrite is mapped in place to the instruction's variadic |
| 387 | // operands. In this case, latency is not additive. If the current Variant |
| 388 | // is already part of a Sequence, then that entire chain leading up to |
| 389 | // the Variant is distributed over the variadic operands. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 390 | class SchedVar<SchedPredicateBase pred, list<SchedReadWrite> selected> { |
| 391 | SchedPredicateBase Predicate = pred; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 392 | list<SchedReadWrite> Selected = selected; |
| 393 | } |
| 394 | |
| 395 | // SchedModel silences warnings but is ignored. |
| 396 | class SchedVariant<list<SchedVar> variants> { |
| 397 | list<SchedVar> Variants = variants; |
| 398 | bit Variadic = 0; |
| 399 | SchedMachineModel SchedModel = ?; |
| 400 | } |
| 401 | |
| 402 | // A SchedWriteVariant is a single SchedWrite type that maps to a list |
| 403 | // of SchedWrite types under the conditions defined by its predicates. |
| 404 | // |
| 405 | // A Variadic write is expanded to cover multiple "def" operands. The |
| 406 | // SchedVariant's Expansion list is then interpreted as one write |
| 407 | // per-operand instead of the usual sequential writes feeding a single |
| 408 | // operand. |
| 409 | class SchedWriteVariant<list<SchedVar> variants> : SchedWrite, |
| 410 | SchedVariant<variants> { |
| 411 | } |
| 412 | |
| 413 | // A SchedReadVariant is a single SchedRead type that maps to a list |
| 414 | // of SchedRead types under the conditions defined by its predicates. |
| 415 | // |
| 416 | // A Variadic write is expanded to cover multiple "readsReg" operands as |
| 417 | // explained above. |
| 418 | class SchedReadVariant<list<SchedVar> variants> : SchedRead, |
| 419 | SchedVariant<variants> { |
| 420 | } |
| 421 | |
| 422 | // Map a set of opcodes to a list of SchedReadWrite types. This allows |
| 423 | // the subtarget to easily override specific operations. |
| 424 | // |
| 425 | // SchedModel ties this opcode mapping to a processor. |
| 426 | class InstRW<list<SchedReadWrite> rw, dag instrlist> { |
| 427 | list<SchedReadWrite> OperandReadWrites = rw; |
| 428 | dag Instrs = instrlist; |
| 429 | SchedMachineModel SchedModel = ?; |
| 430 | // Allow a subtarget to mark some instructions as unsupported. |
| 431 | bit Unsupported = 0; |
| 432 | } |
| 433 | |
| 434 | // Map a set of itinerary classes to SchedReadWrite resources. This is |
| 435 | // used to bootstrap a target (e.g. ARM) when itineraries already |
| 436 | // exist and changing InstrInfo is undesirable. |
| 437 | // |
| 438 | // SchedModel ties this ItineraryClass mapping to a processor. |
| 439 | class ItinRW<list<SchedReadWrite> rw, list<InstrItinClass> iic> { |
| 440 | list<InstrItinClass> MatchedItinClasses = iic; |
| 441 | list<SchedReadWrite> OperandReadWrites = rw; |
| 442 | SchedMachineModel SchedModel = ?; |
| 443 | } |
| 444 | |
| 445 | // Alias a target-defined SchedReadWrite to a processor specific |
| 446 | // SchedReadWrite. This allows a subtarget to easily map a |
| 447 | // SchedReadWrite type onto a WriteSequence, SchedWriteVariant, or |
| 448 | // SchedReadVariant. |
| 449 | // |
| 450 | // SchedModel will usually be provided by surrounding let statement |
| 451 | // and ties this SchedAlias mapping to a processor. |
| 452 | class SchedAlias<SchedReadWrite match, SchedReadWrite alias> { |
| 453 | SchedReadWrite MatchRW = match; |
| 454 | SchedReadWrite AliasRW = alias; |
| 455 | SchedMachineModel SchedModel = ?; |
| 456 | } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 457 | |
| 458 | // Allow the definition of processor register files for register renaming |
| 459 | // purposes. |
| 460 | // |
| 461 | // Each processor register file declares: |
| 462 | // - The set of registers that can be renamed. |
| 463 | // - The number of physical registers which can be used for register renaming |
| 464 | // purpose. |
| 465 | // - The cost of a register rename. |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 466 | // - The set of registers that allow move elimination. |
| 467 | // - The maximum number of moves that can be eliminated every cycle. |
| 468 | // - Whether move elimination is limited to register moves whose input |
| 469 | // is known to be zero. |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 470 | // |
| 471 | // The cost of a rename is the number of physical registers allocated by the |
| 472 | // register alias table to map the new definition. By default, register can be |
| 473 | // renamed at the cost of a single physical register. Note that register costs |
| 474 | // are defined at register class granularity (see field `Costs`). |
| 475 | // |
| 476 | // The set of registers that are subject to register renaming is declared using |
| 477 | // a list of register classes (see field `RegClasses`). An empty list of |
| 478 | // register classes means: all the logical registers defined by the target can |
| 479 | // be fully renamed. |
| 480 | // |
| 481 | // A register R can be renamed if its register class appears in the `RegClasses` |
| 482 | // set. When R is written, a new alias is allocated at the cost of one or more |
| 483 | // physical registers; as a result, false dependencies on R are removed. |
| 484 | // |
| 485 | // A sub-register V of register R is implicitly part of the same register file. |
| 486 | // However, V is only renamed if its register class is part of `RegClasses`. |
| 487 | // Otherwise, the processor keeps it (as well as any other different part |
| 488 | // of R) together with R, and a write of V always causes a compulsory read of R. |
| 489 | // |
| 490 | // This is what happens for example on AMD processors (at least from Bulldozer |
| 491 | // onwards), where AL and AH are not treated as independent from AX, and AX is |
| 492 | // not treated as independent from EAX. A write to AL has an implicity false |
| 493 | // dependency on the last write to EAX (or a portion of EAX). As a consequence, |
| 494 | // a write to AL cannot go in parallel with a write to AH. |
| 495 | // |
| 496 | // There is no false dependency if the partial register write belongs to a |
| 497 | // register class that is in `RegClasses`. |
| 498 | // There is also no penalty for writes that "clear the content a super-register" |
| 499 | // (see MC/MCInstrAnalysis.h - method MCInstrAnalysis::clearsSuperRegisters()). |
| 500 | // On x86-64, 32-bit GPR writes implicitly zero the upper half of the underlying |
| 501 | // physical register, effectively removing any false dependencies with the |
| 502 | // previous register definition. |
| 503 | // |
| 504 | // TODO: This implementation assumes that there is no limit in the number of |
| 505 | // renames per cycle, which might not be true for all hardware or register |
| 506 | // classes. Also, there is no limit to how many times the same logical register |
| 507 | // can be renamed during the same cycle. |
| 508 | // |
| 509 | // TODO: we don't currently model merge penalties for the case where a write to |
| 510 | // a part of a register is followed by a read from a larger part of the same |
| 511 | // register. On some Intel chips, different parts of a GPR can be stored in |
| 512 | // different physical registers. However, there is a cost to pay for when the |
| 513 | // partial write is combined with the previous super-register definition. We |
| 514 | // should add support for these cases, and correctly model merge problems with |
| 515 | // partial register accesses. |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 516 | // |
| 517 | // Field MaxMovesEliminatedPerCycle specifies how many moves can be eliminated |
| 518 | // every cycle. A default value of zero for that field means: there is no limit |
| 519 | // to the number of moves that can be eliminated by this register file. |
| 520 | // |
| 521 | // An instruction MI is a candidate for move elimination if a call to |
| 522 | // method TargetSubtargetInfo::isOptimizableRegisterMove(MI) returns true (see |
| 523 | // llvm/CodeGen/TargetSubtargetInfo.h, and llvm/MC/MCInstrAnalysis.h). |
| 524 | // |
| 525 | // Subtargets can instantiate tablegen class IsOptimizableRegisterMove (see |
| 526 | // llvm/Target/TargetInstrPredicate.td) to customize the set of move elimination |
| 527 | // candidates. By default, no instruction is a valid move elimination candidate. |
| 528 | // |
| 529 | // A register move MI is eliminated only if: |
| 530 | // - MI is a move elimination candidate. |
| 531 | // - The destination register is from a register class that allows move |
| 532 | // elimination (see field `AllowMoveElimination` below). |
| 533 | // - Constraints on the move kind, and the maximum number of moves that can be |
| 534 | // eliminated per cycle are all met. |
| 535 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 536 | class RegisterFile<int numPhysRegs, list<RegisterClass> Classes = [], |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 537 | list<int> Costs = [], list<bit> AllowMoveElim = [], |
| 538 | int MaxMoveElimPerCy = 0, bit AllowZeroMoveElimOnly = 0> { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 539 | list<RegisterClass> RegClasses = Classes; |
| 540 | list<int> RegCosts = Costs; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 541 | list<bit> AllowMoveElimination = AllowMoveElim; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 542 | int NumPhysRegs = numPhysRegs; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 543 | int MaxMovesEliminatedPerCycle = MaxMoveElimPerCy; |
| 544 | bit AllowZeroMoveEliminationOnly = AllowZeroMoveElimOnly; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 545 | SchedMachineModel SchedModel = ?; |
| 546 | } |
| 547 | |
| 548 | // Describe the retire control unit. |
| 549 | // A retire control unit specifies the size of the reorder buffer, as well as |
| 550 | // the maximum number of opcodes that can be retired every cycle. |
| 551 | // A value less-than-or-equal-to zero for field 'ReorderBufferSize' means: "the |
| 552 | // size is unknown". The idea is that external tools can fall-back to using |
| 553 | // field MicroOpBufferSize in SchedModel if the reorder buffer size is unknown. |
| 554 | // A zero or negative value for field 'MaxRetirePerCycle' means "no |
| 555 | // restrictions on the number of instructions retired per cycle". |
| 556 | // Models can optionally specify up to one instance of RetireControlUnit per |
| 557 | // scheduling model. |
| 558 | class RetireControlUnit<int bufferSize, int retirePerCycle> { |
| 559 | int ReorderBufferSize = bufferSize; |
| 560 | int MaxRetirePerCycle = retirePerCycle; |
| 561 | SchedMachineModel SchedModel = ?; |
| 562 | } |
| 563 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 564 | // Base class for Load/StoreQueue. It is used to identify processor resources |
| 565 | // which describe load/store queues in the LS unit. |
| 566 | class MemoryQueue<ProcResource PR> { |
| 567 | ProcResource QueueDescriptor = PR; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 568 | SchedMachineModel SchedModel = ?; |
| 569 | } |
| 570 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 571 | class LoadQueue<ProcResource LDQueue> : MemoryQueue<LDQueue>; |
| 572 | class StoreQueue<ProcResource STQueue> : MemoryQueue<STQueue>; |