1 //==- SystemZMachineScheduler.h - SystemZ Scheduler Interface ----*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // -------------------------- Post RA scheduling ---------------------------- //
11 // SystemZPostRASchedStrategy is a scheduling strategy which is plugged into
12 // the MachineScheduler. It has a sorted Available set of SUs and a pickNode()
13 // implementation that looks to optimize decoder grouping and balance the
14 // usage of processor resources.
15 //===----------------------------------------------------------------------===//
17 #include "SystemZHazardRecognizer.h"
18 #include "llvm/CodeGen/MachineScheduler.h"
19 #include "llvm/CodeGen/ScheduleDAG.h"
22 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
23 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
29 /// A MachineSchedStrategy implementation for SystemZ post RA scheduling.
30 class SystemZPostRASchedStrategy : public MachineSchedStrategy {
33 /// A candidate during instruction evaluation.
37 /// The decoding cost.
40 /// The processor resources cost.
41 int ResourcesCost = 0;
43 Candidate() = default;
44 Candidate(SUnit *SU_, SystemZHazardRecognizer &HazardRec);
46 // Compare two candidates.
47 bool operator<(const Candidate &other);
49 // Check if this node is free of cost ("as good as any").
51 return (GroupingCost <= 0 && !ResourcesCost);
55 // A sorter for the Available set that makes sure that SUs are considered
58 bool operator() (SUnit *lhs, SUnit *rhs) const {
59 if (lhs->isScheduleHigh && !rhs->isScheduleHigh)
61 if (!lhs->isScheduleHigh && rhs->isScheduleHigh)
64 if (lhs->getHeight() > rhs->getHeight())
66 else if (lhs->getHeight() < rhs->getHeight())
69 return (lhs->NodeNum < rhs->NodeNum);
72 // A set of SUs with a sorter and dump method.
73 struct SUSet : std::set<SUnit*, SUSorter> {
75 void dump(SystemZHazardRecognizer &HazardRec) const;
79 /// The set of available SUs to schedule next.
82 // HazardRecognizer that tracks the scheduler state for the current
84 SystemZHazardRecognizer HazardRec;
87 SystemZPostRASchedStrategy(const MachineSchedContext *C);
89 /// PostRA scheduling does not track pressure.
90 bool shouldTrackPressure() const override { return false; }
92 /// Initialize the strategy after building the DAG for a new region.
93 void initialize(ScheduleDAGMI *dag) override;
95 /// Pick the next node to schedule, or return NULL.
96 SUnit *pickNode(bool &IsTopNode) override;
98 /// ScheduleDAGMI has scheduled an instruction - tell HazardRec
100 void schedNode(SUnit *SU, bool IsTopNode) override;
102 /// SU has had all predecessor dependencies resolved. Put it into
104 void releaseTopNode(SUnit *SU) override;
106 /// Currently only scheduling top-down, so this method is empty.
107 void releaseBottomNode(SUnit *SU) override {};
110 } // end namespace llvm
112 #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H