18 #define DEBUG_TYPE "machine-scheduler"
21 class GCNMinRegScheduler {
26 Candidate(
const SUnit *SU_,
int Priority_ = 0)
27 : SU(SU_), Priority(Priority_) {}
34 std::vector<unsigned> NumPreds;
36 bool isScheduled(
const SUnit *SU)
const {
41 void setIsScheduled(
const SUnit *SU) {
46 unsigned getNumPreds(
const SUnit *SU)
const {
52 unsigned decNumPreds(
const SUnit *SU) {
60 int getReadySuccessors(
const SUnit *SU)
const;
61 int getNotReadySuccessors(
const SUnit *SU)
const;
63 template <
typename Calc>
64 unsigned findMax(
unsigned Num, Calc
C);
66 Candidate* pickCandidate();
68 void bumpPredsPriority(
const SUnit *SchedSU,
int Priority);
69 void releaseSuccessors(
const SUnit* SU,
int Priority);
78 NumPreds.resize(SUnits.size());
79 for (
unsigned I = 0;
I < SUnits.size(); ++
I)
80 NumPreds[
I] = SUnits[
I].NumPredsLeft;
83 int GCNMinRegScheduler::getReadySuccessors(
const SUnit *SU)
const {
84 unsigned NumSchedSuccs = 0;
86 bool wouldBeScheduled =
true;
88 auto PSU = PDep.getSUnit();
89 assert(!PSU->isBoundaryNode());
90 if (PSU != SU && !isScheduled(PSU)) {
91 wouldBeScheduled =
false;
95 NumSchedSuccs += wouldBeScheduled ? 1 : 0;
100 int GCNMinRegScheduler::getNotReadySuccessors(
const SUnit *SU)
const {
101 return SU->
Succs.size() - getReadySuccessors(SU);
104 template <
typename Calc>
105 unsigned GCNMinRegScheduler::findMax(
unsigned Num, Calc
C) {
106 assert(!RQ.empty() && Num <= RQ.size());
107 typedef decltype(
C(*RQ.begin()))
T;
108 T Max = std::numeric_limits<
T>::
min();
128 GCNMinRegScheduler::Candidate* GCNMinRegScheduler::pickCandidate() {
130 unsigned Num = RQ.size();
133 DEBUG(
dbgs() <<
"\nSelecting max priority candidates among " << Num <<
'\n');
134 Num = findMax(Num, [=](
const Candidate &C) {
return C.Priority; });
137 DEBUG(
dbgs() <<
"\nSelecting min non-ready producing candidate among "
139 Num = findMax(Num, [=](
const Candidate &C) {
141 int Res = getNotReadySuccessors(SU);
143 << Res <<
" successors, metric = " << -Res <<
'\n');
148 DEBUG(
dbgs() <<
"\nSelecting most producing candidate among "
150 Num = findMax(Num, [=](
const Candidate &C) {
152 auto Res = getReadySuccessors(SU);
154 << Res <<
" successors, metric = " << Res <<
'\n');
159 Num = Num ? Num : RQ.size();
160 DEBUG(
dbgs() <<
"\nCan't find best candidate, selecting in program order among "
162 Num = findMax(Num, [=](
const Candidate &C) {
return -(int64_t)C.SU->NodeNum; });
169 void GCNMinRegScheduler::bumpPredsPriority(
const SUnit *SchedSU,
int Priority) {
171 for (
const auto &S : SchedSU->
Succs) {
172 if (S.getSUnit()->isBoundaryNode() || isScheduled(S.getSUnit()) ||
175 for (
const auto &
P : S.getSUnit()->Preds) {
176 auto PSU =
P.getSUnit();
177 assert(!PSU->isBoundaryNode());
178 if (PSU != SchedSU && !isScheduled(PSU)) {
184 while (!Worklist.empty()) {
185 auto SU = Worklist.pop_back_val();
187 for (
const auto &
P : SU->
Preds) {
188 if (!
P.getSUnit()->isBoundaryNode() && !isScheduled(
P.getSUnit()) &&
190 Worklist.push_back(
P.getSUnit());
194 <<
")'s non-ready successors of " << Priority
195 <<
" priority in ready queue: ");
196 const auto SetEnd = Set.
end();
198 if (Set.
find(C.SU) != SetEnd) {
199 C.Priority = Priority;
200 DEBUG(
dbgs() <<
" SU(" << C.SU->NodeNum <<
')');
206 void GCNMinRegScheduler::releaseSuccessors(
const SUnit* SU,
int Priority) {
207 for (
const auto &S : SU->
Succs) {
208 auto SuccSU = S.getSUnit();
211 assert(SuccSU->isBoundaryNode() || getNumPreds(SuccSU) > 0);
212 if (!SuccSU->isBoundaryNode() && decNumPreds(SuccSU) == 0)
213 RQ.push_front(*new (
Alloc.
Allocate()) Candidate(SuccSU, Priority));
217 std::vector<const SUnit*>
220 const auto &SUnits = DAG.
SUnits;
221 std::vector<const SUnit*> Schedule;
222 Schedule.reserve(SUnits.size());
224 initNumPreds(SUnits);
228 for (
auto SU : TopRoots) {
231 releaseSuccessors(&DAG.
EntrySU, StepNo);
233 while (!RQ.empty()) {
235 dbgs() <<
"\n=== Picking candidate, Step = " << StepNo <<
"\n"
238 dbgs() <<
' ' << C.SU->NodeNum <<
"(P" << C.Priority <<
')';
242 auto C = pickCandidate();
248 releaseSuccessors(SU, StepNo);
249 Schedule.push_back(SU);
252 if (getReadySuccessors(SU) == 0)
253 bumpPredsPriority(SU, StepNo);
257 assert(SUnits.size() == Schedule.size());
265 GCNMinRegScheduler S;
266 return S.schedule(TopRoots, DAG);
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
SmallVector< SDep, 4 > Preds
All sunit predecessors.
Regular data dependence (aka true-dependence).
A simple intrusive list implementation.
void dump(const ScheduleDAG *G) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
std::vector< const SUnit * > makeMinRegSchedule(ArrayRef< const SUnit * > TopRoots, const ScheduleDAG &DAG)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator find(ConstPtrType Ptr) const
bool isBoundaryNode() const
Boundary nodes are placeholders for the boundary of the scheduling region.
SUnit EntrySU
Special node for the region entry.
unsigned NodeNum
Entry # of node in the node vector.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SmallVector< SDep, 4 > Succs
All sunit successors.
std::vector< SUnit > SUnits
The scheduling units.
Scheduling unit. This is a node in the scheduling DAG.