32#define DEBUG_TYPE "igrouplp"
38 cl::desc(
"Whether to use the exponential time solver to fit "
39 "the instructions to the pipeline as closely as "
45 cl::desc(
"The maximum number of scheduling group conflicts "
46 "which we attempt to solve with the exponential time "
47 "exact solver. Problem sizes greater than this will"
48 "be solved by the less accurate greedy algorithm. Selecting "
49 "solver by size is superseded by manually selecting "
50 "the solver (e.g. by amdgpu-igrouplp-exact-solver"));
54 cl::desc(
"The amount of branches that we are willing to explore with"
55 "the exact algorithm before giving up."));
59 cl::desc(
"Whether to use the cost heuristic to make choices as we "
60 "traverse the search space using the exact solver. Defaulted "
61 "to on, and if turned off, we will use the node order -- "
62 "attempting to put the later nodes in the later sched groups. "
63 "Experimentally, results are mixed, so this should be set on a "
64 "case-by-case basis."));
68enum class SchedGroupMask {
81 ALL = ALU | VALU |
SALU |
MFMA |
VMEM | VMEM_READ | VMEM_WRITE |
DS |
82 DS_READ | DS_WRITE |
TRANS,
91class InstructionRule {
97 std::optional<SmallVector<SUnit *, 4>> Cache;
107 bool NeedsCache =
false)
114 virtual ~InstructionRule() =
default;
127 SchedGroupMask SGMask;
130 std::optional<unsigned> MaxSize;
143 static unsigned NumSchedGroups;
160 bool canAddSU(
SUnit &SU)
const;
165 void link(
SUnit &SU,
bool MakePred =
false);
169 int link(
SUnit &SU,
bool MakePred,
170 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
179 void link(SchedGroup &OtherGroup);
182 bool isFull()
const {
return MaxSize && Collection.
size() >= *MaxSize; }
188 void addRule(std::shared_ptr<InstructionRule> NewRule) {
193 bool allowedByRules(
const SUnit *SU,
195 for (
auto &Rule : Rules) {
196 if (!Rule->apply(SU, Collection, SyncPipe))
203 void add(
SUnit &SU) {
205 <<
format_hex((
int)SGMask, 10,
true) <<
" adding "
211 void pop() { Collection.
pop_back(); }
214 void findCandidateSUnits(
T Begin,
T End,
215 SUnitsToCandidateSGsMap &SyncedInstrs);
220 void findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs);
222 int getSyncID() {
return SyncID; }
224 int getSGID() {
return SGID; }
226 SchedGroupMask
getMask() {
return SGMask; }
228 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
230 : SGMask(SGMask), MaxSize(MaxSize), DAG(DAG),
TII(
TII) {
231 SGID = NumSchedGroups++;
234 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
int SyncID,
236 : SGMask(SGMask), MaxSize(MaxSize), SyncID(SyncID), DAG(DAG),
TII(
TII) {
237 SGID = NumSchedGroups++;
241using SUToCandSGsPair = std::pair<SUnit *, SmallVector<int, 4>>;
253class PipelineSolver {
266 bool NeedsSolver =
false;
270 unsigned computeProblemSize();
281 int CurrConflInstNo = 0;
283 int CurrSyncGroupIdx = 0;
285 int BeginSyncGroupIdx = 0;
291 bool IsBottomUp =
true;
294 void advancePosition();
297 void retreatPosition();
306 template <
typename T>
307 void greedyFind(std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
312 template <
typename T>
319 template <
typename T>
void linkSchedGroups(
T I,
T E);
323 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
327 template <
typename T>
328 int linkSUnit(
SUnit *SU,
int SGID,
329 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
331 void removeEdges(
const std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
333 void convertSyncMapsToArrays();
345 : DAG(DAG), SyncedInstrs(SyncedInstrs),
346 SyncedSchedGroups(SyncedSchedGroups), IsBottomUp(IsBottomUp) {
348 for (
auto &PipelineInstrs : SyncedInstrs) {
349 if (!PipelineInstrs.second.
empty()) {
358 convertSyncMapsToArrays();
360 CurrPipeline = BestPipeline;
362 while (
static_cast<size_t>(BeginSyncGroupIdx) < PipelineInstrs.
size() &&
363 PipelineInstrs[BeginSyncGroupIdx].
empty())
366 if (
static_cast<size_t>(BeginSyncGroupIdx) >= PipelineInstrs.
size())
371void PipelineSolver::reset() {
373 for (
auto &SyncPipeline : CurrPipeline) {
374 for (
auto &SG : SyncPipeline) {
376 SG.Collection.
clear();
380 if (SchedBarr != TempCollection.
end())
381 SG.Collection.push_back(*SchedBarr);
385 CurrSyncGroupIdx = BeginSyncGroupIdx;
390void PipelineSolver::convertSyncMapsToArrays() {
391 for (
auto &SyncPipe : SyncedSchedGroups) {
392 BestPipeline.insert(BestPipeline.begin(), SyncPipe.second);
395 int PipelineIDx = SyncedInstrs.size() - 1;
396 PipelineInstrs.resize(SyncedInstrs.size());
397 for (
auto &SyncInstrMap : SyncedInstrs) {
398 for (
auto &SUsToCandSGs : SyncInstrMap.second) {
399 if (PipelineInstrs[PipelineIDx].empty()) {
400 PipelineInstrs[PipelineIDx].push_back(
401 std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
404 auto *SortPosition = PipelineInstrs[PipelineIDx].begin();
407 while (SortPosition != PipelineInstrs[PipelineIDx].end() &&
408 SUsToCandSGs.first->NodeNum > SortPosition->first->NodeNum)
410 PipelineInstrs[PipelineIDx].insert(
411 SortPosition, std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
417template <
typename T>
void PipelineSolver::linkSchedGroups(
T I,
T E) {
418 for (;
I !=
E; ++
I) {
420 for (
auto J = std::next(
I); J !=
E; ++J) {
427void PipelineSolver::makePipeline() {
429 for (
auto &SyncPipeline : BestPipeline) {
431 for (
auto &SG : SyncPipeline) {
434 SUnit *SGBarr =
nullptr;
435 for (
auto &SU : SG.Collection) {
436 if (SU->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
443 SG.link(*SGBarr,
false);
447 for (
auto &SyncPipeline : BestPipeline) {
448 IsBottomUp ? linkSchedGroups(SyncPipeline.rbegin(), SyncPipeline.rend())
449 : linkSchedGroups(SyncPipeline.begin(), SyncPipeline.end());
454int PipelineSolver::linkSUnit(
455 SUnit *SU,
int SGID, std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
457 bool MakePred =
false;
460 if (
I->getSGID() == SGID) {
465 AddedCost += Group.link(*SU, MakePred, AddedEdges);
471int PipelineSolver::addEdges(
473 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
483 return IsBottomUp ? linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
rbegin(),
485 : linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
begin(),
489void PipelineSolver::removeEdges(
490 const std::list<std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
493 for (
auto &PredSuccPair : EdgesToRemove) {
494 SUnit *Pred = PredSuccPair.first;
495 SUnit *Succ = PredSuccPair.second;
498 Succ->
Preds, [&Pred](
SDep &
P) { return P.getSUnit() == Pred; });
499 if (Match != Succ->
Preds.end()) {
500 assert(Match->isArtificial());
506void PipelineSolver::advancePosition() {
509 if (
static_cast<size_t>(CurrConflInstNo) >=
510 PipelineInstrs[CurrSyncGroupIdx].
size()) {
514 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size() &&
515 PipelineInstrs[CurrSyncGroupIdx].empty())
520void PipelineSolver::retreatPosition() {
521 assert(CurrConflInstNo >= 0);
522 assert(CurrSyncGroupIdx >= 0);
524 if (CurrConflInstNo > 0) {
529 if (CurrConflInstNo == 0) {
532 if (CurrSyncGroupIdx == BeginSyncGroupIdx)
537 while (PipelineInstrs[CurrSyncGroupIdx].empty())
540 CurrConflInstNo = PipelineInstrs[CurrSyncGroupIdx].size() - 1;
544bool PipelineSolver::checkOptimal() {
545 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size()) {
546 if (BestCost == -1 || CurrCost < BestCost) {
547 BestPipeline = CurrPipeline;
554 bool DoneExploring =
false;
555 if (MaxBranchesExplored > 0 && BranchesExplored >= MaxBranchesExplored)
556 DoneExploring =
true;
558 return (DoneExploring || BestCost == 0);
562void PipelineSolver::populateReadyList(
564 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
565 auto SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
566 assert(CurrSU.second.size() >= 1);
568 for (;
I !=
E; ++
I) {
569 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
571 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
572 return SG.getSGID() == CandSGID;
577 if (Match->isFull()) {
578 ReadyList.push_back(std::pair(*
I, MissPenalty));
582 int TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
583 ReadyList.push_back(std::pair(*
I, TempCost));
584 removeEdges(AddedEdges);
586 ReadyList.push_back(std::pair(*
I, -1));
592 assert(ReadyList.size() == CurrSU.second.size());
595bool PipelineSolver::solveExact() {
599 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size())
602 assert(
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size());
603 assert(
static_cast<size_t>(CurrConflInstNo) <
604 PipelineInstrs[CurrSyncGroupIdx].
size());
605 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
607 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
612 IsBottomUp ? populateReadyList(ReadyList, CurrSU.second.
rbegin(),
613 CurrSU.second.rend())
614 : populateReadyList(ReadyList, CurrSU.second.
begin(),
615 CurrSU.second.end());
617 auto *
I = ReadyList.
begin();
618 auto *
E = ReadyList.
end();
619 for (;
I !=
E; ++
I) {
623 if (BestCost != -1 && (CurrCost +
I->second > BestCost))
626 int CandSGID =
I->first;
628 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
629 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
631 for (
auto &SG : SyncPipeline) {
632 if (SG.getSGID() == CandSGID)
639 if (!Match->allowedByRules(CurrSU.first, SyncPipeline))
643 << (
int)Match->getMask() <<
"and ID " << CandSGID
645 Match->add(*CurrSU.first);
646 AddedCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
647 LLVM_DEBUG(
dbgs() <<
"Cost of Assignment: " << AddedCost <<
"\n");
648 CurrCost += AddedCost;
651 bool FinishedExploring =
false;
654 if (CurrCost < BestCost || BestCost == -1) {
656 FinishedExploring = BestCost != 0;
657 if (!FinishedExploring)
663 CurrCost -= AddedCost;
664 removeEdges(AddedEdges);
666 CurrPipeline[CurrSyncGroupIdx] = SyncPipeline;
667 if (FinishedExploring)
674 CurrCost += MissPenalty;
677 LLVM_DEBUG(
dbgs() <<
"NOT Assigned (" << CurrSU.first->NodeNum <<
")\n");
679 bool FinishedExploring =
false;
680 if (CurrCost < BestCost || BestCost == -1) {
682 bool FinishedExploring = BestCost != 0;
683 if (!FinishedExploring)
689 CurrCost -= MissPenalty;
690 return FinishedExploring;
694void PipelineSolver::greedyFind(
695 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E) {
696 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
700 std::list<std::pair<SUnit *, SUnit *>> Edges;
703 std::optional<GroupInfo> Best;
705 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
707 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
713 for (;
I !=
E; ++
I) {
715 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
716 return SG.getSGID() == CandSGID;
720 LLVM_DEBUG(
dbgs() <<
"Trying SGID # " << CandSGID <<
" with Mask "
721 << (
int)Match->getMask() <<
"\n");
723 if (Match->isFull()) {
727 if (!Match->allowedByRules(CurrSU.first, SyncPipeline)) {
728 LLVM_DEBUG(
dbgs() <<
"SGID # " << CandSGID <<
" has conflicting rule\n");
732 std::list<std::pair<SUnit *, SUnit *>> TempEdges;
733 int TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, TempEdges);
736 if (!Best || TempCost < Best->Cost) {
737 Best = {Match, TempEdges, TempCost};
742 removeEdges(TempEdges);
746 SchedGroup *SG = Best->SG;
747 std::list<std::pair<SUnit *, SUnit *>> &Edges = Best->Edges;
749 SG->add(*CurrSU.first);
750 if (AddedEdges.empty())
753 AddedEdges.splice(std::prev(AddedEdges.cend()), Edges);
755 for (
const std::pair<SUnit *, SUnit *> &
E : Edges) {
756 if (!SG->tryAddEdge(
E.first,
E.second))
760 LLVM_DEBUG(
dbgs() <<
"Best Group has ID: " << SG->getSGID() <<
" and Mask"
761 << (
int)SG->getMask() <<
"\n");
762 BestCost += Best->Cost;
764 BestCost += MissPenalty;
767bool PipelineSolver::solveGreedy() {
769 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
771 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size()) {
772 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
774 ? greedyFind(AddedEdges, CurrSU.second.rbegin(), CurrSU.second.rend())
775 : greedyFind(AddedEdges, CurrSU.second.begin(), CurrSU.second.end());
778 BestPipeline = CurrPipeline;
779 removeEdges(AddedEdges);
783unsigned PipelineSolver::computeProblemSize() {
784 unsigned ProblemSize = 0;
785 for (
auto &PipeConflicts : PipelineInstrs) {
786 ProblemSize += PipeConflicts.size();
792void PipelineSolver::solve() {
796 unsigned ProblemSize = computeProblemSize();
799 bool BelowCutoff = (CutoffForExact > 0) && ProblemSize <= CutoffForExact;
800 MissPenalty = (ProblemSize / 2) + 1;
803 if (EnableExactSolver || BelowCutoff) {
807 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
811 LLVM_DEBUG(
dbgs() <<
"Exact produced best cost of " << BestCost <<
"\n");
816 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
833 virtual bool applyIGLPStrategy(
842 bool IsBottomUp =
true;
847 virtual ~IGLPStrategy() =
default;
850class MFMASmallGemmOpt final :
public IGLPStrategy {
853 bool applyIGLPStrategy(
864 : IGLPStrategy(DAG,
TII) {
869bool MFMASmallGemmOpt::applyIGLPStrategy(
874 unsigned MFMACount = 0;
876 if (
TII->isMFMAorWMMA(
I))
879 const unsigned PipelineSyncID = 0;
880 SchedGroup *SG =
nullptr;
881 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
882 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
883 SchedGroupMask::DS, 2, PipelineSyncID, DAG,
TII);
884 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
886 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
887 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
888 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
894class MFMAExpInterleaveOpt final :
public IGLPStrategy {
897 static unsigned TransPipeCount;
899 static unsigned MFMAPipeCount;
901 static unsigned AddPipeCount;
903 static unsigned MFMAEnablement;
905 static unsigned ExpRequirement;
907 static unsigned MFMAChains;
912 static bool HasChainBetweenCvt;
914 static std::optional<unsigned> FirstPipeDSR;
923 class IsPipeExp final :
public InstructionRule {
928 auto *DAG = SyncPipe[0].DAG;
930 if (Cache->empty()) {
931 auto I = DAG->SUnits.rbegin();
932 auto E = DAG->SUnits.rend();
933 for (;
I !=
E;
I++) {
934 if (
TII->isMFMAorWMMA(*
I->getInstr()))
935 Cache->push_back(&*
I);
941 auto Reaches =
any_of(*Cache, [&SU, &DAG](
SUnit *TargetSU) {
942 return DAG->IsReachable(TargetSU,
const_cast<SUnit *
>(SU));
947 IsPipeExp(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
948 : InstructionRule(
TII, SGID, NeedsCache) {}
953 class EnablesNthMFMA final :
public InstructionRule {
960 bool FoundTrans =
false;
961 unsigned Counter = 1;
962 auto *DAG = SyncPipe[0].DAG;
964 if (Cache->empty()) {
965 auto I = DAG->SUnits.begin();
966 auto E = DAG->SUnits.end();
967 for (;
I !=
E;
I++) {
968 if (FoundTrans &&
TII->isMFMAorWMMA(*
I->getInstr())) {
970 Cache->push_back(&*
I);
975 if (!FoundTrans &&
TII->isTRANS(
I->getInstr()->getOpcode()))
982 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
986 bool NeedsCache =
false)
992 class EnablesNthMFMAInChain final :
public InstructionRule {
1000 auto *DAG = SyncPipe[0].DAG;
1002 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1005 if (Cache->empty()) {
1006 auto *TempSU = ChainSeed;
1011 for (
auto &Succ : TempSU->Succs) {
1012 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1013 TempSU = Succ.getSUnit();
1022 Cache->push_back(TempSU);
1028 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1031 EnablesNthMFMAInChain(
unsigned Number,
SUnit *ChainSeed,
1033 bool NeedsCache =
false)
1035 ChainSeed(ChainSeed) {}
1041 class LessThanNSuccs final :
public InstructionRule {
1044 bool HasIntermediary =
false;
1049 if (!SyncPipe.
size())
1053 return Succ.getKind() == SDep::Data;
1055 if (SuccSize >=
Size)
1058 if (HasIntermediary) {
1059 for (
auto Succ : SU->
Succs) {
1062 return SuccSucc.getKind() == SDep::Data;
1064 if (SuccSize >=
Size)
1072 bool HasIntermediary =
false,
bool NeedsCache =
false)
1073 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1074 HasIntermediary(HasIntermediary) {}
1081 class GreaterThanOrEqualToNSuccs final :
public InstructionRule {
1084 bool HasIntermediary =
false;
1089 if (!SyncPipe.
size())
1093 return Succ.getKind() == SDep::Data;
1095 if (SuccSize >=
Size)
1098 if (HasIntermediary) {
1099 for (
auto Succ : SU->
Succs) {
1102 return SuccSucc.getKind() == SDep::Data;
1104 if (SuccSize >=
Size)
1112 unsigned SGID,
bool HasIntermediary =
false,
1113 bool NeedsCache =
false)
1114 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1115 HasIntermediary(HasIntermediary) {}
1119 class IsCvt final :
public InstructionRule {
1124 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
1125 Opc == AMDGPU::V_CVT_I32_F32_e32;
1127 IsCvt(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1128 : InstructionRule(
TII, SGID, NeedsCache) {}
1132 class IsFMA final :
public InstructionRule {
1139 IsFMA(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1140 : InstructionRule(
TII, SGID, NeedsCache) {}
1144 class IsPipeAdd final :
public InstructionRule {
1150 IsPipeAdd(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1151 : InstructionRule(
TII, SGID, NeedsCache) {}
1156 class IsSuccOfPrevNthGroup final :
public InstructionRule {
1158 unsigned Distance = 1;
1163 SchedGroup *OtherGroup =
nullptr;
1164 if (!SyncPipe.
size())
1167 for (
auto &PipeSG : SyncPipe) {
1168 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1169 OtherGroup = &PipeSG;
1174 if (!OtherGroup->Collection.size())
1177 for (
auto &OtherEle : OtherGroup->Collection) {
1178 for (
auto &Succ : OtherEle->Succs) {
1179 if (Succ.getSUnit() == SU && Succ.getKind() ==
SDep::Data)
1187 unsigned SGID,
bool NeedsCache =
false)
1188 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1193 class IsReachableFromPrevNthGroup final :
public InstructionRule {
1195 unsigned Distance = 1;
1200 SchedGroup *OtherGroup =
nullptr;
1201 if (!SyncPipe.
size())
1204 for (
auto &PipeSG : SyncPipe) {
1205 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1206 OtherGroup = &PipeSG;
1211 if (!OtherGroup->Collection.size())
1214 auto *DAG = SyncPipe[0].DAG;
1216 for (
auto &OtherEle : OtherGroup->Collection)
1217 if (DAG->IsReachable(
const_cast<SUnit *
>(SU), OtherEle))
1222 IsReachableFromPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
1223 unsigned SGID,
bool NeedsCache =
false)
1224 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1228 class OccursAtOrAfterNode final :
public InstructionRule {
1239 bool NeedsCache =
false)
1245 class IsExactMFMA final :
public InstructionRule {
1253 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1256 if (Cache->empty()) {
1257 auto *TempSU = ChainSeed;
1262 for (
auto &Succ : TempSU->Succs) {
1263 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1264 TempSU = Succ.getSUnit();
1273 Cache->push_back(TempSU);
1279 return (*Cache)[0] == SU;
1283 unsigned SGID,
bool NeedsCache =
false)
1285 ChainSeed(ChainSeed) {}
1291 class OccursAfterExp final :
public InstructionRule {
1296 auto *DAG = SyncPipe[0].DAG;
1297 if (Cache->empty()) {
1298 for (
auto &SU : DAG->SUnits)
1300 Cache->push_back(&SU);
1307 return SU->
NodeNum > (*Cache)[0]->NodeNum;
1311 bool NeedsCache =
false)
1312 : InstructionRule(
TII, SGID, NeedsCache) {}
1316 bool applyIGLPStrategy(
1325 : IGLPStrategy(DAG,
TII) {
1330unsigned MFMAExpInterleaveOpt::TransPipeCount = 0;
1331unsigned MFMAExpInterleaveOpt::MFMAPipeCount = 0;
1332unsigned MFMAExpInterleaveOpt::AddPipeCount = 0;
1333unsigned MFMAExpInterleaveOpt::MFMAEnablement = 0;
1334unsigned MFMAExpInterleaveOpt::ExpRequirement = 0;
1335unsigned MFMAExpInterleaveOpt::MFMAChains = 0;
1336bool MFMAExpInterleaveOpt::HasCvt =
false;
1337bool MFMAExpInterleaveOpt::HasChainBetweenCvt =
false;
1338std::optional<unsigned> MFMAExpInterleaveOpt::FirstPipeDSR = std::nullopt;
1347 auto isBitPack = [](
unsigned Opc) {
1348 return Opc == AMDGPU::V_PACK_B32_F16_e64 ||
Opc == AMDGPU::V_PERM_B32_e64;
1351 auto isCvt = [](
unsigned Opc) {
1352 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
Opc == AMDGPU::V_CVT_I32_F32_e32;
1355 auto isAdd = [](
unsigned Opc) {
return Opc == AMDGPU::V_ADD_F32_e32; };
1358 for (
SUnit &SU : DAG->SUnits) {
1362 if (SU.
Succs.size() >= 7)
1364 for (
auto &Succ : SU.
Succs) {
1365 if (Succ.getSUnit()->Succs.size() >= 7)
1384 if (!(PackSUs.
size() && MFMAPipeCands.
size() && ExpPipeCands.
size()))
1389 std::optional<SUnit *> TempMFMA;
1390 std::optional<SUnit *> TempExp;
1392 for (
auto &PredSU : ExpPipeCands) {
1393 for (
auto &SuccSU : MFMAPipeCands) {
1394 if (DAG->IsReachable(SuccSU, PredSU)) {
1406 if (!(TempExp && TempMFMA))
1409 HasChainBetweenCvt =
none_of((*TempExp)->Succs, [&isCvt](
SDep &Succ) {
1410 return isCvt(Succ.getSUnit()->getInstr()->getOpcode());
1414 for (
auto &SuccSU : MFMAPipeCands) {
1415 if (MFMAPipeSUs.
size() &&
1416 any_of(MFMAPipeSUs, [&SuccSU](
SUnit *PotentialMatch) {
1417 return PotentialMatch->
NodeNum == SuccSU->NodeNum;
1421 for (
auto &PredSU : ExpPipeCands) {
1422 if (DAG->IsReachable(SuccSU, PredSU)) {
1429 MFMAPipeCount = MFMAPipeSUs.
size();
1431 assert(TempExp && TempMFMA);
1432 assert(MFMAPipeCount > 0);
1434 std::optional<SUnit *> TempCvt;
1435 for (
auto &SuccSU : CvtSUs) {
1436 if (DAG->IsReachable(SuccSU, *TempExp)) {
1443 if (TempCvt.has_value()) {
1444 for (
auto &SuccSU : MFMAPipeSUs) {
1445 if (DAG->IsReachable(SuccSU, *TempCvt)) {
1453 for (
auto &MFMAPipeSU : MFMAPipeSUs) {
1457 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1459 MFMAChainSeeds.push_back(MFMAPipeSU);
1467 for (
auto Pred : MFMAChainSeeds[0]->Preds) {
1468 if (
TII->isDS(Pred.getSUnit()->getInstr()->getOpcode()) &&
1469 Pred.getSUnit()->getInstr()->mayLoad())
1470 FirstPipeDSR = Pred.getSUnit()->NodeNum;
1474 unsigned PackSuccCount =
1476 return DAG->IsReachable(VPack, *TempExp);
1480 unsigned PackPredCount =
1482 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1483 return isBitPack(Opc);
1487 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1488 return isBitPack(Opc);
1491 if (PackPred == (*TempMFMA)->Preds.end())
1499 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1503 MFMAEnablement *= PackSuccCount;
1508 return DAG->IsReachable(PackPred->getSUnit(), ExpBase);
1511 ExpRequirement *= PackPredCount;
1521 MFMAChainSeeds.clear();
1528bool MFMAExpInterleaveOpt::applyIGLPStrategy(
1533 bool IsSmallKernelType =
1534 MFMAEnablement == 2 && ExpRequirement == 4 && TransPipeCount == 32;
1535 bool IsLargeKernelType =
1536 MFMAEnablement == 4 && ExpRequirement == 4 && TransPipeCount == 64;
1538 if (!(IsSmallKernelType || IsLargeKernelType))
1544 unsigned PipelineSyncID = 0;
1545 SchedGroup *SG =
nullptr;
1547 unsigned MFMAChain = 0;
1548 unsigned PositionInChain = 0;
1549 unsigned CurrMFMAForTransPosition = 0;
1551 auto incrementTransPosition = [&MFMAChain, &PositionInChain,
1552 &CurrMFMAForTransPosition]() {
1553 CurrMFMAForTransPosition += MFMAEnablement;
1554 PositionInChain = (CurrMFMAForTransPosition / MFMAChains);
1555 MFMAChain = CurrMFMAForTransPosition % MFMAChains;
1558 auto getNextTransPositionInChain = [&CurrMFMAForTransPosition]() {
1559 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1560 return (TempMFMAForTrans / MFMAChains);
1563 auto getNextTransMFMAChain = [&CurrMFMAForTransPosition]() {
1564 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1565 return TempMFMAForTrans % MFMAChains;
1568 unsigned CurrMFMAPosition = 0;
1569 unsigned MFMAChainForMFMA = 0;
1570 unsigned PositionInChainForMFMA = 0;
1572 auto incrementMFMAPosition = [&CurrMFMAPosition, &MFMAChainForMFMA,
1573 &PositionInChainForMFMA]() {
1575 MFMAChainForMFMA = CurrMFMAPosition % MFMAChains;
1576 PositionInChainForMFMA = CurrMFMAPosition / MFMAChains;
1580 assert(IsPostRA || MFMAChainSeeds.size() == MFMAChains);
1582 bool UsesFMA = IsSmallKernelType || !IsPostRA;
1583 bool UsesDSRead = IsLargeKernelType && !IsPostRA && FirstPipeDSR;
1584 bool UsesCvt = HasCvt && (IsSmallKernelType || !IsPostRA);
1585 bool UsesVALU = IsSmallKernelType;
1590 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1591 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1592 if (!IsPostRA && MFMAChains) {
1593 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1594 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1598 std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1599 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1600 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1603 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1604 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1605 if (!IsPostRA && MFMAChains) {
1606 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1607 getNextTransPositionInChain(),
1608 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1610 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1611 SG->getSGID(),
true));
1612 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1613 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1617 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1618 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1619 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1621 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1625 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1626 SchedGroupMask::TRANS, ExpRequirement, PipelineSyncID, DAG,
TII);
1627 if (!IsPostRA && MFMAChains)
1628 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1629 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
true));
1631 SG->addRule(std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1632 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1633 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1634 HasChainBetweenCvt));
1635 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1637 incrementTransPosition();
1640 for (
unsigned I = 0;
I < ExpRequirement;
I++) {
1643 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1644 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1645 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1646 if (HasChainBetweenCvt)
1647 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1648 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1650 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(
1651 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1652 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1657 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1658 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1659 if (!IsPostRA && MFMAChains) {
1660 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1661 getNextTransPositionInChain(),
1662 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1664 SG->addRule(std::make_shared<EnablesNthMFMA>(2 * MFMAEnablement + 1,
1665 TII, SG->getSGID(),
true));
1666 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1667 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1671 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1672 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1673 if (!IsPostRA && MFMAChains)
1674 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1675 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1678 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1679 SG->getSGID(),
true));
1680 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1681 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1682 HasChainBetweenCvt));
1683 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1688 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1689 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1690 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1691 SG->addRule(std::make_shared<GreaterThanOrEqualToNSuccs>(
1692 8,
TII, SG->getSGID(), HasChainBetweenCvt));
1693 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1698 unsigned MFMARatio =
1699 MFMAEnablement > ExpRequirement ? MFMAEnablement / ExpRequirement : 1;
1702 MFMAEnablement > ExpRequirement ? 1 : ExpRequirement / MFMAEnablement;
1704 unsigned RemainingExp = TransPipeCount > (2 * ExpRequirement)
1705 ? TransPipeCount - (2 * ExpRequirement)
1707 unsigned ExpLoopCount = RemainingExp / ExpRatio;
1709 unsigned MFMAInLoop = MFMAPipeCount > (MFMAEnablement * 2)
1710 ? MFMAPipeCount - (MFMAEnablement * 2)
1712 unsigned MFMALoopCount = MFMAInLoop / MFMARatio;
1714 AddPipeCount < MFMAPipeCount ? 1 : AddPipeCount / MFMAPipeCount;
1715 unsigned LoopSize = std::min(ExpLoopCount, MFMALoopCount);
1717 for (
unsigned I = 0;
I < LoopSize;
I++) {
1718 if (!(
I * ExpRatio % ExpRequirement))
1719 incrementTransPosition();
1722 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1723 SchedGroupMask::MFMA, MFMARatio, PipelineSyncID, DAG,
TII);
1724 if (!IsPostRA && MFMAChains)
1725 SG->addRule(std::make_shared<IsExactMFMA>(
1726 PositionInChainForMFMA, MFMAChainSeeds[MFMAChainForMFMA],
TII,
1727 SG->getSGID(),
true));
1729 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1730 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1731 incrementMFMAPosition();
1734 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1735 SchedGroupMask::VALU, VALUOps, PipelineSyncID, DAG,
TII);
1736 SG->addRule(std::make_shared<IsPipeAdd>(
TII, SG->getSGID()));
1737 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1740 if (UsesDSRead && !(
I % 4)) {
1741 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1742 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1743 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1745 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1749 for (
unsigned J = 0; J < ExpRatio; J++) {
1750 auto MFMAOffset = (1 + UsesVALU) * MFMARatio * (
I + 1);
1751 auto MaxMFMAOffset =
1752 (1 + UsesVALU) * ExpRequirement * MFMARatio / ExpRatio;
1756 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1757 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1758 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1759 auto BaseDiff = (2 + UsesFMA) * (ExpRequirement - 1) + 1;
1760 auto DSROffset =
I / 4 + 1;
1761 auto MaxDSROffset = MaxMFMAOffset / 4;
1763 auto ExpOffset =
I * ExpRatio + J >= ExpRequirement ? 0 : 1;
1764 auto CurrentOffset = UsesDSRead * std::min(MaxDSROffset, DSROffset) +
1765 std::min(MaxMFMAOffset, MFMAOffset) + BaseDiff +
1767 if (HasChainBetweenCvt)
1768 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1769 CurrentOffset,
TII, SG->getSGID()));
1771 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(CurrentOffset,
TII,
1773 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1778 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1779 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1780 if (!IsPostRA && MFMAChains)
1781 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1782 getNextTransPositionInChain(),
1783 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
1786 SG->addRule(std::make_shared<EnablesNthMFMA>(
1787 (((
I * ExpRatio + J) / ExpRequirement) + 3) * MFMAEnablement + 1,
1788 TII, SG->getSGID(),
true));
1789 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1790 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1794 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1795 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1796 if (!IsPostRA && MFMAChains)
1797 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1798 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1801 SG->addRule(std::make_shared<EnablesNthMFMA>(
1802 (((
I * ExpRatio + J) / ExpRequirement) + 2) * MFMAEnablement + 1,
1803 TII, SG->getSGID(),
true));
1804 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1805 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1806 HasChainBetweenCvt));
1807 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1812 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1813 SchedGroupMask::MFMA, MFMAEnablement * 2, PipelineSyncID, DAG,
TII);
1814 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1815 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1819class MFMAExpSimpleInterleaveOpt final :
public IGLPStrategy {
1821 bool applyIGLPStrategy(
1832 : IGLPStrategy(DAG,
TII) {
1837bool MFMAExpSimpleInterleaveOpt::applyIGLPStrategy(
1842 unsigned MFMACount = 0;
1844 if (
TII->isMFMAorWMMA(
I))
1847 const unsigned PipelineSyncID = 0;
1848 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
1849 SchedGroup *SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1850 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1851 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1853 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1854 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
1855 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1861class MFMASmallGemmSingleWaveOpt final :
public IGLPStrategy {
1864 class EnablesInitialMFMA final :
public InstructionRule {
1868 if (!SyncPipe.
size())
1871 if (!Cache->size()) {
1872 for (
auto &Elt : SyncPipe[0].DAG->
SUnits) {
1873 if (
TII->isMFMAorWMMA(*Elt.getInstr())) {
1877 Cache->push_back(&Elt);
1882 auto *DAG = SyncPipe[0].DAG;
1883 for (
auto &Elt : *Cache) {
1891 bool NeedsCache =
false)
1892 : InstructionRule(
TII, SGID, NeedsCache) {}
1896 class IsPermForDSW final :
public InstructionRule {
1901 if (
MI->getOpcode() != AMDGPU::V_PERM_B32_e64)
1904 bool FitsInGroup =
false;
1906 if (!Collection.
size()) {
1907 for (
auto &Succ : SU->
Succs) {
1908 SUnit *SuccUnit = Succ.getSUnit();
1911 Cache->push_back(SuccUnit);
1922 return ThisSucc.getSUnit() == Elt;
1927 IsPermForDSW(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1928 : InstructionRule(
TII, SGID, NeedsCache) {}
1932 class IsSuccOfPrevGroup final :
public InstructionRule {
1936 SchedGroup *OtherGroup =
nullptr;
1937 for (
auto &PipeSG : SyncPipe) {
1938 if ((
unsigned)PipeSG.getSGID() == SGID - 1) {
1939 OtherGroup = &PipeSG;
1945 if (!OtherGroup->Collection.size())
1949 return any_of(OtherGroup->Collection, [&SU](
SUnit *Elt) {
1950 return any_of(Elt->Succs,
1951 [&SU](SDep &Succ) { return Succ.getSUnit() == SU; });
1955 bool NeedsCache =
false)
1956 : InstructionRule(
TII, SGID, NeedsCache) {}
1960 class VMEMSize final :
public InstructionRule {
1965 if (
MI->getOpcode() == TargetOpcode::BUNDLE)
1967 if (!Collection.
size())
1972 auto TRI =
TII->getRegisterInfo();
1973 auto &MRI =
MI->getMF()->getRegInfo();
1974 for (
auto &Elt : Collection) {
1975 auto Op = Elt->getInstr()->getOperand(0);
1977 TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(MRI,
Op));
1981 if (NumBits < 128) {
1983 if (NumBits +
TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(
1984 MRI,
MI->getOperand(0))) <=
1992 VMEMSize(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1993 : InstructionRule(
TII, SGID, NeedsCache) {}
1998 class SharesPredWithPrevNthGroup final :
public InstructionRule {
2000 unsigned Distance = 1;
2005 SchedGroup *OtherGroup =
nullptr;
2006 if (!SyncPipe.
size())
2009 if (!Cache->size()) {
2011 for (
auto &PipeSG : SyncPipe) {
2012 if ((
unsigned)PipeSG.getSGID() == SGID - Distance) {
2013 OtherGroup = &PipeSG;
2019 if (!OtherGroup->Collection.size())
2022 for (
auto &OtherEle : OtherGroup->Collection) {
2023 for (
auto &Pred : OtherEle->Preds) {
2024 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2025 AMDGPU::V_PERM_B32_e64)
2026 Cache->push_back(Pred.getSUnit());
2035 auto *DAG = SyncPipe[0].DAG;
2042 SharesPredWithPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
2043 unsigned SGID,
bool NeedsCache =
false)
2044 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
2048 bool applyIGLPStrategy(
2059 : IGLPStrategy(DAG,
TII) {
2064static unsigned DSWCount = 0;
2065static unsigned DSWWithPermCount = 0;
2066static unsigned DSWWithSharedVMEMCount = 0;
2068bool MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
2069 DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
2072 unsigned MFMACount = 0;
2073 unsigned DSRCount = 0;
2075 bool IsInitial =
Phase == AMDGPU::SchedulingPhase::Initial;
2077 assert((!IsInitial || (DSWCount == 0 && DSWWithPermCount == 0 &&
2078 DSWWithSharedVMEMCount == 0)) &&
2079 "DSWCounters should be zero in pre-RA scheduling!");
2081 for (
auto &SU : DAG->SUnits) {
2082 auto *
I = SU.getInstr();
2083 if (
TII->isMFMAorWMMA(*
I))
2085 else if (
TII->isDS(*
I)) {
2088 else if (
I->mayStore() && IsInitial) {
2090 for (
auto Pred : SU.Preds) {
2091 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2092 AMDGPU::V_PERM_B32_e64) {
2102 DSWWithPermCount = DSWithPerms.
size();
2103 auto *
I = DSWithPerms.
begin();
2104 auto *
E = DSWithPerms.
end();
2112 DenseMap<MachineInstr *, SUnit *> VMEMLookup;
2114 for (;
I !=
E;
I++) {
2115 SUnit *Cand =
nullptr;
2116 bool MissedAny =
false;
2117 for (
auto &Pred : (*I)->Preds) {
2118 if (Pred.getSUnit()->getInstr()->getOpcode() != AMDGPU::V_PERM_B32_e64)
2124 for (
auto &Succ : Pred.getSUnit()->Succs) {
2125 auto *
MI = Succ.getSUnit()->getInstr();
2126 if (!
TII->isVMEM(*
MI) || !
MI->mayLoad())
2129 if (MissedAny || !VMEMLookup.
size()) {
2131 VMEMLookup[
MI] = *
I;
2148 if (!MissedAny && Cand) {
2149 DSWWithSharedVMEMCount += 2;
2156 assert(DSWWithSharedVMEMCount <= DSWWithPermCount);
2158 unsigned PipelineSyncID = 0;
2160 if (DSWWithPermCount) {
2161 for (
unsigned I = 0;
I < MFMACount;
I++) {
2162 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2163 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2164 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2166 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2167 SchedGroupMask::VALU, 2, PipelineSyncID, DAG,
TII);
2168 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2178 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2179 SchedGroupMask::DS_READ, 4, PipelineSyncID, DAG,
TII);
2180 SG->addRule(std::make_shared<EnablesInitialMFMA>(
TII, SG->getSGID(),
true));
2181 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2183 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2184 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2185 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2188 for (
unsigned I = 4;
I < DSRCount; ++
I) {
2189 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2190 SchedGroupMask::DS_READ, 1, PipelineSyncID, DAG,
TII);
2191 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2193 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2194 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2195 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2201 for (
unsigned I = DSWWithSharedVMEMCount;
I < DSWWithPermCount; ++
I) {
2202 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2203 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2204 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2205 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2207 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2208 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2209 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2210 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2212 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2213 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2214 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2215 1,
TII, SG->getSGID(),
true));
2216 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2217 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2219 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2220 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2221 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2223 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2224 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2225 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2226 3,
TII, SG->getSGID(),
true));
2227 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2228 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2230 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2231 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2232 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2238 for (
unsigned I = DSWWithPermCount;
I < DSWCount;
I++) {
2239 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2240 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2241 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2243 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2244 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2245 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2246 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2248 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2249 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2250 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2258 for (
unsigned I = 0;
I < DSWWithSharedVMEMCount; ++
I) {
2259 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2260 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2261 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2262 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2264 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2265 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2266 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2267 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2269 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2270 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2271 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2273 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2274 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2275 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2276 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2278 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2279 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2280 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2281 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2283 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2284 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2285 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2287 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2288 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2289 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2290 2,
TII, SG->getSGID(),
true));
2291 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2292 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2294 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2295 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2296 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2298 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2299 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2300 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2301 4,
TII, SG->getSGID(),
true));
2302 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2303 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2305 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2306 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2307 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2313static std::unique_ptr<IGLPStrategy>
2315 const SIInstrInfo *
TII) {
2318 return std::make_unique<MFMASmallGemmOpt>(DAG,
TII);
2320 return std::make_unique<MFMASmallGemmSingleWaveOpt>(DAG,
TII);
2322 return std::make_unique<MFMAExpInterleaveOpt>(DAG,
TII);
2324 return std::make_unique<MFMAExpSimpleInterleaveOpt>(DAG,
TII);
2330class IGroupLPDAGMutation :
public ScheduleDAGMutation {
2332 const SIInstrInfo *
TII;
2339 DenseMap<int, SmallVector<SchedGroup, 4>> SyncedSchedGroups;
2342 DenseMap<int, SUnitsToCandidateSGsMap> SyncedInstrs;
2345 void addSchedBarrierEdges(SUnit &SU);
2356 SchedGroupMask invertSchedBarrierMask(SchedGroupMask Mask)
const;
2359 void initSchedGroupBarrierPipelineStage(
2360 std::vector<SUnit>::reverse_iterator RIter);
2362 bool initIGLPOpt(SUnit &SU);
2365 void apply(ScheduleDAGInstrs *DAGInstrs)
override;
2372 bool IsBottomUp =
true;
2377 IGroupLPDAGMutation() =
default;
2381unsigned SchedGroup::NumSchedGroups = 0;
2383bool SchedGroup::tryAddEdge(SUnit *
A, SUnit *
B) {
2387bool SchedGroup::canAddMI(
const MachineInstr &
MI)
const {
2389 if (
MI.isMetaInstruction())
2392 else if (
MI.isInlineAsm()) {
2394 auto &MRI =
MI.getParent()->getParent()->getRegInfo();
2395 bool SGPR_used =
false, SGPR_big_def =
false, VGPR_used =
false,
2396 VMFMA_used =
false, VReg32_used =
false,
MayLoad =
MI.mayLoad(),
2398 for (
const MachineOperand &Operand :
MI.operands())
2399 if (Operand.isReg()) {
2400 const TargetRegisterClass &RegClass =
2401 *
TRI.getRegClassForOperandReg(MRI, Operand);
2402 if (
TRI.hasVGPRs(&RegClass)) {
2404 if (Operand.isUse() &&
TRI.getRegSizeInBits(RegClass) == 32)
2410 if (
TRI.hasAGPRs(&RegClass) ||
TRI.getRegSizeInBits(RegClass) > 128)
2412 if (
TRI.hasSGPRs(&RegClass))
2414 if (
TRI.getRegSizeInBits(RegClass) > 64 && Operand.isDef())
2415 SGPR_big_def =
true;
2418 typedef std::underlying_type_t<SchedGroupMask> SGMask_t;
2419 SGMask_t InlineAsmMask = 0;
2420 if (VGPR_used && !VMFMA_used && !MayLoad && !MayStore)
2421 InlineAsmMask |= (SGMask_t)SchedGroupMask::VALU;
2422 if (SGPR_used && !VGPR_used && !MayLoad && !MayStore)
2423 InlineAsmMask |= (SGMask_t)SchedGroupMask::SALU;
2425 InlineAsmMask |= (SGMask_t)SchedGroupMask::MFMA;
2426 if (VGPR_used && MayLoad)
2427 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_READ
2428 : SchedGroupMask::VMEM_READ);
2429 if (VGPR_used && MayStore)
2430 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_WRITE
2431 : SchedGroupMask::VMEM_WRITE);
2433 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS_READ;
2434 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VALU ||
2435 InlineAsmMask & (SGMask_t)SchedGroupMask::SALU)
2436 InlineAsmMask |= (SGMask_t)SchedGroupMask::ALU;
2437 if (InlineAsmMask & (SGMask_t)SchedGroupMask::DS_READ ||
2438 InlineAsmMask & (SGMask_t)SchedGroupMask::DS_WRITE)
2439 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS;
2440 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_READ ||
2441 InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_WRITE)
2442 InlineAsmMask |= (SGMask_t)SchedGroupMask::VMEM;
2444 Result = ((SGMask_t)SGMask & InlineAsmMask) != 0;
2447 else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
2452 else if (((SGMask & SchedGroupMask::VALU) != SchedGroupMask::NONE) &&
2460 else if (((SGMask & SchedGroupMask::SALU) != SchedGroupMask::NONE) &&
2464 else if (((SGMask & SchedGroupMask::MFMA) != SchedGroupMask::NONE) &&
2465 TII->isMFMAorWMMA(
MI))
2468 else if (((SGMask & SchedGroupMask::VMEM) != SchedGroupMask::NONE) &&
2472 else if (((SGMask & SchedGroupMask::VMEM_READ) != SchedGroupMask::NONE) &&
2473 MI.mayLoad() &&
TII->isVMEM(
MI))
2476 else if (((SGMask & SchedGroupMask::VMEM_WRITE) != SchedGroupMask::NONE) &&
2477 MI.mayStore() &&
TII->isVMEM(
MI))
2480 else if (((SGMask & SchedGroupMask::DS) != SchedGroupMask::NONE) &&
2484 else if (((SGMask & SchedGroupMask::DS_READ) != SchedGroupMask::NONE) &&
2485 MI.mayLoad() &&
TII->isDS(
MI))
2488 else if (((SGMask & SchedGroupMask::DS_WRITE) != SchedGroupMask::NONE) &&
2489 MI.mayStore() &&
TII->isDS(
MI))
2492 else if (((SGMask & SchedGroupMask::TRANS) != SchedGroupMask::NONE) &&
2497 dbgs() <<
"For SchedGroup with mask " <<
format_hex((
int)SGMask, 10,
true)
2498 << (Result ?
" could classify " :
" unable to classify ") <<
MI);
2503int SchedGroup::link(SUnit &SU,
bool MakePred,
2504 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
2505 int MissedEdges = 0;
2506 for (
auto *
A : Collection) {
2508 if (
A ==
B ||
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2518 bool Added = tryAddEdge(
A,
B);
2520 AddedEdges.emplace_back(
A,
B);
2528void SchedGroup::link(SUnit &SU,
bool MakePred) {
2529 for (
auto *
A : Collection) {
2531 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2540void SchedGroup::link(SUnit &SU,
2541 function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>
P) {
2542 for (
auto *
A : Collection) {
2551void SchedGroup::link(SchedGroup &OtherGroup) {
2552 for (
auto *
B : OtherGroup.Collection)
2556bool SchedGroup::canAddSU(SUnit &SU)
const {
2558 if (
MI.getOpcode() != TargetOpcode::BUNDLE)
2559 return canAddMI(
MI);
2562 const MachineBasicBlock *
MBB =
MI.getParent();
2564 while (
E !=
MBB->
end() &&
E->isBundledWithPred())
2568 return std::all_of(
B,
E, [
this](MachineInstr &
MI) {
return canAddMI(
MI); });
2572void SchedGroup::findCandidateSUnits(
T Begin,
T End,
2573 SUnitsToCandidateSGsMap &SyncedInstrs) {
2576 SyncedInstrs[&SU].push_back(SGID);
2580void SchedGroup::findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs) {
2581 findCandidateSUnits(DAG->
SUnits.rbegin(), DAG->
SUnits.rend(), SyncedInstrs);
2584void IGroupLPDAGMutation::apply(ScheduleDAGInstrs *DAGInstrs) {
2585 const TargetSchedModel *TSchedModel = DAGInstrs->
getSchedModel();
2586 if (!TSchedModel || DAGInstrs->
SUnits.empty())
2591 TII =
ST.getInstrInfo();
2592 DAG =
static_cast<ScheduleDAGMI *
>(DAGInstrs);
2593 SyncedSchedGroups.clear();
2594 SyncedInstrs.clear();
2595 bool FoundSB =
false;
2596 bool FoundIGLP =
false;
2597 bool ShouldApplyIGLP =
false;
2598 for (
auto R = DAG->
SUnits.rbegin(),
E = DAG->
SUnits.rend(); R !=
E; ++R) {
2599 unsigned Opc =
R->getInstr()->getOpcode();
2601 if (
Opc == AMDGPU::SCHED_BARRIER) {
2602 addSchedBarrierEdges(*R);
2604 }
else if (
Opc == AMDGPU::SCHED_GROUP_BARRIER) {
2605 initSchedGroupBarrierPipelineStage(R);
2607 }
else if (
Opc == AMDGPU::IGLP_OPT) {
2608 if (!FoundSB && !FoundIGLP) {
2610 ShouldApplyIGLP = initIGLPOpt(*R);
2615 if (FoundSB || (FoundIGLP && ShouldApplyIGLP)) {
2616 PipelineSolver PS(SyncedSchedGroups, SyncedInstrs, DAG, IsBottomUp);
2624void IGroupLPDAGMutation::addSchedBarrierEdges(SUnit &SchedBarrier) {
2626 assert(
MI.getOpcode() == AMDGPU::SCHED_BARRIER);
2627 LLVM_DEBUG(
dbgs() <<
"Building SchedGroup for SchedBarrier with Mask: "
2628 <<
MI.getOperand(0).getImm() <<
"\n");
2630 invertSchedBarrierMask((SchedGroupMask)
MI.getOperand(0).getImm());
2631 SchedGroup SG(InvertedMask, std::nullopt, DAG,
TII);
2633 for (SUnit &SU : DAG->
SUnits)
2634 if (SG.canAddSU(SU))
2640 (function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>)[](
2641 const SUnit *
A,
const SUnit *
B) {
return A->NodeNum >
B->NodeNum; });
2645IGroupLPDAGMutation::invertSchedBarrierMask(SchedGroupMask Mask)
const {
2648 SchedGroupMask InvertedMask = ~Mask;
2651 if ((InvertedMask & SchedGroupMask::ALU) == SchedGroupMask::NONE)
2652 InvertedMask &= ~SchedGroupMask::VALU & ~SchedGroupMask
::SALU &
2655 else if ((InvertedMask & SchedGroupMask::VALU) == SchedGroupMask::NONE ||
2656 (InvertedMask & SchedGroupMask::SALU) == SchedGroupMask::NONE ||
2657 (InvertedMask & SchedGroupMask::MFMA) == SchedGroupMask::NONE ||
2658 (InvertedMask & SchedGroupMask::TRANS) == SchedGroupMask::NONE)
2659 InvertedMask &= ~SchedGroupMask::ALU;
2662 if ((InvertedMask & SchedGroupMask::VMEM) == SchedGroupMask::NONE)
2663 InvertedMask &= ~SchedGroupMask::VMEM_READ & ~SchedGroupMask::VMEM_WRITE;
2665 else if ((InvertedMask & SchedGroupMask::VMEM_READ) == SchedGroupMask::NONE ||
2666 (InvertedMask & SchedGroupMask::VMEM_WRITE) == SchedGroupMask::NONE)
2667 InvertedMask &= ~SchedGroupMask
::VMEM;
2670 if ((InvertedMask & SchedGroupMask::DS) == SchedGroupMask::NONE)
2671 InvertedMask &= ~SchedGroupMask::DS_READ & ~SchedGroupMask::DS_WRITE;
2673 else if ((InvertedMask & SchedGroupMask::DS_READ) == SchedGroupMask::NONE ||
2674 (InvertedMask & SchedGroupMask::DS_WRITE) == SchedGroupMask::NONE)
2675 InvertedMask &= ~SchedGroupMask
::DS;
2677 LLVM_DEBUG(
dbgs() <<
"After Inverting, SchedGroup Mask: " << (
int)InvertedMask
2680 return InvertedMask;
2683void IGroupLPDAGMutation::initSchedGroupBarrierPipelineStage(
2684 std::vector<SUnit>::reverse_iterator RIter) {
2685 MachineInstr &SGB = *RIter->getInstr();
2692 auto &SG = SyncedSchedGroups[SyncID].emplace_back((SchedGroupMask)SGMask,
2695 SG.findCandidateSUnits(RIter, SG.DAG->
SUnits.rend(),
2696 SyncedInstrs[SG.getSyncID()]);
2699bool IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
2702 auto S = createIGLPStrategy(StrategyID, DAG,
TII);
2703 if (!S->shouldApplyStrategy(DAG,
Phase))
2706 IsBottomUp = S->IsBottomUp;
2707 return S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups,
Phase);
2717std::unique_ptr<ScheduleDAGMutation>
2719 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.
IGLPStrategyID
Operand 0 immediate for IGLP_OPT pseudo instructions.
@ MFMASmallGemmSingleWaveOptID
@ MFMAExpSimpleInterleaveID
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:...