27#define DEBUG_TYPE "igrouplp"
33 cl::desc(
"Whether to use the exponential time solver to fit "
34 "the instructions to the pipeline as closely as "
40 cl::desc(
"The maximum number of scheduling group conflicts "
41 "which we attempt to solve with the exponential time "
42 "exact solver. Problem sizes greater than this will"
43 "be solved by the less accurate greedy algorithm. Selecting "
44 "solver by size is superseded by manually selecting "
45 "the solver (e.g. by amdgpu-igrouplp-exact-solver"));
49 cl::desc(
"The amount of branches that we are willing to explore with"
50 "the exact algorithm before giving up."));
54 cl::desc(
"Whether to use the cost heuristic to make choices as we "
55 "traverse the search space using the exact solver. Defaulted "
56 "to on, and if turned off, we will use the node order -- "
57 "attempting to put the later nodes in the later sched groups. "
58 "Experimentally, results are mixed, so this should be set on a "
59 "case-by-case basis."));
66class InstructionRule {
72 std::optional<SmallVector<SUnit *, 4>> Cache;
82 bool NeedsCache =
false)
89 virtual ~InstructionRule() =
default;
105 std::optional<unsigned> MaxSize;
118 static unsigned NumSchedGroups;
135 bool canAddSU(
SUnit &SU)
const;
140 void link(
SUnit &SU,
bool MakePred =
false);
144 int link(
SUnit &SU,
bool MakePred,
145 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
154 void link(SchedGroup &OtherGroup);
157 bool isFull()
const {
return MaxSize && Collection.
size() >= *MaxSize; }
163 void addRule(std::shared_ptr<InstructionRule> NewRule) {
168 bool allowedByRules(
const SUnit *SU,
170 for (
auto &Rule : Rules) {
171 if (!Rule->apply(SU, Collection, SyncPipe))
178 void add(
SUnit &SU) {
180 <<
format_hex((
int)SGMask, 10,
true) <<
" adding "
186 void pop() { Collection.
pop_back(); }
189 void findCandidateSUnits(
T Begin,
T End,
190 SUnitsToCandidateSGsMap &SyncedInstrs);
195 void findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs);
197 int getSyncID() {
return SyncID; }
199 int getSGID() {
return SGID; }
203 SchedGroup(
SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
205 : SGMask(SGMask), MaxSize(MaxSize), DAG(DAG),
TII(
TII) {
206 SGID = NumSchedGroups++;
209 SchedGroup(
SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
int SyncID,
211 : SGMask(SGMask), MaxSize(MaxSize), SyncID(SyncID), DAG(DAG),
TII(
TII) {
212 SGID = NumSchedGroups++;
216using SUToCandSGsPair = std::pair<SUnit *, SmallVector<int, 4>>;
228class PipelineSolver {
241 bool NeedsSolver =
false;
245 unsigned computeProblemSize();
256 int CurrConflInstNo = 0;
258 int CurrSyncGroupIdx = 0;
260 int BeginSyncGroupIdx = 0;
266 bool IsBottomUp =
true;
269 void advancePosition();
272 void retreatPosition();
281 template <
typename T>
282 void greedyFind(std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
287 template <
typename T>
294 template <
typename T>
void linkSchedGroups(
T I,
T E);
298 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
304 class EdgeSetBuilder {
310 bool Initialized =
false;
314 template <
bool ComputePreds>
328 : SU(SU), SyncPipeline(SyncPipeline), IsBottomUp(IsBottomUp) {}
334 int build(
int SGID, std::list<std::pair<SUnit *, SUnit *>> &NewEdges);
337 template <
typename T>
339 std::list<std::pair<SUnit *, SUnit *>> &NewEdges);
345 template <
typename T>
346 int linkSUnit(
SUnit *SU,
int SGID,
347 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
349 void removeEdges(
const std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
351 void convertSyncMapsToArrays();
363 : DAG(DAG), SyncedInstrs(SyncedInstrs),
364 SyncedSchedGroups(SyncedSchedGroups), IsBottomUp(IsBottomUp) {
366 for (
auto &PipelineInstrs : SyncedInstrs) {
367 if (!PipelineInstrs.second.
empty()) {
376 convertSyncMapsToArrays();
378 CurrPipeline = BestPipeline;
380 while (
static_cast<size_t>(BeginSyncGroupIdx) < PipelineInstrs.
size() &&
381 PipelineInstrs[BeginSyncGroupIdx].
empty())
384 if (
static_cast<size_t>(BeginSyncGroupIdx) >= PipelineInstrs.
size())
389void PipelineSolver::reset() {
391 for (
auto &SyncPipeline : CurrPipeline) {
392 for (
auto &SG : SyncPipeline) {
394 SG.Collection.
clear();
398 if (SchedBarr != TempCollection.
end())
399 SG.Collection.push_back(*SchedBarr);
403 CurrSyncGroupIdx = BeginSyncGroupIdx;
408void PipelineSolver::convertSyncMapsToArrays() {
409 for (
auto &SyncPipe : SyncedSchedGroups) {
410 BestPipeline.insert(BestPipeline.begin(), SyncPipe.second);
413 int PipelineIDx = SyncedInstrs.size() - 1;
414 PipelineInstrs.resize(SyncedInstrs.size());
415 for (
auto &SyncInstrMap : SyncedInstrs) {
416 for (
auto &SUsToCandSGs : SyncInstrMap.second) {
417 if (PipelineInstrs[PipelineIDx].empty()) {
418 PipelineInstrs[PipelineIDx].push_back(
419 std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
422 auto *SortPosition = PipelineInstrs[PipelineIDx].begin();
425 while (SortPosition != PipelineInstrs[PipelineIDx].end() &&
426 SUsToCandSGs.first->NodeNum > SortPosition->first->NodeNum)
428 PipelineInstrs[PipelineIDx].insert(
429 SortPosition, std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
435template <
typename T>
void PipelineSolver::linkSchedGroups(
T I,
T E) {
436 for (;
I !=
E; ++
I) {
438 for (
auto J = std::next(
I); J !=
E; ++J) {
445void PipelineSolver::makePipeline() {
447 for (
auto &SyncPipeline : BestPipeline) {
449 for (
auto &SG : SyncPipeline) {
452 SUnit *SGBarr =
nullptr;
453 for (
auto &SU : SG.Collection) {
454 if (SU->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
461 SG.link(*SGBarr,
false);
465 for (
auto &SyncPipeline : BestPipeline) {
466 IsBottomUp ? linkSchedGroups(SyncPipeline.rbegin(), SyncPipeline.rend())
467 : linkSchedGroups(SyncPipeline.begin(), SyncPipeline.end());
472int PipelineSolver::linkSUnit(
473 SUnit *SU,
int SGID, std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
475 bool MakePred =
false;
478 if (
I->getSGID() == SGID) {
483 AddedCost += Group.link(*SU, MakePred, AddedEdges);
489template <
bool ComputePreds>
490void PipelineSolver::EdgeSetBuilder::computeReachable(
492 if (!Reachable.insert(Start).second)
497 while (!WorkList.
empty()) {
500 for (
const SDep &Dep : ComputePreds ? Current->
Preds : Current->
Succs) {
501 if (Reachable.insert(Dep.getSUnit()).second)
509 computeReachable<
true>(Preds, Start);
514 computeReachable<
false>(Succs, Start);
517int PipelineSolver::EdgeSetBuilder::build(
518 int SGID, std::list<std::pair<SUnit *, SUnit *>> &NewEdges) {
520 computePreds(InitialPreds, SU);
521 computeSuccs(Succs, SU);
526 return IsBottomUp ? buildImpl(SGID,
reverse(SyncPipeline), NewEdges)
534int PipelineSolver::EdgeSetBuilder::buildImpl(
536 std::list<std::pair<SUnit *, SUnit *>> &NewEdges) {
554 bool MakePred =
false;
555 for (SchedGroup &SG : SchedGroups) {
556 if (SG.getSGID() == SGID) {
561 for (
SUnit *
A : SG.Collection) {
562 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
573 NewEdges.emplace_back(SU,
A);
582 NewEdges.emplace_back(
A, SU);
583 computePreds(Preds,
A);
590int PipelineSolver::addEdges(
592 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
602 return IsBottomUp ? linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
rbegin(),
604 : linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
begin(),
608void PipelineSolver::removeEdges(
609 const std::list<std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
612 for (
auto &PredSuccPair : EdgesToRemove) {
613 SUnit *Pred = PredSuccPair.first;
614 SUnit *Succ = PredSuccPair.second;
617 return P.getSUnit() == Pred && P.isArtificial();
619 if (Match != Succ->
Preds.end())
624void PipelineSolver::advancePosition() {
627 if (
static_cast<size_t>(CurrConflInstNo) >=
628 PipelineInstrs[CurrSyncGroupIdx].
size()) {
632 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size() &&
633 PipelineInstrs[CurrSyncGroupIdx].empty())
638void PipelineSolver::retreatPosition() {
639 assert(CurrConflInstNo >= 0);
640 assert(CurrSyncGroupIdx >= 0);
642 if (CurrConflInstNo > 0) {
647 if (CurrConflInstNo == 0) {
650 if (CurrSyncGroupIdx == BeginSyncGroupIdx)
655 while (PipelineInstrs[CurrSyncGroupIdx].empty())
658 CurrConflInstNo = PipelineInstrs[CurrSyncGroupIdx].size() - 1;
662bool PipelineSolver::checkOptimal() {
663 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size()) {
664 if (BestCost == -1 || CurrCost < BestCost) {
665 BestPipeline = CurrPipeline;
672 bool DoneExploring =
false;
673 if (MaxBranchesExplored > 0 && BranchesExplored >= MaxBranchesExplored)
674 DoneExploring =
true;
676 return (DoneExploring || BestCost == 0);
680void PipelineSolver::populateReadyList(
682 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
683 auto SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
684 assert(CurrSU.second.size() >= 1);
686 for (;
I !=
E; ++
I) {
687 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
689 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
690 return SG.getSGID() == CandSGID;
695 if (Match->isFull()) {
696 ReadyList.push_back(std::pair(*
I, MissPenalty));
700 int TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
701 ReadyList.push_back(std::pair(*
I, TempCost));
702 removeEdges(AddedEdges);
704 ReadyList.push_back(std::pair(*
I, -1));
710 assert(ReadyList.size() == CurrSU.second.size());
713bool PipelineSolver::solveExact() {
717 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size())
720 assert(
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size());
721 assert(
static_cast<size_t>(CurrConflInstNo) <
722 PipelineInstrs[CurrSyncGroupIdx].
size());
723 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
725 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
730 IsBottomUp ? populateReadyList(ReadyList, CurrSU.second.
rbegin(),
731 CurrSU.second.rend())
732 : populateReadyList(ReadyList, CurrSU.second.
begin(),
733 CurrSU.second.end());
735 auto *
I = ReadyList.
begin();
736 auto *
E = ReadyList.
end();
737 for (;
I !=
E; ++
I) {
741 if (BestCost != -1 && (CurrCost +
I->second > BestCost))
744 int CandSGID =
I->first;
746 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
747 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
748 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
749 return SG.getSGID() == CandSGID;
756 if (!Match->allowedByRules(CurrSU.first, SyncPipeline))
760 << (
int)Match->getMask() <<
"and ID " << CandSGID
762 Match->add(*CurrSU.first);
763 AddedCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
764 LLVM_DEBUG(
dbgs() <<
"Cost of Assignment: " << AddedCost <<
"\n");
765 CurrCost += AddedCost;
768 bool FinishedExploring =
false;
771 if (CurrCost < BestCost || BestCost == -1) {
773 FinishedExploring = BestCost != 0;
774 if (!FinishedExploring)
780 CurrCost -= AddedCost;
781 removeEdges(AddedEdges);
783 CurrPipeline[CurrSyncGroupIdx] = SyncPipeline;
784 if (FinishedExploring)
791 CurrCost += MissPenalty;
794 LLVM_DEBUG(
dbgs() <<
"NOT Assigned (" << CurrSU.first->NodeNum <<
")\n");
796 bool FinishedExploring =
false;
797 if (CurrCost < BestCost || BestCost == -1) {
799 bool FinishedExploring = BestCost != 0;
800 if (!FinishedExploring)
806 CurrCost -= MissPenalty;
807 return FinishedExploring;
811void PipelineSolver::greedyFind(
812 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E) {
813 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
817 std::list<std::pair<SUnit *, SUnit *>> Edges;
820 std::optional<GroupInfo> Best;
822 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
824 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
826 EdgeSetBuilder Builder(CurrSU.first, SyncPipeline, IsBottomUp);
832 for (;
I !=
E; ++
I) {
834 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
835 return SG.getSGID() == CandSGID;
839 LLVM_DEBUG(
dbgs() <<
"Trying SGID # " << CandSGID <<
" with Mask "
840 << (
int)Match->getMask() <<
"\n");
842 if (Match->isFull()) {
846 if (!Match->allowedByRules(CurrSU.first, SyncPipeline)) {
847 LLVM_DEBUG(
dbgs() <<
"SGID # " << CandSGID <<
" has conflicting rule\n");
851 std::list<std::pair<SUnit *, SUnit *>> TempEdges;
852 int TempCost = Builder.build(CandSGID, TempEdges);
855 if (!Best || TempCost < Best->Cost) {
856 Best = {Match, TempEdges, TempCost};
863 SchedGroup *SG = Best->SG;
864 std::list<std::pair<SUnit *, SUnit *>> &Edges = Best->Edges;
866 SG->add(*CurrSU.first);
867 if (AddedEdges.empty())
870 AddedEdges.splice(std::prev(AddedEdges.cend()), Edges);
872 for (
const std::pair<SUnit *, SUnit *> &
E : Edges) {
873 if (!SG->tryAddEdge(
E.first,
E.second))
877 LLVM_DEBUG(
dbgs() <<
"Best Group has ID: " << SG->getSGID() <<
" and Mask"
878 << (
int)SG->getMask() <<
"\n");
879 BestCost += Best->Cost;
881 BestCost += MissPenalty;
884bool PipelineSolver::solveGreedy() {
886 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
888 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size()) {
889 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
891 ? greedyFind(AddedEdges, CurrSU.second.rbegin(), CurrSU.second.rend())
892 : greedyFind(AddedEdges, CurrSU.second.begin(), CurrSU.second.end());
895 BestPipeline = CurrPipeline;
896 removeEdges(AddedEdges);
900unsigned PipelineSolver::computeProblemSize() {
901 unsigned ProblemSize = 0;
902 for (
auto &PipeConflicts : PipelineInstrs) {
903 ProblemSize += PipeConflicts.size();
909void PipelineSolver::solve() {
913 unsigned ProblemSize = computeProblemSize();
916 bool BelowCutoff = (CutoffForExact > 0) && ProblemSize <= CutoffForExact;
917 MissPenalty = (ProblemSize / 2) + 1;
920 if (EnableExactSolver || BelowCutoff) {
924 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
928 LLVM_DEBUG(
dbgs() <<
"Exact produced best cost of " << BestCost <<
"\n");
933 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
950 virtual bool applyIGLPStrategy(
959 bool IsBottomUp =
true;
964 virtual ~IGLPStrategy() =
default;
967class MFMASmallGemmOpt final :
public IGLPStrategy {
970 bool applyIGLPStrategy(
981 : IGLPStrategy(DAG,
TII) {
986bool MFMASmallGemmOpt::applyIGLPStrategy(
991 unsigned MFMACount = 0;
993 if (
TII->isMFMAorWMMA(
I))
996 const unsigned PipelineSyncID = 0;
997 SchedGroup *SG =
nullptr;
998 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
999 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1001 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1003 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1005 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1011class MFMAExpInterleaveOpt final :
public IGLPStrategy {
1014 static unsigned TransPipeCount;
1016 static unsigned MFMAPipeCount;
1018 static unsigned AddPipeCount;
1020 static unsigned MFMAEnablement;
1022 static unsigned ExpRequirement;
1024 static unsigned MFMAChains;
1029 static bool HasChainBetweenCvt;
1031 static std::optional<unsigned> FirstPipeDSR;
1040 class IsPipeExp final :
public InstructionRule {
1045 auto *DAG = SyncPipe[0].DAG;
1047 if (Cache->empty()) {
1048 auto I = DAG->SUnits.rbegin();
1049 auto E = DAG->SUnits.rend();
1050 for (;
I !=
E;
I++) {
1051 if (
TII->isMFMAorWMMA(*
I->getInstr()))
1052 Cache->push_back(&*
I);
1058 auto Reaches =
any_of(*Cache, [&SU, &DAG](
SUnit *TargetSU) {
1059 return DAG->IsReachable(TargetSU,
const_cast<SUnit *
>(SU));
1064 IsPipeExp(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1065 : InstructionRule(
TII, SGID, NeedsCache) {}
1070 class EnablesNthMFMA final :
public InstructionRule {
1077 bool FoundTrans =
false;
1078 unsigned Counter = 1;
1079 auto *DAG = SyncPipe[0].DAG;
1081 if (Cache->empty()) {
1082 auto I = DAG->SUnits.begin();
1083 auto E = DAG->SUnits.end();
1084 for (;
I !=
E;
I++) {
1085 if (FoundTrans &&
TII->isMFMAorWMMA(*
I->getInstr())) {
1087 Cache->push_back(&*
I);
1092 if (!FoundTrans &&
TII->isTRANS(
I->getInstr()->getOpcode()))
1099 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1103 bool NeedsCache =
false)
1109 class EnablesNthMFMAInChain final :
public InstructionRule {
1117 auto *DAG = SyncPipe[0].DAG;
1119 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1122 if (Cache->empty()) {
1123 auto *TempSU = ChainSeed;
1128 for (
auto &Succ : TempSU->Succs) {
1129 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1130 TempSU = Succ.getSUnit();
1139 Cache->push_back(TempSU);
1145 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1148 EnablesNthMFMAInChain(
unsigned Number,
SUnit *ChainSeed,
1150 bool NeedsCache =
false)
1152 ChainSeed(ChainSeed) {}
1158 class LessThanNSuccs final :
public InstructionRule {
1161 bool HasIntermediary =
false;
1166 if (!SyncPipe.
size())
1170 return Succ.getKind() == SDep::Data;
1172 if (SuccSize >=
Size)
1175 if (HasIntermediary) {
1176 for (
auto Succ : SU->
Succs) {
1179 return SuccSucc.getKind() == SDep::Data;
1181 if (SuccSize >=
Size)
1189 bool HasIntermediary =
false,
bool NeedsCache =
false)
1190 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1191 HasIntermediary(HasIntermediary) {}
1198 class GreaterThanOrEqualToNSuccs final :
public InstructionRule {
1201 bool HasIntermediary =
false;
1206 if (!SyncPipe.
size())
1210 return Succ.getKind() == SDep::Data;
1212 if (SuccSize >=
Size)
1215 if (HasIntermediary) {
1216 for (
auto Succ : SU->
Succs) {
1219 return SuccSucc.getKind() == SDep::Data;
1221 if (SuccSize >=
Size)
1229 unsigned SGID,
bool HasIntermediary =
false,
1230 bool NeedsCache =
false)
1231 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1232 HasIntermediary(HasIntermediary) {}
1236 class IsCvt final :
public InstructionRule {
1241 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
1242 Opc == AMDGPU::V_CVT_I32_F32_e32;
1244 IsCvt(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1245 : InstructionRule(
TII, SGID, NeedsCache) {}
1249 class IsFMA final :
public InstructionRule {
1256 IsFMA(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1257 : InstructionRule(
TII, SGID, NeedsCache) {}
1261 class IsPipeAdd final :
public InstructionRule {
1267 IsPipeAdd(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1268 : InstructionRule(
TII, SGID, NeedsCache) {}
1273 class IsSuccOfPrevNthGroup final :
public InstructionRule {
1275 unsigned Distance = 1;
1280 SchedGroup *OtherGroup =
nullptr;
1281 if (!SyncPipe.
size())
1284 for (
auto &PipeSG : SyncPipe) {
1285 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1286 OtherGroup = &PipeSG;
1291 if (!OtherGroup->Collection.size())
1294 for (
auto &OtherEle : OtherGroup->Collection) {
1295 for (
auto &Succ : OtherEle->Succs) {
1296 if (Succ.getSUnit() == SU && Succ.getKind() ==
SDep::Data)
1304 unsigned SGID,
bool NeedsCache =
false)
1305 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1310 class IsReachableFromPrevNthGroup final :
public InstructionRule {
1312 unsigned Distance = 1;
1317 SchedGroup *OtherGroup =
nullptr;
1318 if (!SyncPipe.
size())
1321 for (
auto &PipeSG : SyncPipe) {
1322 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1323 OtherGroup = &PipeSG;
1328 if (!OtherGroup->Collection.size())
1331 auto *DAG = SyncPipe[0].DAG;
1333 for (
auto &OtherEle : OtherGroup->Collection)
1334 if (DAG->IsReachable(
const_cast<SUnit *
>(SU), OtherEle))
1339 IsReachableFromPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
1340 unsigned SGID,
bool NeedsCache =
false)
1341 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1345 class OccursAtOrAfterNode final :
public InstructionRule {
1356 bool NeedsCache =
false)
1362 class IsExactMFMA final :
public InstructionRule {
1370 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1373 if (Cache->empty()) {
1374 auto *TempSU = ChainSeed;
1379 for (
auto &Succ : TempSU->Succs) {
1380 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1381 TempSU = Succ.getSUnit();
1390 Cache->push_back(TempSU);
1396 return (*Cache)[0] == SU;
1400 unsigned SGID,
bool NeedsCache =
false)
1402 ChainSeed(ChainSeed) {}
1408 class OccursAfterExp final :
public InstructionRule {
1413 auto *DAG = SyncPipe[0].DAG;
1414 if (Cache->empty()) {
1415 for (
auto &SU : DAG->SUnits)
1417 Cache->push_back(&SU);
1424 return SU->
NodeNum > (*Cache)[0]->NodeNum;
1428 bool NeedsCache =
false)
1429 : InstructionRule(
TII, SGID, NeedsCache) {}
1433 bool applyIGLPStrategy(
1442 : IGLPStrategy(DAG,
TII) {
1447unsigned MFMAExpInterleaveOpt::TransPipeCount = 0;
1448unsigned MFMAExpInterleaveOpt::MFMAPipeCount = 0;
1449unsigned MFMAExpInterleaveOpt::AddPipeCount = 0;
1450unsigned MFMAExpInterleaveOpt::MFMAEnablement = 0;
1451unsigned MFMAExpInterleaveOpt::ExpRequirement = 0;
1452unsigned MFMAExpInterleaveOpt::MFMAChains = 0;
1453bool MFMAExpInterleaveOpt::HasCvt =
false;
1454bool MFMAExpInterleaveOpt::HasChainBetweenCvt =
false;
1455std::optional<unsigned> MFMAExpInterleaveOpt::FirstPipeDSR = std::nullopt;
1464 auto isBitPack = [](
unsigned Opc) {
1465 return Opc == AMDGPU::V_PACK_B32_F16_e64 ||
Opc == AMDGPU::V_PERM_B32_e64;
1468 auto isCvt = [](
unsigned Opc) {
1469 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
Opc == AMDGPU::V_CVT_I32_F32_e32;
1472 auto isAdd = [](
unsigned Opc) {
return Opc == AMDGPU::V_ADD_F32_e32; };
1479 if (SU.
Succs.size() >= 7)
1481 for (
auto &Succ : SU.
Succs) {
1482 if (Succ.getSUnit()->Succs.size() >= 7)
1501 if (!(PackSUs.
size() && MFMAPipeCands.
size() && ExpPipeCands.
size()))
1506 std::optional<SUnit *> TempMFMA;
1507 std::optional<SUnit *> TempExp;
1509 for (
auto &PredSU : ExpPipeCands) {
1510 for (
auto &SuccSU : MFMAPipeCands) {
1523 if (!(TempExp && TempMFMA))
1526 HasChainBetweenCvt =
none_of((*TempExp)->Succs, [&isCvt](
SDep &Succ) {
1527 return isCvt(Succ.getSUnit()->getInstr()->getOpcode());
1531 for (
auto &SuccSU : MFMAPipeCands) {
1532 if (MFMAPipeSUs.
size() &&
1533 any_of(MFMAPipeSUs, [&SuccSU](
SUnit *PotentialMatch) {
1534 return PotentialMatch->
NodeNum == SuccSU->NodeNum;
1538 for (
auto &PredSU : ExpPipeCands) {
1546 MFMAPipeCount = MFMAPipeSUs.
size();
1548 assert(TempExp && TempMFMA);
1549 assert(MFMAPipeCount > 0);
1551 std::optional<SUnit *> TempCvt;
1552 for (
auto &SuccSU : CvtSUs) {
1560 if (TempCvt.has_value()) {
1561 for (
auto &SuccSU : MFMAPipeSUs) {
1570 for (
auto &MFMAPipeSU : MFMAPipeSUs) {
1574 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1576 MFMAChainSeeds.push_back(MFMAPipeSU);
1584 for (
auto Pred : MFMAChainSeeds[0]->Preds) {
1585 if (
TII->isDS(Pred.getSUnit()->getInstr()->getOpcode()) &&
1586 Pred.getSUnit()->getInstr()->mayLoad())
1587 FirstPipeDSR = Pred.getSUnit()->NodeNum;
1591 unsigned PackSuccCount =
1597 unsigned PackPredCount =
1599 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1600 return isBitPack(Opc);
1604 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1605 return isBitPack(Opc);
1608 if (PackPred == (*TempMFMA)->Preds.end())
1616 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1620 MFMAEnablement *= PackSuccCount;
1625 return DAG->
IsReachable(PackPred->getSUnit(), ExpBase);
1628 ExpRequirement *= PackPredCount;
1638 MFMAChainSeeds.clear();
1645bool MFMAExpInterleaveOpt::applyIGLPStrategy(
1650 bool IsSmallKernelType =
1651 MFMAEnablement == 2 && ExpRequirement == 4 && TransPipeCount == 32;
1652 bool IsLargeKernelType =
1653 MFMAEnablement == 4 && ExpRequirement == 4 && TransPipeCount == 64;
1655 if (!(IsSmallKernelType || IsLargeKernelType))
1661 unsigned PipelineSyncID = 0;
1662 SchedGroup *SG =
nullptr;
1664 unsigned MFMAChain = 0;
1665 unsigned PositionInChain = 0;
1666 unsigned CurrMFMAForTransPosition = 0;
1668 auto incrementTransPosition = [&MFMAChain, &PositionInChain,
1669 &CurrMFMAForTransPosition]() {
1670 CurrMFMAForTransPosition += MFMAEnablement;
1671 PositionInChain = (CurrMFMAForTransPosition / MFMAChains);
1672 MFMAChain = CurrMFMAForTransPosition % MFMAChains;
1675 auto getNextTransPositionInChain = [&CurrMFMAForTransPosition]() {
1676 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1677 return (TempMFMAForTrans / MFMAChains);
1680 auto getNextTransMFMAChain = [&CurrMFMAForTransPosition]() {
1681 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1682 return TempMFMAForTrans % MFMAChains;
1685 unsigned CurrMFMAPosition = 0;
1686 unsigned MFMAChainForMFMA = 0;
1687 unsigned PositionInChainForMFMA = 0;
1689 auto incrementMFMAPosition = [&CurrMFMAPosition, &MFMAChainForMFMA,
1690 &PositionInChainForMFMA]() {
1692 MFMAChainForMFMA = CurrMFMAPosition % MFMAChains;
1693 PositionInChainForMFMA = CurrMFMAPosition / MFMAChains;
1697 assert(IsPostRA || MFMAChainSeeds.size() == MFMAChains);
1699 bool UsesFMA = IsSmallKernelType || !IsPostRA;
1700 bool UsesDSRead = IsLargeKernelType && !IsPostRA && FirstPipeDSR;
1701 bool UsesCvt = HasCvt && (IsSmallKernelType || !IsPostRA);
1702 bool UsesVALU = IsSmallKernelType;
1707 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1709 if (!IsPostRA && MFMAChains) {
1710 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1711 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1715 std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1716 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1717 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1720 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1722 if (!IsPostRA && MFMAChains) {
1723 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1724 getNextTransPositionInChain(),
1725 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1727 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1728 SG->getSGID(),
true));
1729 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1730 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1734 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1736 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1738 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1742 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1744 if (!IsPostRA && MFMAChains)
1745 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1746 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
true));
1748 SG->addRule(std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1749 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1750 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1751 HasChainBetweenCvt));
1752 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1754 incrementTransPosition();
1757 for (
unsigned I = 0;
I < ExpRequirement;
I++) {
1760 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1762 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1763 if (HasChainBetweenCvt)
1764 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1765 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1767 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(
1768 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1769 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1774 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1776 if (!IsPostRA && MFMAChains) {
1777 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1778 getNextTransPositionInChain(),
1779 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1781 SG->addRule(std::make_shared<EnablesNthMFMA>(2 * MFMAEnablement + 1,
1782 TII, SG->getSGID(),
true));
1783 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1784 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1788 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1790 if (!IsPostRA && MFMAChains)
1791 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1792 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1795 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1796 SG->getSGID(),
true));
1797 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1798 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1799 HasChainBetweenCvt));
1800 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1805 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1807 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1808 SG->addRule(std::make_shared<GreaterThanOrEqualToNSuccs>(
1809 8,
TII, SG->getSGID(), HasChainBetweenCvt));
1810 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1815 unsigned MFMARatio =
1816 MFMAEnablement > ExpRequirement ? MFMAEnablement / ExpRequirement : 1;
1819 MFMAEnablement > ExpRequirement ? 1 : ExpRequirement / MFMAEnablement;
1821 unsigned RemainingExp = TransPipeCount > (2 * ExpRequirement)
1822 ? TransPipeCount - (2 * ExpRequirement)
1824 unsigned ExpLoopCount = RemainingExp / ExpRatio;
1826 unsigned MFMAInLoop = MFMAPipeCount > (MFMAEnablement * 2)
1827 ? MFMAPipeCount - (MFMAEnablement * 2)
1829 unsigned MFMALoopCount = MFMAInLoop / MFMARatio;
1831 AddPipeCount < MFMAPipeCount ? 1 : AddPipeCount / MFMAPipeCount;
1832 unsigned LoopSize = std::min(ExpLoopCount, MFMALoopCount);
1834 for (
unsigned I = 0;
I < LoopSize;
I++) {
1835 if (!(
I * ExpRatio % ExpRequirement))
1836 incrementTransPosition();
1839 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1841 if (!IsPostRA && MFMAChains)
1842 SG->addRule(std::make_shared<IsExactMFMA>(
1843 PositionInChainForMFMA, MFMAChainSeeds[MFMAChainForMFMA],
TII,
1844 SG->getSGID(),
true));
1846 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1847 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1848 incrementMFMAPosition();
1851 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1853 SG->addRule(std::make_shared<IsPipeAdd>(
TII, SG->getSGID()));
1854 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1857 if (UsesDSRead && !(
I % 4)) {
1858 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1860 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1862 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1866 for (
unsigned J = 0; J < ExpRatio; J++) {
1867 auto MFMAOffset = (1 + UsesVALU) * MFMARatio * (
I + 1);
1868 auto MaxMFMAOffset =
1869 (1 + UsesVALU) * ExpRequirement * MFMARatio / ExpRatio;
1873 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1875 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1876 auto BaseDiff = (2 + UsesFMA) * (ExpRequirement - 1) + 1;
1877 auto DSROffset =
I / 4 + 1;
1878 auto MaxDSROffset = MaxMFMAOffset / 4;
1880 auto ExpOffset =
I * ExpRatio + J >= ExpRequirement ? 0 : 1;
1881 auto CurrentOffset = UsesDSRead * std::min(MaxDSROffset, DSROffset) +
1882 std::min(MaxMFMAOffset, MFMAOffset) + BaseDiff +
1884 if (HasChainBetweenCvt)
1885 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1886 CurrentOffset,
TII, SG->getSGID()));
1888 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(CurrentOffset,
TII,
1890 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1895 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1897 if (!IsPostRA && MFMAChains)
1898 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1899 getNextTransPositionInChain(),
1900 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
1903 SG->addRule(std::make_shared<EnablesNthMFMA>(
1904 (((
I * ExpRatio + J) / ExpRequirement) + 3) * MFMAEnablement + 1,
1905 TII, SG->getSGID(),
true));
1906 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1907 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1911 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1913 if (!IsPostRA && MFMAChains)
1914 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1915 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1918 SG->addRule(std::make_shared<EnablesNthMFMA>(
1919 (((
I * ExpRatio + J) / ExpRequirement) + 2) * MFMAEnablement + 1,
1920 TII, SG->getSGID(),
true));
1921 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1922 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1923 HasChainBetweenCvt));
1924 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1929 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1931 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1932 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1936class MFMAExpSimpleInterleaveOpt final :
public IGLPStrategy {
1938 bool applyIGLPStrategy(
1949 : IGLPStrategy(DAG,
TII) {
1954bool MFMAExpSimpleInterleaveOpt::applyIGLPStrategy(
1959 unsigned MFMACount = 0;
1961 if (
TII->isMFMAorWMMA(
I))
1964 const unsigned PipelineSyncID = 0;
1965 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
1966 SchedGroup *SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1968 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1970 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1972 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1978class MFMASmallGemmSingleWaveOpt final :
public IGLPStrategy {
1981 class EnablesInitialMFMA final :
public InstructionRule {
1985 if (!SyncPipe.
size())
1988 if (!Cache->size()) {
1989 for (
auto &Elt : SyncPipe[0].DAG->
SUnits) {
1990 if (
TII->isMFMAorWMMA(*Elt.getInstr())) {
1994 Cache->push_back(&Elt);
1999 auto *DAG = SyncPipe[0].DAG;
2000 for (
auto &Elt : *Cache) {
2008 bool NeedsCache =
false)
2009 : InstructionRule(
TII, SGID, NeedsCache) {}
2013 class IsPermForDSW final :
public InstructionRule {
2018 if (
MI->getOpcode() != AMDGPU::V_PERM_B32_e64)
2021 bool FitsInGroup =
false;
2023 if (!Collection.
size()) {
2024 for (
auto &Succ : SU->
Succs) {
2025 SUnit *SuccUnit = Succ.getSUnit();
2028 Cache->push_back(SuccUnit);
2039 return ThisSucc.getSUnit() == Elt;
2044 IsPermForDSW(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
2045 : InstructionRule(
TII, SGID, NeedsCache) {}
2049 class IsSuccOfPrevGroup final :
public InstructionRule {
2053 SchedGroup *OtherGroup =
nullptr;
2054 for (
auto &PipeSG : SyncPipe) {
2055 if ((
unsigned)PipeSG.getSGID() == SGID - 1) {
2056 OtherGroup = &PipeSG;
2062 if (!OtherGroup->Collection.size())
2066 return any_of(OtherGroup->Collection, [&SU](
SUnit *Elt) {
2067 return any_of(Elt->Succs,
2068 [&SU](SDep &Succ) { return Succ.getSUnit() == SU; });
2072 bool NeedsCache =
false)
2073 : InstructionRule(
TII, SGID, NeedsCache) {}
2077 class VMEMSize final :
public InstructionRule {
2082 if (
MI->getOpcode() == TargetOpcode::BUNDLE)
2084 if (!Collection.
size())
2089 auto TRI =
TII->getRegisterInfo();
2090 auto &MRI =
MI->getMF()->getRegInfo();
2091 for (
auto &Elt : Collection) {
2092 auto Op = Elt->getInstr()->getOperand(0);
2094 TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(MRI,
Op));
2098 if (NumBits < 128) {
2100 if (NumBits +
TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(
2101 MRI,
MI->getOperand(0))) <=
2109 VMEMSize(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
2110 : InstructionRule(
TII, SGID, NeedsCache) {}
2115 class SharesPredWithPrevNthGroup final :
public InstructionRule {
2117 unsigned Distance = 1;
2122 SchedGroup *OtherGroup =
nullptr;
2123 if (!SyncPipe.
size())
2126 if (!Cache->size()) {
2128 for (
auto &PipeSG : SyncPipe) {
2129 if ((
unsigned)PipeSG.getSGID() == SGID - Distance) {
2130 OtherGroup = &PipeSG;
2136 if (!OtherGroup->Collection.size())
2139 for (
auto &OtherEle : OtherGroup->Collection) {
2140 for (
auto &Pred : OtherEle->Preds) {
2141 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2142 AMDGPU::V_PERM_B32_e64)
2143 Cache->push_back(Pred.getSUnit());
2152 auto *DAG = SyncPipe[0].DAG;
2159 SharesPredWithPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
2160 unsigned SGID,
bool NeedsCache =
false)
2161 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
2165 bool applyIGLPStrategy(
2176 : IGLPStrategy(DAG,
TII) {
2181static unsigned DSWCount = 0;
2182static unsigned DSWWithPermCount = 0;
2183static unsigned DSWWithSharedVMEMCount = 0;
2185bool MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
2186 DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
2189 unsigned MFMACount = 0;
2190 unsigned DSRCount = 0;
2192 bool IsInitial =
Phase == AMDGPU::SchedulingPhase::Initial;
2194 assert((!IsInitial || (DSWCount == 0 && DSWWithPermCount == 0 &&
2195 DSWWithSharedVMEMCount == 0)) &&
2196 "DSWCounters should be zero in pre-RA scheduling!");
2198 for (
auto &SU : DAG->
SUnits) {
2199 auto *
I = SU.getInstr();
2200 if (
TII->isMFMAorWMMA(*
I))
2202 else if (
TII->isDS(*
I)) {
2205 else if (
I->mayStore() && IsInitial) {
2207 for (
auto Pred : SU.Preds) {
2208 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2209 AMDGPU::V_PERM_B32_e64) {
2219 DSWWithPermCount = DSWithPerms.
size();
2220 auto *
I = DSWithPerms.
begin();
2221 auto *
E = DSWithPerms.
end();
2229 DenseMap<MachineInstr *, SUnit *> VMEMLookup;
2231 for (;
I !=
E;
I++) {
2232 SUnit *Cand =
nullptr;
2233 bool MissedAny =
false;
2234 for (
auto &Pred : (*I)->Preds) {
2235 if (Pred.getSUnit()->getInstr()->getOpcode() != AMDGPU::V_PERM_B32_e64)
2241 for (
auto &Succ : Pred.getSUnit()->Succs) {
2242 auto *
MI = Succ.getSUnit()->getInstr();
2243 if (!
TII->isVMEM(*
MI) || !
MI->mayLoad())
2246 if (MissedAny || !VMEMLookup.
size()) {
2248 VMEMLookup[
MI] = *
I;
2265 if (!MissedAny && Cand) {
2266 DSWWithSharedVMEMCount += 2;
2273 assert(DSWWithSharedVMEMCount <= DSWWithPermCount);
2275 unsigned PipelineSyncID = 0;
2277 if (DSWWithPermCount) {
2278 for (
unsigned I = 0;
I < MFMACount;
I++) {
2279 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2280 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2281 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2283 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2284 SchedGroupMask::VALU, 2, PipelineSyncID, DAG,
TII);
2285 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2295 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2296 SchedGroupMask::DS_READ, 4, PipelineSyncID, DAG,
TII);
2297 SG->addRule(std::make_shared<EnablesInitialMFMA>(
TII, SG->getSGID(),
true));
2298 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2300 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2301 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2302 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2305 for (
unsigned I = 4;
I < DSRCount; ++
I) {
2306 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2307 SchedGroupMask::DS_READ, 1, PipelineSyncID, DAG,
TII);
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()]);
2318 for (
unsigned I = DSWWithSharedVMEMCount;
I < DSWWithPermCount; ++
I) {
2319 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2320 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2321 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2322 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2324 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2325 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2326 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2327 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2329 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2330 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2331 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2332 1,
TII, SG->getSGID(),
true));
2333 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2334 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2336 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2337 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2338 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2340 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2341 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2342 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2343 3,
TII, SG->getSGID(),
true));
2344 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2345 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2347 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2348 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2349 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2355 for (
unsigned I = DSWWithPermCount;
I < DSWCount;
I++) {
2356 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2357 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2358 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2360 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2361 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2362 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2363 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2365 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2366 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2367 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2375 for (
unsigned I = 0;
I < DSWWithSharedVMEMCount; ++
I) {
2376 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2377 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2378 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2379 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2381 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2382 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2383 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2384 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2386 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2387 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2388 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2390 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2391 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2392 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2393 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2395 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2396 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2397 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2398 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2400 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2401 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2402 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2404 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2405 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2406 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2407 2,
TII, SG->getSGID(),
true));
2408 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2409 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2411 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2412 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2413 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2415 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2416 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2417 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2418 4,
TII, SG->getSGID(),
true));
2419 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2420 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2422 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2423 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2424 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2430static std::unique_ptr<IGLPStrategy>
2432 const SIInstrInfo *
TII) {
2435 return std::make_unique<MFMASmallGemmOpt>(DAG,
TII);
2437 return std::make_unique<MFMASmallGemmSingleWaveOpt>(DAG,
TII);
2439 return std::make_unique<MFMAExpInterleaveOpt>(DAG,
TII);
2441 return std::make_unique<MFMAExpSimpleInterleaveOpt>(DAG,
TII);
2447class IGroupLPDAGMutation :
public ScheduleDAGMutation {
2449 const SIInstrInfo *
TII;
2456 DenseMap<int, SmallVector<SchedGroup, 4>> SyncedSchedGroups;
2459 DenseMap<int, SUnitsToCandidateSGsMap> SyncedInstrs;
2462 void addSchedBarrierEdges(SUnit &SU);
2476 void initSchedGroupBarrierPipelineStage(
2477 std::vector<SUnit>::reverse_iterator RIter);
2479 bool initIGLPOpt(SUnit &SU);
2482 void apply(ScheduleDAGInstrs *DAGInstrs)
override;
2489 bool IsBottomUp =
true;
2494 IGroupLPDAGMutation() =
default;
2498unsigned SchedGroup::NumSchedGroups = 0;
2500bool SchedGroup::tryAddEdge(SUnit *
A, SUnit *
B) {
2504bool SchedGroup::canAddMI(
const MachineInstr &
MI)
const {
2506 if (
MI.isMetaInstruction())
2509 else if (
MI.isInlineAsm()) {
2511 auto &MRI =
MI.getParent()->getParent()->getRegInfo();
2512 bool SGPR_used =
false, SGPR_big_def =
false, VGPR_used =
false,
2513 VMFMA_used =
false, VReg32_used =
false,
MayLoad =
MI.mayLoad(),
2515 for (
const MachineOperand &Operand :
MI.operands())
2516 if (Operand.isReg()) {
2518 *
TRI.getRegClassForOperandReg(MRI, Operand);
2519 if (
TRI.hasVGPRs(&RegClass)) {
2521 if (Operand.isUse() &&
TRI.getRegSizeInBits(RegClass) == 32)
2527 if (
TRI.hasAGPRs(&RegClass) ||
TRI.getRegSizeInBits(RegClass) > 128)
2529 if (
TRI.hasSGPRs(&RegClass))
2531 if (
TRI.getRegSizeInBits(RegClass) > 64 && Operand.isDef())
2532 SGPR_big_def =
true;
2535 typedef std::underlying_type_t<SchedGroupMask> SGMask_t;
2536 SGMask_t InlineAsmMask = 0;
2537 if (VGPR_used && !VMFMA_used && !MayLoad && !MayStore)
2538 InlineAsmMask |= (SGMask_t)SchedGroupMask::VALU;
2539 if (SGPR_used && !VGPR_used && !MayLoad && !MayStore)
2540 InlineAsmMask |= (SGMask_t)SchedGroupMask::SALU;
2542 InlineAsmMask |= (SGMask_t)SchedGroupMask::MFMA;
2543 if (VGPR_used && MayLoad)
2544 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_READ
2545 : SchedGroupMask::VMEM_READ);
2546 if (VGPR_used && MayStore)
2547 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_WRITE
2548 : SchedGroupMask::VMEM_WRITE);
2550 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS_READ;
2551 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VALU ||
2552 InlineAsmMask & (SGMask_t)SchedGroupMask::SALU)
2553 InlineAsmMask |= (SGMask_t)SchedGroupMask::ALU;
2554 if (InlineAsmMask & (SGMask_t)SchedGroupMask::DS_READ ||
2555 InlineAsmMask & (SGMask_t)SchedGroupMask::DS_WRITE)
2556 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS;
2557 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_READ ||
2558 InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_WRITE)
2559 InlineAsmMask |= (SGMask_t)SchedGroupMask::VMEM;
2561 Result = ((SGMask_t)SGMask & InlineAsmMask) != 0;
2564 else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
2565 (
TII->isVALU(
MI,
true) ||
TII->isMFMAorWMMA(
MI) ||
2569 else if (((SGMask & SchedGroupMask::VALU) != SchedGroupMask::NONE) &&
2570 TII->isVALU(
MI,
false) && !
TII->isMFMAorWMMA(
MI) &&
2571 !
TII->isTRANS(
MI)) {
2578 else if (((SGMask & SchedGroupMask::SALU) != SchedGroupMask::NONE) &&
2582 else if (((SGMask & SchedGroupMask::MFMA) != SchedGroupMask::NONE) &&
2583 TII->isMFMAorWMMA(
MI))
2586 else if (((SGMask & SchedGroupMask::VMEM) != SchedGroupMask::NONE) &&
2590 else if (((SGMask & SchedGroupMask::VMEM_READ) != SchedGroupMask::NONE) &&
2594 else if (((SGMask & SchedGroupMask::VMEM_WRITE) != SchedGroupMask::NONE) &&
2595 MI.mayStore() &&
TII->isVMEM(
MI) && !
TII->isLDSDMA(
MI))
2598 else if (((SGMask & SchedGroupMask::DS) != SchedGroupMask::NONE) &&
2602 else if (((SGMask & SchedGroupMask::DS_READ) != SchedGroupMask::NONE) &&
2603 MI.mayLoad() &&
TII->isDS(
MI))
2606 else if (((SGMask & SchedGroupMask::DS_WRITE) != SchedGroupMask::NONE) &&
2607 MI.mayStore() &&
TII->isDS(
MI))
2610 else if (((SGMask & SchedGroupMask::TRANS) != SchedGroupMask::NONE) &&
2614 else if (((SGMask & SchedGroupMask::LDSDMA) != SchedGroupMask::NONE) &&
2619 dbgs() <<
"For SchedGroup with mask " <<
format_hex((
int)SGMask, 10,
true)
2620 << (Result ?
" could classify " :
" unable to classify ") <<
MI);
2625int SchedGroup::link(SUnit &SU,
bool MakePred,
2626 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
2627 int MissedEdges = 0;
2628 for (
auto *
A : Collection) {
2630 if (
A ==
B ||
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2640 bool Added = tryAddEdge(
A,
B);
2642 AddedEdges.emplace_back(
A,
B);
2650void SchedGroup::link(SUnit &SU,
bool MakePred) {
2651 for (
auto *
A : Collection) {
2653 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2662void SchedGroup::link(SUnit &SU,
2663 function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>
P) {
2664 for (
auto *
A : Collection) {
2673void SchedGroup::link(SchedGroup &OtherGroup) {
2674 for (
auto *
B : OtherGroup.Collection)
2678bool SchedGroup::canAddSU(SUnit &SU)
const {
2680 if (
MI.getOpcode() != TargetOpcode::BUNDLE)
2681 return canAddMI(
MI);
2686 while (
E !=
MBB->
end() &&
E->isBundledWithPred())
2690 return std::all_of(
B,
E, [
this](MachineInstr &
MI) {
return canAddMI(
MI); });
2694void SchedGroup::findCandidateSUnits(
T Begin,
T End,
2695 SUnitsToCandidateSGsMap &SyncedInstrs) {
2698 SyncedInstrs[&SU].push_back(SGID);
2702void SchedGroup::findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs) {
2703 findCandidateSUnits(DAG->
SUnits.rbegin(), DAG->
SUnits.rend(), SyncedInstrs);
2706void IGroupLPDAGMutation::apply(ScheduleDAGInstrs *DAGInstrs) {
2707 const TargetSchedModel *TSchedModel = DAGInstrs->
getSchedModel();
2708 if (!TSchedModel || DAGInstrs->
SUnits.empty())
2713 TII =
ST.getInstrInfo();
2714 DAG =
static_cast<ScheduleDAGMI *
>(DAGInstrs);
2715 SyncedSchedGroups.clear();
2716 SyncedInstrs.clear();
2717 bool FoundSB =
false;
2718 bool FoundIGLP =
false;
2719 bool ShouldApplyIGLP =
false;
2720 for (
auto R = DAG->
SUnits.rbegin(),
E = DAG->
SUnits.rend(); R !=
E; ++R) {
2721 unsigned Opc =
R->getInstr()->getOpcode();
2723 if (
Opc == AMDGPU::SCHED_BARRIER) {
2724 addSchedBarrierEdges(*R);
2726 }
else if (
Opc == AMDGPU::SCHED_GROUP_BARRIER) {
2727 initSchedGroupBarrierPipelineStage(R);
2729 }
else if (
Opc == AMDGPU::IGLP_OPT) {
2730 if (!FoundSB && !FoundIGLP) {
2732 ShouldApplyIGLP = initIGLPOpt(*R);
2737 if (FoundSB || (FoundIGLP && ShouldApplyIGLP)) {
2738 PipelineSolver PS(SyncedSchedGroups, SyncedInstrs, DAG, IsBottomUp);
2746void IGroupLPDAGMutation::addSchedBarrierEdges(SUnit &SchedBarrier) {
2748 assert(
MI.getOpcode() == AMDGPU::SCHED_BARRIER);
2749 LLVM_DEBUG(
dbgs() <<
"Building SchedGroup for SchedBarrier with Mask: "
2750 <<
MI.getOperand(0).getImm() <<
"\n");
2753 SchedGroup SG(InvertedMask, std::nullopt, DAG,
TII);
2755 for (SUnit &SU : DAG->
SUnits)
2756 if (SG.canAddSU(SU))
2762 (function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>)[](
2763 const SUnit *
A,
const SUnit *
B) {
return A->NodeNum >
B->NodeNum; });
2767IGroupLPDAGMutation::invertSchedBarrierMask(
SchedGroupMask Mask)
const {
2772 static constexpr std::pair<SchedGroupMask, SchedGroupMask> ImpliedGroups[] = {
2773 {SchedGroupMask::ALU, SchedGroupMask::VALU | SchedGroupMask::SALU |
2774 SchedGroupMask::MFMA | SchedGroupMask::TRANS},
2775 {SchedGroupMask::VMEM, SchedGroupMask::VMEM_READ |
2776 SchedGroupMask::VMEM_WRITE |
2777 SchedGroupMask::LDSDMA},
2778 {SchedGroupMask::DS, SchedGroupMask::DS_READ | SchedGroupMask::DS_WRITE |
2779 SchedGroupMask::LDSDMA},
2782 for (
auto [Aggregate, Members] : ImpliedGroups) {
2784 if ((InvertedMask & Aggregate) == SchedGroupMask::NONE)
2785 InvertedMask &= ~Members;
2787 else if ((InvertedMask & Members) != Members)
2788 InvertedMask &= ~Aggregate;
2791 LLVM_DEBUG(
dbgs() <<
"After Inverting, SchedGroup Mask: " << (
int)InvertedMask
2794 return InvertedMask;
2797void IGroupLPDAGMutation::initSchedGroupBarrierPipelineStage(
2798 std::vector<SUnit>::reverse_iterator RIter) {
2799 MachineInstr &SGB = *RIter->getInstr();
2806 auto &SG = SyncedSchedGroups[SyncID].emplace_back((
SchedGroupMask)SGMask,
2809 SG.findCandidateSUnits(RIter, SG.DAG->
SUnits.rend(),
2810 SyncedInstrs[SG.getSyncID()]);
2813bool IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
2816 auto S = createIGLPStrategy(StrategyID, DAG,
TII);
2817 if (!S->shouldApplyStrategy(DAG,
Phase))
2820 IsBottomUp = S->IsBottomUp;
2821 return S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups,
Phase);
2831std::unique_ptr<ScheduleDAGMutation>
2833 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!")
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")
const HexagonInstrInfo * TII
static std::pair< Value *, APInt > getMask(Value *WideMask, unsigned Factor, ElementCount LeafValueEC)
Register const TargetRegisterInfo * TRI
Interface definition for SIInstrInfo.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Implements a dense probed hash-table based set.
const HexagonRegisterInfo & getRegisterInfo() const
Instructions::iterator instr_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
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.
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
#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
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.
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.
auto reverse(ContainerTy &&C)
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.
MCRegisterClass TargetRegisterClass
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:...