#include "GCNIterativeScheduler.h"
#include "GCNSchedStrategy.h"
#include "SIMachineFunctionInfo.h"
usingnamespacellvm;
#define DEBUG_TYPE …
namespace llvm {
std::vector<const SUnit *> makeMinRegSchedule(ArrayRef<const SUnit *> TopRoots,
const ScheduleDAG &DAG);
std::vector<const SUnit *> makeGCNILPScheduler(ArrayRef<const SUnit *> BotRoots,
const ScheduleDAG &DAG);
}
static inline MachineInstr *getMachineInstr(MachineInstr *MI) { … }
static inline MachineInstr *getMachineInstr(const SUnit *SU) { … }
static inline MachineInstr *getMachineInstr(const SUnit &SU) { … }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
static void printRegion(raw_ostream &OS,
MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End,
const LiveIntervals *LIS,
unsigned MaxInstNum =
std::numeric_limits<unsigned>::max()) {
auto BB = Begin->getParent();
OS << BB->getParent()->getName() << ":" << printMBBReference(*BB) << ' '
<< BB->getName() << ":\n";
auto I = Begin;
MaxInstNum = std::max(MaxInstNum, 1u);
for (; I != End && MaxInstNum; ++I, --MaxInstNum) {
if (!I->isDebugInstr() && LIS)
OS << LIS->getInstructionIndex(*I);
OS << '\t' << *I;
}
if (I != End) {
OS << "\t...\n";
I = std::prev(End);
if (!I->isDebugInstr() && LIS)
OS << LIS->getInstructionIndex(*I);
OS << '\t' << *I;
}
if (End != BB->end()) {
OS << "----\n";
if (LIS) OS << LIS->getInstructionIndex(*End) << '\t';
OS << *End;
}
}
LLVM_DUMP_METHOD
static void printLivenessInfo(raw_ostream &OS,
MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End,
const LiveIntervals *LIS) {
const auto BB = Begin->getParent();
const auto &MRI = BB->getParent()->getRegInfo();
const auto LiveIns = getLiveRegsBefore(*Begin, *LIS);
OS << "LIn RP: " << print(getRegPressure(MRI, LiveIns));
const auto BottomMI = End == BB->end() ? std::prev(End) : End;
const auto LiveOuts = getLiveRegsAfter(*BottomMI, *LIS);
OS << "LOt RP: " << print(getRegPressure(MRI, LiveOuts));
}
LLVM_DUMP_METHOD
void GCNIterativeScheduler::printRegions(raw_ostream &OS) const {
const auto &ST = MF.getSubtarget<GCNSubtarget>();
for (const auto R : Regions) {
OS << "Region to schedule ";
printRegion(OS, R->Begin, R->End, LIS, 1);
printLivenessInfo(OS, R->Begin, R->End, LIS);
OS << "Max RP: " << print(R->MaxPressure, &ST);
}
}
LLVM_DUMP_METHOD
void GCNIterativeScheduler::printSchedResult(raw_ostream &OS,
const Region *R,
const GCNRegPressure &RP) const {
OS << "\nAfter scheduling ";
printRegion(OS, R->Begin, R->End, LIS);
printSchedRP(OS, R->MaxPressure, RP);
OS << '\n';
}
LLVM_DUMP_METHOD
void GCNIterativeScheduler::printSchedRP(raw_ostream &OS,
const GCNRegPressure &Before,
const GCNRegPressure &After) const {
const auto &ST = MF.getSubtarget<GCNSubtarget>();
OS << "RP before: " << print(Before, &ST)
<< "RP after: " << print(After, &ST);
}
#endif
class GCNIterativeScheduler::BuildDAG { … };
class GCNIterativeScheduler::OverrideLegacyStrategy { … };
namespace {
class SchedStrategyStub : public MachineSchedStrategy { … };
}
GCNIterativeScheduler::GCNIterativeScheduler(MachineSchedContext *C,
StrategyKind S)
: … { … }
GCNRegPressure
GCNIterativeScheduler::getRegionPressure(MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End)
const { … }
template <typename Range> GCNRegPressure
GCNIterativeScheduler::getSchedulePressure(const Region &R,
Range &&Schedule) const { … }
void GCNIterativeScheduler::enterRegion(MachineBasicBlock *BB,
MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End,
unsigned NumRegionInstrs) { … }
void GCNIterativeScheduler::schedule() { … }
void GCNIterativeScheduler::finalizeSchedule() { … }
std::vector<MachineInstr*>
GCNIterativeScheduler::detachSchedule(ScheduleRef Schedule) const { … }
void GCNIterativeScheduler::setBestSchedule(Region &R,
ScheduleRef Schedule,
const GCNRegPressure &MaxRP) { … }
void GCNIterativeScheduler::scheduleBest(Region &R) { … }
template <typename Range>
void GCNIterativeScheduler::scheduleRegion(Region &R, Range &&Schedule,
const GCNRegPressure &MaxRP) { … }
void GCNIterativeScheduler::sortRegionsByPressure(unsigned TargetOcc) { … }
unsigned GCNIterativeScheduler::tryMaximizeOccupancy(unsigned TargetOcc) { … }
void GCNIterativeScheduler::scheduleLegacyMaxOccupancy(
bool TryMaximizeOccupancy) { … }
void GCNIterativeScheduler::scheduleMinReg(bool force) { … }
void GCNIterativeScheduler::scheduleILP(
bool TryMaximizeOccupancy) { … }