TargetSchedule.td 25 KB

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