#include "llvm/CodeGen/VLIWMachineScheduler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/DFAPacketizer.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/RegisterPressure.h"
#include "llvm/CodeGen/ScheduleDAG.h"
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSchedule.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <limits>
#include <memory>
#include <sstream>
usingnamespacellvm;
#define DEBUG_TYPE …
static cl::opt<bool> IgnoreBBRegPressure("ignore-bb-reg-pressure", cl::Hidden,
cl::init(false));
static cl::opt<bool> UseNewerCandidate("use-newer-candidate", cl::Hidden,
cl::init(true));
static cl::opt<unsigned> SchedDebugVerboseLevel("misched-verbose-level",
cl::Hidden, cl::init(1));
static cl::opt<bool> CheckEarlyAvail("check-early-avail", cl::Hidden,
cl::init(true));
static cl::opt<float> RPThreshold("vliw-misched-reg-pressure", cl::Hidden,
cl::init(0.75f),
cl::desc("High register pressure threhold."));
VLIWResourceModel::VLIWResourceModel(const TargetSubtargetInfo &STI,
const TargetSchedModel *SM)
: … { … }
void VLIWResourceModel::reset() { … }
VLIWResourceModel::~VLIWResourceModel() { … }
bool VLIWResourceModel::hasDependence(const SUnit *SUd, const SUnit *SUu) { … }
bool VLIWResourceModel::isResourceAvailable(SUnit *SU, bool IsTop) { … }
bool VLIWResourceModel::reserveResources(SUnit *SU, bool IsTop) { … }
DFAPacketizer *
VLIWResourceModel::createPacketizer(const TargetSubtargetInfo &STI) const { … }
void VLIWMachineScheduler::schedule() { … }
void ConvergingVLIWScheduler::initialize(ScheduleDAGMI *dag) { … }
VLIWResourceModel *ConvergingVLIWScheduler::createVLIWResourceModel(
const TargetSubtargetInfo &STI, const TargetSchedModel *SchedModel) const { … }
void ConvergingVLIWScheduler::releaseTopNode(SUnit *SU) { … }
void ConvergingVLIWScheduler::releaseBottomNode(SUnit *SU) { … }
ConvergingVLIWScheduler::VLIWSchedBoundary::~VLIWSchedBoundary() { … }
bool ConvergingVLIWScheduler::VLIWSchedBoundary::checkHazard(SUnit *SU) { … }
void ConvergingVLIWScheduler::VLIWSchedBoundary::releaseNode(
SUnit *SU, unsigned ReadyCycle) { … }
void ConvergingVLIWScheduler::VLIWSchedBoundary::bumpCycle() { … }
void ConvergingVLIWScheduler::VLIWSchedBoundary::bumpNode(SUnit *SU) { … }
void ConvergingVLIWScheduler::VLIWSchedBoundary::releasePending() { … }
void ConvergingVLIWScheduler::VLIWSchedBoundary::removeReady(SUnit *SU) { … }
SUnit *ConvergingVLIWScheduler::VLIWSchedBoundary::pickOnlyChoice() { … }
#ifndef NDEBUG
void ConvergingVLIWScheduler::traceCandidate(const char *Label,
const ReadyQueue &Q, SUnit *SU,
int Cost, PressureChange P) {
dbgs() << Label << " " << Q.getName() << " ";
if (P.isValid())
dbgs() << DAG->TRI->getRegPressureSetName(P.getPSet()) << ":"
<< P.getUnitInc() << " ";
else
dbgs() << " ";
dbgs() << "cost(" << Cost << ")\t";
DAG->dumpNode(*SU);
}
void ConvergingVLIWScheduler::readyQueueVerboseDump(
const RegPressureTracker &RPTracker, SchedCandidate &Candidate,
ReadyQueue &Q) {
RegPressureTracker &TempTracker = const_cast<RegPressureTracker &>(RPTracker);
dbgs() << ">>> " << Q.getName() << "\n";
for (ReadyQueue::iterator I = Q.begin(), E = Q.end(); I != E; ++I) {
RegPressureDelta RPDelta;
TempTracker.getMaxPressureDelta((*I)->getInstr(), RPDelta,
DAG->getRegionCriticalPSets(),
DAG->getRegPressure().MaxSetPressure);
std::stringstream dbgstr;
dbgstr << "SU(" << std::setw(3) << (*I)->NodeNum << ")";
dbgs() << dbgstr.str();
SchedulingCost(Q, *I, Candidate, RPDelta, true);
dbgs() << "\t";
(*I)->getInstr()->dump();
}
dbgs() << "\n";
}
#endif
static inline bool isSingleUnscheduledPred(SUnit *SU, SUnit *SU2) { … }
static inline bool isSingleUnscheduledSucc(SUnit *SU, SUnit *SU2) { … }
int ConvergingVLIWScheduler::pressureChange(const SUnit *SU, bool isBotUp) { … }
int ConvergingVLIWScheduler::SchedulingCost(ReadyQueue &Q, SUnit *SU,
SchedCandidate &Candidate,
RegPressureDelta &Delta,
bool verbose) { … }
ConvergingVLIWScheduler::CandResult
ConvergingVLIWScheduler::pickNodeFromQueue(VLIWSchedBoundary &Zone,
const RegPressureTracker &RPTracker,
SchedCandidate &Candidate) { … }
SUnit *ConvergingVLIWScheduler::pickNodeBidrectional(bool &IsTopNode) { … }
SUnit *ConvergingVLIWScheduler::pickNode(bool &IsTopNode) { … }
void ConvergingVLIWScheduler::schedNode(SUnit *SU, bool IsTopNode) { … }