Jonas Paulsson | 8010b63 | 2016-10-20 08:27:16 +0000 | [diff] [blame^] | 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 | |
| 17 | #include "SystemZInstrInfo.h" |
| 18 | #include "SystemZHazardRecognizer.h" |
| 19 | #include "llvm/CodeGen/MachineScheduler.h" |
| 20 | #include "llvm/Support/Debug.h" |
| 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. |
| 30 | class SystemZPostRASchedStrategy : public MachineSchedStrategy { |
| 31 | ScheduleDAGMI *DAG; |
| 32 | |
| 33 | /// A candidate during instruction evaluation. |
| 34 | struct Candidate { |
| 35 | SUnit *SU; |
| 36 | |
| 37 | /// The decoding cost. |
| 38 | int GroupingCost; |
| 39 | |
| 40 | /// The processor resources cost. |
| 41 | int ResourcesCost; |
| 42 | |
| 43 | Candidate() : SU(nullptr), GroupingCost(0), ResourcesCost(0) {} |
| 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 inline noCost() { |
| 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); |
| 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: |
| 87 | 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 | |
| 110 | } // namespace llvm |
| 111 | |
| 112 | #endif /* LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H */ |