Path: blob/main/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZMachineScheduler.h
35266 views
//==- SystemZMachineScheduler.h - SystemZ Scheduler Interface ----*- C++ -*-==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// -------------------------- Post RA scheduling ---------------------------- //9// SystemZPostRASchedStrategy is a scheduling strategy which is plugged into10// the MachineScheduler. It has a sorted Available set of SUs and a pickNode()11// implementation that looks to optimize decoder grouping and balance the12// usage of processor resources. Scheduler states are saved for the end13// region of each MBB, so that a successor block can learn from it.14//===----------------------------------------------------------------------===//1516#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H17#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H1819#include "SystemZHazardRecognizer.h"20#include "llvm/CodeGen/MachineScheduler.h"21#include "llvm/CodeGen/ScheduleDAG.h"22#include <set>2324using namespace llvm;2526namespace llvm {2728/// A MachineSchedStrategy implementation for SystemZ post RA scheduling.29class SystemZPostRASchedStrategy : public MachineSchedStrategy {3031const MachineLoopInfo *MLI;32const SystemZInstrInfo *TII;3334// A SchedModel is needed before any DAG is built while advancing past35// non-scheduled instructions, so it would not always be possible to call36// DAG->getSchedClass(SU).37TargetSchedModel SchedModel;3839/// A candidate during instruction evaluation.40struct Candidate {41SUnit *SU = nullptr;4243/// The decoding cost.44int GroupingCost = 0;4546/// The processor resources cost.47int ResourcesCost = 0;4849Candidate() = default;50Candidate(SUnit *SU_, SystemZHazardRecognizer &HazardRec);5152// Compare two candidates.53bool operator<(const Candidate &other);5455// Check if this node is free of cost ("as good as any").56bool noCost() const {57return (GroupingCost <= 0 && !ResourcesCost);58}5960#ifndef NDEBUG61void dumpCosts() {62if (GroupingCost != 0)63dbgs() << " Grouping cost:" << GroupingCost;64if (ResourcesCost != 0)65dbgs() << " Resource cost:" << ResourcesCost;66}67#endif68};6970// A sorter for the Available set that makes sure that SUs are considered71// in the best order.72struct SUSorter {73bool operator() (SUnit *lhs, SUnit *rhs) const {74if (lhs->isScheduleHigh && !rhs->isScheduleHigh)75return true;76if (!lhs->isScheduleHigh && rhs->isScheduleHigh)77return false;7879if (lhs->getHeight() > rhs->getHeight())80return true;81else if (lhs->getHeight() < rhs->getHeight())82return false;8384return (lhs->NodeNum < rhs->NodeNum);85}86};87// A set of SUs with a sorter and dump method.88struct SUSet : std::set<SUnit*, SUSorter> {89#ifndef NDEBUG90void dump(SystemZHazardRecognizer &HazardRec) const;91#endif92};9394/// The set of available SUs to schedule next.95SUSet Available;9697/// Current MBB98MachineBasicBlock *MBB;99100/// Maintain hazard recognizers for all blocks, so that the scheduler state101/// can be maintained past BB boundaries when appropariate.102typedef std::map<MachineBasicBlock*, SystemZHazardRecognizer*> MBB2HazRec;103MBB2HazRec SchedStates;104105/// Pointer to the HazardRecognizer that tracks the scheduler state for106/// the current region.107SystemZHazardRecognizer *HazardRec;108109/// Update the scheduler state by emitting (non-scheduled) instructions110/// up to, but not including, NextBegin.111void advanceTo(MachineBasicBlock::iterator NextBegin);112113public:114SystemZPostRASchedStrategy(const MachineSchedContext *C);115virtual ~SystemZPostRASchedStrategy();116117/// Called for a region before scheduling.118void initPolicy(MachineBasicBlock::iterator Begin,119MachineBasicBlock::iterator End,120unsigned NumRegionInstrs) override;121122/// PostRA scheduling does not track pressure.123bool shouldTrackPressure() const override { return false; }124125// Process scheduling regions top-down so that scheduler states can be126// transferrred over scheduling boundaries.127bool doMBBSchedRegionsTopDown() const override { return true; }128129void initialize(ScheduleDAGMI *dag) override;130131/// Tell the strategy that MBB is about to be processed.132void enterMBB(MachineBasicBlock *NextMBB) override;133134/// Tell the strategy that current MBB is done.135void leaveMBB() override;136137/// Pick the next node to schedule, or return NULL.138SUnit *pickNode(bool &IsTopNode) override;139140/// ScheduleDAGMI has scheduled an instruction - tell HazardRec141/// about it.142void schedNode(SUnit *SU, bool IsTopNode) override;143144/// SU has had all predecessor dependencies resolved. Put it into145/// Available.146void releaseTopNode(SUnit *SU) override;147148/// Currently only scheduling top-down, so this method is empty.149void releaseBottomNode(SUnit *SU) override {};150};151152} // end namespace llvm153154#endif // LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZMACHINESCHEDULER_H155156157