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 {
82 ALL = ALU | VALU |
SALU |
MFMA |
VMEM | VMEM_READ | VMEM_WRITE |
DS |
83 DS_READ | DS_WRITE |
TRANS | LDSDMA,
92class InstructionRule {
98 std::optional<SmallVector<SUnit *, 4>> Cache;
108 bool NeedsCache =
false)
115 virtual ~InstructionRule() =
default;
128 SchedGroupMask SGMask;
131 std::optional<unsigned> MaxSize;
144 static unsigned NumSchedGroups;
161 bool canAddSU(
SUnit &SU)
const;
166 void link(
SUnit &SU,
bool MakePred =
false);
170 int link(
SUnit &SU,
bool MakePred,
171 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
180 void link(SchedGroup &OtherGroup);
183 bool isFull()
const {
return MaxSize && Collection.
size() >= *MaxSize; }
189 void addRule(std::shared_ptr<InstructionRule> NewRule) {
194 bool allowedByRules(
const SUnit *SU,
196 for (
auto &Rule : Rules) {
197 if (!Rule->apply(SU, Collection, SyncPipe))
204 void add(
SUnit &SU) {
206 <<
format_hex((
int)SGMask, 10,
true) <<
" adding "
212 void pop() { Collection.
pop_back(); }
215 void findCandidateSUnits(
T Begin,
T End,
216 SUnitsToCandidateSGsMap &SyncedInstrs);
221 void findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs);
223 int getSyncID() {
return SyncID; }
225 int getSGID() {
return SGID; }
227 SchedGroupMask
getMask() {
return SGMask; }
229 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
231 : SGMask(SGMask), MaxSize(MaxSize), DAG(DAG),
TII(
TII) {
232 SGID = NumSchedGroups++;
235 SchedGroup(SchedGroupMask SGMask, std::optional<unsigned> MaxSize,
int SyncID,
237 : SGMask(SGMask), MaxSize(MaxSize), SyncID(SyncID), DAG(DAG),
TII(
TII) {
238 SGID = NumSchedGroups++;
242using SUToCandSGsPair = std::pair<SUnit *, SmallVector<int, 4>>;
254class PipelineSolver {
267 bool NeedsSolver =
false;
271 unsigned computeProblemSize();
282 int CurrConflInstNo = 0;
284 int CurrSyncGroupIdx = 0;
286 int BeginSyncGroupIdx = 0;
292 bool IsBottomUp =
true;
295 void advancePosition();
298 void retreatPosition();
307 template <
typename T>
308 void greedyFind(std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
313 template <
typename T>
320 template <
typename T>
void linkSchedGroups(
T I,
T E);
324 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
330 class EdgeSetBuilder {
336 bool Initialized =
false;
340 template <
bool ComputePreds>
354 : SU(SU), SyncPipeline(SyncPipeline), IsBottomUp(IsBottomUp) {}
360 int build(
int SGID, std::list<std::pair<SUnit *, SUnit *>> &NewEdges);
363 template <
typename T>
365 std::list<std::pair<SUnit *, SUnit *>> &NewEdges);
371 template <
typename T>
372 int linkSUnit(
SUnit *SU,
int SGID,
373 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E);
375 void removeEdges(
const std::list<std::pair<SUnit *, SUnit *>> &AddedEdges);
377 void convertSyncMapsToArrays();
389 : DAG(DAG), SyncedInstrs(SyncedInstrs),
390 SyncedSchedGroups(SyncedSchedGroups), IsBottomUp(IsBottomUp) {
392 for (
auto &PipelineInstrs : SyncedInstrs) {
393 if (!PipelineInstrs.second.
empty()) {
402 convertSyncMapsToArrays();
404 CurrPipeline = BestPipeline;
406 while (
static_cast<size_t>(BeginSyncGroupIdx) < PipelineInstrs.
size() &&
407 PipelineInstrs[BeginSyncGroupIdx].
empty())
410 if (
static_cast<size_t>(BeginSyncGroupIdx) >= PipelineInstrs.
size())
415void PipelineSolver::reset() {
417 for (
auto &SyncPipeline : CurrPipeline) {
418 for (
auto &SG : SyncPipeline) {
420 SG.Collection.
clear();
424 if (SchedBarr != TempCollection.
end())
425 SG.Collection.push_back(*SchedBarr);
429 CurrSyncGroupIdx = BeginSyncGroupIdx;
434void PipelineSolver::convertSyncMapsToArrays() {
435 for (
auto &SyncPipe : SyncedSchedGroups) {
436 BestPipeline.insert(BestPipeline.begin(), SyncPipe.second);
439 int PipelineIDx = SyncedInstrs.size() - 1;
440 PipelineInstrs.resize(SyncedInstrs.size());
441 for (
auto &SyncInstrMap : SyncedInstrs) {
442 for (
auto &SUsToCandSGs : SyncInstrMap.second) {
443 if (PipelineInstrs[PipelineIDx].empty()) {
444 PipelineInstrs[PipelineIDx].push_back(
445 std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
448 auto *SortPosition = PipelineInstrs[PipelineIDx].begin();
451 while (SortPosition != PipelineInstrs[PipelineIDx].end() &&
452 SUsToCandSGs.first->NodeNum > SortPosition->first->NodeNum)
454 PipelineInstrs[PipelineIDx].insert(
455 SortPosition, std::pair(SUsToCandSGs.first, SUsToCandSGs.second));
461template <
typename T>
void PipelineSolver::linkSchedGroups(
T I,
T E) {
462 for (;
I !=
E; ++
I) {
464 for (
auto J = std::next(
I); J !=
E; ++J) {
471void PipelineSolver::makePipeline() {
473 for (
auto &SyncPipeline : BestPipeline) {
475 for (
auto &SG : SyncPipeline) {
478 SUnit *SGBarr =
nullptr;
479 for (
auto &SU : SG.Collection) {
480 if (SU->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
487 SG.link(*SGBarr,
false);
491 for (
auto &SyncPipeline : BestPipeline) {
492 IsBottomUp ? linkSchedGroups(SyncPipeline.rbegin(), SyncPipeline.rend())
493 : linkSchedGroups(SyncPipeline.begin(), SyncPipeline.end());
498int PipelineSolver::linkSUnit(
499 SUnit *SU,
int SGID, std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
501 bool MakePred =
false;
504 if (
I->getSGID() == SGID) {
509 AddedCost += Group.link(*SU, MakePred, AddedEdges);
515template <
bool ComputePreds>
516void PipelineSolver::EdgeSetBuilder::computeReachable(
518 if (!Reachable.insert(Start).second)
523 while (!WorkList.
empty()) {
526 for (
const SDep &Dep : ComputePreds ? Current->
Preds : Current->
Succs) {
527 if (Reachable.insert(Dep.getSUnit()).second)
535 computeReachable<
true>(Preds, Start);
540 computeReachable<
false>(Succs, Start);
543int PipelineSolver::EdgeSetBuilder::build(
544 int SGID, std::list<std::pair<SUnit *, SUnit *>> &NewEdges) {
546 computePreds(InitialPreds, SU);
547 computeSuccs(Succs, SU);
552 return IsBottomUp ? buildImpl(SGID,
reverse(SyncPipeline), NewEdges)
560int PipelineSolver::EdgeSetBuilder::buildImpl(
562 std::list<std::pair<SUnit *, SUnit *>> &NewEdges) {
580 bool MakePred =
false;
581 for (SchedGroup &SG : SchedGroups) {
582 if (SG.getSGID() == SGID) {
587 for (
SUnit *
A : SG.Collection) {
588 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
599 NewEdges.emplace_back(SU,
A);
608 NewEdges.emplace_back(
A, SU);
609 computePreds(Preds,
A);
616int PipelineSolver::addEdges(
618 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
628 return IsBottomUp ? linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
rbegin(),
630 : linkSUnit(SU, SGID, AddedEdges, SyncPipeline.
begin(),
634void PipelineSolver::removeEdges(
635 const std::list<std::pair<SUnit *, SUnit *>> &EdgesToRemove) {
638 for (
auto &PredSuccPair : EdgesToRemove) {
639 SUnit *Pred = PredSuccPair.first;
640 SUnit *Succ = PredSuccPair.second;
643 return P.getSUnit() == Pred && P.isArtificial();
645 if (Match != Succ->
Preds.end())
650void PipelineSolver::advancePosition() {
653 if (
static_cast<size_t>(CurrConflInstNo) >=
654 PipelineInstrs[CurrSyncGroupIdx].
size()) {
658 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size() &&
659 PipelineInstrs[CurrSyncGroupIdx].empty())
664void PipelineSolver::retreatPosition() {
665 assert(CurrConflInstNo >= 0);
666 assert(CurrSyncGroupIdx >= 0);
668 if (CurrConflInstNo > 0) {
673 if (CurrConflInstNo == 0) {
676 if (CurrSyncGroupIdx == BeginSyncGroupIdx)
681 while (PipelineInstrs[CurrSyncGroupIdx].empty())
684 CurrConflInstNo = PipelineInstrs[CurrSyncGroupIdx].size() - 1;
688bool PipelineSolver::checkOptimal() {
689 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size()) {
690 if (BestCost == -1 || CurrCost < BestCost) {
691 BestPipeline = CurrPipeline;
698 bool DoneExploring =
false;
699 if (MaxBranchesExplored > 0 && BranchesExplored >= MaxBranchesExplored)
700 DoneExploring =
true;
702 return (DoneExploring || BestCost == 0);
706void PipelineSolver::populateReadyList(
708 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
709 auto SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
710 assert(CurrSU.second.size() >= 1);
712 for (;
I !=
E; ++
I) {
713 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
715 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
716 return SG.getSGID() == CandSGID;
721 if (Match->isFull()) {
722 ReadyList.push_back(std::pair(*
I, MissPenalty));
726 int TempCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
727 ReadyList.push_back(std::pair(*
I, TempCost));
728 removeEdges(AddedEdges);
730 ReadyList.push_back(std::pair(*
I, -1));
736 assert(ReadyList.size() == CurrSU.second.size());
739bool PipelineSolver::solveExact() {
743 if (
static_cast<size_t>(CurrSyncGroupIdx) == PipelineInstrs.size())
746 assert(
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size());
747 assert(
static_cast<size_t>(CurrConflInstNo) <
748 PipelineInstrs[CurrSyncGroupIdx].
size());
749 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
751 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
756 IsBottomUp ? populateReadyList(ReadyList, CurrSU.second.
rbegin(),
757 CurrSU.second.rend())
758 : populateReadyList(ReadyList, CurrSU.second.
begin(),
759 CurrSU.second.end());
761 auto *
I = ReadyList.
begin();
762 auto *
E = ReadyList.
end();
763 for (;
I !=
E; ++
I) {
767 if (BestCost != -1 && (CurrCost +
I->second > BestCost))
770 int CandSGID =
I->first;
772 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
773 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
774 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
775 return SG.getSGID() == CandSGID;
782 if (!Match->allowedByRules(CurrSU.first, SyncPipeline))
786 << (
int)Match->getMask() <<
"and ID " << CandSGID
788 Match->add(*CurrSU.first);
789 AddedCost = addEdges(SyncPipeline, CurrSU.first, CandSGID, AddedEdges);
790 LLVM_DEBUG(
dbgs() <<
"Cost of Assignment: " << AddedCost <<
"\n");
791 CurrCost += AddedCost;
794 bool FinishedExploring =
false;
797 if (CurrCost < BestCost || BestCost == -1) {
799 FinishedExploring = BestCost != 0;
800 if (!FinishedExploring)
806 CurrCost -= AddedCost;
807 removeEdges(AddedEdges);
809 CurrPipeline[CurrSyncGroupIdx] = SyncPipeline;
810 if (FinishedExploring)
817 CurrCost += MissPenalty;
820 LLVM_DEBUG(
dbgs() <<
"NOT Assigned (" << CurrSU.first->NodeNum <<
")\n");
822 bool FinishedExploring =
false;
823 if (CurrCost < BestCost || BestCost == -1) {
825 bool FinishedExploring = BestCost != 0;
826 if (!FinishedExploring)
832 CurrCost -= MissPenalty;
833 return FinishedExploring;
837void PipelineSolver::greedyFind(
838 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges,
T I,
T E) {
839 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
843 std::list<std::pair<SUnit *, SUnit *>> Edges;
846 std::optional<GroupInfo> Best;
848 auto &SyncPipeline = CurrPipeline[CurrSyncGroupIdx];
850 <<
") in Pipeline # " << CurrSyncGroupIdx <<
"\n");
852 EdgeSetBuilder Builder(CurrSU.first, SyncPipeline, IsBottomUp);
858 for (;
I !=
E; ++
I) {
860 SchedGroup *Match =
llvm::find_if(SyncPipeline, [CandSGID](SchedGroup &SG) {
861 return SG.getSGID() == CandSGID;
865 LLVM_DEBUG(
dbgs() <<
"Trying SGID # " << CandSGID <<
" with Mask "
866 << (
int)Match->getMask() <<
"\n");
868 if (Match->isFull()) {
872 if (!Match->allowedByRules(CurrSU.first, SyncPipeline)) {
873 LLVM_DEBUG(
dbgs() <<
"SGID # " << CandSGID <<
" has conflicting rule\n");
877 std::list<std::pair<SUnit *, SUnit *>> TempEdges;
878 int TempCost = Builder.build(CandSGID, TempEdges);
881 if (!Best || TempCost < Best->Cost) {
882 Best = {Match, TempEdges, TempCost};
889 SchedGroup *SG = Best->SG;
890 std::list<std::pair<SUnit *, SUnit *>> &Edges = Best->Edges;
892 SG->add(*CurrSU.first);
893 if (AddedEdges.empty())
896 AddedEdges.splice(std::prev(AddedEdges.cend()), Edges);
898 for (
const std::pair<SUnit *, SUnit *> &
E : Edges) {
899 if (!SG->tryAddEdge(
E.first,
E.second))
903 LLVM_DEBUG(
dbgs() <<
"Best Group has ID: " << SG->getSGID() <<
" and Mask"
904 << (
int)SG->getMask() <<
"\n");
905 BestCost += Best->Cost;
907 BestCost += MissPenalty;
910bool PipelineSolver::solveGreedy() {
912 std::list<std::pair<SUnit *, SUnit *>> AddedEdges;
914 while (
static_cast<size_t>(CurrSyncGroupIdx) < PipelineInstrs.size()) {
915 SUToCandSGsPair CurrSU = PipelineInstrs[CurrSyncGroupIdx][CurrConflInstNo];
917 ? greedyFind(AddedEdges, CurrSU.second.rbegin(), CurrSU.second.rend())
918 : greedyFind(AddedEdges, CurrSU.second.begin(), CurrSU.second.end());
921 BestPipeline = CurrPipeline;
922 removeEdges(AddedEdges);
926unsigned PipelineSolver::computeProblemSize() {
927 unsigned ProblemSize = 0;
928 for (
auto &PipeConflicts : PipelineInstrs) {
929 ProblemSize += PipeConflicts.size();
935void PipelineSolver::solve() {
939 unsigned ProblemSize = computeProblemSize();
942 bool BelowCutoff = (CutoffForExact > 0) && ProblemSize <= CutoffForExact;
943 MissPenalty = (ProblemSize / 2) + 1;
946 if (EnableExactSolver || BelowCutoff) {
950 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
954 LLVM_DEBUG(
dbgs() <<
"Exact produced best cost of " << BestCost <<
"\n");
959 LLVM_DEBUG(
dbgs() <<
"Greedy produced best cost of " << BestCost <<
"\n");
976 virtual bool applyIGLPStrategy(
985 bool IsBottomUp =
true;
990 virtual ~IGLPStrategy() =
default;
993class MFMASmallGemmOpt final :
public IGLPStrategy {
996 bool applyIGLPStrategy(
1007 : IGLPStrategy(DAG,
TII) {
1012bool MFMASmallGemmOpt::applyIGLPStrategy(
1017 unsigned MFMACount = 0;
1019 if (
TII->isMFMAorWMMA(
I))
1022 const unsigned PipelineSyncID = 0;
1023 SchedGroup *SG =
nullptr;
1024 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
1025 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1026 SchedGroupMask::DS, 2, PipelineSyncID, DAG,
TII);
1027 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1029 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1030 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
1031 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1037class MFMAExpInterleaveOpt final :
public IGLPStrategy {
1040 static unsigned TransPipeCount;
1042 static unsigned MFMAPipeCount;
1044 static unsigned AddPipeCount;
1046 static unsigned MFMAEnablement;
1048 static unsigned ExpRequirement;
1050 static unsigned MFMAChains;
1055 static bool HasChainBetweenCvt;
1057 static std::optional<unsigned> FirstPipeDSR;
1066 class IsPipeExp final :
public InstructionRule {
1071 auto *DAG = SyncPipe[0].DAG;
1073 if (Cache->empty()) {
1074 auto I = DAG->SUnits.rbegin();
1075 auto E = DAG->SUnits.rend();
1076 for (;
I !=
E;
I++) {
1077 if (
TII->isMFMAorWMMA(*
I->getInstr()))
1078 Cache->push_back(&*
I);
1084 auto Reaches =
any_of(*Cache, [&SU, &DAG](
SUnit *TargetSU) {
1085 return DAG->IsReachable(TargetSU,
const_cast<SUnit *
>(SU));
1090 IsPipeExp(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1091 : InstructionRule(
TII, SGID, NeedsCache) {}
1096 class EnablesNthMFMA final :
public InstructionRule {
1103 bool FoundTrans =
false;
1104 unsigned Counter = 1;
1105 auto *DAG = SyncPipe[0].DAG;
1107 if (Cache->empty()) {
1108 auto I = DAG->SUnits.begin();
1109 auto E = DAG->SUnits.end();
1110 for (;
I !=
E;
I++) {
1111 if (FoundTrans &&
TII->isMFMAorWMMA(*
I->getInstr())) {
1113 Cache->push_back(&*
I);
1118 if (!FoundTrans &&
TII->isTRANS(
I->getInstr()->getOpcode()))
1125 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1129 bool NeedsCache =
false)
1135 class EnablesNthMFMAInChain final :
public InstructionRule {
1143 auto *DAG = SyncPipe[0].DAG;
1145 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1148 if (Cache->empty()) {
1149 auto *TempSU = ChainSeed;
1154 for (
auto &Succ : TempSU->Succs) {
1155 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1156 TempSU = Succ.getSUnit();
1165 Cache->push_back(TempSU);
1171 return DAG->IsReachable((*Cache)[0],
const_cast<SUnit *
>(SU));
1174 EnablesNthMFMAInChain(
unsigned Number,
SUnit *ChainSeed,
1176 bool NeedsCache =
false)
1178 ChainSeed(ChainSeed) {}
1184 class LessThanNSuccs final :
public InstructionRule {
1187 bool HasIntermediary =
false;
1192 if (!SyncPipe.
size())
1196 return Succ.getKind() == SDep::Data;
1198 if (SuccSize >=
Size)
1201 if (HasIntermediary) {
1202 for (
auto Succ : SU->
Succs) {
1205 return SuccSucc.getKind() == SDep::Data;
1207 if (SuccSize >=
Size)
1215 bool HasIntermediary =
false,
bool NeedsCache =
false)
1216 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1217 HasIntermediary(HasIntermediary) {}
1224 class GreaterThanOrEqualToNSuccs final :
public InstructionRule {
1227 bool HasIntermediary =
false;
1232 if (!SyncPipe.
size())
1236 return Succ.getKind() == SDep::Data;
1238 if (SuccSize >=
Size)
1241 if (HasIntermediary) {
1242 for (
auto Succ : SU->
Succs) {
1245 return SuccSucc.getKind() == SDep::Data;
1247 if (SuccSize >=
Size)
1255 unsigned SGID,
bool HasIntermediary =
false,
1256 bool NeedsCache =
false)
1257 : InstructionRule(
TII, SGID, NeedsCache),
Size(
Size),
1258 HasIntermediary(HasIntermediary) {}
1262 class IsCvt final :
public InstructionRule {
1267 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
1268 Opc == AMDGPU::V_CVT_I32_F32_e32;
1270 IsCvt(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1271 : InstructionRule(
TII, SGID, NeedsCache) {}
1275 class IsFMA final :
public InstructionRule {
1282 IsFMA(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1283 : InstructionRule(
TII, SGID, NeedsCache) {}
1287 class IsPipeAdd final :
public InstructionRule {
1293 IsPipeAdd(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
1294 : InstructionRule(
TII, SGID, NeedsCache) {}
1299 class IsSuccOfPrevNthGroup final :
public InstructionRule {
1301 unsigned Distance = 1;
1306 SchedGroup *OtherGroup =
nullptr;
1307 if (!SyncPipe.
size())
1310 for (
auto &PipeSG : SyncPipe) {
1311 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1312 OtherGroup = &PipeSG;
1317 if (!OtherGroup->Collection.size())
1320 for (
auto &OtherEle : OtherGroup->Collection) {
1321 for (
auto &Succ : OtherEle->Succs) {
1322 if (Succ.getSUnit() == SU && Succ.getKind() ==
SDep::Data)
1330 unsigned SGID,
bool NeedsCache =
false)
1331 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1336 class IsReachableFromPrevNthGroup final :
public InstructionRule {
1338 unsigned Distance = 1;
1343 SchedGroup *OtherGroup =
nullptr;
1344 if (!SyncPipe.
size())
1347 for (
auto &PipeSG : SyncPipe) {
1348 if ((
unsigned)PipeSG.getSGID() == SGID - Distance)
1349 OtherGroup = &PipeSG;
1354 if (!OtherGroup->Collection.size())
1357 auto *DAG = SyncPipe[0].DAG;
1359 for (
auto &OtherEle : OtherGroup->Collection)
1360 if (DAG->IsReachable(
const_cast<SUnit *
>(SU), OtherEle))
1365 IsReachableFromPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
1366 unsigned SGID,
bool NeedsCache =
false)
1367 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
1371 class OccursAtOrAfterNode final :
public InstructionRule {
1382 bool NeedsCache =
false)
1388 class IsExactMFMA final :
public InstructionRule {
1396 if (!SU || !
TII->isMFMAorWMMA(*ChainSeed->
getInstr()))
1399 if (Cache->empty()) {
1400 auto *TempSU = ChainSeed;
1405 for (
auto &Succ : TempSU->Succs) {
1406 if (
TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr())) {
1407 TempSU = Succ.getSUnit();
1416 Cache->push_back(TempSU);
1422 return (*Cache)[0] == SU;
1426 unsigned SGID,
bool NeedsCache =
false)
1428 ChainSeed(ChainSeed) {}
1434 class OccursAfterExp final :
public InstructionRule {
1439 auto *DAG = SyncPipe[0].DAG;
1440 if (Cache->empty()) {
1441 for (
auto &SU : DAG->SUnits)
1443 Cache->push_back(&SU);
1450 return SU->
NodeNum > (*Cache)[0]->NodeNum;
1454 bool NeedsCache =
false)
1455 : InstructionRule(
TII, SGID, NeedsCache) {}
1459 bool applyIGLPStrategy(
1468 : IGLPStrategy(DAG,
TII) {
1473unsigned MFMAExpInterleaveOpt::TransPipeCount = 0;
1474unsigned MFMAExpInterleaveOpt::MFMAPipeCount = 0;
1475unsigned MFMAExpInterleaveOpt::AddPipeCount = 0;
1476unsigned MFMAExpInterleaveOpt::MFMAEnablement = 0;
1477unsigned MFMAExpInterleaveOpt::ExpRequirement = 0;
1478unsigned MFMAExpInterleaveOpt::MFMAChains = 0;
1479bool MFMAExpInterleaveOpt::HasCvt =
false;
1480bool MFMAExpInterleaveOpt::HasChainBetweenCvt =
false;
1481std::optional<unsigned> MFMAExpInterleaveOpt::FirstPipeDSR = std::nullopt;
1490 auto isBitPack = [](
unsigned Opc) {
1491 return Opc == AMDGPU::V_PACK_B32_F16_e64 ||
Opc == AMDGPU::V_PERM_B32_e64;
1494 auto isCvt = [](
unsigned Opc) {
1495 return Opc == AMDGPU::V_CVT_F16_F32_e32 ||
Opc == AMDGPU::V_CVT_I32_F32_e32;
1498 auto isAdd = [](
unsigned Opc) {
return Opc == AMDGPU::V_ADD_F32_e32; };
1505 if (SU.
Succs.size() >= 7)
1507 for (
auto &Succ : SU.
Succs) {
1508 if (Succ.getSUnit()->Succs.size() >= 7)
1527 if (!(PackSUs.
size() && MFMAPipeCands.
size() && ExpPipeCands.
size()))
1532 std::optional<SUnit *> TempMFMA;
1533 std::optional<SUnit *> TempExp;
1535 for (
auto &PredSU : ExpPipeCands) {
1536 for (
auto &SuccSU : MFMAPipeCands) {
1549 if (!(TempExp && TempMFMA))
1552 HasChainBetweenCvt =
none_of((*TempExp)->Succs, [&isCvt](
SDep &Succ) {
1553 return isCvt(Succ.getSUnit()->getInstr()->getOpcode());
1557 for (
auto &SuccSU : MFMAPipeCands) {
1558 if (MFMAPipeSUs.
size() &&
1559 any_of(MFMAPipeSUs, [&SuccSU](
SUnit *PotentialMatch) {
1560 return PotentialMatch->
NodeNum == SuccSU->NodeNum;
1564 for (
auto &PredSU : ExpPipeCands) {
1572 MFMAPipeCount = MFMAPipeSUs.
size();
1574 assert(TempExp && TempMFMA);
1575 assert(MFMAPipeCount > 0);
1577 std::optional<SUnit *> TempCvt;
1578 for (
auto &SuccSU : CvtSUs) {
1586 if (TempCvt.has_value()) {
1587 for (
auto &SuccSU : MFMAPipeSUs) {
1596 for (
auto &MFMAPipeSU : MFMAPipeSUs) {
1600 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1602 MFMAChainSeeds.push_back(MFMAPipeSU);
1610 for (
auto Pred : MFMAChainSeeds[0]->Preds) {
1611 if (
TII->isDS(Pred.getSUnit()->getInstr()->getOpcode()) &&
1612 Pred.getSUnit()->getInstr()->mayLoad())
1613 FirstPipeDSR = Pred.getSUnit()->NodeNum;
1617 unsigned PackSuccCount =
1623 unsigned PackPredCount =
1625 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1626 return isBitPack(Opc);
1630 auto Opc = Pred.getSUnit()->getInstr()->getOpcode();
1631 return isBitPack(Opc);
1634 if (PackPred == (*TempMFMA)->Preds.end())
1642 return TII->isMFMAorWMMA(*Succ.getSUnit()->getInstr());
1646 MFMAEnablement *= PackSuccCount;
1651 return DAG->
IsReachable(PackPred->getSUnit(), ExpBase);
1654 ExpRequirement *= PackPredCount;
1664 MFMAChainSeeds.clear();
1671bool MFMAExpInterleaveOpt::applyIGLPStrategy(
1676 bool IsSmallKernelType =
1677 MFMAEnablement == 2 && ExpRequirement == 4 && TransPipeCount == 32;
1678 bool IsLargeKernelType =
1679 MFMAEnablement == 4 && ExpRequirement == 4 && TransPipeCount == 64;
1681 if (!(IsSmallKernelType || IsLargeKernelType))
1687 unsigned PipelineSyncID = 0;
1688 SchedGroup *SG =
nullptr;
1690 unsigned MFMAChain = 0;
1691 unsigned PositionInChain = 0;
1692 unsigned CurrMFMAForTransPosition = 0;
1694 auto incrementTransPosition = [&MFMAChain, &PositionInChain,
1695 &CurrMFMAForTransPosition]() {
1696 CurrMFMAForTransPosition += MFMAEnablement;
1697 PositionInChain = (CurrMFMAForTransPosition / MFMAChains);
1698 MFMAChain = CurrMFMAForTransPosition % MFMAChains;
1701 auto getNextTransPositionInChain = [&CurrMFMAForTransPosition]() {
1702 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1703 return (TempMFMAForTrans / MFMAChains);
1706 auto getNextTransMFMAChain = [&CurrMFMAForTransPosition]() {
1707 auto TempMFMAForTrans = CurrMFMAForTransPosition + MFMAEnablement;
1708 return TempMFMAForTrans % MFMAChains;
1711 unsigned CurrMFMAPosition = 0;
1712 unsigned MFMAChainForMFMA = 0;
1713 unsigned PositionInChainForMFMA = 0;
1715 auto incrementMFMAPosition = [&CurrMFMAPosition, &MFMAChainForMFMA,
1716 &PositionInChainForMFMA]() {
1718 MFMAChainForMFMA = CurrMFMAPosition % MFMAChains;
1719 PositionInChainForMFMA = CurrMFMAPosition / MFMAChains;
1723 assert(IsPostRA || MFMAChainSeeds.size() == MFMAChains);
1725 bool UsesFMA = IsSmallKernelType || !IsPostRA;
1726 bool UsesDSRead = IsLargeKernelType && !IsPostRA && FirstPipeDSR;
1727 bool UsesCvt = HasCvt && (IsSmallKernelType || !IsPostRA);
1728 bool UsesVALU = IsSmallKernelType;
1733 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1734 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1735 if (!IsPostRA && MFMAChains) {
1736 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1737 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1741 std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1742 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1743 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1746 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1747 SchedGroupMask::VALU, ExpRequirement, PipelineSyncID, DAG,
TII);
1748 if (!IsPostRA && MFMAChains) {
1749 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1750 getNextTransPositionInChain(),
1751 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1753 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1754 SG->getSGID(),
true));
1755 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1756 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1760 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1761 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1762 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1764 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1768 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1769 SchedGroupMask::TRANS, ExpRequirement, PipelineSyncID, DAG,
TII);
1770 if (!IsPostRA && MFMAChains)
1771 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1772 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
true));
1774 SG->addRule(std::make_shared<EnablesNthMFMA>(1,
TII, SG->getSGID(),
true));
1775 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1776 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1777 HasChainBetweenCvt));
1778 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1780 incrementTransPosition();
1783 for (
unsigned I = 0;
I < ExpRequirement;
I++) {
1786 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1787 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1788 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1789 if (HasChainBetweenCvt)
1790 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1791 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1793 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(
1794 1 + (2 + UsesFMA) *
I,
TII, SG->getSGID()));
1795 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1800 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1801 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1802 if (!IsPostRA && MFMAChains) {
1803 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1804 getNextTransPositionInChain(),
1805 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
true));
1807 SG->addRule(std::make_shared<EnablesNthMFMA>(2 * MFMAEnablement + 1,
1808 TII, SG->getSGID(),
true));
1809 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1810 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1814 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1815 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1816 if (!IsPostRA && MFMAChains)
1817 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1818 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1821 SG->addRule(std::make_shared<EnablesNthMFMA>(MFMAEnablement + 1,
TII,
1822 SG->getSGID(),
true));
1823 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1824 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1825 HasChainBetweenCvt));
1826 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1831 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1832 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1833 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1834 SG->addRule(std::make_shared<GreaterThanOrEqualToNSuccs>(
1835 8,
TII, SG->getSGID(), HasChainBetweenCvt));
1836 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1841 unsigned MFMARatio =
1842 MFMAEnablement > ExpRequirement ? MFMAEnablement / ExpRequirement : 1;
1845 MFMAEnablement > ExpRequirement ? 1 : ExpRequirement / MFMAEnablement;
1847 unsigned RemainingExp = TransPipeCount > (2 * ExpRequirement)
1848 ? TransPipeCount - (2 * ExpRequirement)
1850 unsigned ExpLoopCount = RemainingExp / ExpRatio;
1852 unsigned MFMAInLoop = MFMAPipeCount > (MFMAEnablement * 2)
1853 ? MFMAPipeCount - (MFMAEnablement * 2)
1855 unsigned MFMALoopCount = MFMAInLoop / MFMARatio;
1857 AddPipeCount < MFMAPipeCount ? 1 : AddPipeCount / MFMAPipeCount;
1858 unsigned LoopSize = std::min(ExpLoopCount, MFMALoopCount);
1860 for (
unsigned I = 0;
I < LoopSize;
I++) {
1861 if (!(
I * ExpRatio % ExpRequirement))
1862 incrementTransPosition();
1865 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1866 SchedGroupMask::MFMA, MFMARatio, PipelineSyncID, DAG,
TII);
1867 if (!IsPostRA && MFMAChains)
1868 SG->addRule(std::make_shared<IsExactMFMA>(
1869 PositionInChainForMFMA, MFMAChainSeeds[MFMAChainForMFMA],
TII,
1870 SG->getSGID(),
true));
1872 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1873 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1874 incrementMFMAPosition();
1877 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1878 SchedGroupMask::VALU, VALUOps, PipelineSyncID, DAG,
TII);
1879 SG->addRule(std::make_shared<IsPipeAdd>(
TII, SG->getSGID()));
1880 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1883 if (UsesDSRead && !(
I % 4)) {
1884 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1885 SchedGroupMask::DS_READ, 2, PipelineSyncID, DAG,
TII);
1886 SG->addRule(std::make_shared<OccursAtOrAfterNode>(*FirstPipeDSR,
TII,
1888 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1892 for (
unsigned J = 0; J < ExpRatio; J++) {
1893 auto MFMAOffset = (1 + UsesVALU) * MFMARatio * (
I + 1);
1894 auto MaxMFMAOffset =
1895 (1 + UsesVALU) * ExpRequirement * MFMARatio / ExpRatio;
1899 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1900 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1901 SG->addRule(std::make_shared<IsCvt>(
TII, SG->getSGID()));
1902 auto BaseDiff = (2 + UsesFMA) * (ExpRequirement - 1) + 1;
1903 auto DSROffset =
I / 4 + 1;
1904 auto MaxDSROffset = MaxMFMAOffset / 4;
1906 auto ExpOffset =
I * ExpRatio + J >= ExpRequirement ? 0 : 1;
1907 auto CurrentOffset = UsesDSRead * std::min(MaxDSROffset, DSROffset) +
1908 std::min(MaxMFMAOffset, MFMAOffset) + BaseDiff +
1910 if (HasChainBetweenCvt)
1911 SG->addRule(std::make_shared<IsReachableFromPrevNthGroup>(
1912 CurrentOffset,
TII, SG->getSGID()));
1914 SG->addRule(std::make_shared<IsSuccOfPrevNthGroup>(CurrentOffset,
TII,
1916 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1921 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1922 SchedGroupMask::VALU, 1, PipelineSyncID, DAG,
TII);
1923 if (!IsPostRA && MFMAChains)
1924 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1925 getNextTransPositionInChain(),
1926 MFMAChainSeeds[getNextTransMFMAChain()],
TII, SG->getSGID(),
1929 SG->addRule(std::make_shared<EnablesNthMFMA>(
1930 (((
I * ExpRatio + J) / ExpRequirement) + 3) * MFMAEnablement + 1,
1931 TII, SG->getSGID(),
true));
1932 SG->addRule(std::make_shared<IsFMA>(
TII, SG->getSGID()));
1933 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1937 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1938 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1939 if (!IsPostRA && MFMAChains)
1940 SG->addRule(std::make_shared<EnablesNthMFMAInChain>(
1941 PositionInChain, MFMAChainSeeds[MFMAChain],
TII, SG->getSGID(),
1944 SG->addRule(std::make_shared<EnablesNthMFMA>(
1945 (((
I * ExpRatio + J) / ExpRequirement) + 2) * MFMAEnablement + 1,
1946 TII, SG->getSGID(),
true));
1947 SG->addRule(std::make_shared<IsPipeExp>(
TII, SG->getSGID(),
true));
1948 SG->addRule(std::make_shared<LessThanNSuccs>(8,
TII, SG->getSGID(),
1949 HasChainBetweenCvt));
1950 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1955 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1956 SchedGroupMask::MFMA, MFMAEnablement * 2, PipelineSyncID, DAG,
TII);
1957 SG->addRule(std::make_shared<OccursAfterExp>(
TII, SG->getSGID(),
true));
1958 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1962class MFMAExpSimpleInterleaveOpt final :
public IGLPStrategy {
1964 bool applyIGLPStrategy(
1975 : IGLPStrategy(DAG,
TII) {
1980bool MFMAExpSimpleInterleaveOpt::applyIGLPStrategy(
1985 unsigned MFMACount = 0;
1987 if (
TII->isMFMAorWMMA(
I))
1990 const unsigned PipelineSyncID = 0;
1991 for (
unsigned I = 0;
I < MFMACount * 3; ++
I) {
1992 SchedGroup *SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1993 SchedGroupMask::TRANS, 1, PipelineSyncID, DAG,
TII);
1994 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
1996 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
1997 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
1998 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2004class MFMASmallGemmSingleWaveOpt final :
public IGLPStrategy {
2007 class EnablesInitialMFMA final :
public InstructionRule {
2011 if (!SyncPipe.
size())
2014 if (!Cache->size()) {
2015 for (
auto &Elt : SyncPipe[0].DAG->
SUnits) {
2016 if (
TII->isMFMAorWMMA(*Elt.getInstr())) {
2020 Cache->push_back(&Elt);
2025 auto *DAG = SyncPipe[0].DAG;
2026 for (
auto &Elt : *Cache) {
2034 bool NeedsCache =
false)
2035 : InstructionRule(
TII, SGID, NeedsCache) {}
2039 class IsPermForDSW final :
public InstructionRule {
2044 if (
MI->getOpcode() != AMDGPU::V_PERM_B32_e64)
2047 bool FitsInGroup =
false;
2049 if (!Collection.
size()) {
2050 for (
auto &Succ : SU->
Succs) {
2051 SUnit *SuccUnit = Succ.getSUnit();
2054 Cache->push_back(SuccUnit);
2065 return ThisSucc.getSUnit() == Elt;
2070 IsPermForDSW(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
2071 : InstructionRule(
TII, SGID, NeedsCache) {}
2075 class IsSuccOfPrevGroup final :
public InstructionRule {
2079 SchedGroup *OtherGroup =
nullptr;
2080 for (
auto &PipeSG : SyncPipe) {
2081 if ((
unsigned)PipeSG.getSGID() == SGID - 1) {
2082 OtherGroup = &PipeSG;
2088 if (!OtherGroup->Collection.size())
2092 return any_of(OtherGroup->Collection, [&SU](
SUnit *Elt) {
2093 return any_of(Elt->Succs,
2094 [&SU](SDep &Succ) { return Succ.getSUnit() == SU; });
2098 bool NeedsCache =
false)
2099 : InstructionRule(
TII, SGID, NeedsCache) {}
2103 class VMEMSize final :
public InstructionRule {
2108 if (
MI->getOpcode() == TargetOpcode::BUNDLE)
2110 if (!Collection.
size())
2115 auto TRI =
TII->getRegisterInfo();
2116 auto &MRI =
MI->getMF()->getRegInfo();
2117 for (
auto &Elt : Collection) {
2118 auto Op = Elt->getInstr()->getOperand(0);
2120 TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(MRI,
Op));
2124 if (NumBits < 128) {
2126 if (NumBits +
TRI.getRegSizeInBits(*
TRI.getRegClassForOperandReg(
2127 MRI,
MI->getOperand(0))) <=
2135 VMEMSize(
const SIInstrInfo *
TII,
unsigned SGID,
bool NeedsCache =
false)
2136 : InstructionRule(
TII, SGID, NeedsCache) {}
2141 class SharesPredWithPrevNthGroup final :
public InstructionRule {
2143 unsigned Distance = 1;
2148 SchedGroup *OtherGroup =
nullptr;
2149 if (!SyncPipe.
size())
2152 if (!Cache->size()) {
2154 for (
auto &PipeSG : SyncPipe) {
2155 if ((
unsigned)PipeSG.getSGID() == SGID - Distance) {
2156 OtherGroup = &PipeSG;
2162 if (!OtherGroup->Collection.size())
2165 for (
auto &OtherEle : OtherGroup->Collection) {
2166 for (
auto &Pred : OtherEle->Preds) {
2167 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2168 AMDGPU::V_PERM_B32_e64)
2169 Cache->push_back(Pred.getSUnit());
2178 auto *DAG = SyncPipe[0].DAG;
2185 SharesPredWithPrevNthGroup(
unsigned Distance,
const SIInstrInfo *
TII,
2186 unsigned SGID,
bool NeedsCache =
false)
2187 : InstructionRule(
TII, SGID, NeedsCache), Distance(Distance) {}
2191 bool applyIGLPStrategy(
2202 : IGLPStrategy(DAG,
TII) {
2207static unsigned DSWCount = 0;
2208static unsigned DSWWithPermCount = 0;
2209static unsigned DSWWithSharedVMEMCount = 0;
2211bool MFMASmallGemmSingleWaveOpt::applyIGLPStrategy(
2212 DenseMap<int, SUnitsToCandidateSGsMap> &SyncedInstrs,
2215 unsigned MFMACount = 0;
2216 unsigned DSRCount = 0;
2218 bool IsInitial =
Phase == AMDGPU::SchedulingPhase::Initial;
2220 assert((!IsInitial || (DSWCount == 0 && DSWWithPermCount == 0 &&
2221 DSWWithSharedVMEMCount == 0)) &&
2222 "DSWCounters should be zero in pre-RA scheduling!");
2224 for (
auto &SU : DAG->
SUnits) {
2225 auto *
I = SU.getInstr();
2226 if (
TII->isMFMAorWMMA(*
I))
2228 else if (
TII->isDS(*
I)) {
2231 else if (
I->mayStore() && IsInitial) {
2233 for (
auto Pred : SU.Preds) {
2234 if (Pred.getSUnit()->getInstr()->getOpcode() ==
2235 AMDGPU::V_PERM_B32_e64) {
2245 DSWWithPermCount = DSWithPerms.
size();
2246 auto *
I = DSWithPerms.
begin();
2247 auto *
E = DSWithPerms.
end();
2255 DenseMap<MachineInstr *, SUnit *> VMEMLookup;
2257 for (;
I !=
E;
I++) {
2258 SUnit *Cand =
nullptr;
2259 bool MissedAny =
false;
2260 for (
auto &Pred : (*I)->Preds) {
2261 if (Pred.getSUnit()->getInstr()->getOpcode() != AMDGPU::V_PERM_B32_e64)
2267 for (
auto &Succ : Pred.getSUnit()->Succs) {
2268 auto *
MI = Succ.getSUnit()->getInstr();
2269 if (!
TII->isVMEM(*
MI) || !
MI->mayLoad())
2272 if (MissedAny || !VMEMLookup.
size()) {
2274 VMEMLookup[
MI] = *
I;
2291 if (!MissedAny && Cand) {
2292 DSWWithSharedVMEMCount += 2;
2299 assert(DSWWithSharedVMEMCount <= DSWWithPermCount);
2301 unsigned PipelineSyncID = 0;
2303 if (DSWWithPermCount) {
2304 for (
unsigned I = 0;
I < MFMACount;
I++) {
2305 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2306 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2307 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2309 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2310 SchedGroupMask::VALU, 2, PipelineSyncID, DAG,
TII);
2311 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2321 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2322 SchedGroupMask::DS_READ, 4, PipelineSyncID, DAG,
TII);
2323 SG->addRule(std::make_shared<EnablesInitialMFMA>(
TII, SG->getSGID(),
true));
2324 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2326 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2327 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2328 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2331 for (
unsigned I = 4;
I < DSRCount; ++
I) {
2332 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2333 SchedGroupMask::DS_READ, 1, PipelineSyncID, DAG,
TII);
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()]);
2344 for (
unsigned I = DSWWithSharedVMEMCount;
I < DSWWithPermCount; ++
I) {
2345 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2346 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2347 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2348 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2350 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2351 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2352 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2353 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2355 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2356 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2357 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2358 1,
TII, SG->getSGID(),
true));
2359 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2360 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2362 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2363 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2364 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2366 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2367 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2368 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2369 3,
TII, SG->getSGID(),
true));
2370 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2371 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2373 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2374 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2375 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2381 for (
unsigned I = DSWWithPermCount;
I < DSWCount;
I++) {
2382 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2383 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2384 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2386 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2387 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2388 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2389 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2391 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2392 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2393 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2401 for (
unsigned I = 0;
I < DSWWithSharedVMEMCount; ++
I) {
2402 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2403 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2404 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2405 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2407 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2408 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2409 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2410 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2412 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2413 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2414 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2416 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2417 SchedGroupMask::VALU, 4, PipelineSyncID, DAG,
TII);
2418 SG->addRule(std::make_shared<IsPermForDSW>(
TII, SG->getSGID(),
true));
2419 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2421 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2422 SchedGroupMask::DS_WRITE, 1, PipelineSyncID, DAG,
TII);
2423 SG->addRule(std::make_shared<IsSuccOfPrevGroup>(
TII, SG->getSGID()));
2424 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2426 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2427 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2428 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2430 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2431 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2432 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2433 2,
TII, SG->getSGID(),
true));
2434 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2435 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2437 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2438 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2439 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2441 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2442 SchedGroupMask::VMEM_READ, 4, PipelineSyncID, DAG,
TII);
2443 SG->addRule(std::make_shared<SharesPredWithPrevNthGroup>(
2444 4,
TII, SG->getSGID(),
true));
2445 SG->addRule(std::make_shared<VMEMSize>(
TII, SG->getSGID()));
2446 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2448 SG = &SyncedSchedGroups[PipelineSyncID].emplace_back(
2449 SchedGroupMask::MFMA, 1, PipelineSyncID, DAG,
TII);
2450 SG->findCandidateSUnits(SyncedInstrs[SG->getSyncID()]);
2456static std::unique_ptr<IGLPStrategy>
2458 const SIInstrInfo *
TII) {
2461 return std::make_unique<MFMASmallGemmOpt>(DAG,
TII);
2463 return std::make_unique<MFMASmallGemmSingleWaveOpt>(DAG,
TII);
2465 return std::make_unique<MFMAExpInterleaveOpt>(DAG,
TII);
2467 return std::make_unique<MFMAExpSimpleInterleaveOpt>(DAG,
TII);
2473class IGroupLPDAGMutation :
public ScheduleDAGMutation {
2475 const SIInstrInfo *
TII;
2482 DenseMap<int, SmallVector<SchedGroup, 4>> SyncedSchedGroups;
2485 DenseMap<int, SUnitsToCandidateSGsMap> SyncedInstrs;
2488 void addSchedBarrierEdges(SUnit &SU);
2499 SchedGroupMask invertSchedBarrierMask(SchedGroupMask Mask)
const;
2502 void initSchedGroupBarrierPipelineStage(
2503 std::vector<SUnit>::reverse_iterator RIter);
2505 bool initIGLPOpt(SUnit &SU);
2508 void apply(ScheduleDAGInstrs *DAGInstrs)
override;
2515 bool IsBottomUp =
true;
2520 IGroupLPDAGMutation() =
default;
2524unsigned SchedGroup::NumSchedGroups = 0;
2526bool SchedGroup::tryAddEdge(SUnit *
A, SUnit *
B) {
2530bool SchedGroup::canAddMI(
const MachineInstr &
MI)
const {
2532 if (
MI.isMetaInstruction())
2535 else if (
MI.isInlineAsm()) {
2537 auto &MRI =
MI.getParent()->getParent()->getRegInfo();
2538 bool SGPR_used =
false, SGPR_big_def =
false, VGPR_used =
false,
2539 VMFMA_used =
false, VReg32_used =
false,
MayLoad =
MI.mayLoad(),
2541 for (
const MachineOperand &Operand :
MI.operands())
2542 if (Operand.isReg()) {
2544 *
TRI.getRegClassForOperandReg(MRI, Operand);
2545 if (
TRI.hasVGPRs(&RegClass)) {
2547 if (Operand.isUse() &&
TRI.getRegSizeInBits(RegClass) == 32)
2553 if (
TRI.hasAGPRs(&RegClass) ||
TRI.getRegSizeInBits(RegClass) > 128)
2555 if (
TRI.hasSGPRs(&RegClass))
2557 if (
TRI.getRegSizeInBits(RegClass) > 64 && Operand.isDef())
2558 SGPR_big_def =
true;
2561 typedef std::underlying_type_t<SchedGroupMask> SGMask_t;
2562 SGMask_t InlineAsmMask = 0;
2563 if (VGPR_used && !VMFMA_used && !MayLoad && !MayStore)
2564 InlineAsmMask |= (SGMask_t)SchedGroupMask::VALU;
2565 if (SGPR_used && !VGPR_used && !MayLoad && !MayStore)
2566 InlineAsmMask |= (SGMask_t)SchedGroupMask::SALU;
2568 InlineAsmMask |= (SGMask_t)SchedGroupMask::MFMA;
2569 if (VGPR_used && MayLoad)
2570 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_READ
2571 : SchedGroupMask::VMEM_READ);
2572 if (VGPR_used && MayStore)
2573 InlineAsmMask |= (SGMask_t)(VReg32_used ? SchedGroupMask::DS_WRITE
2574 : SchedGroupMask::VMEM_WRITE);
2576 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS_READ;
2577 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VALU ||
2578 InlineAsmMask & (SGMask_t)SchedGroupMask::SALU)
2579 InlineAsmMask |= (SGMask_t)SchedGroupMask::ALU;
2580 if (InlineAsmMask & (SGMask_t)SchedGroupMask::DS_READ ||
2581 InlineAsmMask & (SGMask_t)SchedGroupMask::DS_WRITE)
2582 InlineAsmMask |= (SGMask_t)SchedGroupMask::DS;
2583 if (InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_READ ||
2584 InlineAsmMask & (SGMask_t)SchedGroupMask::VMEM_WRITE)
2585 InlineAsmMask |= (SGMask_t)SchedGroupMask::VMEM;
2587 Result = ((SGMask_t)SGMask & InlineAsmMask) != 0;
2590 else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
2591 (
TII->isVALU(
MI,
true) ||
TII->isMFMAorWMMA(
MI) ||
2595 else if (((SGMask & SchedGroupMask::VALU) != SchedGroupMask::NONE) &&
2596 TII->isVALU(
MI,
true) && !
TII->isMFMAorWMMA(
MI) &&
2604 else if (((SGMask & SchedGroupMask::SALU) != SchedGroupMask::NONE) &&
2608 else if (((SGMask & SchedGroupMask::MFMA) != SchedGroupMask::NONE) &&
2609 TII->isMFMAorWMMA(
MI))
2612 else if (((SGMask & SchedGroupMask::VMEM) != SchedGroupMask::NONE) &&
2616 else if (((SGMask & SchedGroupMask::VMEM_READ) != SchedGroupMask::NONE) &&
2617 MI.mayLoad() &&
TII->isVMEM(
MI))
2620 else if (((SGMask & SchedGroupMask::VMEM_WRITE) != SchedGroupMask::NONE) &&
2621 MI.mayStore() &&
TII->isVMEM(
MI))
2624 else if (((SGMask & SchedGroupMask::DS) != SchedGroupMask::NONE) &&
2628 else if (((SGMask & SchedGroupMask::DS_READ) != SchedGroupMask::NONE) &&
2629 MI.mayLoad() &&
TII->isDS(
MI))
2632 else if (((SGMask & SchedGroupMask::DS_WRITE) != SchedGroupMask::NONE) &&
2633 MI.mayStore() &&
TII->isDS(
MI))
2636 else if (((SGMask & SchedGroupMask::TRANS) != SchedGroupMask::NONE) &&
2640 else if (((SGMask & SchedGroupMask::LDSDMA) != SchedGroupMask::NONE) &&
2645 dbgs() <<
"For SchedGroup with mask " <<
format_hex((
int)SGMask, 10,
true)
2646 << (Result ?
" could classify " :
" unable to classify ") <<
MI);
2651int SchedGroup::link(SUnit &SU,
bool MakePred,
2652 std::list<std::pair<SUnit *, SUnit *>> &AddedEdges) {
2653 int MissedEdges = 0;
2654 for (
auto *
A : Collection) {
2656 if (
A ==
B ||
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2666 bool Added = tryAddEdge(
A,
B);
2668 AddedEdges.emplace_back(
A,
B);
2676void SchedGroup::link(SUnit &SU,
bool MakePred) {
2677 for (
auto *
A : Collection) {
2679 if (
A->getInstr()->getOpcode() == AMDGPU::SCHED_GROUP_BARRIER)
2688void SchedGroup::link(SUnit &SU,
2689 function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>
P) {
2690 for (
auto *
A : Collection) {
2699void SchedGroup::link(SchedGroup &OtherGroup) {
2700 for (
auto *
B : OtherGroup.Collection)
2704bool SchedGroup::canAddSU(SUnit &SU)
const {
2706 if (
MI.getOpcode() != TargetOpcode::BUNDLE)
2707 return canAddMI(
MI);
2710 const MachineBasicBlock *
MBB =
MI.getParent();
2712 while (
E !=
MBB->
end() &&
E->isBundledWithPred())
2716 return std::all_of(
B,
E, [
this](MachineInstr &
MI) {
return canAddMI(
MI); });
2720void SchedGroup::findCandidateSUnits(
T Begin,
T End,
2721 SUnitsToCandidateSGsMap &SyncedInstrs) {
2724 SyncedInstrs[&SU].push_back(SGID);
2728void SchedGroup::findCandidateSUnits(SUnitsToCandidateSGsMap &SyncedInstrs) {
2729 findCandidateSUnits(DAG->
SUnits.rbegin(), DAG->
SUnits.rend(), SyncedInstrs);
2732void IGroupLPDAGMutation::apply(ScheduleDAGInstrs *DAGInstrs) {
2733 const TargetSchedModel *TSchedModel = DAGInstrs->
getSchedModel();
2734 if (!TSchedModel || DAGInstrs->
SUnits.empty())
2739 TII =
ST.getInstrInfo();
2740 DAG =
static_cast<ScheduleDAGMI *
>(DAGInstrs);
2741 SyncedSchedGroups.clear();
2742 SyncedInstrs.clear();
2743 bool FoundSB =
false;
2744 bool FoundIGLP =
false;
2745 bool ShouldApplyIGLP =
false;
2746 for (
auto R = DAG->
SUnits.rbegin(),
E = DAG->
SUnits.rend(); R !=
E; ++R) {
2747 unsigned Opc =
R->getInstr()->getOpcode();
2749 if (
Opc == AMDGPU::SCHED_BARRIER) {
2750 addSchedBarrierEdges(*R);
2752 }
else if (
Opc == AMDGPU::SCHED_GROUP_BARRIER) {
2753 initSchedGroupBarrierPipelineStage(R);
2755 }
else if (
Opc == AMDGPU::IGLP_OPT) {
2756 if (!FoundSB && !FoundIGLP) {
2758 ShouldApplyIGLP = initIGLPOpt(*R);
2763 if (FoundSB || (FoundIGLP && ShouldApplyIGLP)) {
2764 PipelineSolver PS(SyncedSchedGroups, SyncedInstrs, DAG, IsBottomUp);
2772void IGroupLPDAGMutation::addSchedBarrierEdges(SUnit &SchedBarrier) {
2774 assert(
MI.getOpcode() == AMDGPU::SCHED_BARRIER);
2775 LLVM_DEBUG(
dbgs() <<
"Building SchedGroup for SchedBarrier with Mask: "
2776 <<
MI.getOperand(0).getImm() <<
"\n");
2778 invertSchedBarrierMask((SchedGroupMask)
MI.getOperand(0).getImm());
2779 SchedGroup SG(InvertedMask, std::nullopt, DAG,
TII);
2781 for (SUnit &SU : DAG->
SUnits)
2782 if (SG.canAddSU(SU))
2788 (function_ref<
bool(
const SUnit *
A,
const SUnit *
B)>)[](
2789 const SUnit *
A,
const SUnit *
B) {
return A->NodeNum >
B->NodeNum; });
2793IGroupLPDAGMutation::invertSchedBarrierMask(SchedGroupMask Mask)
const {
2796 SchedGroupMask InvertedMask = ~Mask;
2798 static constexpr std::pair<SchedGroupMask, SchedGroupMask> ImpliedGroups[] = {
2799 {SchedGroupMask::ALU, SchedGroupMask::VALU | SchedGroupMask::SALU |
2800 SchedGroupMask::MFMA | SchedGroupMask::TRANS},
2801 {SchedGroupMask::VMEM, SchedGroupMask::VMEM_READ |
2802 SchedGroupMask::VMEM_WRITE |
2803 SchedGroupMask::LDSDMA},
2804 {SchedGroupMask::DS, SchedGroupMask::DS_READ | SchedGroupMask::DS_WRITE |
2805 SchedGroupMask::LDSDMA},
2808 for (
auto [Aggregate, Members] : ImpliedGroups) {
2810 if ((InvertedMask & Aggregate) == SchedGroupMask::NONE)
2811 InvertedMask &= ~Members;
2813 else if ((InvertedMask & Members) != Members)
2814 InvertedMask &= ~Aggregate;
2817 LLVM_DEBUG(
dbgs() <<
"After Inverting, SchedGroup Mask: " << (
int)InvertedMask
2820 return InvertedMask;
2823void IGroupLPDAGMutation::initSchedGroupBarrierPipelineStage(
2824 std::vector<SUnit>::reverse_iterator RIter) {
2825 MachineInstr &SGB = *RIter->getInstr();
2832 auto &SG = SyncedSchedGroups[SyncID].emplace_back((SchedGroupMask)SGMask,
2835 SG.findCandidateSUnits(RIter, SG.DAG->
SUnits.rend(),
2836 SyncedInstrs[SG.getSyncID()]);
2839bool IGroupLPDAGMutation::initIGLPOpt(SUnit &SU) {
2842 auto S = createIGLPStrategy(StrategyID, DAG,
TII);
2843 if (!S->shouldApplyStrategy(DAG,
Phase))
2846 IsBottomUp = S->IsBottomUp;
2847 return S->applyIGLPStrategy(SyncedInstrs, SyncedSchedGroups,
Phase);
2857std::unique_ptr<ScheduleDAGMutation>
2859 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.
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 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
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.
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:...