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. Scheduler states are saved for the end
15 // region of each MBB, so that a successor block can learn from it.
16 //===----------------------------------------------------------------------===//
18 #include "SystemZHazardRecognizer.h"
19 #include "llvm/CodeGen/MachineScheduler.h"
20 #include "llvm/CodeGen/ScheduleDAG.h"
23 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
24 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
30 /// A MachineSchedStrategy implementation for SystemZ post RA scheduling.
31 class SystemZPostRASchedStrategy
: public MachineSchedStrategy
{
33 const MachineLoopInfo
*MLI
;
34 const SystemZInstrInfo
*TII
;
36 // A SchedModel is needed before any DAG is built while advancing past
37 // non-scheduled instructions, so it would not always be possible to call
38 // DAG->getSchedClass(SU).
39 TargetSchedModel SchedModel
;
41 /// A candidate during instruction evaluation.
45 /// The decoding cost.
48 /// The processor resources cost.
49 int ResourcesCost
= 0;
51 Candidate() = default;
52 Candidate(SUnit
*SU_
, SystemZHazardRecognizer
&HazardRec
);
54 // Compare two candidates.
55 bool operator<(const Candidate
&other
);
57 // Check if this node is free of cost ("as good as any").
59 return (GroupingCost
<= 0 && !ResourcesCost
);
64 if (GroupingCost
!= 0)
65 dbgs() << " Grouping cost:" << GroupingCost
;
66 if (ResourcesCost
!= 0)
67 dbgs() << " Resource cost:" << ResourcesCost
;
72 // A sorter for the Available set that makes sure that SUs are considered
75 bool operator() (SUnit
*lhs
, SUnit
*rhs
) const {
76 if (lhs
->isScheduleHigh
&& !rhs
->isScheduleHigh
)
78 if (!lhs
->isScheduleHigh
&& rhs
->isScheduleHigh
)
81 if (lhs
->getHeight() > rhs
->getHeight())
83 else if (lhs
->getHeight() < rhs
->getHeight())
86 return (lhs
->NodeNum
< rhs
->NodeNum
);
89 // A set of SUs with a sorter and dump method.
90 struct SUSet
: std::set
<SUnit
*, SUSorter
> {
92 void dump(SystemZHazardRecognizer
&HazardRec
) const;
96 /// The set of available SUs to schedule next.
100 MachineBasicBlock
*MBB
;
102 /// Maintain hazard recognizers for all blocks, so that the scheduler state
103 /// can be maintained past BB boundaries when appropariate.
104 typedef std::map
<MachineBasicBlock
*, SystemZHazardRecognizer
*> MBB2HazRec
;
105 MBB2HazRec SchedStates
;
107 /// Pointer to the HazardRecognizer that tracks the scheduler state for
108 /// the current region.
109 SystemZHazardRecognizer
*HazardRec
;
111 /// Update the scheduler state by emitting (non-scheduled) instructions
112 /// up to, but not including, NextBegin.
113 void advanceTo(MachineBasicBlock::iterator NextBegin
);
116 SystemZPostRASchedStrategy(const MachineSchedContext
*C
);
117 virtual ~SystemZPostRASchedStrategy();
119 /// Called for a region before scheduling.
120 void initPolicy(MachineBasicBlock::iterator Begin
,
121 MachineBasicBlock::iterator End
,
122 unsigned NumRegionInstrs
) override
;
124 /// PostRA scheduling does not track pressure.
125 bool shouldTrackPressure() const override
{ return false; }
127 // Process scheduling regions top-down so that scheduler states can be
128 // transferrred over scheduling boundaries.
129 bool doMBBSchedRegionsTopDown() const override
{ return true; }
131 void initialize(ScheduleDAGMI
*dag
) override
;
133 /// Tell the strategy that MBB is about to be processed.
134 void enterMBB(MachineBasicBlock
*NextMBB
) override
;
136 /// Tell the strategy that current MBB is done.
137 void leaveMBB() override
;
139 /// Pick the next node to schedule, or return NULL.
140 SUnit
*pickNode(bool &IsTopNode
) override
;
142 /// ScheduleDAGMI has scheduled an instruction - tell HazardRec
144 void schedNode(SUnit
*SU
, bool IsTopNode
) override
;
146 /// SU has had all predecessor dependencies resolved. Put it into
148 void releaseTopNode(SUnit
*SU
) override
;
150 /// Currently only scheduling top-down, so this method is empty.
151 void releaseBottomNode(SUnit
*SU
) override
{};
154 } // end namespace llvm
156 #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H