31#define DEBUG_TYPE "igrouplp"
37 cl::desc(
"Whether to use the exponential time solver to fit "
38 "the instructions to the pipeline as closely as "
44 cl::desc(
"The maximum number of scheduling group conflicts "
45 "which we attempt to solve with the exponential time "
46 "exact solver. Problem sizes greater than this will"
47 "be solved by the less accurate greedy algorithm. Selecting "
48 "solver by size is superseded by manually selecting "
49 "the solver (e.g. by amdgpu-igrouplp-exact-solver"));
53 cl::desc(
"The amount of branches that we are willing to explore with"
54 "the exact algorithm before giving up."));
58 cl::desc(
"Whether to use the cost heuristic to make choices as we "
59 "traverse the search space using the exact solver. Defaulted "
60 "to on, and if turned off, we will use the node order -- "
61 "attempting to put the later nodes in the later sched groups. "
62 "Experimentally, results are mixed, so this should be set on a "
63 "case-by-case basis."));
67enum class SchedGroupMask {
80 ALL = ALU | VALU | SALU |
MFMA | VMEM | VMEM_READ | VMEM_WRITE | DS |
81 DS_READ | DS_WRITE | TRANS,
90class InstructionRule {
96 std::optional<SmallVector<SUnit *, 4>> Cache;
106 bool NeedsCache =
false)
113 virtual ~InstructionRule() =
default;
126 SchedGroupMask SGMask;
129 std::optional<unsigned> MaxSize;
142 static unsigned NumSchedGroups;
159 bool canAddSU(
SUnit &SU)
const;
164 void link(
SUnit &SU,
bool MakePred =
false);
168 int link(
SUnit &SU,
bool MakePred,
169 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
178 void link(SchedGroup &OtherGroup);
181 bool isFull()
const {
return MaxSize && Collection.
size() >= *MaxSize; }
187 void addRule(std::shared_ptr<InstructionRule> NewRule) {
192 bool allowedByRules(
const SUnit *SU,
194 for (
auto &Rule : Rules) {
195 if (!Rule->apply(SU, Collection, SyncPipe))
202 void add(
SUnit &SU) {
204 <<
format_hex((
int)SGMask, 10,
true) <<
" adding "
210 void pop() { Collection.
pop_back(); }
213 void findCandidateSUnits(
T Begin,
T End,
214 SUnitsToCandidateSGsMap &SyncedInstrs);
219 void findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs);
221 int getSyncID() {
return SyncID; }
223 int getSGID() {
return SGID; }
225 SchedGroupMask
getMask() {
return SGMask; }
227 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
229 : SGMask(SGMask), MaxSize(MaxSize), DAG(DAG),
TII(
TII) {
230 SGID = NumSchedGroups++;
233 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
int SyncID,
235 : SGMask(SGMask), MaxSize(MaxSize), SyncID(SyncID), DAG(DAG),
TII(
TII) {
236 SGID = NumSchedGroups++;
240using SUToCandSGsPair = std::pair<SUnit *, SmallVector<int, 4>>;
252class PipelineSolver {
265 bool NeedsSolver =
false;
269 unsigned computeProblemSize();
280 int CurrConflInstNo = 0;
282 int CurrSyncGroupIdx = 0;
284 int BeginSyncGroupIdx = 0;
290 bool IsBottomUp =
true;
293 void advancePosition();
296 void retreatPosition();
305 template <
typename T>
306 void greedyFind(std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
311 template <
typename T>
318 template <
typename T>
void linkSchedGroups(
T I,
T E);
322 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
326 template <
typename T>
327 int linkSUnit(
SUnit *SU,
int SGID,
328 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
330 void removeEdges(
const std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
332 void convertSyncMapsToArrays();
344 : DAG(DAG), SyncedInstrs(SyncedInstrs),
345 SyncedSchedGroups(SyncedSchedGroups), IsBottomUp(IsBottomUp) {
347 for (
auto &PipelineInstrs : SyncedInstrs) {
348 if (!PipelineInstrs.second.
empty()) {
357 convertSyncMapsToArrays();
359 CurrPipeline = BestPipeline;
361 while (
static_cast<size_t>(BeginSyncGroupIdx) < PipelineInstrs.
size() &&
362 PipelineInstrs[BeginSyncGroupIdx].
empty())
365 if (
static_cast<size_t>(BeginSyncGroupIdx) >= PipelineInstrs.
size())
370void PipelineSolver::reset() {
372 for (
auto &SyncPipeline : CurrPipeline) {
373 for (
auto &SG : SyncPipeline) {
375 SG.Collection.
clear();
379 if (SchedBarr != TempCollection.
end())
380 SG.Collection.push_back(*SchedBarr);
384 CurrSyncGroupIdx = BeginSyncGroupIdx;
389void PipelineSolver::convertSyncMapsToArrays() {
390 for (
auto &SyncPipe : SyncedSchedGroups) {
391 BestPipeline.insert(BestPipeline.begin(), SyncPipe.second);
394 int PipelineIDx = SyncedInstrs.size() - 1;
395 PipelineInstrs.resize(SyncedInstrs.size());
396 for (
auto &SyncInstrMap : SyncedInstrs) {
397 for (
auto &SUsToCandSGs : SyncInstrMap.second) {
398 if (PipelineInstrs[PipelineIDx].empty()) {
399 PipelineInstrs[PipelineIDx].push_back(
400 std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
403 auto *SortPosition = PipelineInstrs[PipelineIDx].begin();
406 while (SortPosition != PipelineInstrs[PipelineIDx].end() &&
407 SUsToCandSGs.first->NodeNum > SortPosition->first->NodeNum)
409 PipelineInstrs[PipelineIDx].insert(
410 SortPosition, std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
416template <
typename T>
void PipelineSolver::linkSchedGroups(
T I,
T E) {
417 for (;
I !=
E; ++
I) {
419 for (
auto J = std::next(
I); J !=
E; ++J) {
426void PipelineSolver::makePipeline() {
428 for (
auto &SyncPipeline : BestPipeline) {
430 for (
auto &SG : SyncPipeline) {
433 SUnit *SGBarr =
nullptr;
434 for (
auto &SU : SG.Collection) {
435 if (SU->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
442 SG.link(*SGBarr,
false);
446 for (
auto &SyncPipeline : BestPipeline) {
447 IsBottomUp ? linkSchedGroups(SyncPipeline.rbegin(), SyncPipeline.rend())
448 : linkSchedGroups(SyncPipeline.begin(), SyncPipeline.end());
453int PipelineSolver::linkSUnit(
454 SUnit *SU,
int SGID, std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
456 bool MakePred =
false;
459 if (
I->getSGID() == SGID) {
464 AddedCost += Group.link(*SU, MakePred, AddedEdges);
470int PipelineSolver::addEdges(
472 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
482 return IsBottomUp ? linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
rbegin(),
484 : linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
begin(),
488void PipelineSolver::removeEdges(
489 const std::list<std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
492 for (
auto &PredSuccPair : EdgesToRemove) {
493 SUnit *Pred = PredSuccPair.first;
494 SUnit *Succ = PredSuccPair.second;
497 Succ->
Preds, [&Pred](
SDep &
P) { return P.getSUnit() == Pred; });
498 if (Match != Succ->
Preds.end()) {
499 assert(Match->isArtificial());
505void PipelineSolver::advancePosition() {
508 if (
static_cast<size_t>(CurrConflInstNo) >=
509 PipelineInstrs[CurrSyncGroupIdx].
size()) {
513 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size() &&
514 PipelineInstrs[CurrSyncGroupIdx].empty())
519void PipelineSolver::retreatPosition() {
520 assert(CurrConflInstNo >= 0);
521 assert(CurrSyncGroupIdx >= 0);
523 if (CurrConflInstNo > 0) {
528 if (CurrConflInstNo == 0) {
531 if (CurrSyncGroupIdx == BeginSyncGroupIdx)
536 while (PipelineInstrs[CurrSyncGroupIdx].empty())
539 CurrConflInstNo = PipelineInstrs[CurrSyncGroupIdx].size() - 1;
543bool PipelineSolver::checkOptimal() {
544 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size()) {
545 if (BestCost == -1 || CurrCost < BestCost) {
546 BestPipeline = CurrPipeline;
553 bool DoneExploring =
false;
554 if (MaxBranchesExplored > 0 && BranchesExplored >= MaxBranchesExplored)
555 DoneExploring =
true;
557 return (DoneExploring || BestCost == 0);
561void PipelineSolver::populateReadyList(
563 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
564 auto SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
565 assert(CurrSU.second.size() >= 1);
567 for (;
I !=
E; ++
I) {
568 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
570 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
571 return SG.getSGID() == CandSGID;
576 if (Match->isFull()) {
577 ReadyList.push_back(std::pair(*
I, MissPenalty));
581 int TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
582 ReadyList.push_back(std::pair(*
I, TempCost));
583 removeEdges(AddedEdges);
585 ReadyList.push_back(std::pair(*
I, -1));
591 assert(ReadyList.size() == CurrSU.second.size());
594bool PipelineSolver::solveExact() {
598 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size())
601 assert(
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size());
602 assert(
static_cast<size_t>(CurrConflInstNo) <
603 PipelineInstrs[CurrSyncGroupIdx].
size());
604 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
606 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
611 IsBottomUp ? populateReadyList(ReadyList, CurrSU.second.
rbegin(),
612 CurrSU.second.rend())
613 : populateReadyList(ReadyList, CurrSU.second.
begin(),
614 CurrSU.second.end());
616 auto *
I = ReadyList.
begin();
617 auto *
E = ReadyList.
end();
618 for (;
I !=
E; ++
I) {
622 if (BestCost != -1 && (CurrCost +
I->second > BestCost))
625 int CandSGID =
I->first;
627 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
628 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
630 for (
auto &SG : SyncPipeline) {
631 if (SG.getSGID() == CandSGID)
638 if (!Match->allowedByRules(CurrSU.first, SyncPipeline))
642 << (
int)Match->getMask() <<
"and ID " << CandSGID
644 Match->add(*CurrSU.first);
645 AddedCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
646 LLVM_DEBUG(
dbgs() <<
"Cost of Assignment: " << AddedCost <<
"\n");
647 CurrCost += AddedCost;
650 bool FinishedExploring =
false;
653 if (CurrCost < BestCost || BestCost == -1) {
655 FinishedExploring = BestCost != 0;
656 if (!FinishedExploring)
662 CurrCost -= AddedCost;
663 removeEdges(AddedEdges);
665 CurrPipeline[CurrSyncGroupIdx] = SyncPipeline;
666 if (FinishedExploring)
673 CurrCost += MissPenalty;
676 LLVM_DEBUG(
dbgs() <<
"NOT Assigned (" << CurrSU.first->NodeNum <<
")\n");
678 bool FinishedExploring =
false;
679 if (CurrCost < BestCost || BestCost == -1) {
681 bool FinishedExploring = BestCost != 0;
682 if (!FinishedExploring)
688 CurrCost -= MissPenalty;
689 return FinishedExploring;
693void PipelineSolver::greedyFind(
694 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E) {
695 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
696 int BestNodeCost = -1;
698 SchedGroup *BestGroup =
nullptr;
699 int BestGroupID = -1;
700 std::list<std::pair<SUnit *, SUnit *>> BestEdges;
701 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
703 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
709 for (;
I !=
E; ++
I) {
711 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
712 return SG.getSGID() == CandSGID;
716 LLVM_DEBUG(
dbgs() <<
"Trying SGID # " << CandSGID <<
" with Mask "
717 << (
int)Match->getMask() <<
"\n");
719 if (Match->isFull()) {
723 if (!Match->allowedByRules(CurrSU.first, SyncPipeline)) {
724 LLVM_DEBUG(
dbgs() <<
"SGID # " << CandSGID <<
" has conflicting rule\n");
728 std::list<std::pair<SUnit *, SUnit *>> TempEdges;
729 TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, TempEdges);
732 if (TempCost < BestNodeCost || BestNodeCost == -1) {
733 BestEdges = TempEdges;
735 BestNodeCost = TempCost;
736 BestGroupID = CandSGID;
738 if (BestNodeCost == 0)
742 removeEdges(TempEdges);
745 if (BestGroupID != -1) {
746 BestGroup->add(*CurrSU.first);
747 if (AddedEdges.empty())
748 AddedEdges = BestEdges;
750 AddedEdges.splice(std::prev(AddedEdges.cend()), BestEdges);
752 for (
const std::pair<SUnit *, SUnit *> &
E : BestEdges) {
753 if (!BestGroup->tryAddEdge(
E.first,
E.second))
757 LLVM_DEBUG(
dbgs() <<
"Best Group has ID: " << BestGroupID <<
" and Mask"
758 << (
int)BestGroup->getMask() <<
"\n");
759 BestCost += TempCost;
761 BestCost += MissPenalty;
763 CurrPipeline[CurrSyncGroupIdx] = SyncPipeline;
766bool PipelineSolver::solveGreedy() {
768 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
770 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size()) {
771 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
773 ? greedyFind(AddedEdges, CurrSU.second.rbegin(), CurrSU.second.rend())
774 : greedyFind(AddedEdges, CurrSU.second.begin(), CurrSU.second.end());
777 BestPipeline = CurrPipeline;
778 removeEdges(AddedEdges);
782unsigned PipelineSolver::computeProblemSize() {
783 unsigned ProblemSize = 0;
784 for (
auto &PipeConflicts : PipelineInstrs) {
785 ProblemSize += PipeConflicts.size();
791void PipelineSolver::solve() {
795 unsigned ProblemSize = computeProblemSize();
798 bool BelowCutoff = (CutoffForExact > 0) && ProblemSize <= CutoffForExact;
799 MissPenalty = (ProblemSize / 2) + 1;
802 if (EnableExactSolver || BelowCutoff) {
806 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
810 LLVM_DEBUG(
dbgs() <<
"Exact produced best cost of " << BestCost <<
"\n");
822enum IGLPStrategyID :
int {
823 MFMASmallGemmOptID = 0,
824 MFMASmallGemmSingleWaveOptID = 1,
825 MFMAExpInterleaveID = 2,
826 MFMAExpSimpleInterleaveID = 3
838 virtual bool applyIGLPStrategy(
847 bool IsBottomUp =
true;
852 virtual ~IGLPStrategy() =
default;
855class MFMASmallGemmOpt final :
public IGLPStrategy {
858 bool applyIGLPStrategy(
869 : IGLPStrategy(DAG,
TII) {
874bool MFMASmallGemmOpt::applyIGLPStrategy(
879 unsigned MFMACount = 0;
881 if (
TII->isMFMAorWMMA(
I))
884 const unsigned PipelineSyncID = 0;
885 SchedGroup *SG =
nullptr;
886 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
887 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
888 SchedGroupMask::DS, 2, PipelineSyncID, DAG,
TII);
889 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
891 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
892 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
893 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
899class MFMAExpInterleaveOpt final :
public IGLPStrategy {
902 static unsigned TransPipeCount;
904 static unsigned MFMAPipeCount;
906 static unsigned AddPipeCount;
908 static unsigned MFMAEnablement;
910 static unsigned ExpRequirement;
912 static unsigned MFMAChains;
917 static bool HasChainBetweenCvt;
919 static std::optional<unsigned> FirstPipeDSR;
928 class IsPipeExp final :
public InstructionRule {
933 auto *DAG = SyncPipe[0].DAG;
935 if (Cache->empty()) {
936 auto I = DAG->SUnits.rbegin();
937 auto E = DAG->SUnits.rend();
938 for (;
I !=
E;
I++) {
939 if (
TII->isMFMAorWMMA(*
I->getInstr()))
940 Cache->push_back(&*
I);
946 auto Reaches =
any_of(*Cache, [&SU, &DAG](
SUnit *TargetSU) {
947 return DAG->IsReachable(TargetSU,
const_cast<SUnit *
>(SU));
952 IsPipeExp(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
953 : InstructionRule(
TII, SGID, NeedsCache) {}
958 class EnablesNthMFMA final :
public InstructionRule {
965 bool FoundTrans =
false;
966 unsigned Counter = 1;
967 auto *DAG = SyncPipe[0].DAG;
969 if (Cache->empty()) {
970 auto I = DAG->SUnits.begin();
971 auto E = DAG->SUnits.end();
972 for (;
I !=
E;
I++) {
973 if (FoundTrans &&
TII->isMFMAorWMMA(*
I->getInstr())) {
975 Cache->push_back(&*
I);
980 if (!FoundTrans &&
TII->isTRANS(
I->getInstr()->getOpcode()))
987 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
991 bool NeedsCache =
false)
997 class EnablesNthMFMAInChain final :
public InstructionRule {
1005 auto *DAG = SyncPipe[0].DAG;
1007 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1010 if (Cache->empty()) {
1011 auto *TempSU = ChainSeed;
1016 for (
auto &Succ : TempSU->Succs) {
1017 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1018 TempSU = Succ.getSUnit();
1027 Cache->push_back(TempSU);
1033 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1036 EnablesNthMFMAInChain(
unsigned Number,
SUnit *ChainSeed,
1038 bool NeedsCache =
false)
1040 ChainSeed(ChainSeed) {}
1046 class LessThanNSuccs final :
public InstructionRule {
1049 bool HasIntermediary =
false;
1054 if (!SyncPipe.
size())
1058 return Succ.getKind() == SDep::Data;
1060 if (SuccSize >=
Size)
1063 if (HasIntermediary) {
1064 for (
auto Succ : SU->
Succs) {
1067 return SuccSucc.getKind() == SDep::Data;
1069 if (SuccSize >=
Size)
1077 bool HasIntermediary =
false,
bool NeedsCache =
false)
1078 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1079 HasIntermediary(HasIntermediary) {}
1086 class GreaterThanOrEqualToNSuccs final :
public InstructionRule {
1089 bool HasIntermediary =
false;
1094 if (!SyncPipe.
size())
1098 return Succ.getKind() == SDep::Data;
1100 if (SuccSize >=
Size)
1103 if (HasIntermediary) {
1104 for (
auto Succ : SU->
Succs) {
1107 return SuccSucc.getKind() == SDep::Data;
1109 if (SuccSize >=
Size)
1117 unsigned SGID,
bool HasIntermediary =
false,
1118 bool NeedsCache =
false)
1119 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1120 HasIntermediary(HasIntermediary) {}
1124 class IsCvt final :
public InstructionRule {
1129 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
1130 Opc == AMDGPU::V_CVT_I32_F32_e32;
1132 IsCvt(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1133 : InstructionRule(
TII, SGID, NeedsCache) {}
1137 class IsFMA final :
public InstructionRule {
1144 IsFMA(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1145 : InstructionRule(
TII, SGID, NeedsCache) {}
1149 class IsPipeAdd final :
public InstructionRule {
1155 IsPipeAdd(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1156 : InstructionRule(
TII, SGID, NeedsCache) {}
1161 class IsSuccOfPrevNthGroup final :
public InstructionRule {
1163 unsigned Distance = 1;
1168 SchedGroup *OtherGroup =
nullptr;
1169 if (!SyncPipe.
size())
1172 for (
auto &PipeSG : SyncPipe) {
1173 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1174 OtherGroup = &PipeSG;
1179 if (!OtherGroup->Collection.size())
1182 for (
auto &OtherEle : OtherGroup->Collection) {
1183 for (
auto &Succ : OtherEle->Succs) {
1184 if (Succ.getSUnit() == SU && Succ.getKind() ==
SDep::Data)
1192 unsigned SGID,
bool NeedsCache =
false)
1193 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1198 class IsReachableFromPrevNthGroup final :
public InstructionRule {
1200 unsigned Distance = 1;
1205 SchedGroup *OtherGroup =
nullptr;
1206 if (!SyncPipe.
size())
1209 for (
auto &PipeSG : SyncPipe) {
1210 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1211 OtherGroup = &PipeSG;
1216 if (!OtherGroup->Collection.size())
1219 auto *DAG = SyncPipe[0].DAG;
1221 for (
auto &OtherEle : OtherGroup->Collection)
1222 if (DAG->IsReachable(
const_cast<SUnit *
>(SU), OtherEle))
1227 IsReachableFromPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
1228 unsigned SGID,
bool NeedsCache =
false)
1229 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1233 class OccursAtOrAfterNode final :
public InstructionRule {
1244 bool NeedsCache =
false)
1250 class IsExactMFMA final :
public InstructionRule {
1258 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1261 if (Cache->empty()) {
1262 auto *TempSU = ChainSeed;
1267 for (
auto &Succ : TempSU->Succs) {
1268 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1269 TempSU = Succ.getSUnit();
1278 Cache->push_back(TempSU);
1284 return (*Cache)[0] == SU;
1288 unsigned SGID,
bool NeedsCache =
false)
1290 ChainSeed(ChainSeed) {}
1296 class OccursAfterExp final :
public InstructionRule {
1301 auto *DAG = SyncPipe[0].DAG;
1302 if (Cache->empty()) {
1303 for (
auto &SU : DAG->SUnits)
1305 Cache->push_back(&SU);
1312 return SU->
NodeNum > (*Cache)[0]->NodeNum;
1316 bool NeedsCache =
false)
1317 : InstructionRule(
TII, SGID, NeedsCache) {}
1321 bool applyIGLPStrategy(
1330 : IGLPStrategy(DAG,
TII) {
1335unsigned MFMAExpInterleaveOpt::TransPipeCount = 0;
1336unsigned MFMAExpInterleaveOpt::MFMAPipeCount = 0;
1337unsigned MFMAExpInterleaveOpt::AddPipeCount = 0;
1338unsigned MFMAExpInterleaveOpt::MFMAEnablement = 0;
1339unsigned MFMAExpInterleaveOpt::ExpRequirement = 0;
1340unsigned MFMAExpInterleaveOpt::MFMAChains = 0;
1341bool MFMAExpInterleaveOpt::HasCvt =
false;
1342bool MFMAExpInterleaveOpt::HasChainBetweenCvt =
false;
1343std::optional<unsigned> MFMAExpInterleaveOpt::FirstPipeDSR = std::nullopt;
1352 auto isBitPack = [](
unsigned Opc) {
1353 return Opc == AMDGPU::V_PACK_B32_F16_e64 ||
Opc == AMDGPU::V_PERM_B32_e64;
1356 auto isCvt = [](
unsigned Opc) {
1357 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
Opc == AMDGPU::V_CVT_I32_F32_e32;
1360 auto isAdd = [](
unsigned Opc) {
return Opc == AMDGPU::V_ADD_F32_e32; };
1363 for (
SUnit &SU : DAG->SUnits) {
1367 if (SU.
Succs.size() >= 7)
1369 for (
auto &Succ : SU.
Succs) {
1370 if (Succ.getSUnit()->Succs.size() >= 7)
1389 if (!(PackSUs.
size() && MFMAPipeCands.
size() && ExpPipeCands.
size()))
1394 std::optional<SUnit *> TempMFMA;
1395 std::optional<SUnit *> TempExp;
1397 for (
auto &PredSU : ExpPipeCands) {
1398 for (
auto &SuccSU : MFMAPipeCands) {
1399 if (DAG->IsReachable(SuccSU, PredSU)) {
1411 if (!(TempExp && TempMFMA))
1414 HasChainBetweenCvt =
none_of((*TempExp)->Succs, [&isCvt](
SDep &Succ) {
1415 return isCvt(Succ.getSUnit()->getInstr()->getOpcode());
1419 for (
auto &SuccSU : MFMAPipeCands) {
1420 if (MFMAPipeSUs.
size() &&
1421 any_of(MFMAPipeSUs, [&SuccSU](
SUnit *PotentialMatch) {
1422 return PotentialMatch->
NodeNum == SuccSU->NodeNum;
1426 for (
auto &PredSU : ExpPipeCands) {
1427 if (DAG->IsReachable(SuccSU, PredSU)) {
1434 MFMAPipeCount = MFMAPipeSUs.
size();
1436 assert(TempExp && TempMFMA);
1437 assert(MFMAPipeCount > 0);
1439 std::optional<SUnit *> TempCvt;
1440 for (
auto &SuccSU : CvtSUs) {
1441 if (DAG->IsReachable(SuccSU, *TempExp)) {
1448 if (TempCvt.has_value()) {
1449 for (
auto &SuccSU : MFMAPipeSUs) {
1450 if (DAG->IsReachable(SuccSU, *TempCvt)) {
1458 for (
auto &MFMAPipeSU : MFMAPipeSUs) {
1462 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1464 MFMAChainSeeds.push_back(MFMAPipeSU);
1472 for (
auto Pred : MFMAChainSeeds[0]->Preds) {
1473 if (
TII->isDS(Pred.getSUnit()->getInstr()->getOpcode()) &&
1474 Pred.getSUnit()->getInstr()->mayLoad())
1475 FirstPipeDSR = Pred.getSUnit()->NodeNum;
1479 unsigned PackSuccCount =
1481 return DAG->IsReachable(VPack, *TempExp);
1485 unsigned PackPredCount =
1487 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1488 return isBitPack(Opc);
1492 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1493 return isBitPack(Opc);
1496 if (PackPred == (*TempMFMA)->Preds.end())
1504 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1508 MFMAEnablement *= PackSuccCount;
1513 return DAG->IsReachable(PackPred->getSUnit(), ExpBase);
1516 ExpRequirement *= PackPredCount;
1526 MFMAChainSeeds.clear();
1533bool MFMAExpInterleaveOpt::applyIGLPStrategy(
1538 bool IsSmallKernelType =
1539 MFMAEnablement == 2 && ExpRequirement == 4 && TransPipeCount == 32;
1540 bool IsLargeKernelType =
1541 MFMAEnablement == 4 && ExpRequirement == 4 && TransPipeCount == 64;
1543 if (!(IsSmallKernelType || IsLargeKernelType))
1549 unsigned PipelineSyncID = 0;
1550 SchedGroup *SG =
nullptr;
1552 unsigned MFMAChain = 0;
1553 unsigned PositionInChain = 0;
1554 unsigned CurrMFMAForTransPosition = 0;
1556 auto incrementTransPosition = [&MFMAChain, &PositionInChain,
1557 &CurrMFMAForTransPosition]() {
1558 CurrMFMAForTransPosition += MFMAEnablement;
1559 PositionInChain = (CurrMFMAForTransPosition / MFMAChains);
1560 MFMAChain = CurrMFMAForTransPosition % MFMAChains;
1563 auto getNextTransPositionInChain = [&CurrMFMAForTransPosition]() {
1564 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1565 return (TempMFMAForTrans / MFMAChains);
1568 auto getNextTransMFMAChain = [&CurrMFMAForTransPosition]() {
1569 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1570 return TempMFMAForTrans % MFMAChains;
1573 unsigned CurrMFMAPosition = 0;
1574 unsigned MFMAChainForMFMA = 0;
1575 unsigned PositionInChainForMFMA = 0;
1577 auto incrementMFMAPosition = [&CurrMFMAPosition, &MFMAChainForMFMA,
1578 &PositionInChainForMFMA]() {
1580 MFMAChainForMFMA = CurrMFMAPosition % MFMAChains;
1581 PositionInChainForMFMA = CurrMFMAPosition / MFMAChains;
1585 assert(IsPostRA || MFMAChainSeeds.size() == MFMAChains);
1587 bool UsesFMA = IsSmallKernelType || !IsPostRA;
1588 bool UsesDSRead = IsLargeKernelType && !IsPostRA && FirstPipeDSR;
1589 bool UsesCvt = HasCvt && (IsSmallKernelType || !IsPostRA);
1590 bool UsesVALU = IsSmallKernelType;
1595 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1596 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1597 if (!IsPostRA && MFMAChains) {
1598 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1599 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1603 std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1604 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1605 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1608 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1609 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1610 if (!IsPostRA && MFMAChains) {
1611 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1612 getNextTransPositionInChain(),
1613 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1615 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1616 SG->getSGID(),
true));
1617 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1618 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1622 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1623 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1624 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1626 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1630 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1631 SchedGroupMask::TRANS, ExpRequirement, PipelineSyncID, DAG,
TII);
1632 if (!IsPostRA && MFMAChains)
1633 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1634 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
true));
1636 SG->addRule(std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1637 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1638 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1639 HasChainBetweenCvt));
1640 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1642 incrementTransPosition();
1645 for (
unsigned I = 0;
I < ExpRequirement;
I++) {
1648 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1649 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1650 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1651 if (HasChainBetweenCvt)
1652 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1653 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1655 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(
1656 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1657 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1662 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1663 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1664 if (!IsPostRA && MFMAChains) {
1665 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1666 getNextTransPositionInChain(),
1667 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1669 SG->addRule(std::make_shared<EnablesNthMFMA>(2 * MFMAEnablement + 1,
1670 TII, SG->getSGID(),
true));
1671 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1672 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1676 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1677 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1678 if (!IsPostRA && MFMAChains)
1679 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1680 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1683 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1684 SG->getSGID(),
true));
1685 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1686 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1687 HasChainBetweenCvt));
1688 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1693 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1694 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1695 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1696 SG->addRule(std::make_shared<GreaterThanOrEqualToNSuccs>(
1697 8,
TII, SG->getSGID(), HasChainBetweenCvt));
1698 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1703 unsigned MFMARatio =
1704 MFMAEnablement > ExpRequirement ? MFMAEnablement / ExpRequirement : 1;
1707 MFMAEnablement > ExpRequirement ? 1 : ExpRequirement / MFMAEnablement;
1709 unsigned RemainingExp = TransPipeCount > (2 * ExpRequirement)
1710 ? TransPipeCount - (2 * ExpRequirement)
1712 unsigned ExpLoopCount = RemainingExp / ExpRatio;
1714 unsigned MFMAInLoop = MFMAPipeCount > (MFMAEnablement * 2)
1715 ? MFMAPipeCount - (MFMAEnablement * 2)
1717 unsigned MFMALoopCount = MFMAInLoop / MFMARatio;
1719 AddPipeCount < MFMAPipeCount ? 1 : AddPipeCount / MFMAPipeCount;
1720 unsigned LoopSize = std::min(ExpLoopCount, MFMALoopCount);
1722 for (
unsigned I = 0;
I < LoopSize;
I++) {
1723 if (!(
I * ExpRatio % ExpRequirement))
1724 incrementTransPosition();
1727 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1728 SchedGroupMask::MFMA, MFMARatio, PipelineSyncID, DAG,
TII);
1729 if (!IsPostRA && MFMAChains)
1730 SG->addRule(std::make_shared<IsExactMFMA>(
1731 PositionInChainForMFMA, MFMAChainSeeds[MFMAChainForMFMA],
TII,
1732 SG->getSGID(),
true));
1734 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1735 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1736 incrementMFMAPosition();
1739 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1740 SchedGroupMask::VALU, VALUOps, PipelineSyncID, DAG,
TII);
1741 SG->addRule(std::make_shared<IsPipeAdd>(
TII, SG->getSGID()));
1742 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1745 if (UsesDSRead && !(
I % 4)) {
1746 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1747 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1748 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1750 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1754 for (
unsigned J = 0; J < ExpRatio; J++) {
1755 auto MFMAOffset = (1 + UsesVALU) * MFMARatio * (
I + 1);
1756 auto MaxMFMAOffset =
1757 (1 + UsesVALU) * ExpRequirement * MFMARatio / ExpRatio;
1761 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1762 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1763 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1764 auto BaseDiff = (2 + UsesFMA) * (ExpRequirement - 1) + 1;
1765 auto DSROffset =
I / 4 + 1;
1766 auto MaxDSROffset = MaxMFMAOffset / 4;
1768 auto ExpOffset =
I * ExpRatio + J >= ExpRequirement ? 0 : 1;
1769 auto CurrentOffset = UsesDSRead * std::min(MaxDSROffset, DSROffset) +
1770 std::min(MaxMFMAOffset, MFMAOffset) + BaseDiff +
1772 if (HasChainBetweenCvt)
1773 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1774 CurrentOffset,
TII, SG->getSGID()));
1776 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(CurrentOffset,
TII,
1778 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1783 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1784 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1785 if (!IsPostRA && MFMAChains)
1786 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1787 getNextTransPositionInChain(),
1788 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
1791 SG->addRule(std::make_shared<EnablesNthMFMA>(
1792 (((
I * ExpRatio + J) / ExpRequirement) + 3) * MFMAEnablement + 1,
1793 TII, SG->getSGID(),
true));
1794 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1795 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1799 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1800 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1801 if (!IsPostRA && MFMAChains)
1802 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1803 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1806 SG->addRule(std::make_shared<EnablesNthMFMA>(
1807 (((
I * ExpRatio + J) / ExpRequirement) + 2) * MFMAEnablement + 1,
1808 TII, SG->getSGID(),
true));
1809 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1810 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1811 HasChainBetweenCvt));
1812 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1817 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1818 SchedGroupMask::MFMA, MFMAEnablement * 2, PipelineSyncID, DAG,
TII);
1819 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1820 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1824class MFMAExpSimpleInterleaveOpt final :
public IGLPStrategy {
1826 bool applyIGLPStrategy(
1837 : IGLPStrategy(DAG,
TII) {
1842bool MFMAExpSimpleInterleaveOpt::applyIGLPStrategy(
1847 unsigned MFMACount = 0;
1849 if (
TII->isMFMAorWMMA(
I))
1852 const unsigned PipelineSyncID = 0;
1853 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
1854 SchedGroup *SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1855 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1856 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1858 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1859 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
1860 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1866class MFMASmallGemmSingleWaveOpt final :
public IGLPStrategy {
1869 class EnablesInitialMFMA final :
public InstructionRule {
1873 if (!SyncPipe.
size())
1876 if (!Cache->size()) {
1877 for (
auto &Elt : SyncPipe[0].DAG->
SUnits) {
1878 if (
TII->isMFMAorWMMA(*Elt.getInstr())) {
1882 Cache->push_back(&Elt);
1887 auto *DAG = SyncPipe[0].DAG;
1888 for (
auto &Elt : *Cache) {
1896 bool NeedsCache =
false)
1897 : InstructionRule(
TII, SGID, NeedsCache) {}
1901 class IsPermForDSW final :
public InstructionRule {
1906 if (
MI->getOpcode() != AMDGPU::V_PERM_B32_e64)
1909 bool FitsInGroup =
false;
1911 if (!Collection.
size()) {
1912 for (
auto &Succ : SU->
Succs) {
1913 SUnit *SuccUnit = Succ.getSUnit();
1916 Cache->push_back(SuccUnit);
1927 return ThisSucc.getSUnit() == Elt;
1932 IsPermForDSW(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1933 : InstructionRule(
TII, SGID, NeedsCache) {}
1937 class IsSuccOfPrevGroup final :
public InstructionRule {
1941 SchedGroup *OtherGroup =
nullptr;
1942 for (
auto &PipeSG : SyncPipe) {
1943 if ((
unsigned)PipeSG.getSGID() == SGID - 1) {
1944 OtherGroup = &PipeSG;
1950 if (!OtherGroup->Collection.size())
1954 return any_of(OtherGroup->Collection, [&SU](
SUnit *Elt) {
1955 return any_of(Elt->Succs,
1956 [&SU](SDep &Succ) { return Succ.getSUnit() == SU; });
1960 bool NeedsCache =
false)
1961 : InstructionRule(
TII, SGID, NeedsCache) {}
1965 class VMEMSize final :
public InstructionRule {
1970 if (
MI->getOpcode() == TargetOpcode::BUNDLE)
1972 if (!Collection.
size())
1977 auto TRI =
TII->getRegisterInfo();
1978 auto &MRI =
MI->getMF()->getRegInfo();
1979 for (
auto &Elt : Collection) {
1980 auto Op = Elt->getInstr()->getOperand(0);
1982 TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(MRI,
Op));
1986 if (NumBits < 128) {
1988 if (NumBits +
TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(
1989 MRI,
MI->getOperand(0))) <=
1997 VMEMSize(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1998 : InstructionRule(
TII, SGID, NeedsCache) {}
2003 class SharesPredWithPrevNthGroup final :
public InstructionRule {
2005 unsigned Distance = 1;
2010 SchedGroup *OtherGroup =
nullptr;
2011 if (!SyncPipe.
size())
2014 if (!Cache->size()) {
2016 for (
auto &PipeSG : SyncPipe) {
2017 if ((
unsigned)PipeSG.getSGID() == SGID - Distance) {
2018 OtherGroup = &PipeSG;
2024 if (!OtherGroup->Collection.size())
2027 for (
auto &OtherEle : OtherGroup->Collection) {
2028 for (
auto &Pred : OtherEle->Preds) {
2029 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2030 AMDGPU::V_PERM_B32_e64)
2031 Cache->push_back(Pred.getSUnit());
2040 auto *DAG = SyncPipe[0].DAG;
2047 SharesPredWithPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
2048 unsigned SGID,
bool NeedsCache =
false)
2049 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
2053 bool applyIGLPStrategy(
2064 : IGLPStrategy(DAG,
TII) {
2069static unsigned DSWCount = 0;
2070static unsigned DSWWithPermCount = 0;
2071static unsigned DSWWithSharedVMEMCount = 0;
2073bool MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
2074 DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
2077 unsigned MFMACount = 0;
2078 unsigned DSRCount = 0;
2080 bool IsInitial =
Phase == AMDGPU::SchedulingPhase::Initial;
2082 assert((!IsInitial || (DSWCount == 0 && DSWWithPermCount == 0 &&
2083 DSWWithSharedVMEMCount == 0)) &&
2084 "DSWCounters should be zero in pre-RA scheduling!");
2086 for (
auto &SU : DAG->SUnits) {
2087 auto *
I = SU.getInstr();
2088 if (
TII->isMFMAorWMMA(*
I))
2090 else if (
TII->isDS(*
I)) {
2093 else if (
I->mayStore() && IsInitial) {
2095 for (
auto Pred : SU.Preds) {
2096 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2097 AMDGPU::V_PERM_B32_e64) {
2107 DSWWithPermCount = DSWithPerms.
size();
2108 auto *
I = DSWithPerms.
begin();
2109 auto *
E = DSWithPerms.
end();
2117 DenseMap<MachineInstr *, SUnit *> VMEMLookup;
2119 for (;
I !=
E;
I++) {
2120 SUnit *Cand =
nullptr;
2121 bool MissedAny =
false;
2122 for (
auto &Pred : (*I)->Preds) {
2123 if (Pred.getSUnit()->getInstr()->getOpcode() != AMDGPU::V_PERM_B32_e64)
2129 for (
auto &Succ : Pred.getSUnit()->Succs) {
2130 auto *
MI = Succ.getSUnit()->getInstr();
2131 if (!
TII->isVMEM(*
MI) || !
MI->mayLoad())
2134 if (MissedAny || !VMEMLookup.
size()) {
2136 VMEMLookup[
MI] = *
I;
2153 if (!MissedAny && Cand) {
2154 DSWWithSharedVMEMCount += 2;
2161 assert(DSWWithSharedVMEMCount <= DSWWithPermCount);
2163 unsigned PipelineSyncID = 0;
2165 if (DSWWithPermCount) {
2166 for (
unsigned I = 0;
I < MFMACount;
I++) {
2167 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2168 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2169 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2171 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2172 SchedGroupMask::VALU, 2, PipelineSyncID, DAG,
TII);
2173 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2183 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2184 SchedGroupMask::DS_READ, 4, PipelineSyncID, DAG,
TII);
2185 SG->addRule(std::make_shared<EnablesInitialMFMA>(
TII, SG->getSGID(),
true));
2186 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2188 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2189 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2190 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2193 for (
unsigned I = 4;
I < DSRCount; ++
I) {
2194 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2195 SchedGroupMask::DS_READ, 1, PipelineSyncID, DAG,
TII);
2196 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2198 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2199 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2200 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2206 for (
unsigned I = DSWWithSharedVMEMCount;
I < DSWWithPermCount; ++
I) {
2207 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2208 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2209 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2210 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2212 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2213 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2214 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2215 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2217 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2218 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2219 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2220 1,
TII, SG->getSGID(),
true));
2221 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2222 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2224 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2225 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2226 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2228 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2229 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2230 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2231 3,
TII, SG->getSGID(),
true));
2232 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2233 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2235 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2236 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2237 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2243 for (
unsigned I = DSWWithPermCount;
I < DSWCount;
I++) {
2244 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2245 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2246 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2248 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2249 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2250 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2251 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2253 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2254 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2255 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2263 for (
unsigned I = 0;
I < DSWWithSharedVMEMCount; ++
I) {
2264 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2265 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2266 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2267 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2269 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2270 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2271 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2272 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2274 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2275 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2276 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2278 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2279 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2280 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2281 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2283 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2284 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2285 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2286 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2288 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2289 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2290 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2292 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2293 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2294 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2295 2,
TII, SG->getSGID(),
true));
2296 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2297 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2299 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2300 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2301 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2303 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2304 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2305 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2306 4,
TII, SG->getSGID(),
true));
2307 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2308 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2310 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2311 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2312 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2318static std::unique_ptr<IGLPStrategy>
2319createIGLPStrategy(IGLPStrategyID
ID, ScheduleDAGInstrs *DAG,
2320 const SIInstrInfo *
TII) {
2322 case MFMASmallGemmOptID:
2323 return std::make_unique<MFMASmallGemmOpt>(DAG,
TII);
2324 case MFMASmallGemmSingleWaveOptID:
2325 return std::make_unique<MFMASmallGemmSingleWaveOpt>(DAG,
TII);
2326 case MFMAExpInterleaveID:
2327 return std::make_unique<MFMAExpInterleaveOpt>(DAG,
TII);
2328 case MFMAExpSimpleInterleaveID:
2329 return std::make_unique<MFMAExpSimpleInterleaveOpt>(DAG,
TII);
2335class IGroupLPDAGMutation :
public ScheduleDAGMutation {
2337 const SIInstrInfo *
TII;
2344 DenseMap<int, SmallVector<SchedGroup, 4>> SyncedSchedGroups;
2347 DenseMap<int, SUnitsToCandidateSGsMap> SyncedInstrs;
2350 void addSchedBarrierEdges(SUnit &SU);
2361 SchedGroupMask invertSchedBarrierMask(SchedGroupMask Mask)
const;
2364 void initSchedGroupBarrierPipelineStage(
2365 std::vector<SUnit>::reverse_iterator RIter);
2367 bool initIGLPOpt(SUnit &SU);
2370 void apply(ScheduleDAGInstrs *DAGInstrs)
override;
2377 bool IsBottomUp =
true;
2382 IGroupLPDAGMutation() =
default;
2386unsigned SchedGroup::NumSchedGroups = 0;
2388bool SchedGroup::tryAddEdge(SUnit *
A, SUnit *
B) {
2392bool SchedGroup::canAddMI(
const MachineInstr &
MI)
const {
2394 if (
MI.isMetaInstruction())
2397 else if (
MI.isInlineAsm()) {
2399 auto &MRI =
MI.getParent()->getParent()->getRegInfo();
2400 bool SGPR_used =
false, SGPR_big_def =
false, VGPR_used =
false,
2401 VMFMA_used =
false, VReg32_used =
false,
MayLoad =
MI.mayLoad(),
2403 for (
const MachineOperand &Operand :
MI.operands())
2404 if (Operand.isReg()) {
2405 const TargetRegisterClass &RegClass =
2406 *
TRI.getRegClassForOperandReg(MRI, Operand);
2407 if (
TRI.hasVGPRs(&RegClass)) {
2409 if (Operand.isUse() &&
TRI.getRegSizeInBits(RegClass) == 32)
2415 if (
TRI.hasAGPRs(&RegClass) ||
TRI.getRegSizeInBits(RegClass) > 128)
2417 if (
TRI.hasSGPRs(&RegClass))
2419 if (
TRI.getRegSizeInBits(RegClass) > 64 && Operand.isDef())
2420 SGPR_big_def =
true;
2423 typedef std::underlying_type_t<SchedGroupMask> SGMask_t;
2424 SGMask_t InlineAsmMask = 0;
2425 if (VGPR_used && !VMFMA_used && !MayLoad && !MayStore)
2426 InlineAsmMask |= (SGMask_t)SchedGroupMask::VALU;
2427 if (SGPR_used && !VGPR_used && !MayLoad && !MayStore)
2428 InlineAsmMask |= (SGMask_t)SchedGroupMask::SALU;
2430 InlineAsmMask |= (SGMask_t)SchedGroupMask::MFMA;
2431 if (VGPR_used && MayLoad)
2432 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_READ
2433 : SchedGroupMask::VMEM_READ);
2434 if (VGPR_used && MayStore)
2435 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_WRITE
2436 : SchedGroupMask::VMEM_WRITE);
2438 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS_READ;
2439 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VALU ||
2440 InlineAsmMask & (SGMask_t)SchedGroupMask::SALU)
2441 InlineAsmMask |= (SGMask_t)SchedGroupMask::ALU;
2442 if (InlineAsmMask & (SGMask_t)SchedGroupMask::DS_READ ||
2443 InlineAsmMask & (SGMask_t)SchedGroupMask::DS_WRITE)
2444 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS;
2445 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_READ ||
2446 InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_WRITE)
2447 InlineAsmMask |= (SGMask_t)SchedGroupMask::VMEM;
2449 Result = ((SGMask_t)SGMask & InlineAsmMask) != 0;
2452 else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
2457 else if (((SGMask & SchedGroupMask::VALU) != SchedGroupMask::NONE) &&
2465 else if (((SGMask & SchedGroupMask::SALU) != SchedGroupMask::NONE) &&
2469 else if (((SGMask & SchedGroupMask::MFMA) != SchedGroupMask::NONE) &&
2470 TII->isMFMAorWMMA(
MI))
2473 else if (((SGMask & SchedGroupMask::VMEM) != SchedGroupMask::NONE) &&
2477 else if (((SGMask & SchedGroupMask::VMEM_READ) != SchedGroupMask::NONE) &&
2478 MI.mayLoad() &&
TII->isVMEM(
MI))
2481 else if (((SGMask & SchedGroupMask::VMEM_WRITE) != SchedGroupMask::NONE) &&
2482 MI.mayStore() &&
TII->isVMEM(
MI))
2485 else if (((SGMask & SchedGroupMask::DS) != SchedGroupMask::NONE) &&
2489 else if (((SGMask & SchedGroupMask::DS_READ) != SchedGroupMask::NONE) &&
2490 MI.mayLoad() &&
TII->isDS(
MI))
2493 else if (((SGMask & SchedGroupMask::DS_WRITE) != SchedGroupMask::NONE) &&
2494 MI.mayStore() &&
TII->isDS(
MI))
2497 else if (((SGMask & SchedGroupMask::TRANS) != SchedGroupMask::NONE) &&
2502 dbgs() <<
"For SchedGroup with mask " <<
format_hex((
int)SGMask, 10,
true)
2503 << (Result ?
" could classify " :
" unable to classify ") <<
MI);
2508int SchedGroup::link(SUnit &SU,
bool MakePred,
2509 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
2510 int MissedEdges = 0;
2511 for (
auto *
A : Collection) {
2513 if (
A ==
B ||
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2523 bool Added = tryAddEdge(
A,
B);
2525 AddedEdges.emplace_back(
A,
B);
2533void SchedGroup::link(SUnit &SU,
bool MakePred) {
2534 for (
auto *
A : Collection) {
2536 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2545void SchedGroup::link(SUnit &SU,
2546 function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>
P) {
2547 for (
auto *
A : Collection) {
2556void SchedGroup::link(SchedGroup &OtherGroup) {
2557 for (
auto *
B : OtherGroup.Collection)
2561bool SchedGroup::canAddSU(SUnit &SU)
const {
2563 if (
MI.getOpcode() != TargetOpcode::BUNDLE)
2564 return canAddMI(
MI);
2567 const MachineBasicBlock *
MBB =
MI.getParent();
2569 while (
E !=
MBB->
end() &&
E->isBundledWithPred())
2573 return std::all_of(
B,
E, [
this](MachineInstr &
MI) {
return canAddMI(
MI); });
2577void SchedGroup::findCandidateSUnits(
T Begin,
T End,
2578 SUnitsToCandidateSGsMap &SyncedInstrs) {
2581 SyncedInstrs[&SU].push_back(SGID);
2585void SchedGroup::findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs) {
2586 findCandidateSUnits(DAG->
SUnits.rbegin(), DAG->
SUnits.rend(), SyncedInstrs);
2589void IGroupLPDAGMutation::apply(ScheduleDAGInstrs *DAGInstrs) {
2590 const TargetSchedModel *TSchedModel = DAGInstrs->
getSchedModel();
2591 if (!TSchedModel || DAGInstrs->
SUnits.empty())
2596 TII =
ST.getInstrInfo();
2597 DAG =
static_cast<ScheduleDAGMI *
>(DAGInstrs);
2598 SyncedSchedGroups.clear();
2599 SyncedInstrs.clear();
2600 bool FoundSB =
false;
2601 bool FoundIGLP =
false;
2602 bool ShouldApplyIGLP =
false;
2603 for (
auto R = DAG->
SUnits.rbegin(),
E = DAG->
SUnits.rend(); R !=
E; ++R) {
2604 unsigned Opc =
R->getInstr()->getOpcode();
2606 if (
Opc == AMDGPU::SCHED_BARRIER) {
2607 addSchedBarrierEdges(*R);
2609 }
else if (
Opc == AMDGPU::SCHED_GROUP_BARRIER) {
2610 initSchedGroupBarrierPipelineStage(R);
2612 }
else if (
Opc == AMDGPU::IGLP_OPT) {
2613 if (!FoundSB && !FoundIGLP) {
2615 ShouldApplyIGLP = initIGLPOpt(*R);
2620 if (FoundSB || (FoundIGLP && ShouldApplyIGLP)) {
2621 PipelineSolver PS(SyncedSchedGroups, SyncedInstrs, DAG, IsBottomUp);
2629void IGroupLPDAGMutation::addSchedBarrierEdges(SUnit &SchedBarrier) {
2631 assert(
MI.getOpcode() == AMDGPU::SCHED_BARRIER);
2632 LLVM_DEBUG(
dbgs() <<
"Building SchedGroup for SchedBarrier with Mask: "
2633 <<
MI.getOperand(0).getImm() <<
"\n");
2635 invertSchedBarrierMask((SchedGroupMask)
MI.getOperand(0).getImm());
2636 SchedGroup SG(InvertedMask, std::nullopt, DAG,
TII);
2638 for (SUnit &SU : DAG->
SUnits)
2639 if (SG.canAddSU(SU))
2645 (function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>)[](
2646 const SUnit *
A,
const SUnit *
B) {
return A->NodeNum >
B->NodeNum; });
2650IGroupLPDAGMutation::invertSchedBarrierMask(SchedGroupMask Mask)
const {
2653 SchedGroupMask InvertedMask = ~Mask;
2656 if ((InvertedMask & SchedGroupMask::ALU) == SchedGroupMask::NONE)
2657 InvertedMask &= ~SchedGroupMask::VALU & ~SchedGroupMask::SALU &
2658 ~SchedGroupMask
::MFMA & ~SchedGroupMask::TRANS;
2660 else if ((InvertedMask & SchedGroupMask::VALU) == SchedGroupMask::NONE ||
2661 (InvertedMask & SchedGroupMask::SALU) == SchedGroupMask::NONE ||
2662 (InvertedMask & SchedGroupMask::MFMA) == SchedGroupMask::NONE ||
2663 (InvertedMask & SchedGroupMask::TRANS) == SchedGroupMask::NONE)
2664 InvertedMask &= ~SchedGroupMask::ALU;
2667 if ((InvertedMask & SchedGroupMask::VMEM) == SchedGroupMask::NONE)
2668 InvertedMask &= ~SchedGroupMask::VMEM_READ & ~SchedGroupMask::VMEM_WRITE;
2670 else if ((InvertedMask & SchedGroupMask::VMEM_READ) == SchedGroupMask::NONE ||
2671 (InvertedMask & SchedGroupMask::VMEM_WRITE) == SchedGroupMask::NONE)
2672 InvertedMask &= ~SchedGroupMask::VMEM;
2675 if ((InvertedMask & SchedGroupMask::DS) == SchedGroupMask::NONE)
2676 InvertedMask &= ~SchedGroupMask::DS_READ & ~SchedGroupMask::DS_WRITE;
2678 else if ((InvertedMask & SchedGroupMask::DS_READ) == SchedGroupMask::NONE ||
2679 (InvertedMask & SchedGroupMask::DS_WRITE) == SchedGroupMask::NONE)
2680 InvertedMask &= ~SchedGroupMask::DS;
2682 LLVM_DEBUG(
dbgs() <<
"After Inverting, SchedGroup Mask: " << (
int)InvertedMask
2685 return InvertedMask;
2688void IGroupLPDAGMutation::initSchedGroupBarrierPipelineStage(
2689 std::vector<SUnit>::reverse_iterator RIter) {
2690 MachineInstr &SGB = *RIter->getInstr();
2697 auto &SG = SyncedSchedGroups[SyncID].emplace_back((SchedGroupMask)SGMask,
2700 SG.findCandidateSUnits(RIter, SG.DAG->
SUnits.rend(),
2701 SyncedInstrs[SG.getSyncID()]);
2704bool IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
2705 IGLPStrategyID StrategyID =
2707 auto S = createIGLPStrategy(StrategyID, DAG,
TII);
2708 if (!S->shouldApplyStrategy(DAG,
Phase))
2711 IsBottomUp = S->IsBottomUp;
2712 return S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups,
Phase);
2722std::unique_ptr<ScheduleDAGMutation>
2724 return std::make_unique<IGroupLPDAGMutation>(
Phase);
aarch64 falkor hwpf fix Falkor HW Prefetch Fix Late Phase
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
AMDGPU Rewrite AGPR Copy MFMA
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
Register const TargetRegisterInfo * TRI
Interface definition for SIInstrInfo.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
const HexagonRegisterInfo & getRegisterInfo() const
Instructions::iterator instr_iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const MachineOperand & getOperand(unsigned i) const
@ Data
Regular data dependence (aka true-dependence).
@ Artificial
Arbitrary strong DAG edge (no real dependence).
Scheduling unit. This is a node in the scheduling DAG.
unsigned NodeNum
Entry # of node in the node vector.
LLVM_ABI void removePred(const SDep &D)
Removes the specified edge as a pred of the current node if it exists.
SmallVector< SDep, 4 > Succs
All sunit successors.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
A ScheduleDAG for scheduling lists of MachineInstr.
const TargetSchedModel * getSchedModel() const
Gets the machine model for instruction scheduling.
bool addEdge(SUnit *SuccSU, const SDep &PredDep)
Add a DAG edge to the given SU with the given predecessor dependence data.
bool IsReachable(SUnit *SU, SUnit *TargetSU)
IsReachable - Checks if SU is reachable from TargetSU.
void dump() const override
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
std::vector< SUnit > SUnits
The scheduling units.
MachineFunction & MF
Machine function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
reverse_iterator rbegin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
void apply(Opt *O, const Mod &M, const Mods &... Ms)
initializer< Ty > init(const Ty &Val)
LLVM_ABI void link(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
Link the given graph.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
@ LLVM_MARK_AS_BITMASK_ENUM
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
DWARFExpression::Operation Op
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Function object to check whether the second component of a container supported by std::get (like std:...