LLVM 24.0.0git
MachineScheduler.h
Go to the documentation of this file.
1//===- MachineScheduler.h - MachineInstr Scheduling Pass --------*- C++ -*-===//
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 provides an interface for customizing the standard MachineScheduler
10// pass. Note that the entire pass may be replaced as follows:
11//
12// <Target>TargetMachine::createPassConfig(PassManagerBase &PM) {
13// PM.substitutePass(&MachineSchedulerID, &CustomSchedulerPassID);
14// ...}
15//
16// The MachineScheduler pass is only responsible for choosing the regions to be
17// scheduled. Targets can override the DAG builder and scheduler without
18// replacing the pass as follows:
19//
20// ScheduleDAGInstrs *<Target>TargetMachine::
21// createMachineScheduler(MachineSchedContext *C) {
22// return new CustomMachineScheduler(C);
23// }
24//
25// The default scheduler, ScheduleDAGMILive, builds the DAG and drives list
26// scheduling while updating the instruction stream, register pressure, and live
27// intervals. Most targets don't need to override the DAG builder and list
28// scheduler, but subtargets that require custom scheduling heuristics may
29// plugin an alternate MachineSchedStrategy. The strategy is responsible for
30// selecting the highest priority node from the list:
31//
32// ScheduleDAGInstrs *<Target>TargetMachine::
33// createMachineScheduler(MachineSchedContext *C) {
34// return new ScheduleDAGMILive(C, CustomStrategy(C));
35// }
36//
37// The DAG builder can also be customized in a sense by adding DAG mutations
38// that will run after DAG building and before list scheduling. DAG mutations
39// can adjust dependencies based on target-specific knowledge or add weak edges
40// to aid heuristics:
41//
42// ScheduleDAGInstrs *<Target>TargetMachine::
43// createMachineScheduler(MachineSchedContext *C) {
44// ScheduleDAGMI *DAG = createSchedLive(C);
45// DAG->addMutation(new CustomDAGMutation(...));
46// return DAG;
47// }
48//
49// A target that supports alternative schedulers can use the
50// MachineSchedRegistry to allow command line selection. This can be done by
51// implementing the following boilerplate:
52//
53// static ScheduleDAGInstrs *createCustomMachineSched(MachineSchedContext *C) {
54// return new CustomMachineScheduler(C);
55// }
56// static MachineSchedRegistry
57// SchedCustomRegistry("custom", "Run my target's custom scheduler",
58// createCustomMachineSched);
59//
60//
61// Finally, subtargets that don't need to implement custom heuristics but would
62// like to configure the GenericScheduler's policy for a given scheduler region,
63// including scheduling direction and register pressure tracking policy, can do
64// this:
65//
66// void <SubTarget>Subtarget::
67// overrideSchedPolicy(MachineSchedPolicy &Policy,
68// const SchedRegion &Region) const {
69// Policy.<Flag> = true;
70// }
71//
72//===----------------------------------------------------------------------===//
73
74#ifndef LLVM_CODEGEN_MACHINESCHEDULER_H
75#define LLVM_CODEGEN_MACHINESCHEDULER_H
76
77#include "llvm/ADT/APInt.h"
78#include "llvm/ADT/ArrayRef.h"
79#include "llvm/ADT/BitVector.h"
80#include "llvm/ADT/STLExtras.h"
82#include "llvm/ADT/StringRef.h"
83#include "llvm/ADT/Twine.h"
96#include <algorithm>
97#include <cassert>
98#include <list>
100#include <memory>
101#include <string>
102#include <vector>
103
104namespace llvm {
105namespace impl_detail {
106// FIXME: Remove these declarations once RegisterClassInfo is queryable as an
107// analysis.
111} // namespace impl_detail
112
113namespace MISched {
120} // namespace MISched
121
122/// Returns -misched-prera-direction.
124/// Returns -misched-postra-break-antideps.
126/// Returns whether -verify-misched is set.
128/// Return -misched-print-dags, which is false in a build without assertions.
130/// Return -misched-view-dags, which is false in a build without assertions.
132
133class AAResults;
134class LiveIntervals;
135class MachineFunction;
136class MachineInstr;
137class MachineLoopInfo;
138class RegisterClassInfo;
139class SchedDFSResult;
140class TargetInstrInfo;
141class TargetRegisterInfo;
142
143/// MachineSchedContext provides enough context from the MachineScheduler pass
144/// for the target to instantiate a scheduler.
160
161/// MachineSchedRegistry provides a selection of available machine instruction
162/// schedulers.
165 ScheduleDAGInstrs *(*)(MachineSchedContext *)> {
166public:
168
169 // RegisterPassParser requires a (misnamed) FunctionPassCtor type.
171
173
174 MachineSchedRegistry(const char *N, const char *D, ScheduleDAGCtor C)
176 Registry.Add(this);
177 }
178
179 ~MachineSchedRegistry() { Registry.Remove(this); }
180
181 // Accessors.
182 //
186
188 return (MachineSchedRegistry *)Registry.getList();
189 }
190
192 Registry.setListener(L);
193 }
194};
195
196class ScheduleDAGMI;
197
198/// Define a generic scheduling policy for targets that don't provide their own
199/// MachineSchedStrategy. This can be overriden for each scheduling region
200/// before building the DAG.
202 // Allow the scheduler to disable register pressure tracking.
204 /// Track LaneMasks to allow reordering of independent subregister writes
205 /// of the same vreg. \sa MachineSchedStrategy::shouldTrackLaneMasks()
207
208 // Allow the scheduler to force top-down or bottom-up scheduling. If neither
209 // is true, the scheduler runs in both directions and converges.
210 bool OnlyTopDown = false;
211 bool OnlyBottomUp = false;
212
213 // Disable heuristic that tries to fetch nodes from long dependency chains
214 // first.
216
217 // Compute DFSResult for use in scheduling heuristics.
218 bool ComputeDFSResult = false;
219
220 // If enabled, some extra cases of physreg defs will be biased towards user.
221 bool BiasPRegsExtra = false;
222
224};
225
226/// A region of an MBB for scheduling.
228 /// RegionBegin is the first instruction in the scheduling region, and
229 /// RegionEnd is either MBB->end() or the scheduling boundary after the
230 /// last instruction in the scheduling region. These iterators cannot refer
231 /// to instructions outside of the identified scheduling region because
232 /// those may be reordered before scheduling this region.
236
240};
241
242/// MachineSchedStrategy - Interface to the scheduling algorithm used by
243/// ScheduleDAGMI.
244///
245/// Initialization sequence:
246/// initPolicy -> shouldTrackPressure -> initialize(DAG) -> registerRoots
248 virtual void anchor();
249
250public:
251 virtual ~MachineSchedStrategy() = default;
252
253 /// Optionally override the per-region scheduling policy.
256 unsigned NumRegionInstrs) {}
257
258 virtual MachineSchedPolicy getPolicy() const { return {}; }
259 virtual void dumpPolicy() const {}
260
261 /// Check if pressure tracking is needed before building the DAG and
262 /// initializing this strategy. Called after initPolicy.
263 virtual bool shouldTrackPressure() const { return true; }
264
265 /// Returns true if lanemasks should be tracked. LaneMask tracking is
266 /// necessary to reorder independent subregister defs for the same vreg.
267 /// This has to be enabled in combination with shouldTrackPressure().
268 virtual bool shouldTrackLaneMasks() const { return false; }
269
270 // If this method returns true, handling of the scheduling regions
271 // themselves (in case of a scheduling boundary in MBB) will be done
272 // beginning with the topmost region of MBB.
273 virtual bool doMBBSchedRegionsTopDown() const { return false; }
274
275 /// Initialize the strategy after building the DAG for a new region.
276 virtual void initialize(ScheduleDAGMI *DAG) = 0;
277
278 /// Tell the strategy that MBB is about to be processed.
279 virtual void enterMBB(MachineBasicBlock *MBB) {};
280
281 /// Tell the strategy that current MBB is done.
282 virtual void leaveMBB() {};
283
284 /// Notify this strategy that all roots have been released (including those
285 /// that depend on EntrySU or ExitSU).
286 virtual void registerRoots() {}
287
288 /// Pick the next node to schedule, or return NULL. Set IsTopNode to true to
289 /// schedule the node at the top of the unscheduled region. Otherwise it will
290 /// be scheduled at the bottom.
291 virtual SUnit *pickNode(bool &IsTopNode) = 0;
292
293 /// Scheduler callback to notify that a new subtree is scheduled.
294 virtual void scheduleTree(unsigned SubtreeID) {}
295
296 /// Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an
297 /// instruction and updated scheduled/remaining flags in the DAG nodes.
298 virtual void schedNode(SUnit *SU, bool IsTopNode) = 0;
299
300 /// When all predecessor dependencies have been resolved, free this node for
301 /// top-down scheduling.
302 virtual void releaseTopNode(SUnit *SU) = 0;
303
304 /// When all successor dependencies have been resolved, free this node for
305 /// bottom-up scheduling.
306 virtual void releaseBottomNode(SUnit *SU) = 0;
307};
308
309/// State for breaking physical-register anti-dependencies while scheduling a
310/// machine basic block after register allocation.
312 /// The selected breaker, or null when anti-dependency breaking is disabled.
313 std::unique_ptr<AntiDepBreaker> Breaker;
314
315 /// Instruction index of the current region's end in its basic block.
316 unsigned RegionEndIndex = 0;
317
318 /// Position from which boundary instructions are scanned for liveness.
319 MachineBasicBlock::iterator BoundaryScanPos;
320
321 /// Instruction index corresponding to `BoundaryScanPos`.
322 unsigned BoundaryScanIndex = 0;
323
324 /// Whether ScheduleDAGMI::schedule() processed the current region.
325 bool RegionProcessed = false;
326
327public:
330
332
333 void finishBlock();
334
336
339
340 bool breakAntiDependencies(const std::vector<SUnit> &SUnits,
344
345private:
346 void scanRangeBackwards(MachineBasicBlock::iterator From,
348};
349
350/// ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply
351/// schedules machine instructions according to the given MachineSchedStrategy
352/// without much extra book-keeping. This is the common functionality between
353/// PreRA and PostRA MachineScheduler.
355protected:
359 std::unique_ptr<MachineSchedStrategy> SchedImpl;
360
361 /// State for optional post-RA anti-dependency breaking.
363
364 /// Ordered list of DAG postprocessing steps.
365 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
366
367 /// The top of the unscheduled zone.
369
370 /// The bottom of the unscheduled zone.
372
373#if LLVM_ENABLE_ABI_BREAKING_CHECKS
374 /// The number of instructions scheduled so far. Used to cut off the
375 /// scheduler at the point determined by misched-cutoff.
376 unsigned NumInstrsScheduled = 0;
377#endif
378
379public:
380 ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
381 bool RemoveKillFlags)
383 TargetSubtargetInfo::ANTIDEP_NONE) {}
384
385 /// Construct a post-RA scheduler with the requested anti-dependency mode.
386 ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
387 bool RemoveKillFlags,
390 LIS(C->LIS), MBFI(C->MBFI), SchedImpl(std::move(S)),
392 ? TargetSubtargetInfo::ANTIDEP_NONE
393 : AntiDepMode) {}
394
395 // Provide a vtable anchor
396 ~ScheduleDAGMI() override;
397
398 /// If this method returns true, handling of the scheduling regions
399 /// themselves (in case of a scheduling boundary in MBB) will be done
400 /// beginning with the topmost region of MBB.
401 bool doMBBSchedRegionsTopDown() const override {
402 return SchedImpl->doMBBSchedRegionsTopDown();
403 }
404
405 // Returns LiveIntervals instance for use in DAG mutators and such.
406 LiveIntervals *getLIS() const { return LIS; }
407
408 /// Return true if this DAG supports VReg liveness and RegPressure.
409 virtual bool hasVRegLiveness() const { return false; }
410
411 /// Add a postprocessing step to the DAG builder.
412 /// Mutations are applied in the order that they are added after normal DAG
413 /// building and before MachineSchedStrategy initialization.
414 ///
415 /// ScheduleDAGMI takes ownership of the Mutation object.
416 void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
417 if (Mutation)
418 Mutations.push_back(std::move(Mutation));
419 }
420
423
424 /// Implement the ScheduleDAGInstrs interface for handling the next scheduling
425 /// region. This covers all instructions in a block, while schedule() may only
426 /// cover a subset.
427 void enterRegion(MachineBasicBlock *bb, MachineBasicBlock::iterator begin,
429 unsigned regioninstrs) override;
430
431 void exitRegion() override;
432
433 /// Implement ScheduleDAGInstrs interface for scheduling a sequence of
434 /// reorderable instructions.
435 void schedule() override;
436
437 void startBlock(MachineBasicBlock *bb) override;
438 void finishBlock() override;
439
440 /// Change the position of an instruction within the basic block and update
441 /// live ranges and region boundary iterators.
442 void moveInstruction(MachineInstr *MI, MachineBasicBlock::iterator InsertPos);
443
444 void viewGraph(const Twine &Name, const Twine &Title) override;
445 void viewGraph() override;
446
447protected:
448 // Top-Level entry points for the schedule() driver...
449
450 /// Apply each ScheduleDAGMutation step in order. This allows different
451 /// instances of ScheduleDAGMI to perform custom DAG postprocessing.
452 void postProcessDAG();
453
454 /// Release ExitSU predecessors and setup scheduler queues.
455 void initQueues(ArrayRef<SUnit*> TopRoots, ArrayRef<SUnit*> BotRoots);
456
457 /// Update scheduler DAG and queues after scheduling an instruction.
458 void updateQueues(SUnit *SU, bool IsTopNode);
459
460 /// Reinsert debug_values recorded in ScheduleDAGInstrs::DbgValues.
461 void placeDebugValues();
462
463 /// dump the scheduled Sequence.
464 void dumpSchedule() const;
465 /// Print execution trace of the schedule top-down or bottom-up.
466 void dumpScheduleTraceTopDown() const;
467 void dumpScheduleTraceBottomUp() const;
468
469 // Lesser helpers...
470 bool checkSchedLimit();
471
472 void findRootsAndBiasEdges(SmallVectorImpl<SUnit*> &TopRoots,
473 SmallVectorImpl<SUnit*> &BotRoots);
474
475 void releaseSucc(SUnit *SU, SDep *SuccEdge);
476 void releaseSuccessors(SUnit *SU);
477 void releasePred(SUnit *SU, SDep *PredEdge);
478 void releasePredecessors(SUnit *SU);
479};
480
481/// ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules
482/// machine instructions while updating LiveIntervals and tracking regpressure.
484protected:
486
487 /// Information about DAG subtrees. If DFSResult is NULL, then SchedulerTrees
488 /// will be empty.
491
493
494 /// Maps vregs to the SUnits of their uses in the current scheduling region.
496
497 // Map each SU to its summary of pressure changes. This array is updated for
498 // liveness during bottom-up scheduling. Top-down scheduling may proceed but
499 // has no affect on the pressure diffs.
501
502 /// Register pressure in this region computed by initRegPressure.
507
508 /// List of pressure sets that exceed the target's pressure limit before
509 /// scheduling, listed in increasing set ID order. Each pressure set is paired
510 /// with its max pressure in the currently scheduled regions.
511 std::vector<PressureChange> RegionCriticalPSets;
512
513 /// The top of the unscheduled zone.
516
517 /// The bottom of the unscheduled zone.
520
521public:
523 std::unique_ptr<MachineSchedStrategy> S)
524 : ScheduleDAGMI(C, std::move(S), /*RemoveKillFlags=*/false),
527
528 ~ScheduleDAGMILive() override;
529
530 /// Return true if this DAG supports VReg liveness and RegPressure.
531 bool hasVRegLiveness() const override { return true; }
532
533 /// Return true if register pressure tracking is enabled.
535
536 /// Get current register pressure for the top scheduled instructions.
537 const IntervalPressure &getTopPressure() const { return TopPressure; }
539
540 /// Get current register pressure for the bottom scheduled instructions.
541 const IntervalPressure &getBotPressure() const { return BotPressure; }
543
544 /// Get register pressure for the entire scheduling region before scheduling.
545 const IntervalPressure &getRegPressure() const { return RegPressure; }
546
547 const std::vector<PressureChange> &getRegionCriticalPSets() const {
548 return RegionCriticalPSets;
549 }
550
552 return SUPressureDiffs[SU->NodeNum];
553 }
554 const PressureDiff &getPressureDiff(const SUnit *SU) const {
555 return SUPressureDiffs[SU->NodeNum];
556 }
557
558 /// Compute a DFSResult after DAG building is complete, and before any
559 /// queue comparisons.
560 void computeDFSResult();
561
562 /// Return a non-null DFS result if the scheduling strategy initialized it.
563 const SchedDFSResult *getDFSResult() const { return DFSResult; }
564
566
567 /// Implement the ScheduleDAGInstrs interface for handling the next scheduling
568 /// region. This covers all instructions in a block, while schedule() may only
569 /// cover a subset.
570 void enterRegion(MachineBasicBlock *bb,
573 unsigned regioninstrs) override;
574
575 /// Implement ScheduleDAGInstrs interface for scheduling a sequence of
576 /// reorderable instructions.
577 void schedule() override;
578
579 /// Compute the cyclic critical path through the DAG.
580 unsigned computeCyclicCriticalPath();
581
582 void dump() const override;
583
584protected:
585 // Top-Level entry points for the schedule() driver...
586
587 /// Call ScheduleDAGInstrs::buildSchedGraph with register pressure tracking
588 /// enabled. This sets up three trackers. RPTracker will cover the entire DAG
589 /// region, TopTracker and BottomTracker will be initialized to the top and
590 /// bottom of the DAG region without covereing any unscheduled instruction.
591 void buildDAGWithRegPressure();
592
593 /// Release ExitSU predecessors and setup scheduler queues. Re-position
594 /// the Top RP tracker in case the region beginning has changed.
595 void initQueues(ArrayRef<SUnit*> TopRoots, ArrayRef<SUnit*> BotRoots);
596
597 /// Move an instruction and update register pressure.
598 void scheduleMI(SUnit *SU, bool IsTopNode);
599
600 // Lesser helpers...
601
602 void initRegPressure();
603
604 void updatePressureDiffs(ArrayRef<VRegMaskOrUnit> LiveUses);
605
606 void updateScheduledPressure(const SUnit *SU,
607 const std::vector<unsigned> &NewMaxPressure);
608
609 void collectVRegUses(SUnit &SU);
610};
611
612//===----------------------------------------------------------------------===//
613///
614/// Helpers for implementing custom MachineSchedStrategy classes. These take
615/// care of the book-keeping associated with list scheduling heuristics.
616///
617//===----------------------------------------------------------------------===//
618
619/// ReadyQueue encapsulates vector of "ready" SUnits with basic convenience
620/// methods for pushing and removing nodes. ReadyQueue's are uniquely identified
621/// by an ID. SUnit::NodeQueueId is a mask of the ReadyQueues the SUnit is in.
622///
623/// This is a convenience class that may be used by implementations of
624/// MachineSchedStrategy.
626 unsigned ID;
627 std::string Name;
628 std::vector<SUnit*> Queue;
629
630public:
631 ReadyQueue(unsigned id, const Twine &name): ID(id), Name(name.str()) {}
632
633 unsigned getID() const { return ID; }
634
635 StringRef getName() const { return Name; }
636
637 // SU is in this queue if it's NodeQueueID is a superset of this ID.
638 bool isInQueue(SUnit *SU) const { return (SU->NodeQueueId & ID); }
639
640 bool empty() const { return Queue.empty(); }
641
642 void clear() { Queue.clear(); }
643
644 unsigned size() const { return Queue.size(); }
645
646 using iterator = std::vector<SUnit*>::iterator;
647
648 iterator begin() { return Queue.begin(); }
649
650 iterator end() { return Queue.end(); }
651
652 ArrayRef<SUnit*> elements() { return Queue; }
653
654 iterator find(SUnit *SU) { return llvm::find(Queue, SU); }
655
656 void push(SUnit *SU) {
657 Queue.push_back(SU);
658 SU->NodeQueueId |= ID;
659 }
660
662 (*I)->NodeQueueId &= ~ID;
663 *I = Queue.back();
664 unsigned idx = I - Queue.begin();
665 Queue.pop_back();
666 return Queue.begin() + idx;
667 }
668
669 LLVM_ABI void dump() const;
670};
671
672/// Summarize the unscheduled region.
674 // Critical path through the DAG in expected latency.
675 unsigned CriticalPath;
677
678 // Scaled count of micro-ops left to schedule.
680
682
683 // Unscheduled resources
685
687
688 void reset() {
689 CriticalPath = 0;
690 CyclicCritPath = 0;
691 RemIssueCount = 0;
693 RemainingCounts.clear();
694 }
695
696 LLVM_ABI void init(ScheduleDAGMI *DAG, const TargetSchedModel *SchedModel);
697};
698
699/// ResourceSegments are a collection of intervals closed on the
700/// left and opened on the right:
701///
702/// list{ [a1, b1), [a2, b2), ..., [a_N, b_N) }
703///
704/// The collection has the following properties:
705///
706/// 1. The list is ordered: a_i < b_i and b_i < a_(i+1)
707///
708/// 2. The intervals in the collection do not intersect each other.
709///
710/// A \ref ResourceSegments instance represents the cycle
711/// reservation history of the instance of and individual resource.
713public:
714 /// Represents an interval of discrete integer values closed on
715 /// the left and open on the right: [a, b).
716 typedef std::pair<int64_t, int64_t> IntervalTy;
717
718 /// Adds an interval [a, b) to the collection of the instance.
719 ///
720 /// When adding [a, b[ to the collection, the operation merges the
721 /// adjacent intervals. For example
722 ///
723 /// 0 1 2 3 4 5 6 7 8 9 10
724 /// [-----) [--) [--)
725 /// + [--)
726 /// = [-----------) [--)
727 ///
728 /// To be able to debug duplicate resource usage, the function has
729 /// assertion that checks that no interval should be added if it
730 /// overlaps any of the intervals in the collection. We can
731 /// require this because by definition a \ref ResourceSegments is
732 /// attached only to an individual resource instance.
733 LLVM_ABI void add(IntervalTy A, const unsigned CutOff = 10);
734
735public:
736 /// Checks whether intervals intersect.
738
739 /// These function return the interval used by a resource in bottom and top
740 /// scheduling.
741 ///
742 /// Consider an instruction that uses resources X0, X1 and X2 as follows:
743 ///
744 /// X0 X1 X1 X2 +--------+-------------+--------------+
745 /// |Resource|AcquireAtCycle|ReleaseAtCycle|
746 /// +--------+-------------+--------------+
747 /// | X0 | 0 | 1 |
748 /// +--------+-------------+--------------+
749 /// | X1 | 1 | 3 |
750 /// +--------+-------------+--------------+
751 /// | X2 | 3 | 4 |
752 /// +--------+-------------+--------------+
753 ///
754 /// If we can schedule the instruction at cycle C, we need to
755 /// compute the interval of the resource as follows:
756 ///
757 /// # TOP DOWN SCHEDULING
758 ///
759 /// Cycles scheduling flows to the _right_, in the same direction
760 /// of time.
761 ///
762 /// C 1 2 3 4 5 ...
763 /// ------|------|------|------|------|------|----->
764 /// X0 X1 X1 X2 ---> direction of time
765 /// X0 [C, C+1)
766 /// X1 [C+1, C+3)
767 /// X2 [C+3, C+4)
768 ///
769 /// Therefore, the formula to compute the interval for a resource
770 /// of an instruction that can be scheduled at cycle C in top-down
771 /// scheduling is:
772 ///
773 /// [C+AcquireAtCycle, C+ReleaseAtCycle)
774 ///
775 ///
776 /// # BOTTOM UP SCHEDULING
777 ///
778 /// Cycles scheduling flows to the _left_, in opposite direction
779 /// of time.
780 ///
781 /// In bottom up scheduling, the scheduling happens in opposite
782 /// direction to the execution of the cycles of the
783 /// instruction. When the instruction is scheduled at cycle `C`,
784 /// the resources are allocated in the past relative to `C`:
785 ///
786 /// 2 1 C -1 -2 -3 -4 -5 ...
787 /// <-----|------|------|------|------|------|------|------|---
788 /// X0 X1 X1 X2 ---> direction of time
789 /// X0 (C+1, C]
790 /// X1 (C, C-2]
791 /// X2 (C-2, C-3]
792 ///
793 /// Therefore, the formula to compute the interval for a resource
794 /// of an instruction that can be scheduled at cycle C in bottom-up
795 /// scheduling is:
796 ///
797 /// [C-ReleaseAtCycle+1, C-AcquireAtCycle+1)
798 ///
799 ///
800 /// NOTE: In both cases, the number of cycles booked by a
801 /// resources is the value (ReleaseAtCycle - AcquireAtCycle).
802 static IntervalTy getResourceIntervalBottom(unsigned C, unsigned AcquireAtCycle,
803 unsigned ReleaseAtCycle) {
804 return std::make_pair<long, long>((long)C - (long)ReleaseAtCycle + 1L,
805 (long)C - (long)AcquireAtCycle + 1L);
806 }
807 static IntervalTy getResourceIntervalTop(unsigned C, unsigned AcquireAtCycle,
808 unsigned ReleaseAtCycle) {
809 return std::make_pair<long, long>((long)C + (long)AcquireAtCycle,
810 (long)C + (long)ReleaseAtCycle);
811 }
812
813private:
814 /// Finds the first cycle in which a resource can be allocated.
815 ///
816 /// The function uses the \param IntervalBuider [*] to build a
817 /// resource interval [a, b[ out of the input parameters \param
818 /// CurrCycle, \param AcquireAtCycle and \param ReleaseAtCycle.
819 ///
820 /// The function then loops through the intervals in the ResourceSegments
821 /// and shifts the interval [a, b[ and the ReturnCycle to the
822 /// right until there is no intersection between the intervals of
823 /// the \ref ResourceSegments instance and the new shifted [a, b[. When
824 /// this condition is met, the ReturnCycle (which
825 /// correspond to the cycle in which the resource can be
826 /// allocated) is returned.
827 ///
828 /// c = CurrCycle in input
829 /// c 1 2 3 4 5 6 7 8 9 10 ... ---> (time
830 /// flow)
831 /// ResourceSegments... [---) [-------) [-----------)
832 /// c [1 3[ -> AcquireAtCycle=1, ReleaseAtCycle=3
833 /// ++c [1 3)
834 /// ++c [1 3)
835 /// ++c [1 3)
836 /// ++c [1 3)
837 /// ++c [1 3) ---> returns c
838 /// incremented by 5 (c+5)
839 ///
840 ///
841 /// Notice that for bottom-up scheduling the diagram is slightly
842 /// different because the current cycle c is always on the right
843 /// of the interval [a, b) (see \ref
844 /// `getResourceIntervalBottom`). This is because the cycle
845 /// increments for bottom-up scheduling moved in the direction
846 /// opposite to the direction of time:
847 ///
848 /// --------> direction of time.
849 /// XXYZZZ (resource usage)
850 /// --------> direction of top-down execution cycles.
851 /// <-------- direction of bottom-up execution cycles.
852 ///
853 /// Even though bottom-up scheduling moves against the flow of
854 /// time, the algorithm used to find the first free slot in between
855 /// intervals is the same as for top-down scheduling.
856 ///
857 /// [*] See \ref `getResourceIntervalTop` and
858 /// \ref `getResourceIntervalBottom` to see how such resource intervals
859 /// are built.
860 LLVM_ABI unsigned getFirstAvailableAt(
861 unsigned CurrCycle, unsigned AcquireAtCycle, unsigned ReleaseAtCycle,
862 std::function<IntervalTy(unsigned, unsigned, unsigned)> IntervalBuilder)
863 const;
864
865public:
866 /// getFirstAvailableAtFromBottom and getFirstAvailableAtFromTop
867 /// should be merged in a single function in which a function that
868 /// creates the `NewInterval` is passed as a parameter.
869 unsigned getFirstAvailableAtFromBottom(unsigned CurrCycle,
870 unsigned AcquireAtCycle,
871 unsigned ReleaseAtCycle) const {
872 return getFirstAvailableAt(CurrCycle, AcquireAtCycle, ReleaseAtCycle,
874 }
875 unsigned getFirstAvailableAtFromTop(unsigned CurrCycle,
876 unsigned AcquireAtCycle,
877 unsigned ReleaseAtCycle) const {
878 return getFirstAvailableAt(CurrCycle, AcquireAtCycle, ReleaseAtCycle,
880 }
881
882private:
883 std::list<IntervalTy> _Intervals;
884 /// Merge all adjacent intervals in the collection. For all pairs
885 /// of adjacient intervals, it performs [a, b) + [b, c) -> [a, c).
886 ///
887 /// Before performing the merge operation, the intervals are
888 /// sorted with \ref sort_predicate.
889 LLVM_ABI void sortAndMerge();
890
891public:
892 // constructor for empty set
893 explicit ResourceSegments() = default;
894 bool empty() const { return _Intervals.empty(); }
895 explicit ResourceSegments(const std::list<IntervalTy> &Intervals)
896 : _Intervals(Intervals) {
897 sortAndMerge();
898 }
899
900 friend bool operator==(const ResourceSegments &c1,
901 const ResourceSegments &c2) {
902 return c1._Intervals == c2._Intervals;
903 }
905 const ResourceSegments &Segments) {
906 os << "{ ";
907 for (auto p : Segments._Intervals)
908 os << "[" << p.first << ", " << p.second << "), ";
909 os << "}\n";
910 return os;
911 }
912};
913
914/// Each Scheduling boundary is associated with ready queues. It tracks the
915/// current cycle in the direction of movement, and maintains the state
916/// of "hazards" and other interlocks at the current cycle.
918public:
919 /// SUnit::NodeQueueId: 0 (none), 1 (top), 2 (bot), 3 (both)
920 enum {
924 };
925
926 ScheduleDAGMI *DAG = nullptr;
927 const TargetSchedModel *SchedModel = nullptr;
928 SchedRemainder *Rem = nullptr;
929
932
933 std::unique_ptr<ScheduleHazardRecognizer> HazardRec;
934
935private:
936 /// True if the pending Q should be checked/updated before scheduling another
937 /// instruction.
938 bool CheckPending;
939
940 /// Number of cycles it takes to issue the instructions scheduled in this
941 /// zone. It is defined as: scheduled-micro-ops / issue-width + stalls.
942 /// See getStalls().
943 unsigned CurrCycle;
944
945 /// Micro-ops issued in the current cycle
946 unsigned CurrMOps;
947
948 /// MinReadyCycle - Cycle of the soonest available instruction.
949 unsigned MinReadyCycle;
950
951 // The expected latency of the critical path in this scheduled zone.
952 unsigned ExpectedLatency;
953
954 // The latency of dependence chains leading into this zone.
955 // For each node scheduled bottom-up: DLat = max DLat, N.Depth.
956 // For each cycle scheduled: DLat -= 1.
957 unsigned DependentLatency;
958
959 /// Count the scheduled (issued) micro-ops that can be retired by
960 /// time=CurrCycle assuming the first scheduled instr is retired at time=0.
961 unsigned RetiredMOps;
962
963 // Count scheduled resources that have been executed. Resources are
964 // considered executed if they become ready in the time that it takes to
965 // saturate any resource including the one in question. Counts are scaled
966 // for direct comparison with other resources. Counts can be compared with
967 // MOps * getMicroOpFactor and Latency * getLatencyFactor.
968 SmallVector<unsigned, 16> ExecutedResCounts;
969
970 /// Cache the max count for a single resource.
971 unsigned MaxExecutedResCount;
972
973 // Cache the critical resources ID in this scheduled zone.
974 unsigned ZoneCritResIdx;
975
976 // Is the scheduled region resource limited vs. latency limited.
977 bool IsResourceLimited;
978
979public:
980private:
981 /// Record how resources have been allocated across the cycles of
982 /// the execution.
983 std::map<unsigned, ResourceSegments> ReservedResourceSegments;
984 std::vector<unsigned> ReservedCycles;
985 /// For each PIdx, stores first index into ReservedResourceSegments that
986 /// corresponds to it.
987 ///
988 /// For example, consider the following 3 resources (ResourceCount =
989 /// 3):
990 ///
991 /// +------------+--------+
992 /// |ResourceName|NumUnits|
993 /// +------------+--------+
994 /// | X | 2 |
995 /// +------------+--------+
996 /// | Y | 3 |
997 /// +------------+--------+
998 /// | Z | 1 |
999 /// +------------+--------+
1000 ///
1001 /// In this case, the total number of resource instances is 6. The
1002 /// vector \ref ReservedResourceSegments will have a slot for each instance.
1003 /// The vector \ref ReservedCyclesIndex will track at what index the first
1004 /// instance of the resource is found in the vector of \ref
1005 /// ReservedResourceSegments:
1006 ///
1007 /// Indexes of instances in
1008 /// ReservedResourceSegments
1009 ///
1010 /// 0 1 2 3 4 5
1011 /// ReservedCyclesIndex[0] = 0; [X0, X1,
1012 /// ReservedCyclesIndex[1] = 2; Y0, Y1, Y2
1013 /// ReservedCyclesIndex[2] = 5; Z
1014 SmallVector<unsigned, 16> ReservedCyclesIndex;
1015
1016 // For each PIdx, stores the resource group IDs of its subunits
1017 SmallVector<APInt, 16> ResourceGroupSubUnitMasks;
1018
1019#if LLVM_ENABLE_ABI_BREAKING_CHECKS
1020 // Remember the greatest possible stall as an upper bound on the number of
1021 // times we should retry the pending queue because of a hazard.
1022 unsigned MaxObservedStall;
1023#endif
1024
1025public:
1026 /// Pending queues extend the ready queues with the same ID and the
1027 /// PendingFlag set.
1028 SchedBoundary(unsigned ID, const Twine &Name):
1029 Available(ID, Name+".A"), Pending(ID << LogMaxQID, Name+".P") {
1030 reset();
1031 }
1032 SchedBoundary &operator=(const SchedBoundary &other) = delete;
1033 SchedBoundary(const SchedBoundary &other) = delete;
1035
1036 LLVM_ABI void reset();
1037
1038 LLVM_ABI void init(ScheduleDAGMI *dag, const TargetSchedModel *smodel,
1039 SchedRemainder *rem);
1040
1041 bool isTop() const {
1042 return Available.getID() == TopQID;
1043 }
1044
1045 /// Number of cycles to issue the instructions scheduled in this zone.
1046 unsigned getCurrCycle() const { return CurrCycle; }
1047
1048 /// Micro-ops issued in the current cycle
1049 unsigned getCurrMOps() const { return CurrMOps; }
1050
1051 // The latency of dependence chains leading into this zone.
1052 unsigned getDependentLatency() const { return DependentLatency; }
1053
1054 /// Get the number of latency cycles "covered" by the scheduled
1055 /// instructions. This is the larger of the critical path within the zone
1056 /// and the number of cycles required to issue the instructions.
1057 unsigned getScheduledLatency() const {
1058 return std::max(ExpectedLatency, CurrCycle);
1059 }
1060
1061 unsigned getUnscheduledLatency(SUnit *SU) const {
1062 return isTop() ? SU->getHeight() : SU->getDepth();
1063 }
1064
1065 unsigned getResourceCount(unsigned ResIdx) const {
1066 return ExecutedResCounts[ResIdx];
1067 }
1068
1069 /// Get the scaled count of scheduled micro-ops and resources, including
1070 /// executed resources.
1071 unsigned getCriticalCount() const {
1072 if (!ZoneCritResIdx)
1073 return RetiredMOps * SchedModel->getMicroOpFactor();
1074 return getResourceCount(ZoneCritResIdx);
1075 }
1076
1077 /// Get a scaled count for the minimum execution time of the scheduled
1078 /// micro-ops that are ready to execute by getExecutedCount. Notice the
1079 /// feedback loop.
1080 unsigned getExecutedCount() const {
1081 return std::max(CurrCycle * SchedModel->getLatencyFactor(),
1082 MaxExecutedResCount);
1083 }
1084
1085 unsigned getZoneCritResIdx() const { return ZoneCritResIdx; }
1086
1087 // Is the scheduled region resource limited vs. latency limited.
1088 bool isResourceLimited() const { return IsResourceLimited; }
1089
1090 /// Get the difference between the given SUnit's ready time and the current
1091 /// cycle.
1092 LLVM_ABI unsigned getLatencyStallCycles(SUnit *SU);
1093
1094 LLVM_ABI unsigned getNextResourceCycleByInstance(unsigned InstanceIndex,
1095 unsigned ReleaseAtCycle,
1096 unsigned AcquireAtCycle);
1097
1098 LLVM_ABI std::pair<unsigned, unsigned>
1099 getNextResourceCycle(const MCSchedClassDesc *SC, unsigned PIdx,
1100 unsigned ReleaseAtCycle, unsigned AcquireAtCycle);
1101
1102 bool isReservedGroup(unsigned PIdx) const {
1103 return SchedModel->getProcResource(PIdx)->SubUnitsIdxBegin &&
1104 !SchedModel->getProcResource(PIdx)->BufferSize;
1105 }
1106
1107 LLVM_ABI bool checkHazard(SUnit *SU);
1108
1109 LLVM_ABI unsigned findMaxLatency(ArrayRef<SUnit *> ReadySUs);
1110
1111 LLVM_ABI unsigned getOtherResourceCount(unsigned &OtherCritIdx);
1112
1113 /// Release SU to make it ready. If it's not in hazard, remove it from
1114 /// pending queue (if already in) and push into available queue.
1115 /// Otherwise, push the SU into pending queue.
1116 ///
1117 /// @param SU The unit to be released.
1118 /// @param ReadyCycle Until which cycle the unit is ready.
1119 /// @param InPQueue Whether SU is already in pending queue.
1120 /// @param Idx Position offset in pending queue (if in it).
1121 LLVM_ABI void releaseNode(SUnit *SU, unsigned ReadyCycle, bool InPQueue,
1122 unsigned Idx = 0);
1123
1124 LLVM_ABI void bumpCycle(unsigned NextCycle);
1125
1126 LLVM_ABI void incExecutedResources(unsigned PIdx, unsigned Count);
1127
1128 LLVM_ABI unsigned countResource(const MCSchedClassDesc *SC, unsigned PIdx,
1129 unsigned Cycles, unsigned ReadyCycle,
1130 unsigned StartAtCycle);
1131
1132 LLVM_ABI void bumpNode(SUnit *SU);
1133
1134 LLVM_ABI void releasePending();
1135
1136 LLVM_ABI void removeReady(SUnit *SU);
1137
1138 /// Call this before applying any other heuristics to the Available queue.
1139 /// Updates the Available/Pending Q's if necessary and returns the single
1140 /// available instruction, or NULL if there are multiple candidates.
1142
1143 /// Dump the state of the information that tracks resource usage.
1144 LLVM_ABI void dumpReservedCycles() const;
1145 LLVM_ABI void dumpScheduledState() const;
1146};
1147
1148/// Base class for GenericScheduler. This class maintains information about
1149/// scheduling candidates based on TargetSchedModel making it easy to implement
1150/// heuristics for either preRA or postRA scheduling.
1152public:
1153 /// Represent the type of SchedCandidate found within a single queue.
1154 /// pickNodeBidirectional depends on these listed by decreasing priority.
1174
1175#ifndef NDEBUG
1176 static const char *getReasonStr(GenericSchedulerBase::CandReason Reason);
1177#endif
1178
1179 /// Policy for scheduling the next instruction in the candidate's zone.
1180 struct CandPolicy {
1181 bool ReduceLatency = false;
1182 unsigned ReduceResIdx = 0;
1183 unsigned DemandResIdx = 0;
1184
1185 CandPolicy() = default;
1186
1187 bool operator==(const CandPolicy &RHS) const {
1188 return ReduceLatency == RHS.ReduceLatency &&
1189 ReduceResIdx == RHS.ReduceResIdx &&
1190 DemandResIdx == RHS.DemandResIdx;
1191 }
1192 bool operator!=(const CandPolicy &RHS) const {
1193 return !(*this == RHS);
1194 }
1195 };
1196
1197 /// Status of an instruction's critical resource consumption.
1199 // Count critical resources in the scheduled region required by SU.
1200 unsigned CritResources = 0;
1201
1202 // Count critical resources from another region consumed by SU.
1203 unsigned DemandedResources = 0;
1204
1206
1207 bool operator==(const SchedResourceDelta &RHS) const {
1208 return CritResources == RHS.CritResources
1209 && DemandedResources == RHS.DemandedResources;
1210 }
1211 bool operator!=(const SchedResourceDelta &RHS) const {
1212 return !operator==(RHS);
1213 }
1214 };
1215
1216 /// Store the state used by GenericScheduler heuristics, required for the
1217 /// lifetime of one invocation of pickNode().
1220
1221 // The best SUnit candidate.
1223
1224 // The reason for this candidate.
1226
1227 // Whether this candidate should be scheduled at top/bottom.
1228 bool AtTop;
1229
1230 // Register pressure values for the best candidate.
1232
1233 // Critical resource consumption of the best candidate.
1235
1238
1239 void reset(const CandPolicy &NewPolicy) {
1240 Policy = NewPolicy;
1241 SU = nullptr;
1242 Reason = NoCand;
1243 AtTop = false;
1246 }
1247
1248 bool isValid() const { return SU; }
1249
1250 // Copy the status of another candidate without changing policy.
1252 assert(Best.Reason != NoCand && "uninitialized Sched candidate");
1253 SU = Best.SU;
1254 Reason = Best.Reason;
1255 AtTop = Best.AtTop;
1256 RPDelta = Best.RPDelta;
1257 ResDelta = Best.ResDelta;
1258 }
1259
1262 };
1263
1264protected:
1267 const TargetRegisterInfo *TRI = nullptr;
1268 unsigned TopIdx = 0;
1269 unsigned BotIdx = 0;
1270 unsigned NumRegionInstrs = 0;
1271
1273
1275
1277
1278 LLVM_ABI void setPolicy(CandPolicy &Policy, bool IsPostRA,
1279 SchedBoundary &CurrZone, SchedBoundary *OtherZone);
1280
1281 MachineSchedPolicy getPolicy() const override { return RegionPolicy; }
1282
1283#ifndef NDEBUG
1284 void traceCandidate(const SchedCandidate &Cand);
1285#endif
1286
1287private:
1288 bool shouldReduceLatency(const CandPolicy &Policy, SchedBoundary &CurrZone,
1289 bool ComputeRemLatency, unsigned &RemLatency) const;
1290};
1291
1292// Utility functions used by heuristics in tryCandidate().
1293LLVM_ABI unsigned computeRemLatency(SchedBoundary &CurrZone);
1294LLVM_ABI bool tryLess(int TryVal, int CandVal,
1295 GenericSchedulerBase::SchedCandidate &TryCand,
1296 GenericSchedulerBase::SchedCandidate &Cand,
1298LLVM_ABI bool tryGreater(int TryVal, int CandVal,
1299 GenericSchedulerBase::SchedCandidate &TryCand,
1300 GenericSchedulerBase::SchedCandidate &Cand,
1302LLVM_ABI bool tryLatency(GenericSchedulerBase::SchedCandidate &TryCand,
1303 GenericSchedulerBase::SchedCandidate &Cand,
1304 SchedBoundary &Zone);
1305LLVM_ABI bool tryPressure(const PressureChange &TryP,
1306 const PressureChange &CandP,
1307 GenericSchedulerBase::SchedCandidate &TryCand,
1308 GenericSchedulerBase::SchedCandidate &Cand,
1310 const TargetRegisterInfo *TRI,
1311 const MachineFunction &MF);
1312LLVM_ABI bool tryBiasPhysRegs(GenericSchedulerBase::SchedCandidate &TryCand,
1313 GenericSchedulerBase::SchedCandidate &Cand,
1314 SchedBoundary *Zone, bool BiasPRegsExtra);
1315LLVM_ABI unsigned getWeakLeft(const SUnit *SU, bool isTop);
1316LLVM_ABI int biasPhysReg(const SUnit *SU, bool isTop,
1317 bool BiasPRegsExtra = false);
1318
1319/// GenericScheduler shrinks the unscheduled zone using heuristics to balance
1320/// the schedule.
1322public:
1324 GenericSchedulerBase(C), Top(SchedBoundary::TopQID, "TopQ"),
1325 Bot(SchedBoundary::BotQID, "BotQ") {}
1326
1327 void initPolicy(MachineBasicBlock::iterator Begin,
1329 unsigned NumRegionInstrs) override;
1330
1331 void dumpPolicy() const override;
1332
1333 bool shouldTrackPressure() const override {
1334 return RegionPolicy.ShouldTrackPressure;
1335 }
1336
1337 bool shouldTrackLaneMasks() const override {
1338 return RegionPolicy.ShouldTrackLaneMasks;
1339 }
1340
1341 void initialize(ScheduleDAGMI *dag) override;
1342
1343 SUnit *pickNode(bool &IsTopNode) override;
1344
1345 void schedNode(SUnit *SU, bool IsTopNode) override;
1346
1347 void releaseTopNode(SUnit *SU) override {
1348 if (SU->isScheduled)
1349 return;
1350
1351 Top.releaseNode(SU, SU->TopReadyCycle, false);
1352 TopCand.SU = nullptr;
1353 }
1354
1355 void releaseBottomNode(SUnit *SU) override {
1356 if (SU->isScheduled)
1357 return;
1358
1359 Bot.releaseNode(SU, SU->BotReadyCycle, false);
1360 BotCand.SU = nullptr;
1361 }
1362
1363 void registerRoots() override;
1364
1365protected:
1367
1368 // State of the top and bottom scheduled instruction boundaries.
1371
1374
1375 /// Candidate last picked from Top boundary.
1377 /// Candidate last picked from Bot boundary.
1379
1380 void checkAcyclicLatency();
1381
1382 void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop,
1383 const RegPressureTracker &RPTracker,
1384 RegPressureTracker &TempTracker);
1385
1386 virtual bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand,
1387 SchedBoundary *Zone) const;
1388
1389 SUnit *pickNodeBidirectional(bool &IsTopNode);
1390
1392 const CandPolicy &ZonePolicy,
1393 const RegPressureTracker &RPTracker,
1394 SchedCandidate &Candidate);
1395
1396 void reschedulePhysReg(SUnit *SU, bool isTop);
1397};
1398
1399/// PostGenericScheduler - Interface to the scheduling algorithm used by
1400/// ScheduleDAGMI.
1401///
1402/// Callbacks from ScheduleDAGMI:
1403/// initPolicy -> initialize(DAG) -> registerRoots -> pickNode ...
1405protected:
1406 ScheduleDAGMI *DAG = nullptr;
1409
1410 /// Candidate last picked from Top boundary.
1412 /// Candidate last picked from Bot boundary.
1414
1417
1418public:
1420 : GenericSchedulerBase(C), Top(SchedBoundary::TopQID, "TopQ"),
1421 Bot(SchedBoundary::BotQID, "BotQ") {}
1422
1423 ~PostGenericScheduler() override = default;
1424
1427 unsigned NumRegionInstrs) override;
1428
1429 /// PostRA scheduling does not track pressure.
1430 bool shouldTrackPressure() const override { return false; }
1431
1432 void initialize(ScheduleDAGMI *Dag) override;
1433
1434 void registerRoots() override;
1435
1436 SUnit *pickNode(bool &IsTopNode) override;
1437
1438 SUnit *pickNodeBidirectional(bool &IsTopNode);
1439
1440 void scheduleTree(unsigned SubtreeID) override {
1441 llvm_unreachable("PostRA scheduler does not support subtree analysis.");
1442 }
1443
1444 void schedNode(SUnit *SU, bool IsTopNode) override;
1445
1446 void releaseTopNode(SUnit *SU) override {
1447 if (SU->isScheduled)
1448 return;
1449 Top.releaseNode(SU, SU->TopReadyCycle, false);
1450 TopCand.SU = nullptr;
1451 }
1452
1453 void releaseBottomNode(SUnit *SU) override {
1454 if (SU->isScheduled)
1455 return;
1456 Bot.releaseNode(SU, SU->BotReadyCycle, false);
1457 BotCand.SU = nullptr;
1458 }
1459
1460protected:
1461 virtual bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand);
1462
1463 void pickNodeFromQueue(SchedBoundary &Zone, SchedCandidate &Cand);
1464};
1465
1466/// If ReorderWhileClustering is set to true, no attempt will be made to
1467/// reduce reordering due to store clustering.
1468LLVM_ABI std::unique_ptr<ScheduleDAGMutation>
1469createLoadClusterDAGMutation(const TargetInstrInfo *TII,
1470 bool ReorderWhileClustering = false);
1471
1472/// If ReorderWhileClustering is set to true, no attempt will be made to
1473/// reduce reordering due to store clustering.
1474LLVM_ABI std::unique_ptr<ScheduleDAGMutation>
1475createStoreClusterDAGMutation(const TargetInstrInfo *TII,
1476 bool ReorderWhileClustering = false);
1477
1478LLVM_ABI std::unique_ptr<ScheduleDAGMutation>
1479createCopyConstrainDAGMutation(const TargetInstrInfo *TII);
1480
1481/// Create the standard converging machine scheduler. This will be used as the
1482/// default scheduler if the target does not set a default.
1483/// Adds default DAG mutations.
1484template <typename Strategy = GenericScheduler>
1486 ScheduleDAGMILive *DAG =
1487 new ScheduleDAGMILive(C, std::make_unique<Strategy>(C));
1488 // Register DAG post-processors.
1489 //
1490 // FIXME: extend the mutation API to allow earlier mutations to instantiate
1491 // data and pass it to later mutations. Have a single mutation that gathers
1492 // the interesting nodes in one pass.
1494 return DAG;
1495}
1496
1497/// Create a generic scheduler with no vreg liveness or DAG mutation passes.
1498template <typename Strategy = PostGenericScheduler>
1500 return new ScheduleDAGMI(C, std::make_unique<Strategy>(C),
1501 /*RemoveKillFlags=*/true, getPostRABreakAntiDeps());
1502}
1503
1505 : public OptionalPassInfoMixin<MachineSchedulerPass> {
1506 // FIXME: Remove this member once RegisterClassInfo is queryable as an
1507 // analysis.
1508 std::unique_ptr<impl_detail::MachineSchedulerImpl> Impl;
1509 const TargetMachine *TM;
1510
1511public:
1517};
1518
1520 : public OptionalPassInfoMixin<SSAMachineSchedulerPass> {
1521 // FIXME: Remove this member once RegisterClassInfo is queryable as an
1522 // analysis.
1523 std::unique_ptr<impl_detail::SSAMachineSchedulerImpl> Impl;
1524 const TargetMachine *TM;
1525
1526public:
1532};
1533
1535 : public OptionalPassInfoMixin<PostMachineSchedulerPass> {
1536 // FIXME: Remove this member once RegisterClassInfo is queryable as an
1537 // analysis.
1538 std::unique_ptr<impl_detail::PostMachineSchedulerImpl> Impl;
1539 const TargetMachine *TM;
1540
1541public:
1547};
1548} // end namespace llvm
1549
1550#endif // LLVM_CODEGEN_MACHINESCHEDULER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock & MBB
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
PowerPC VSX FMA Mutation
This file contains some templates that are useful if you are working with the STL at all.
static const char * name
This file defines the SmallVector class.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
Value * RHS
std::vector< std::pair< MachineInstr *, MachineInstr * > > DbgValueVector
State for breaking physical-register anti-dependencies while scheduling a machine basic block after r...
void startBlock(MachineBasicBlock *MBB)
bool breakAntiDependencies(const std::vector< SUnit > &SUnits, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, AntiDepBreaker::DbgValueVector &DbgValues)
void exitRegion(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
AntiDepState(MachineSchedContext *C, TargetSubtargetInfo::AntiDepBreakMode AntiDepMode)
void enterRegion(MachineBasicBlock::iterator End)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void traceCandidate(const SchedCandidate &Cand)
LLVM_ABI void setPolicy(CandPolicy &Policy, bool IsPostRA, SchedBoundary &CurrZone, SchedBoundary *OtherZone)
Set the CandPolicy given a scheduling zone given the current resources and latencies inside and outsi...
MachineSchedPolicy RegionPolicy
const TargetSchedModel * SchedModel
static const char * getReasonStr(GenericSchedulerBase::CandReason Reason)
MachineSchedPolicy getPolicy() const override
GenericSchedulerBase(const MachineSchedContext *C)
const MachineSchedContext * Context
CandReason
Represent the type of SchedCandidate found within a single queue.
const TargetRegisterInfo * TRI
void checkAcyclicLatency()
Set IsAcyclicLatencyLimited if the acyclic path is longer than the cyclic critical path by more cycle...
SchedCandidate BotCand
Candidate last picked from Bot boundary.
SchedCandidate TopCand
Candidate last picked from Top boundary.
virtual bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const
Apply a set of heuristics to a new candidate.
ScheduleDAGMILive * DAG
void releaseBottomNode(SUnit *SU) override
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop, const RegPressureTracker &RPTracker, RegPressureTracker &TempTracker)
bool shouldTrackPressure() const override
Check if pressure tracking is needed before building the DAG and initializing this strategy.
void releaseTopNode(SUnit *SU) override
When all predecessor dependencies have been resolved, free this node for top-down scheduling.
void reschedulePhysReg(SUnit *SU, bool isTop)
void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy, const RegPressureTracker &RPTracker, SchedCandidate &Candidate)
Pick the best candidate from the queue.
bool shouldTrackLaneMasks() const override
Returns true if lanemasks should be tracked.
GenericScheduler(const MachineSchedContext *C)
SUnit * pickNodeBidirectional(bool &IsTopNode)
Pick the best candidate node from either the top or bottom queue.
MachineInstrBundleIterator< MachineInstr > iterator
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Representation of each machine instruction.
MachinePassRegistryListener - Listener to adds and removals of nodes in registration list.
MachinePassRegistryNode(const char *N, const char *D, ScheduleDAGInstrs *C)
MachinePassRegistryNode * getNext() const
MachinePassRegistry - Track the registration of machine passes.
static void setListener(MachinePassRegistryListener< FunctionPassCtor > *L)
static LLVM_ABI MachinePassRegistry< ScheduleDAGCtor > Registry
MachineSchedRegistry(const char *N, const char *D, ScheduleDAGCtor C)
static MachineSchedRegistry * getList()
ScheduleDAGInstrs *(*)(MachineSchedContext *) ScheduleDAGCtor
MachineSchedRegistry * getNext() const
MachineSchedStrategy - Interface to the scheduling algorithm used by ScheduleDAGMI.
virtual bool shouldTrackPressure() const
Check if pressure tracking is needed before building the DAG and initializing this strategy.
virtual void leaveMBB()
Tell the strategy that current MBB is done.
virtual void enterMBB(MachineBasicBlock *MBB)
Tell the strategy that MBB is about to be processed.
virtual void scheduleTree(unsigned SubtreeID)
Scheduler callback to notify that a new subtree is scheduled.
virtual void schedNode(SUnit *SU, bool IsTopNode)=0
Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/rem...
virtual ~MachineSchedStrategy()=default
virtual void initialize(ScheduleDAGMI *DAG)=0
Initialize the strategy after building the DAG for a new region.
virtual MachineSchedPolicy getPolicy() const
virtual void releaseTopNode(SUnit *SU)=0
When all predecessor dependencies have been resolved, free this node for top-down scheduling.
virtual void dumpPolicy() const
virtual bool doMBBSchedRegionsTopDown() const
virtual SUnit * pickNode(bool &IsTopNode)=0
Pick the next node to schedule, or return NULL.
virtual void initPolicy(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned NumRegionInstrs)
Optionally override the per-region scheduling policy.
virtual void releaseBottomNode(SUnit *SU)=0
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
virtual bool shouldTrackLaneMasks() const
Returns true if lanemasks should be tracked.
virtual void registerRoots()
Notify this strategy that all roots have been released (including those that depend on EntrySU or Exi...
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI MachineSchedulerPass(const TargetMachine *TM)
LLVM_ABI MachineSchedulerPass(MachineSchedulerPass &&Other)
void initPolicy(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned NumRegionInstrs) override
Optionally override the per-region scheduling policy.
bool shouldTrackPressure() const override
PostRA scheduling does not track pressure.
void scheduleTree(unsigned SubtreeID) override
Scheduler callback to notify that a new subtree is scheduled.
SchedCandidate BotCand
Candidate last picked from Bot boundary.
SchedCandidate TopCand
Candidate last picked from Top boundary.
void releaseTopNode(SUnit *SU) override
When all predecessor dependencies have been resolved, free this node for top-down scheduling.
~PostGenericScheduler() override=default
void releaseBottomNode(SUnit *SU) override
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
PostGenericScheduler(const MachineSchedContext *C)
LLVM_ABI PostMachineSchedulerPass(PostMachineSchedulerPass &&Other)
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI PostMachineSchedulerPass(const TargetMachine *TM)
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
List of PressureChanges in order of increasing, unique PSetID.
Array of PressureDiffs.
Helpers for implementing custom MachineSchedStrategy classes.
void push(SUnit *SU)
iterator find(SUnit *SU)
ArrayRef< SUnit * > elements()
LLVM_ABI void dump() const
ReadyQueue(unsigned id, const Twine &name)
bool isInQueue(SUnit *SU) const
std::vector< SUnit * >::iterator iterator
StringRef getName() const
unsigned size() const
iterator remove(iterator I)
unsigned getID() const
Track the current register pressure at some position in the instruction stream, and remember the high...
LLVM_ABI void add(IntervalTy A, const unsigned CutOff=10)
Adds an interval [a, b) to the collection of the instance.
static IntervalTy getResourceIntervalBottom(unsigned C, unsigned AcquireAtCycle, unsigned ReleaseAtCycle)
These function return the interval used by a resource in bottom and top scheduling.
friend bool operator==(const ResourceSegments &c1, const ResourceSegments &c2)
static LLVM_ABI bool intersects(IntervalTy A, IntervalTy B)
Checks whether intervals intersect.
unsigned getFirstAvailableAtFromTop(unsigned CurrCycle, unsigned AcquireAtCycle, unsigned ReleaseAtCycle) const
friend llvm::raw_ostream & operator<<(llvm::raw_ostream &os, const ResourceSegments &Segments)
std::pair< int64_t, int64_t > IntervalTy
Represents an interval of discrete integer values closed on the left and open on the right: [a,...
static IntervalTy getResourceIntervalTop(unsigned C, unsigned AcquireAtCycle, unsigned ReleaseAtCycle)
ResourceSegments(const std::list< IntervalTy > &Intervals)
unsigned getFirstAvailableAtFromBottom(unsigned CurrCycle, unsigned AcquireAtCycle, unsigned ReleaseAtCycle) const
getFirstAvailableAtFromBottom and getFirstAvailableAtFromTop should be merged in a single function in...
Scheduling dependency.
Definition ScheduleDAG.h:54
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
LLVM_ABI SSAMachineSchedulerPass(SSAMachineSchedulerPass &&Other)
LLVM_ABI SSAMachineSchedulerPass(const TargetMachine *TM)
Scheduling unit. This is a node in the scheduling DAG.
unsigned NodeQueueId
Queue id of node.
unsigned TopReadyCycle
Cycle relative to start when node is ready.
unsigned NodeNum
Entry # of node in the node vector.
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
bool isScheduled
True once scheduled.
unsigned BotReadyCycle
Cycle relative to end when node is ready.
Each Scheduling boundary is associated with ready queues.
LLVM_ABI unsigned getNextResourceCycleByInstance(unsigned InstanceIndex, unsigned ReleaseAtCycle, unsigned AcquireAtCycle)
Compute the next cycle at which the given processor resource unit can be scheduled.
LLVM_ABI void releasePending()
Release pending ready nodes in to the available queue.
unsigned getDependentLatency() const
bool isReservedGroup(unsigned PIdx) const
unsigned getScheduledLatency() const
Get the number of latency cycles "covered" by the scheduled instructions.
LLVM_ABI void incExecutedResources(unsigned PIdx, unsigned Count)
bool isResourceLimited() const
const TargetSchedModel * SchedModel
unsigned getExecutedCount() const
Get a scaled count for the minimum execution time of the scheduled micro-ops that are ready to execut...
LLVM_ABI unsigned getLatencyStallCycles(SUnit *SU)
Get the difference between the given SUnit's ready time and the current cycle.
SchedBoundary(const SchedBoundary &other)=delete
LLVM_ABI unsigned findMaxLatency(ArrayRef< SUnit * > ReadySUs)
LLVM_ABI void dumpReservedCycles() const
Dump the state of the information that tracks resource usage.
LLVM_ABI unsigned getOtherResourceCount(unsigned &OtherCritIdx)
SchedRemainder * Rem
LLVM_ABI void bumpNode(SUnit *SU)
Move the boundary of scheduled code by one SUnit.
unsigned getCriticalCount() const
Get the scaled count of scheduled micro-ops and resources, including executed resources.
LLVM_ABI SUnit * pickOnlyChoice()
Call this before applying any other heuristics to the Available queue.
LLVM_ABI void releaseNode(SUnit *SU, unsigned ReadyCycle, bool InPQueue, unsigned Idx=0)
Release SU to make it ready.
LLVM_ABI unsigned countResource(const MCSchedClassDesc *SC, unsigned PIdx, unsigned Cycles, unsigned ReadyCycle, unsigned StartAtCycle)
Add the given processor resource to this scheduled zone.
SchedBoundary(unsigned ID, const Twine &Name)
Pending queues extend the ready queues with the same ID and the PendingFlag set.
LLVM_ABI ~SchedBoundary()
LLVM_ABI void init(ScheduleDAGMI *dag, const TargetSchedModel *smodel, SchedRemainder *rem)
SchedBoundary & operator=(const SchedBoundary &other)=delete
unsigned getResourceCount(unsigned ResIdx) const
LLVM_ABI void bumpCycle(unsigned NextCycle)
Move the boundary of scheduled code by one cycle.
unsigned getCurrMOps() const
Micro-ops issued in the current cycle.
unsigned getCurrCycle() const
Number of cycles to issue the instructions scheduled in this zone.
std::unique_ptr< ScheduleHazardRecognizer > HazardRec
LLVM_ABI bool checkHazard(SUnit *SU)
Does this SU have a hazard within the current instruction group.
LLVM_ABI std::pair< unsigned, unsigned > getNextResourceCycle(const MCSchedClassDesc *SC, unsigned PIdx, unsigned ReleaseAtCycle, unsigned AcquireAtCycle)
Compute the next cycle at which the given processor resource can be scheduled.
LLVM_ABI void dumpScheduledState() const
LLVM_ABI void removeReady(SUnit *SU)
Remove SU from the ready set for this boundary.
unsigned getZoneCritResIdx() const
unsigned getUnscheduledLatency(SUnit *SU) const
Compute the values of each DAG node for various metrics during DFS.
Definition ScheduleDFS.h:65
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGInstrs(MachineFunction &mf, const MachineLoopInfo *mli, bool RemoveKillFlags=false)
const MachineLoopInfo * MLI
bool RemoveKillFlags
True if the DAG builder should remove kill flags (in preparation for rescheduling).
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
VReg2SUnitMultiMap VRegUses
Maps vregs to the SUnits of their uses in the current scheduling region.
PressureDiff & getPressureDiff(const SUnit *SU)
SchedDFSResult * DFSResult
Information about DAG subtrees.
RegPressureTracker BotRPTracker
std::vector< PressureChange > RegionCriticalPSets
List of pressure sets that exceed the target's pressure limit before scheduling, listed in increasing...
IntervalPressure TopPressure
The top of the unscheduled zone.
const RegPressureTracker & getBotRPTracker() const
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
IntervalPressure BotPressure
The bottom of the unscheduled zone.
bool isTrackingPressure() const
Return true if register pressure tracking is enabled.
bool hasVRegLiveness() const override
Return true if this DAG supports VReg liveness and RegPressure.
RegisterClassInfo * RegClassInfo
const SchedDFSResult * getDFSResult() const
Return a non-null DFS result if the scheduling strategy initialized it.
const PressureDiff & getPressureDiff(const SUnit *SU) const
const RegPressureTracker & getTopRPTracker() const
RegPressureTracker RPTracker
bool ShouldTrackPressure
Register pressure in this region computed by initRegPressure.
const IntervalPressure & getRegPressure() const
Get register pressure for the entire scheduling region before scheduling.
const IntervalPressure & getBotPressure() const
Get current register pressure for the bottom scheduled instructions.
MachineBasicBlock::iterator LiveRegionEnd
const IntervalPressure & getTopPressure() const
Get current register pressure for the top scheduled instructions.
const std::vector< PressureChange > & getRegionCriticalPSets() const
IntervalPressure RegPressure
RegPressureTracker TopRPTracker
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
std::unique_ptr< MachineSchedStrategy > SchedImpl
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
MachineBasicBlock::iterator top() const
AntiDepState AntiDep
State for optional post-RA anti-dependency breaking.
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S, bool RemoveKillFlags)
MachineBasicBlock::iterator bottom() const
MachineBasicBlock::iterator CurrentBottom
The bottom of the unscheduled zone.
bool doMBBSchedRegionsTopDown() const override
If this method returns true, handling of the scheduling regions themselves (in case of a scheduling b...
virtual bool hasVRegLiveness() const
Return true if this DAG supports VReg liveness and RegPressure.
LiveIntervals * getLIS() const
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S, bool RemoveKillFlags, TargetSubtargetInfo::AntiDepBreakMode AntiDepMode)
Construct a post-RA scheduler with the requested anti-dependency mode.
~ScheduleDAGMI() override
MachineBasicBlock::iterator CurrentTop
The top of the unscheduled zone.
MachineBlockFrequencyInfo * MBFI
std::vector< std::unique_ptr< ScheduleDAGMutation > > Mutations
Ordered list of DAG postprocessing steps.
const TargetInstrInfo * TII
Target instruction information.
MachineFunction & MF
Machine function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Provide an instruction scheduling machine model to CodeGen passes.
TargetSubtargetInfo - Generic base class for all target subtargets.
enum { ANTIDEP_NONE, ANTIDEP_CRITICAL, ANTIDEP_ALL } AntiDepBreakMode
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
Impl class for MachineScheduler.
Impl class for PostMachineScheduler.
Impl class for SSAMachineScheduler.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI int biasPhysReg(const SUnit *SU, bool isTop, bool BiasPRegsExtra=false)
Minimize physical register live ranges.
ScheduleDAGMILive * createSchedLive(MachineSchedContext *C)
Create the standard converging machine scheduler.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1781
LLVM_ABI unsigned getWeakLeft(const SUnit *SU, bool isTop)
LLVM_ABI bool shouldVerifyScheduling(const MachineFunction &MF)
Returns whether -verify-misched is set.
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createLoadClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI TargetSubtargetInfo::AntiDepBreakMode getPostRABreakAntiDeps()
Returns -misched-postra-break-antideps.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createStoreClusterDAGMutation(const TargetInstrInfo *TII, bool ReorderWhileClustering=false)
If ReorderWhileClustering is set to true, no attempt will be made to reduce reordering due to store c...
LLVM_ABI bool tryPressure(const PressureChange &TryP, const PressureChange &CandP, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason, const TargetRegisterInfo *TRI, const MachineFunction &MF)
SparseMultiSet< VReg2SUnit, Register, VirtReg2IndexFunctor > VReg2SUnitMultiMap
Track local uses of virtual registers.
ScheduleDAGMI * createSchedPostRA(MachineSchedContext *C)
Create a generic scheduler with no vreg liveness or DAG mutation passes.
LLVM_ABI bool shouldPrintMISchedDAGs(const MachineFunction &MF)
Return -misched-print-dags, which is false in a build without assertions.
LLVM_ABI bool tryLatency(GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, SchedBoundary &Zone)
@ Other
Any other memory.
Definition ModRef.h:68
LLVM_ABI MISched::Direction getPreRADirection(const MachineFunction &MF)
Returns -misched-prera-direction.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
LLVM_ABI bool tryBiasPhysRegs(GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, SchedBoundary *Zone, bool BiasPRegsExtra)
LLVM_ABI std::unique_ptr< ScheduleDAGMutation > createCopyConstrainDAGMutation(const TargetInstrInfo *TII)
LLVM_ABI bool tryGreater(int TryVal, int CandVal, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
LLVM_ABI unsigned computeRemLatency(SchedBoundary &CurrZone)
Compute remaining latency.
LLVM_ABI bool tryLess(int TryVal, int CandVal, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason)
Return true if this heuristic determines order.
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
LLVM_ABI bool shouldViewMISchedDAGs(const MachineFunction &MF)
Return -misched-view-dags, which is false in a build without assertions.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
Policy for scheduling the next instruction in the candidate's zone.
bool operator==(const CandPolicy &RHS) const
bool operator!=(const CandPolicy &RHS) const
Store the state used by GenericScheduler heuristics, required for the lifetime of one invocation of p...
void reset(const CandPolicy &NewPolicy)
LLVM_ABI void initResourceDelta(const ScheduleDAGMI *DAG, const TargetSchedModel *SchedModel)
Status of an instruction's critical resource consumption.
bool operator!=(const SchedResourceDelta &RHS) const
bool operator==(const SchedResourceDelta &RHS) const
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.
Summarize the scheduling resources required for an instruction of a particular scheduling class.
Definition MCSchedule.h:124
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
RegisterClassInfo * RegClassInfo
MachineBlockFrequencyInfo * MBFI
const MachineLoopInfo * MLI
const TargetMachine * TM
MachineSchedContext & operator=(const MachineSchedContext &other)=delete
MachineSchedContext(const MachineSchedContext &other)=delete
Define a generic scheduling policy for targets that don't provide their own MachineSchedStrategy.
bool ShouldTrackLaneMasks
Track LaneMasks to allow reordering of independent subregister writes of the same vreg.
A CRTP mix-in for passes that can be skipped.
Store the effects of a change in pressure on things that MI scheduler cares about.
MachineBasicBlock::iterator RegionBegin
RegionBegin is the first instruction in the scheduling region, and RegionEnd is either MBB->end() or ...
MachineBasicBlock::iterator RegionEnd
SchedRegion(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E, unsigned N)
Summarize the unscheduled region.
LLVM_ABI void init(ScheduleDAGMI *DAG, const TargetSchedModel *SchedModel)
SmallVector< unsigned, 16 > RemainingCounts