blob: 12357e0348a9ec95c82a583555b621cd57b02252 [file] [log] [blame]
Eugene Zelenko3943d2b2017-01-24 22:10:43 +00001//==- SystemZMachineScheduler.h - SystemZ Scheduler Interface ----*- C++ -*-==//
Jonas Paulsson8010b632016-10-20 08:27:16 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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//===----------------------------------------------------------------------===//
16
Jonas Paulsson8010b632016-10-20 08:27:16 +000017#include "SystemZHazardRecognizer.h"
18#include "llvm/CodeGen/MachineScheduler.h"
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000019#include "llvm/CodeGen/ScheduleDAG.h"
20#include <set>
Jonas Paulsson8010b632016-10-20 08:27:16 +000021
22#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
23#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
24
25using namespace llvm;
26
27namespace llvm {
28
29/// A MachineSchedStrategy implementation for SystemZ post RA scheduling.
30class SystemZPostRASchedStrategy : public MachineSchedStrategy {
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000031 ScheduleDAGMI *DAG;
Jonas Paulsson8010b632016-10-20 08:27:16 +000032
33 /// A candidate during instruction evaluation.
34 struct Candidate {
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000035 SUnit *SU = nullptr;
Jonas Paulsson8010b632016-10-20 08:27:16 +000036
37 /// The decoding cost.
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000038 int GroupingCost = 0;
Jonas Paulsson8010b632016-10-20 08:27:16 +000039
40 /// The processor resources cost.
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000041 int ResourcesCost = 0;
Jonas Paulsson8010b632016-10-20 08:27:16 +000042
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000043 Candidate() = default;
Jonas Paulsson8010b632016-10-20 08:27:16 +000044 Candidate(SUnit *SU_, SystemZHazardRecognizer &HazardRec);
45
46 // Compare two candidates.
47 bool operator<(const Candidate &other);
48
49 // Check if this node is free of cost ("as good as any").
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000050 bool noCost() const {
Jonas Paulsson8010b632016-10-20 08:27:16 +000051 return (GroupingCost <= 0 && !ResourcesCost);
52 }
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000053 };
Jonas Paulsson8010b632016-10-20 08:27:16 +000054
55 // A sorter for the Available set that makes sure that SUs are considered
56 // in the best order.
57 struct SUSorter {
58 bool operator() (SUnit *lhs, SUnit *rhs) const {
59 if (lhs->isScheduleHigh && !rhs->isScheduleHigh)
60 return true;
61 if (!lhs->isScheduleHigh && rhs->isScheduleHigh)
62 return false;
63
64 if (lhs->getHeight() > rhs->getHeight())
65 return true;
66 else if (lhs->getHeight() < rhs->getHeight())
67 return false;
68
69 return (lhs->NodeNum < rhs->NodeNum);
70 }
71 };
72 // A set of SUs with a sorter and dump method.
73 struct SUSet : std::set<SUnit*, SUSorter> {
74 #ifndef NDEBUG
75 void dump(SystemZHazardRecognizer &HazardRec);
76 #endif
77 };
78
79 /// The set of available SUs to schedule next.
80 SUSet Available;
81
82 // HazardRecognizer that tracks the scheduler state for the current
83 // region.
84 SystemZHazardRecognizer HazardRec;
85
Eugene Zelenko3943d2b2017-01-24 22:10:43 +000086public:
Jonas Paulsson8010b632016-10-20 08:27:16 +000087 SystemZPostRASchedStrategy(const MachineSchedContext *C);
88
89 /// PostRA scheduling does not track pressure.
90 bool shouldTrackPressure() const override { return false; }
91
92 /// Initialize the strategy after building the DAG for a new region.
93 void initialize(ScheduleDAGMI *dag) override;
94
95 /// Pick the next node to schedule, or return NULL.
96 SUnit *pickNode(bool &IsTopNode) override;
97
98 /// ScheduleDAGMI has scheduled an instruction - tell HazardRec
99 /// about it.
100 void schedNode(SUnit *SU, bool IsTopNode) override;
101
102 /// SU has had all predecessor dependencies resolved. Put it into
103 /// Available.
104 void releaseTopNode(SUnit *SU) override;
105
106 /// Currently only scheduling top-down, so this method is empty.
107 void releaseBottomNode(SUnit *SU) override {};
108};
109
Eugene Zelenko3943d2b2017-01-24 22:10:43 +0000110} // end namespace llvm
Jonas Paulsson8010b632016-10-20 08:27:16 +0000111
Eugene Zelenko3943d2b2017-01-24 22:10:43 +0000112#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H