LLVM  5.0.0
SystemZMachineScheduler.h
Go to the documentation of this file.
1 //==- SystemZMachineScheduler.h - SystemZ Scheduler Interface ----*- C++ -*-==//
2 //
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 
20 #include <set>
21 
22 #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
23 #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
24 
25 using namespace llvm;
26 
27 namespace llvm {
28 
29 /// A MachineSchedStrategy implementation for SystemZ post RA scheduling.
31  ScheduleDAGMI *DAG;
32 
33  /// A candidate during instruction evaluation.
34  struct Candidate {
35  SUnit *SU = nullptr;
36 
37  /// The decoding cost.
38  int GroupingCost = 0;
39 
40  /// The processor resources cost.
41  int ResourcesCost = 0;
42 
43  Candidate() = default;
44  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").
50  bool noCost() const {
51  return (GroupingCost <= 0 && !ResourcesCost);
52  }
53  };
54 
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) const;
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 
86 public:
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 
110 } // end namespace llvm
111 
112 #endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H
void releaseTopNode(SUnit *SU) override
SU has had all predecessor dependencies resolved.
SUnit * pickNode(bool &IsTopNode) override
Pick the next node to schedule, or return NULL.
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
Definition: ScheduleDAG.h:411
void initialize(ScheduleDAGMI *dag) override
Initialize the strategy after building the DAG for a new region.
SystemZHazardRecognizer maintains the state during scheduling.
void schedNode(SUnit *SU, bool IsTopNode) override
ScheduleDAGMI has scheduled an instruction - tell HazardRec about it.
A MachineSchedStrategy implementation for SystemZ post RA scheduling.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool isScheduleHigh
True if preferable to schedule high.
Definition: ScheduleDAG.h:290
SystemZPostRASchedStrategy(const MachineSchedContext *C)
bool shouldTrackPressure() const override
PostRA scheduling does not track pressure.
#define C
Definition: LargeTest.cpp:25
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
MachineSchedStrategy - Interface to the scheduling algorithm used by ScheduleDAGMI.
void releaseBottomNode(SUnit *SU) override
Currently only scheduling top-down, so this method is empty.
unsigned NodeNum
Entry # of node in the node vector.
Definition: ScheduleDAG.h:269
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
Scheduling unit. This is a node in the scheduling DAG.
Definition: ScheduleDAG.h:247