111 #include <functional>
118 using namespace llvm;
120 #define DEBUG_TYPE "pipeliner"
122 STATISTIC(NumTrytoPipeline,
"Number of loops that we attempt to pipeline");
123 STATISTIC(NumPipelined,
"Number of loops software pipelined");
128 cl::desc(
"Enable Software Pipelining"));
137 cl::desc(
"Size limit for the the MII."),
143 cl::desc(
"Maximum stages allowed in the generated scheduled."),
150 cl::desc(
"Prune dependences between unrelated Phi nodes."),
157 cl::desc(
"Prune loop carried order dependences."),
172 class SwingSchedulerDAG;
223 MachinePipeliner &
Pass;
239 NodeInfo() : ASAP(0), ALAP(0) {}
242 std::vector<NodeInfo> ScheduleInfo;
244 enum OrderKind { BottomUp = 0, TopDown = 1 };
261 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
265 std::vector<SUnit> &SUnits;
271 static unsigned MaxPaths;
274 Circuits(std::vector<SUnit> &SUs)
275 : SUnits(SUs),
Stack(), Blocked(SUs.size()),
B(SUs.size()),
284 void createAdjacencyStructure(SwingSchedulerDAG *DAG);
285 bool circuit(
int V,
int S, NodeSetType &NodeSets,
bool HasBackedge =
false);
293 Scheduled(
false),
Loop(L), LIS(lis), RegClassInfo(rci),
294 Topo(SUnits, &ExitSU) {
295 P.MF->getSubtarget().getSMSMutations(Mutations);
298 void schedule()
override;
299 void finishBlock()
override;
302 bool hasNewSchedule() {
return Scheduled; }
305 int getASAP(
SUnit *Node) {
return ScheduleInfo[Node->
NodeNum].ASAP; }
308 int getALAP(
SUnit *Node) {
return ScheduleInfo[Node->
NodeNum].ALAP; }
312 int getMOV(
SUnit *Node) {
return getALAP(Node) - getASAP(Node); }
330 static bool isOrder(
SUnit *Source,
const SDep &Dep) {
337 bool isLoopCarriedOrder(
SUnit *Source,
const SDep &Dep,
bool isSucc =
true);
364 void setMII(
unsigned mii) { MII = mii; }
367 bool UpdateDAG =
false);
371 unsigned getInstrBaseReg(
SUnit *SU) {
373 InstrChanges.
find(SU);
374 if (It != InstrChanges.
end())
375 return It->second.first;
379 void addMutation(std::unique_ptr<ScheduleDAGMutation>
Mutation) {
380 Mutations.push_back(std::move(Mutation));
385 void updatePhiDependences();
386 void changeDependences();
387 unsigned calculateResMII();
388 unsigned calculateRecMII(NodeSetType &RecNodeSets);
389 void findCircuits(NodeSetType &NodeSets);
390 void fuseRecs(NodeSetType &NodeSets);
391 void removeDuplicateNodes(NodeSetType &NodeSets);
392 void computeNodeFunctions(NodeSetType &NodeSets);
393 void registerPressureFilter(NodeSetType &NodeSets);
394 void colocateNodeSets(NodeSetType &NodeSets);
395 void checkNodeSets(NodeSetType &NodeSets);
396 void groupRemainingNodes(NodeSetType &NodeSets);
399 void computeNodeOrder(NodeSetType &NodeSets);
400 bool schedulePipeline(SMSchedule &Schedule);
401 void generatePipelinedLoop(SMSchedule &Schedule);
402 void generateProlog(SMSchedule &Schedule,
unsigned LastStage,
404 MBBVectorTy &PrologBBs);
405 void generateEpilog(SMSchedule &Schedule,
unsigned LastStage,
407 MBBVectorTy &EpilogBBs, MBBVectorTy &PrologBBs);
410 SMSchedule &Schedule, ValueMapTy *VRMap,
411 InstrMapTy &InstrMap,
unsigned LastStageNum,
412 unsigned CurStageNum,
bool IsLast);
415 SMSchedule &Schedule, ValueMapTy *VRMap,
416 InstrMapTy &InstrMap,
unsigned LastStageNum,
417 unsigned CurStageNum,
bool IsLast);
419 MBBVectorTy &EpilogBBs);
421 SMSchedule &Schedule);
423 MBBVectorTy &EpilogBBs, SMSchedule &Schedule,
429 unsigned InstStageNum);
431 unsigned InstStageNum,
432 SMSchedule &Schedule);
433 void updateInstruction(
MachineInstr *NewMI,
bool LastDef,
434 unsigned CurStageNum,
unsigned InstStageNum,
435 SMSchedule &Schedule, ValueMapTy *VRMap);
437 unsigned getPrevMapVal(
unsigned StageNum,
unsigned PhiStage,
unsigned LoopVal,
438 unsigned LoopStage, ValueMapTy *VRMap,
441 SMSchedule &Schedule, ValueMapTy *VRMap,
442 InstrMapTy &InstrMap);
444 InstrMapTy &InstrMap,
unsigned CurStageNum,
446 unsigned OldReg,
unsigned NewReg,
447 unsigned PrevReg = 0);
449 unsigned &OffsetPos,
unsigned &NewBase,
451 void postprocessDAG();
462 unsigned Colocate = 0;
463 SUnit *ExceedPressure =
nullptr;
470 NodeSet(iterator S, iterator
E) : Nodes(S, E), HasRecurrence(
true) {}
472 bool insert(
SUnit *SU) {
return Nodes.insert(SU); }
474 void insert(iterator S, iterator
E) { Nodes.insert(S, E); }
476 template <
typename UnaryPredicate>
bool remove_if(UnaryPredicate P) {
477 return Nodes.remove_if(P);
480 unsigned count(
SUnit *SU)
const {
return Nodes.count(SU); }
482 bool hasRecurrence() {
return HasRecurrence; };
484 unsigned size()
const {
return Nodes.size(); }
486 bool empty()
const {
return Nodes.empty(); }
488 SUnit *getNode(
unsigned i)
const {
return Nodes[i]; };
490 void setRecMII(
unsigned mii) { RecMII = mii; };
492 void setColocate(
unsigned c) { Colocate = c; };
494 void setExceedPressure(
SUnit *SU) { ExceedPressure = SU; }
496 bool isExceedSU(
SUnit *SU) {
return ExceedPressure == SU; }
498 int compareRecMII(
NodeSet &RHS) {
return RecMII - RHS.RecMII; }
500 int getRecMII() {
return RecMII; }
503 void computeNodeSetInfo(SwingSchedulerDAG *SSD) {
504 for (
SUnit *SU : *
this) {
505 MaxMOV =
std::max(MaxMOV, SSD->getMOV(SU));
513 HasRecurrence =
false;
517 ExceedPressure =
nullptr;
527 if (RecMII == RHS.RecMII) {
528 if (Colocate != 0 && RHS.Colocate != 0 && Colocate != RHS.Colocate)
529 return Colocate < RHS.Colocate;
530 if (MaxMOV == RHS.MaxMOV)
532 return MaxMOV < RHS.MaxMOV;
534 return RecMII > RHS.RecMII;
538 return RecMII == RHS.RecMII && MaxMOV == RHS.MaxMOV &&
545 iterator
end() {
return Nodes.
end(); }
548 os <<
"Num nodes " << size() <<
" rec " << RecMII <<
" mov " << MaxMOV
549 <<
" depth " <<
MaxDepth <<
" col " << Colocate <<
"\n";
550 for (
const auto &
I : Nodes)
551 os <<
" SU(" <<
I->NodeNum <<
") " << *(
I->getInstr());
555 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
574 std::map<SUnit *, int> InstrToCycle;
580 std::map<unsigned, std::pair<unsigned, bool>> RegToStageDiff;
590 int InitiationInterval;
598 std::unique_ptr<DFAPacketizer> Resources;
602 :
ST(mf->getSubtarget()),
MRI(mf->getRegInfo()),
603 Resources(
ST.getInstrInfo()->CreateTargetScheduleState(
ST)) {
606 InitiationInterval = 0;
610 ScheduledInstrs.clear();
611 InstrToCycle.clear();
612 RegToStageDiff.clear();
615 InitiationInterval = 0;
619 void setInitiationInterval(
int ii) { InitiationInterval = ii; }
623 int getFirstCycle()
const {
return FirstCycle; }
626 int getFinalCycle()
const {
return FirstCycle + InitiationInterval - 1; }
630 int earliestCycleInChain(
const SDep &Dep);
634 int latestCycleInChain(
const SDep &Dep);
636 void computeStart(
SUnit *SU,
int *MaxEarlyStart,
int *MinLateStart,
637 int *MinEnd,
int *MaxStart,
int II, SwingSchedulerDAG *DAG);
638 bool insert(
SUnit *SU,
int StartCycle,
int EndCycle,
int II);
643 const_sched_iterator;
646 bool isScheduledAtStage(
SUnit *SU,
unsigned StageNum) {
647 return (stageScheduled(SU) == (
int)StageNum);
652 int stageScheduled(
SUnit *SU)
const {
653 std::map<SUnit *, int>::const_iterator it = InstrToCycle.
find(SU);
654 if (it == InstrToCycle.end())
656 return (it->second - FirstCycle) / InitiationInterval;
661 unsigned cycleScheduled(
SUnit *SU)
const {
662 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SU);
663 assert(it != InstrToCycle.end() &&
"Instruction hasn't been scheduled.");
664 return (it->second - FirstCycle) % InitiationInterval;
668 unsigned getMaxStageCount() {
669 return (LastCycle - FirstCycle) / InitiationInterval;
674 unsigned getStagesForReg(
int Reg,
unsigned CurStage) {
675 std::pair<unsigned, bool> Stages = RegToStageDiff[
Reg];
676 if (CurStage > getMaxStageCount() && Stages.first == 0 && Stages.second)
687 unsigned getStagesForPhi(
int Reg) {
688 std::pair<unsigned, bool> Stages = RegToStageDiff[
Reg];
691 return Stages.first - 1;
695 std::deque<SUnit *> &getInstructions(
int cycle) {
696 return ScheduledInstrs[cycle];
699 bool isValidSchedule(SwingSchedulerDAG *SSD);
700 void finalizeSchedule(SwingSchedulerDAG *SSD);
701 bool orderDependence(SwingSchedulerDAG *SSD,
SUnit *SU,
702 std::deque<SUnit *> &Insts);
703 bool isLoopCarried(SwingSchedulerDAG *SSD,
MachineInstr &Phi);
704 bool isLoopCarriedDefOfUse(SwingSchedulerDAG *SSD,
MachineInstr *Inst,
712 unsigned SwingSchedulerDAG::Circuits::MaxPaths = 5;
715 int MachinePipeliner::NumTries = 0;
719 "Modulo Software Pipelining",
false,
false)
729 if (skipFunction(*mf.getFunction()))
735 if (mf.getFunction()->getAttributes().hasAttribute(
741 MLI = &getAnalysis<MachineLoopInfo>();
742 MDT = &getAnalysis<MachineDominatorTree>();
743 TII = MF->getSubtarget().getInstrInfo();
744 RegClassInfo.runOnMachineFunction(*MF);
756 bool MachinePipeliner::scheduleLoop(
MachineLoop &L) {
757 bool Changed =
false;
758 for (
auto &InnerLoop : L)
759 Changed |= scheduleLoop(*InnerLoop);
771 if (!canPipelineLoop(L))
776 Changed = swingModuloScheduler(L);
784 bool MachinePipeliner::canPipelineLoop(
MachineLoop &L) {
796 LI.LoopInductionVar =
nullptr;
797 LI.LoopCompare =
nullptr;
811 for (
unsigned i = 1; i != BBI->getNumOperands(); i += 2)
812 if (BBI->getOperand(i).getSubReg() != 0)
822 bool MachinePipeliner::swingModuloScheduler(
MachineLoop &L) {
823 assert(L.
getBlocks().size() == 1 &&
"SMS works on single blocks only.");
825 SwingSchedulerDAG SMS(*
this, L, getAnalysis<LiveIntervals>(), RegClassInfo);
834 unsigned size = MBB->
size();
845 return SMS.hasNewSchedule();
850 void SwingSchedulerDAG::schedule() {
853 addLoopCarriedDependences(AA);
854 updatePhiDependences();
855 Topo.InitDAGTopologicalSorting();
859 for (
unsigned su = 0, e = SUnits.size(); su != e; ++su)
860 SUnits[su].dumpAll(
this);
863 NodeSetType NodeSets;
864 findCircuits(NodeSets);
867 unsigned ResMII = calculateResMII();
868 unsigned RecMII = calculateRecMII(NodeSets);
877 DEBUG(
dbgs() <<
"MII = " << MII <<
" (rec=" << RecMII <<
", res=" << ResMII
888 computeNodeFunctions(NodeSets);
890 registerPressureFilter(NodeSets);
892 colocateNodeSets(NodeSets);
894 checkNodeSets(NodeSets);
897 for (
auto &
I : NodeSets) {
898 dbgs() <<
" Rec NodeSet ";
903 std::sort(NodeSets.begin(), NodeSets.end(), std::greater<NodeSet>());
905 groupRemainingNodes(NodeSets);
907 removeDuplicateNodes(NodeSets);
910 for (
auto &
I : NodeSets) {
911 dbgs() <<
" NodeSet ";
916 computeNodeOrder(NodeSets);
918 SMSchedule Schedule(
Pass.MF);
919 Scheduled = schedulePipeline(Schedule);
924 unsigned numStages = Schedule.getMaxStageCount();
933 generatePipelinedLoop(Schedule);
938 void SwingSchedulerDAG::finishBlock() {
940 MF.DeleteMachineInstr(
I);
950 unsigned &InitVal,
unsigned &LoopVal) {
961 assert(InitVal != 0 && LoopVal != 0 &&
"Unexpected Phi structure.");
985 while (!Worklist.
empty()) {
990 if (Visited.
count(SuccSU))
1028 void SwingSchedulerDAG::addLoopCarriedDependences(
AliasAnalysis *AA) {
1030 for (
auto &SU : SUnits) {
1033 PendingLoads.
clear();
1037 for (
auto V : Objs) {
1044 for (
auto V : Objs) {
1046 PendingLoads.
find(V);
1047 if (I == PendingLoads.
end())
1049 for (
auto Load : I->second) {
1056 unsigned BaseReg1, BaseReg2;
1057 int64_t Offset1, Offset2;
1063 if (BaseReg1 == BaseReg2 && (
int)Offset1 < (
int)Offset2) {
1065 "What happened to the chain edge?");
1107 void SwingSchedulerDAG::updatePhiDependences() {
1112 for (
SUnit &I : SUnits) {
1115 unsigned HasPhiUse = 0;
1116 unsigned HasPhiDef = 0;
1121 MOI != MOE; ++MOI) {
1124 unsigned Reg = MOI->getReg();
1128 UI =
MRI.use_instr_begin(Reg),
1129 UE =
MRI.use_instr_end();
1132 SUnit *SU = getSUnit(UseMI);
1133 if (SU !=
nullptr && UseMI->
isPHI()) {
1141 if (SU->
NodeNum < I.NodeNum && !I.isPred(SU))
1146 }
else if (MOI->isUse()) {
1149 if (DefMI ==
nullptr)
1151 SUnit *SU = getSUnit(DefMI);
1152 if (SU !=
nullptr && DefMI->
isPHI()) {
1162 if (SU->
NodeNum < I.NodeNum && !I.isPred(SU))
1171 for (
auto &PI : I.Preds) {
1174 if (I.getInstr()->isPHI()) {
1183 for (
int i = 0, e = RemoveDeps.
size(); i != e; ++i)
1184 I.removePred(RemoveDeps[i]);
1190 void SwingSchedulerDAG::changeDependences() {
1194 for (
SUnit &I : SUnits) {
1195 unsigned BasePos = 0, OffsetPos = 0, NewBase = 0;
1196 int64_t NewOffset = 0;
1197 if (!canUseLastOffsetValue(I.getInstr(), BasePos, OffsetPos, NewBase,
1202 unsigned OrigBase = I.getInstr()->getOperand(BasePos).getReg();
1206 SUnit *DefSU = getSUnit(DefMI);
1213 SUnit *LastSU = getSUnit(LastMI);
1217 if (Topo.IsReachable(&I, LastSU))
1224 if (P->getSUnit() == DefSU)
1226 for (
int i = 0, e = Deps.
size(); i != e; i++) {
1227 Topo.RemovePred(&I, Deps[i].getSUnit());
1228 I.removePred(Deps[i]);
1232 for (
auto &P : LastSU->
Preds)
1233 if (P.getSUnit() == &I && P.getKind() ==
SDep::Order)
1235 for (
int i = 0, e = Deps.
size(); i != e; i++) {
1236 Topo.RemovePred(LastSU, Deps[i].getSUnit());
1247 InstrChanges[&
I] = std::make_pair(NewBase, NewOffset);
1255 struct FuncUnitSorter {
1262 unsigned minFuncUnits(
const MachineInstr *Inst,
unsigned &
F)
const {
1264 unsigned min = UINT_MAX;
1265 for (
const InstrStage *IS = InstrItins->beginStage(schedClass),
1266 *
IE = InstrItins->endStage(schedClass);
1268 unsigned funcUnits = IS->getUnits();
1270 if (numAlternatives < min) {
1271 min = numAlternatives;
1285 for (
const InstrStage *IS = InstrItins->beginStage(SchedClass),
1286 *
IE = InstrItins->endStage(SchedClass);
1288 unsigned FuncUnits = IS->getUnits();
1290 Resources[FuncUnits]++;
1297 unsigned F1 = 0, F2 = 0;
1298 unsigned MFUs1 = minFuncUnits(IS1, F1);
1299 unsigned MFUs2 = minFuncUnits(IS2, F2);
1300 if (MFUs1 == 1 && MFUs2 == 1)
1301 return Resources.lookup(F1) < Resources.lookup(F2);
1302 return MFUs1 > MFUs2;
1314 unsigned SwingSchedulerDAG::calculateResMII() {
1321 FuncUnitSorter FUS =
1322 FuncUnitSorter(MF.getSubtarget().getInstrItineraryData());
1326 FUS.calcCriticalResources(*I);
1333 FuncUnitOrder.push(&*I);
1335 while (!FuncUnitOrder.empty()) {
1337 FuncUnitOrder.pop();
1342 unsigned NumCycles = getSUnit(MI)->Latency;
1343 unsigned ReservedCycles = 0;
1346 for (
unsigned C = 0;
C < NumCycles; ++
C)
1348 if ((*RI++)->canReserveResources(*MI)) {
1354 for (
unsigned C = 0;
C < ReservedCycles; ++
C) {
1356 (*RI)->reserveResources(*MI);
1359 for (
unsigned C = ReservedCycles;
C < NumCycles; ++
C) {
1367 int Resmii = Resources.
size();
1383 unsigned SwingSchedulerDAG::calculateRecMII(NodeSetType &NodeSets) {
1384 unsigned RecMII = 0;
1386 for (
NodeSet &Nodes : NodeSets) {
1387 if (Nodes.size() == 0)
1390 unsigned Delay = Nodes.size() - 1;
1391 unsigned Distance = 1;
1394 unsigned CurMII = (Delay + Distance - 1) / Distance;
1395 Nodes.setRecMII(CurMII);
1396 if (CurMII > RecMII)
1407 for (
unsigned i = 0, e = SUnits.size(); i != e; ++i) {
1408 SUnit *SU = &SUnits[i];
1413 DepsAdded.
push_back(std::make_pair(SU, *IP));
1416 for (
SmallVector<std::pair<SUnit *, SDep>, 8>::iterator I = DepsAdded.
begin(),
1417 E = DepsAdded.
end();
1420 SUnit *SU = I->first;
1421 SDep &
D = I->second;
1423 unsigned Reg = D.
getReg();
1433 void SwingSchedulerDAG::Circuits::createAdjacencyStructure(
1434 SwingSchedulerDAG *DAG) {
1436 for (
int i = 0, e = SUnits.size(); i != e; ++i) {
1439 for (
auto &SI : SUnits[i].Succs) {
1442 if (
SI.getSUnit()->isBoundaryNode() ||
1443 (
SI.getKind() ==
SDep::Anti && !
SI.getSUnit()->getInstr()->isPHI()))
1445 int N =
SI.getSUnit()->NodeNum;
1446 if (!Added.test(N)) {
1447 AdjK[i].push_back(N);
1453 for (
auto &PI : SUnits[i].Preds) {
1454 if (!SUnits[i].getInstr()->mayStore() ||
1455 !DAG->isLoopCarriedOrder(&SUnits[i], PI,
false))
1457 if (PI.getKind() ==
SDep::Order && PI.getSUnit()->getInstr()->mayLoad()) {
1458 int N = PI.getSUnit()->NodeNum;
1459 if (!Added.test(N)) {
1460 AdjK[i].push_back(N);
1470 bool SwingSchedulerDAG::Circuits::circuit(
int V,
int S, NodeSetType &NodeSets,
1472 SUnit *SV = &SUnits[V];
1477 for (
auto W : AdjK[V]) {
1478 if (NumPaths > MaxPaths)
1488 }
else if (!Blocked.test(W)) {
1489 if (circuit(W, S, NodeSets, W < V ?
true : HasBackedge))
1497 for (
auto W : AdjK[V]) {
1509 void SwingSchedulerDAG::Circuits::unblock(
int U) {
1512 while (!BU.
empty()) {
1514 assert(SI != BU.
end() &&
"Invalid B set.");
1517 if (Blocked.test(W->NodeNum))
1518 unblock(W->NodeNum);
1524 void SwingSchedulerDAG::findCircuits(NodeSetType &NodeSets) {
1529 Circuits Cir(SUnits);
1531 Cir.createAdjacencyStructure(
this);
1532 for (
int i = 0, e = SUnits.size(); i != e; ++i) {
1534 Cir.circuit(i, i, NodeSets);
1556 void SwingSchedulerDAG::computeNodeFunctions(NodeSetType &NodeSets) {
1558 ScheduleInfo.resize(SUnits.size());
1577 EP = SU->
Preds.end();
1583 getDistance(pred, SU, *IP) * MII));
1586 ScheduleInfo[*
I].ASAP = asap;
1600 SUnit *succ = IS->getSUnit();
1602 getDistance(SU, succ, *IS) * MII));
1605 ScheduleInfo[*
I].ALAP = alap;
1610 I.computeNodeSetInfo(
this);
1613 for (
unsigned i = 0; i < SUnits.size(); i++) {
1614 dbgs() <<
"\tNode " << i <<
":\n";
1615 dbgs() <<
"\t ASAP = " << getASAP(&SUnits[i]) <<
"\n";
1616 dbgs() <<
"\t ALAP = " << getALAP(&SUnits[i]) <<
"\n";
1617 dbgs() <<
"\t MOV = " << getMOV(&SUnits[i]) <<
"\n";
1618 dbgs() <<
"\t D = " << getDepth(&SUnits[i]) <<
"\n";
1619 dbgs() <<
"\t H = " << getHeight(&SUnits[i]) <<
"\n";
1635 if (S && S->count(PI->getSUnit()) == 0)
1639 if (NodeOrder.
count(PI->getSUnit()) == 0)
1640 Preds.
insert(PI->getSUnit());
1644 ES = (*I)->Succs.end();
1648 if (S && S->count(IS->getSUnit()) == 0)
1650 if (NodeOrder.
count(IS->getSUnit()) == 0)
1651 Preds.
insert(IS->getSUnit());
1654 return Preds.
size() > 0;
1668 if (S && S->count(SI->getSUnit()) == 0)
1672 if (NodeOrder.
count(SI->getSUnit()) == 0)
1673 Succs.
insert(SI->getSUnit());
1676 PE = (*I)->Preds.end();
1680 if (S && S->count(PI->getSUnit()) == 0)
1682 if (NodeOrder.
count(PI->getSUnit()) == 0)
1683 Succs.
insert(PI->getSUnit());
1686 return Succs.
size() > 0;
1697 if (Exclude.
count(Cur) != 0)
1699 if (DestNodes.
count(Cur) != 0)
1701 if (!Visited.
insert(Cur).second)
1702 return Path.
count(Cur) != 0;
1703 bool FoundPath =
false;
1704 for (
auto &SI : Cur->
Succs)
1705 FoundPath |=
computePath(SI.getSUnit(), Path, DestNodes, Exclude, Visited);
1706 for (
auto &PI : Cur->
Preds)
1709 computePath(PI.getSUnit(), Path, DestNodes, Exclude, Visited);
1716 template <
class S1Ty,
class S2Ty>
static bool isSubset(S1Ty &Set1, S2Ty &Set2) {
1717 for (
typename S1Ty::iterator I = Set1.
begin(), E = Set1.end(); I !=
E; ++
I)
1718 if (Set2.count(*I) == 0)
1732 for (
SUnit *SU : NS) {
1737 if (MO.isReg() && MO.isUse()) {
1738 unsigned Reg = MO.getReg();
1746 for (
SUnit *SU : NS)
1748 if (MO.isReg() && MO.isDef() && !MO.isDead()) {
1749 unsigned Reg = MO.getReg();
1751 if (!Uses.
count(Reg))
1756 if (!Uses.
count(*Units))
1766 void SwingSchedulerDAG::registerPressureFilter(NodeSetType &NodeSets) {
1767 for (
auto &NS : NodeSets) {
1773 RecRPTracker.init(&MF, &RegClassInfo, &LIS, BB, BB->end(),
false,
true);
1775 RecRPTracker.closeBottom();
1777 std::vector<SUnit *> SUnits(NS.begin(), NS.end());
1782 for (
auto &SU : SUnits) {
1788 RecRPTracker.setPos(std::next(CurInstI));
1792 RecRPTracker.getMaxUpwardPressureDelta(SU->
getInstr(),
nullptr, RPDelta,
1799 NS.setExceedPressure(SU);
1802 RecRPTracker.recede();
1809 void SwingSchedulerDAG::colocateNodeSets(NodeSetType &NodeSets) {
1810 unsigned Colocate = 0;
1811 for (
int i = 0, e = NodeSets.size(); i < e; ++i) {
1814 if (N1.empty() || !
succ_L(N1, S1))
1816 for (
int j = i + 1; j < e; ++j) {
1818 if (N1.compareRecMII(N2) != 0)
1821 if (N2.empty() || !
succ_L(N2, S2))
1824 N1.setColocate(++Colocate);
1825 N2.setColocate(Colocate);
1837 void SwingSchedulerDAG::checkNodeSets(NodeSetType &NodeSets) {
1842 for (
auto &NS : NodeSets)
1847 for (
auto &SU : SUnits)
1850 DEBUG(
dbgs() <<
"Clear recurrence node-sets\n");
1857 void SwingSchedulerDAG::groupRemainingNodes(NodeSetType &NodeSets) {
1867 for (
SUnit *NI : N) {
1871 if (Path.
size() > 0)
1876 if (
succ_L(NodesAdded, N)) {
1878 for (
SUnit *NI : N) {
1882 if (Path.
size() > 0)
1892 if (
succ_L(NodesAdded, N))
1894 addConnectedNodes(I, NewSet, NodesAdded);
1895 if (NewSet.size() > 0)
1896 NodeSets.push_back(NewSet);
1901 if (
pred_L(NodesAdded, N))
1903 addConnectedNodes(I, NewSet, NodesAdded);
1904 if (NewSet.size() > 0)
1905 NodeSets.push_back(NewSet);
1909 for (
unsigned i = 0; i < SUnits.size(); ++i) {
1910 SUnit *SU = &SUnits[i];
1911 if (NodesAdded.
count(SU) == 0) {
1913 addConnectedNodes(SU, NewSet, NodesAdded);
1914 if (NewSet.size() > 0)
1915 NodeSets.push_back(NewSet);
1921 void SwingSchedulerDAG::addConnectedNodes(
SUnit *SU,
NodeSet &NewSet,
1925 for (
auto &SI : SU->
Succs) {
1927 if (!SI.isArtificial() && NodesAdded.
count(Successor) == 0)
1928 addConnectedNodes(Successor, NewSet, NodesAdded);
1930 for (
auto &PI : SU->
Preds) {
1931 SUnit *Predecessor = PI.getSUnit();
1932 if (!PI.isArtificial() && NodesAdded.
count(Predecessor) == 0)
1933 addConnectedNodes(Predecessor, NewSet, NodesAdded);
1942 for (
unsigned i = 0, e = Set1.
size(); i != e; ++i) {
1943 SUnit *SU = Set1[i];
1944 if (Set2.count(SU) != 0)
1947 return !Result.
empty();
1951 void SwingSchedulerDAG::fuseRecs(NodeSetType &NodeSets) {
1952 for (NodeSetType::iterator I = NodeSets.
begin(), E = NodeSets.end(); I !=
E;
1955 for (NodeSetType::iterator J = I + 1; J !=
E;) {
1957 if (NI.getNode(0)->NodeNum == NJ.getNode(0)->NodeNum) {
1958 if (NJ.compareRecMII(NI) > 0)
1959 NI.setRecMII(NJ.getRecMII());
1960 for (NodeSet::iterator NII = J->begin(), ENI = J->end(); NII != ENI;
1973 void SwingSchedulerDAG::removeDuplicateNodes(NodeSetType &NodeSets) {
1974 for (NodeSetType::iterator I = NodeSets.
begin(), E = NodeSets.end(); I !=
E;
1976 for (NodeSetType::iterator J = I + 1; J !=
E;) {
1977 J->remove_if([&](
SUnit *SUJ) {
return I->
count(SUJ); });
1979 if (J->size() == 0) {
1990 for (
auto &SI : Inst1->
Succs)
1991 if (SI.getSUnit() == Inst2 && SI.getKind() ==
SDep::Data)
2000 void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
2004 for (
auto &Nodes : NodeSets) {
2005 DEBUG(
dbgs() <<
"NodeSet size " << Nodes.size() <<
"\n");
2020 DEBUG(
dbgs() <<
" Top down (intersect) ");
2021 }
else if (NodeSets.size() == 1) {
2022 for (
auto &N : Nodes)
2023 if (N->Succs.
size() == 0)
2029 SUnit *maxASAP =
nullptr;
2030 for (
SUnit *SU : Nodes) {
2031 if (maxASAP ==
nullptr || getASAP(SU) >= getASAP(maxASAP))
2036 DEBUG(
dbgs() <<
" Bottom up (default) ");
2039 while (!R.
empty()) {
2040 if (Order == TopDown) {
2044 while (!R.
empty()) {
2045 SUnit *maxHeight =
nullptr;
2046 for (
SUnit *I : R) {
2047 if (maxHeight ==
nullptr || getHeight(I) > getHeight(maxHeight))
2049 else if (getHeight(I) == getHeight(maxHeight) &&
2050 getMOV(I) < getMOV(maxHeight) &&
2058 R.remove(maxHeight);
2059 for (
const auto &I : maxHeight->
Succs) {
2060 if (Nodes.count(I.getSUnit()) == 0)
2066 R.insert(I.getSUnit());
2069 for (
const auto &I : maxHeight->
Preds) {
2072 if (Nodes.count(I.getSUnit()) == 0)
2076 R.insert(I.getSUnit());
2080 DEBUG(
dbgs() <<
"\n Switching order to bottom up ");
2088 while (!R.empty()) {
2089 SUnit *maxDepth =
nullptr;
2090 for (
SUnit *I : R) {
2091 if (maxDepth ==
nullptr || getDepth(I) > getDepth(maxDepth))
2093 else if (getDepth(I) == getDepth(maxDepth) &&
2094 getMOV(I) < getMOV(maxDepth) &&
2103 if (Nodes.isExceedSU(maxDepth)) {
2106 R.insert(Nodes.getNode(0));
2109 for (
const auto &I : maxDepth->
Preds) {
2110 if (Nodes.count(I.getSUnit()) == 0)
2116 R.insert(I.getSUnit());
2119 for (
const auto &I : maxDepth->
Succs) {
2122 if (Nodes.count(I.getSUnit()) == 0)
2126 R.insert(I.getSUnit());
2130 DEBUG(
dbgs() <<
"\n Switching order to top down ");
2136 DEBUG(
dbgs() <<
"\nDone with Nodeset\n");
2140 dbgs() <<
"Node order: ";
2142 dbgs() <<
" " << I->NodeNum <<
" ";
2149 bool SwingSchedulerDAG::schedulePipeline(SMSchedule &Schedule) {
2154 bool scheduleFound =
false;
2156 for (
unsigned II = MII; II < MII + 10 && !scheduleFound; ++II) {
2158 Schedule.setInitiationInterval(II);
2159 DEBUG(
dbgs() <<
"Try to schedule with " << II <<
"\n");
2168 int EarlyStart = INT_MIN;
2169 int LateStart = INT_MAX;
2172 int SchedEnd = INT_MAX;
2173 int SchedStart = INT_MIN;
2174 Schedule.computeStart(SU, &EarlyStart, &LateStart, &SchedEnd, &SchedStart,
2182 dbgs() <<
"\tes: " << EarlyStart <<
" ls: " << LateStart
2183 <<
" me: " << SchedEnd <<
" ms: " << SchedStart <<
"\n";
2186 if (EarlyStart > LateStart || SchedEnd < EarlyStart ||
2187 SchedStart > LateStart)
2188 scheduleFound =
false;
2189 else if (EarlyStart != INT_MIN && LateStart == INT_MAX) {
2190 SchedEnd =
std::min(SchedEnd, EarlyStart + (
int)II - 1);
2191 scheduleFound = Schedule.insert(SU, EarlyStart, SchedEnd, II);
2192 }
else if (EarlyStart == INT_MIN && LateStart != INT_MAX) {
2193 SchedStart =
std::max(SchedStart, LateStart - (
int)II + 1);
2194 scheduleFound = Schedule.insert(SU, LateStart, SchedStart, II);
2195 }
else if (EarlyStart != INT_MIN && LateStart != INT_MAX) {
2202 scheduleFound = Schedule.insert(SU, SchedEnd, EarlyStart, II);
2204 scheduleFound = Schedule.insert(SU, EarlyStart, SchedEnd, II);
2206 int FirstCycle = Schedule.getFirstCycle();
2207 scheduleFound = Schedule.insert(SU, FirstCycle + getASAP(SU),
2208 FirstCycle + getASAP(SU) + II - 1, II);
2215 scheduleFound =
false;
2219 dbgs() <<
"\tCan't schedule\n";
2221 }
while (++NI != NE && scheduleFound);
2225 scheduleFound = Schedule.isValidSchedule(
this);
2228 DEBUG(
dbgs() <<
"Schedule Found? " << scheduleFound <<
"\n");
2231 Schedule.finalizeSchedule(
this);
2235 return scheduleFound && Schedule.getMaxStageCount() > 0;
2243 void SwingSchedulerDAG::generatePipelinedLoop(SMSchedule &Schedule) {
2247 unsigned MaxStageCount = Schedule.getMaxStageCount();
2253 ValueMapTy *VRMap =
new ValueMapTy[(MaxStageCount + 1) * 2];
2254 InstrMapTy InstrMap;
2258 generateProlog(Schedule, MaxStageCount, KernelBB, VRMap, PrologBBs);
2259 MF.insert(BB->getIterator(), KernelBB);
2263 for (
int Cycle = Schedule.getFirstCycle(),
2264 LastCycle = Schedule.getFinalCycle();
2265 Cycle <= LastCycle; ++Cycle) {
2266 std::deque<SUnit *> &CycleInstrs = Schedule.getInstructions(Cycle);
2268 for (
SUnit *CI : CycleInstrs) {
2269 if (CI->getInstr()->isPHI())
2271 unsigned StageNum = Schedule.stageScheduled(getSUnit(CI->getInstr()));
2272 MachineInstr *NewMI = cloneInstr(CI->getInstr(), MaxStageCount, StageNum);
2273 updateInstruction(NewMI,
false, MaxStageCount, StageNum, Schedule, VRMap);
2275 InstrMap[NewMI] = CI->getInstr();
2282 E = BB->instr_end();
2285 updateInstruction(NewMI,
false, MaxStageCount, 0, Schedule, VRMap);
2287 InstrMap[NewMI] = &*
I;
2293 generateExistingPhis(KernelBB, PrologBBs.
back(), KernelBB, KernelBB, Schedule,
2294 VRMap, InstrMap, MaxStageCount, MaxStageCount,
false);
2295 generatePhis(KernelBB, PrologBBs.
back(), KernelBB, KernelBB, Schedule, VRMap,
2296 InstrMap, MaxStageCount, MaxStageCount,
false);
2298 DEBUG(
dbgs() <<
"New block\n"; KernelBB->dump(););
2302 generateEpilog(Schedule, MaxStageCount, KernelBB, VRMap, EpilogBBs,
2307 splitLifetimes(KernelBB, EpilogBBs, Schedule);
2310 removeDeadInstructions(KernelBB, EpilogBBs);
2313 addBranches(PrologBBs, KernelBB, EpilogBBs, Schedule, VRMap);
2317 BB->eraseFromParent();
2323 void SwingSchedulerDAG::generateProlog(SMSchedule &Schedule,
unsigned LastStage,
2326 MBBVectorTy &PrologBBs) {
2328 assert(PreheaderBB != NULL &&
2329 "Need to add code to handle loops w/o preheader");
2331 InstrMapTy InstrMap;
2336 for (
unsigned i = 0; i < LastStage; ++i) {
2341 MF.insert(BB->getIterator(), NewBB);
2348 for (
int StageNum = i; StageNum >= 0; --StageNum) {
2350 BBE = BB->getFirstTerminator();
2351 BBI != BBE; ++BBI) {
2352 if (Schedule.isScheduledAtStage(getSUnit(&*BBI), (
unsigned)StageNum)) {
2356 cloneAndChangeInstr(&*BBI, i, (
unsigned)StageNum, Schedule);
2357 updateInstruction(NewMI,
false, i, (
unsigned)StageNum, Schedule,
2360 InstrMap[NewMI] = &*BBI;
2364 rewritePhiValues(NewBB, i, Schedule, VRMap, InstrMap);
2366 dbgs() <<
"prolog:\n";
2385 void SwingSchedulerDAG::generateEpilog(SMSchedule &Schedule,
unsigned LastStage,
2388 MBBVectorTy &EpilogBBs,
2389 MBBVectorTy &PrologBBs) {
2395 assert(!checkBranch &&
"generateEpilog must be able to analyze the branch");
2400 if (*LoopExitI == KernelBB)
2402 assert(LoopExitI != KernelBB->
succ_end() &&
"Expecting a successor");
2407 InstrMapTy InstrMap;
2412 int EpilogStage = LastStage + 1;
2413 for (
unsigned i = LastStage; i >= 1; --i, ++EpilogStage) {
2416 MF.insert(BB->getIterator(), NewBB);
2421 if (EpilogStart == LoopExitBB)
2422 EpilogStart = NewBB;
2426 for (
unsigned StageNum = i; StageNum <= LastStage; ++StageNum) {
2427 for (
auto &BBI : *BB) {
2431 if (Schedule.isScheduledAtStage(getSUnit(In), StageNum)) {
2432 MachineInstr *NewMI = cloneInstr(In, EpilogStage - LastStage, 0);
2433 updateInstruction(NewMI, i == 1, EpilogStage, 0, Schedule, VRMap);
2435 InstrMap[NewMI] =
In;
2439 generateExistingPhis(NewBB, PrologBBs[i - 1], PredBB, KernelBB, Schedule,
2440 VRMap, InstrMap, LastStage, EpilogStage, i == 1);
2441 generatePhis(NewBB, PrologBBs[i - 1], PredBB, KernelBB, Schedule, VRMap,
2442 InstrMap, LastStage, EpilogStage, i == 1);
2446 dbgs() <<
"epilog:\n";
2455 for (
unsigned i = 2, e = MI.
getNumOperands() + 1; i != e; i += 2) {
2467 if (EpilogBBs.size() > 0) {
2499 if (I->getParent()->getParent() != BB)
2507 void SwingSchedulerDAG::generateExistingPhis(
2510 InstrMapTy &InstrMap,
unsigned LastStageNum,
unsigned CurStageNum,
2515 unsigned PrologStage = 0;
2516 unsigned PrevStage = 0;
2517 bool InKernel = (LastStageNum == CurStageNum);
2519 PrologStage = LastStageNum - 1;
2520 PrevStage = CurStageNum;
2522 PrologStage = LastStageNum - (CurStageNum - LastStageNum);
2523 PrevStage = LastStageNum + (CurStageNum - LastStageNum) - 1;
2527 BBE = BB->getFirstNonPHI();
2528 BBI != BBE; ++BBI) {
2529 unsigned Def = BBI->getOperand(0).getReg();
2531 unsigned InitVal = 0;
2532 unsigned LoopVal = 0;
2535 unsigned PhiOp1 = 0;
2538 unsigned PhiOp2 = LoopVal;
2539 if (VRMap[LastStageNum].
count(LoopVal))
2540 PhiOp2 = VRMap[LastStageNum][LoopVal];
2542 int StageScheduled = Schedule.stageScheduled(getSUnit(&*BBI));
2544 Schedule.stageScheduled(getSUnit(
MRI.getVRegDef(LoopVal)));
2545 unsigned NumStages = Schedule.getStagesForReg(Def, CurStageNum);
2546 if (NumStages == 0) {
2549 unsigned NewReg = VRMap[PrevStage][LoopVal];
2550 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, 0, &*BBI,
2552 if (VRMap[CurStageNum].
count(LoopVal))
2553 VRMap[CurStageNum][
Def] = VRMap[CurStageNum][LoopVal];
2557 unsigned NumPhis = NumStages;
2558 if (!InKernel && (
int)PrologStage < LoopValStage)
2562 NumPhis =
std::max((
int)NumPhis - (
int)(LoopValStage - PrologStage), 1);
2565 NumPhis =
std::min(NumPhis, PrologStage + 2);
2567 unsigned NewReg = 0;
2569 unsigned AccessStage = (LoopValStage != -1) ? LoopValStage : StageScheduled;
2576 if (!InKernel && StageScheduled >= LoopValStage && AccessStage == 0 &&
2581 if (InKernel && LoopValStage != -1 && StageScheduled > LoopValStage)
2582 StageDiff = StageScheduled - LoopValStage;
2583 for (
unsigned np = 0; np < NumPhis; ++np) {
2587 if (np > PrologStage || StageScheduled >= (
int)LastStageNum)
2590 else if (PrologStage >= AccessStage + StageDiff + np &&
2591 VRMap[PrologStage - StageDiff - np].
count(LoopVal) != 0)
2592 PhiOp1 = VRMap[PrologStage - StageDiff - np][LoopVal];
2595 else if (PrologStage >= AccessStage + StageDiff + np) {
2601 while (InstOp1 && InstOp1->
isPHI() && InstOp1->
getParent() == BB) {
2602 int PhiStage = Schedule.stageScheduled(getSUnit(InstOp1));
2603 if ((
int)(PrologStage - StageDiff - np) < PhiStage + Indirects)
2607 InstOp1 =
MRI.getVRegDef(PhiOp1);
2608 int PhiOpStage = Schedule.stageScheduled(getSUnit(InstOp1));
2609 int StageAdj = (PhiOpStage != -1 ? PhiStage - PhiOpStage : 0);
2610 if (PhiOpStage != -1 && PrologStage - StageAdj >= Indirects + np &&
2611 VRMap[PrologStage - StageAdj - Indirects - np].
count(PhiOp1)) {
2612 PhiOp1 = VRMap[PrologStage - StageAdj - Indirects - np][PhiOp1];
2626 bool LoopDefIsPhi = PhiInst && PhiInst->
isPHI();
2631 int StageDiffAdj = 0;
2632 if (LoopValStage != -1 && StageScheduled > LoopValStage)
2633 StageDiffAdj = StageScheduled - LoopValStage;
2636 if (np == 0 && PrevStage == LastStageNum &&
2637 (StageScheduled != 0 || LoopValStage != 0) &&
2638 VRMap[PrevStage - StageDiffAdj].
count(LoopVal))
2639 PhiOp2 = VRMap[PrevStage - StageDiffAdj][LoopVal];
2642 else if (np > 0 && PrevStage == LastStageNum &&
2643 VRMap[PrevStage - np + 1].
count(Def))
2644 PhiOp2 = VRMap[PrevStage - np + 1][
Def];
2646 else if ((
unsigned)LoopValStage + StageDiffAdj > PrologStage + 1 &&
2647 VRMap[PrevStage - StageDiffAdj - np].
count(LoopVal))
2648 PhiOp2 = VRMap[PrevStage - StageDiffAdj - np][LoopVal];
2651 else if (VRMap[PrevStage - np].
count(Def) &&
2652 (!LoopDefIsPhi || PrevStage != LastStageNum))
2653 PhiOp2 = VRMap[PrevStage - np][
Def];
2660 if (LoopDefIsPhi && (
int)PrologStage >= StageScheduled) {
2661 int LVNumStages = Schedule.getStagesForPhi(LoopVal);
2662 int StageDiff = (StageScheduled - LoopValStage);
2663 LVNumStages -= StageDiff;
2664 if (LVNumStages > (
int)np) {
2666 unsigned ReuseStage = CurStageNum;
2667 if (Schedule.isLoopCarried(
this, *PhiInst))
2668 ReuseStage -= LVNumStages;
2671 if (VRMap[ReuseStage].
count(LoopVal)) {
2672 NewReg = VRMap[ReuseStage][LoopVal];
2674 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np,
2675 &*BBI, Def, NewReg);
2677 VRMap[CurStageNum - np][
Def] = NewReg;
2679 if (VRMap[LastStageNum - np - 1].
count(LoopVal))
2680 PhiOp2 = VRMap[LastStageNum - np - 1][LoopVal];
2682 if (IsLast && np == NumPhis - 1)
2686 }
else if (InKernel && StageDiff > 0 &&
2687 VRMap[CurStageNum - StageDiff - np].
count(LoopVal))
2688 PhiOp2 = VRMap[CurStageNum - StageDiff - np][LoopVal];
2692 NewReg =
MRI.createVirtualRegister(RC);
2696 TII->get(TargetOpcode::PHI), NewReg);
2700 InstrMap[NewPhi] = &*BBI;
2705 unsigned PrevReg = 0;
2706 if (InKernel && VRMap[PrevStage - np].
count(LoopVal))
2707 PrevReg = VRMap[PrevStage - np][LoopVal];
2708 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np, &*BBI,
2709 Def, NewReg, PrevReg);
2711 if (VRMap[CurStageNum - np].
count(Def)) {
2712 unsigned R = VRMap[CurStageNum - np][
Def];
2713 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np, &*BBI,
2720 if (IsLast && np == NumPhis - 1)
2728 VRMap[CurStageNum - np][
Def] = NewReg;
2731 while (NumPhis++ < NumStages) {
2732 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, NumPhis,
2733 &*BBI, Def, NewReg, 0);
2738 if (NumStages == 0 && IsLast && VRMap[CurStageNum].
count(LoopVal))
2746 void SwingSchedulerDAG::generatePhis(
2749 InstrMapTy &InstrMap,
unsigned LastStageNum,
unsigned CurStageNum,
2753 unsigned PrologStage = 0;
2754 unsigned PrevStage = 0;
2755 unsigned StageDiff = CurStageNum - LastStageNum;
2756 bool InKernel = (StageDiff == 0);
2758 PrologStage = LastStageNum - 1;
2759 PrevStage = CurStageNum;
2761 PrologStage = LastStageNum - StageDiff;
2762 PrevStage = LastStageNum + StageDiff - 1;
2766 BBE = BB->instr_end();
2767 BBI != BBE; ++BBI) {
2768 for (
unsigned i = 0, e = BBI->getNumOperands(); i != e; ++i) {
2774 int StageScheduled = Schedule.stageScheduled(getSUnit(&*BBI));
2775 assert(StageScheduled != -1 &&
"Expecting scheduled instruction.");
2776 unsigned Def = MO.
getReg();
2777 unsigned NumPhis = Schedule.getStagesForReg(Def, CurStageNum);
2781 if (!InKernel && NumPhis == 0 && StageScheduled == 0 &&
2784 if (!InKernel && (
unsigned)StageScheduled > PrologStage)
2787 unsigned PhiOp2 = VRMap[PrevStage][
Def];
2789 if (InstOp2->isPHI() && InstOp2->getParent() == NewBB)
2793 if (NumPhis > PrologStage + 1 - StageScheduled)
2794 NumPhis = PrologStage + 1 - StageScheduled;
2795 for (
unsigned np = 0; np < NumPhis; ++np) {
2796 unsigned PhiOp1 = VRMap[PrologStage][
Def];
2797 if (np <= PrologStage)
2798 PhiOp1 = VRMap[PrologStage - np][
Def];
2806 PhiOp2 = VRMap[PrevStage - np][
Def];
2809 unsigned NewReg =
MRI.createVirtualRegister(RC);
2813 TII->get(TargetOpcode::PHI), NewReg);
2817 InstrMap[NewPhi] = &*BBI;
2822 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np,
2823 &*BBI, PhiOp1, NewReg);
2824 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np,
2825 &*BBI, PhiOp2, NewReg);
2828 VRMap[PrevStage - np - 1][
Def] = NewReg;
2830 VRMap[CurStageNum - np][
Def] = NewReg;
2831 if (np == NumPhis - 1)
2832 rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np,
2833 &*BBI, Def, NewReg);
2835 if (IsLast && np == NumPhis - 1)
2847 MBBVectorTy &EpilogBBs) {
2850 for (MBBVectorTy::reverse_iterator MBB = EpilogBBs.
rbegin(),
2851 MBE = EpilogBBs.rend();
2854 ME = (*MBB)->instr_rend();
2871 MOI != MOE; ++MOI) {
2872 if (!MOI->isReg() || !MOI->isDef())
2874 unsigned reg = MOI->getReg();
2875 unsigned realUses = 0;
2881 if (UI->getParent()->getParent() != BB) {
2905 if (
MRI.use_begin(reg) ==
MRI.use_end()) {
2922 MBBVectorTy &EpilogBBs,
2923 SMSchedule &Schedule) {
2927 BBI != BBF; ++BBI) {
2928 unsigned Def = BBI->getOperand(0).getReg();
2932 E =
MRI.use_instr_end();
2934 if (I->isPHI() && I->getParent() == KernelBB) {
2944 unsigned SplitReg = 0;
2947 if (BBJ.readsRegister(Def)) {
2949 if (SplitReg == 0) {
2950 SplitReg =
MRI.createVirtualRegister(
MRI.getRegClass(Def));
2952 TII->get(TargetOpcode::COPY), SplitReg)
2955 BBJ.substituteRegister(Def, SplitReg, 0, *TRI);
2960 for (
auto &Epilog : EpilogBBs)
2961 for (
auto &I : *Epilog)
2962 if (I.readsRegister(Def))
2963 I.substituteRegister(Def, SplitReg, 0, *TRI);
2987 void SwingSchedulerDAG::addBranches(MBBVectorTy &PrologBBs,
2989 MBBVectorTy &EpilogBBs,
2990 SMSchedule &Schedule, ValueMapTy *VRMap) {
2991 assert(PrologBBs.size() == EpilogBBs.size() &&
"Prolog/Epilog mismatch");
3000 unsigned MaxIter = PrologBBs.
size() - 1;
3001 unsigned LC = UINT_MAX;
3002 unsigned LCMin = UINT_MAX;
3003 for (
unsigned i = 0, j = MaxIter; i <= MaxIter; ++i, --j) {
3019 if (LCMin == UINT_MAX)
3022 unsigned numAdded = 0;
3026 }
else if (j >= LCMin) {
3033 if (LastPro != LastEpi) {
3047 I != E && numAdded > 0; ++
I, --numAdded)
3048 updateInstruction(&*I,
false, j, 0, Schedule, VRMap);
3064 if (BaseDef && BaseDef->
isPHI()) {
3082 void SwingSchedulerDAG::updateMemOperands(
MachineInstr &NewMI,
3094 if (MMO->isVolatile() || (MMO->isInvariant() && MMO->isDereferenceable()) ||
3095 (!MMO->getValue())) {
3096 NewMemRefs[Refs++] = MMO;
3101 int64_t AdjOffset = Delta * Num;
3102 NewMemRefs[Refs++] =
3103 MF.getMachineMemOperand(MMO, AdjOffset, MMO->getSize());
3105 NewMemRefs[Refs++] = MF.getMachineMemOperand(MMO, 0, UINT64_MAX);
3107 NewMI.
setMemRefs(NewMemRefs, NewMemRefs + NumRefs);
3113 unsigned CurStageNum,
3114 unsigned InstStageNum) {
3127 updateMemOperands(*NewMI, *OldMI, CurStageNum - InstStageNum);
3135 unsigned CurStageNum,
3136 unsigned InstStageNum,
3137 SMSchedule &Schedule) {
3140 InstrChanges.
find(getSUnit(OldMI));
3141 if (It != InstrChanges.
end()) {
3142 std::pair<unsigned, int64_t> RegAndOffset = It->second;
3143 unsigned BasePos, OffsetPos;
3147 MachineInstr *LoopDef = findDefInLoop(RegAndOffset.first);
3148 if (Schedule.stageScheduled(getSUnit(LoopDef)) > (signed)InstStageNum)
3149 NewOffset += RegAndOffset.second * (CurStageNum - InstStageNum);
3152 updateMemOperands(*NewMI, *OldMI, CurStageNum - InstStageNum);
3158 void SwingSchedulerDAG::updateInstruction(
MachineInstr *NewMI,
bool LastDef,
3159 unsigned CurStageNum,
3160 unsigned InstrStageNum,
3161 SMSchedule &Schedule,
3162 ValueMapTy *VRMap) {
3167 unsigned reg = MO.
getReg();
3173 VRMap[CurStageNum][reg] = NewReg;
3176 }
else if (MO.
isUse()) {
3179 int DefStageNum = Schedule.stageScheduled(getSUnit(Def));
3180 unsigned StageNum = CurStageNum;
3181 if (DefStageNum != -1 && (
int)InstrStageNum > DefStageNum) {
3183 unsigned StageDiff = (InstrStageNum - DefStageNum);
3185 StageNum -= StageDiff;
3187 if (VRMap[StageNum].
count(reg))
3188 MO.
setReg(VRMap[StageNum][reg]);
3196 MachineInstr *SwingSchedulerDAG::findDefInLoop(
unsigned Reg) {
3199 while (Def->
isPHI()) {
3200 if (!Visited.
insert(Def).second)
3212 unsigned SwingSchedulerDAG::getPrevMapVal(
unsigned StageNum,
unsigned PhiStage,
3213 unsigned LoopVal,
unsigned LoopStage,
3216 unsigned PrevVal = 0;
3217 if (StageNum > PhiStage) {
3219 if (PhiStage == LoopStage && VRMap[StageNum - 1].
count(LoopVal))
3221 PrevVal = VRMap[StageNum - 1][LoopVal];
3222 else if (VRMap[StageNum].
count(LoopVal))
3225 PrevVal = VRMap[StageNum][LoopVal];
3229 else if (StageNum == PhiStage + 1)
3232 else if (StageNum > PhiStage + 1 && LoopInst->
getParent() == BB)
3235 getPrevMapVal(StageNum - 1, PhiStage,
getLoopPhiReg(*LoopInst, BB),
3236 LoopStage, VRMap, BB);
3247 SMSchedule &Schedule,
3249 InstrMapTy &InstrMap) {
3252 BBI != BBE; ++BBI) {
3253 unsigned InitVal = 0;
3254 unsigned LoopVal = 0;
3256 unsigned PhiDef = BBI->getOperand(0).getReg();
3260 unsigned LoopStage =
3262 unsigned NumPhis = Schedule.getStagesForPhi(PhiDef);
3263 if (NumPhis > StageNum)
3265 for (
unsigned np = 0; np <= NumPhis; ++np) {
3267 getPrevMapVal(StageNum - np, PhiStage, LoopVal, LoopStage, VRMap, BB);
3270 rewriteScheduledInstr(NewBB, Schedule, InstrMap, StageNum - np, np, &*BBI,
3279 void SwingSchedulerDAG::rewriteScheduledInstr(
3281 unsigned CurStageNum,
unsigned PhiNum,
MachineInstr *Phi,
unsigned OldReg,
3282 unsigned NewReg,
unsigned PrevReg) {
3283 bool InProlog = (CurStageNum < Schedule.getMaxStageCount());
3284 int StagePhi = Schedule.stageScheduled(getSUnit(Phi)) + PhiNum;
3295 if (UseMI->
isPHI()) {
3301 InstrMapTy::iterator OrigInstr = InstrMap.find(UseMI);
3302 assert(OrigInstr != InstrMap.end() &&
"Instruction not scheduled.");
3303 SUnit *OrigMISU = getSUnit(OrigInstr->second);
3304 int StageSched = Schedule.stageScheduled(OrigMISU);
3305 int CycleSched = Schedule.cycleScheduled(OrigMISU);
3306 unsigned ReplaceReg = 0;
3308 if (StagePhi == StageSched && Phi->
isPHI()) {
3309 int CyclePhi = Schedule.cycleScheduled(getSUnit(Phi));
3310 if (PrevReg && InProlog)
3311 ReplaceReg = PrevReg;
3312 else if (PrevReg && !Schedule.isLoopCarried(
this, *Phi) &&
3313 (CyclePhi <= CycleSched || OrigMISU->getInstr()->isPHI()))
3314 ReplaceReg = PrevReg;
3316 ReplaceReg = NewReg;
3320 if (!InProlog && StagePhi + 1 == StageSched &&
3321 !Schedule.isLoopCarried(
this, *Phi))
3322 ReplaceReg = NewReg;
3323 if (StagePhi > StageSched && Phi->
isPHI())
3324 ReplaceReg = NewReg;
3325 if (!InProlog && !Phi->
isPHI() && StagePhi < StageSched)
3326 ReplaceReg = NewReg;
3329 UseOp.
setReg(ReplaceReg);
3341 bool SwingSchedulerDAG::canUseLastOffsetValue(
MachineInstr *MI,
3343 unsigned &OffsetPos,
3349 unsigned BasePosLd, OffsetPosLd;
3357 if (!Phi || !Phi->
isPHI())
3366 if (!PrevDef || PrevDef == MI)
3372 unsigned BasePos1 = 0, OffsetPos1 = 0;
3379 if ((LoadOffset >= 0) != (StoreOffset >= 0))
3383 BasePos = BasePosLd;
3384 OffsetPos = OffsetPosLd;
3386 Offset = StoreOffset;
3393 SMSchedule &Schedule,
3395 SUnit *SU = getSUnit(MI);
3397 InstrChanges.
find(SU);
3398 if (It != InstrChanges.
end()) {
3399 std::pair<unsigned, int64_t> RegAndOffset = It->second;
3400 unsigned BasePos, OffsetPos;
3405 int DefStageNum = Schedule.stageScheduled(getSUnit(LoopDef));
3406 int DefCycleNum = Schedule.cycleScheduled(getSUnit(LoopDef));
3407 int BaseStageNum = Schedule.stageScheduled(SU);
3408 int BaseCycleNum = Schedule.cycleScheduled(SU);
3409 if (BaseStageNum < DefStageNum) {
3411 int OffsetDiff = DefStageNum - BaseStageNum;
3412 if (DefCycleNum < BaseCycleNum) {
3422 MISUnitMap[NewMI] = SU;
3424 NewMIs.insert(NewMI);
3434 bool SwingSchedulerDAG::isLoopCarriedOrder(
SUnit *Source,
const SDep &Dep,
3446 assert(SI !=
nullptr && DI !=
nullptr &&
"Expecting SUnit with an MI.");
3457 unsigned DeltaS, DeltaD;
3461 unsigned BaseRegS, BaseRegD;
3462 int64_t OffsetS, OffsetD;
3468 if (BaseRegS != BaseRegD)
3476 if (OffsetS >= OffsetD)
3477 return OffsetS + AccessSizeS > DeltaS;
3479 return OffsetD + AccessSizeD > DeltaD;
3484 void SwingSchedulerDAG::postprocessDAG() {
3485 for (
auto &M : Mutations)
3494 bool SMSchedule::insert(
SUnit *SU,
int StartCycle,
int EndCycle,
int II) {
3495 bool forward =
true;
3496 if (StartCycle > EndCycle)
3500 int termCycle = forward ? EndCycle + 1 : EndCycle - 1;
3501 for (
int curCycle = StartCycle; curCycle != termCycle;
3502 forward ? ++curCycle : --curCycle) {
3505 Resources->clearResources();
3506 for (
int checkCycle = FirstCycle + ((curCycle - FirstCycle) % II);
3507 checkCycle <= LastCycle; checkCycle += II) {
3508 std::deque<SUnit *> &cycleInstrs = ScheduledInstrs[checkCycle];
3510 for (std::deque<SUnit *>::iterator I = cycleInstrs.
begin(),
3511 E = cycleInstrs.end();
3515 assert(Resources->canReserveResources(*(*I)->getInstr()) &&
3516 "These instructions have already been scheduled.");
3517 Resources->reserveResources(*(*I)->getInstr());
3521 Resources->canReserveResources(*SU->
getInstr())) {
3523 dbgs() <<
"\tinsert at cycle " << curCycle <<
" ";
3527 ScheduledInstrs[curCycle].push_back(SU);
3528 InstrToCycle.insert(std::make_pair(SU, curCycle));
3529 if (curCycle > LastCycle)
3530 LastCycle = curCycle;
3531 if (curCycle < FirstCycle)
3532 FirstCycle = curCycle;
3536 dbgs() <<
"\tfailed to insert at cycle " << curCycle <<
" ";
3544 int SMSchedule::earliestCycleInChain(
const SDep &Dep) {
3548 int EarlyCycle = INT_MAX;
3549 while (!Worklist.
empty()) {
3552 if (Visited.
count(PrevSU))
3554 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(PrevSU);
3555 if (it == InstrToCycle.end())
3557 EarlyCycle =
std::min(EarlyCycle, it->second);
3558 for (
const auto &PI : PrevSU->
Preds)
3559 if (SwingSchedulerDAG::isOrder(PrevSU, PI))
3567 int SMSchedule::latestCycleInChain(
const SDep &Dep) {
3571 int LateCycle = INT_MIN;
3572 while (!Worklist.
empty()) {
3575 if (Visited.
count(SuccSU))
3577 std::map<SUnit *, int>::const_iterator it = InstrToCycle.find(SuccSU);
3578 if (it == InstrToCycle.end())
3580 LateCycle =
std::max(LateCycle, it->second);
3581 for (
const auto &SI : SuccSU->
Succs)
3582 if (SwingSchedulerDAG::isOrder(SuccSU, SI))
3593 for (
auto &P : SU->
Preds)
3594 if (DAG->isBackedge(SU, P) && P.getSUnit()->getInstr()->isPHI())
3595 for (
auto &S : P.getSUnit()->Succs)
3596 if (S.getKind() ==
SDep::Order && S.getSUnit()->getInstr()->isPHI())
3597 return P.getSUnit();
3603 void SMSchedule::computeStart(
SUnit *SU,
int *MaxEarlyStart,
int *MinLateStart,
3604 int *MinEnd,
int *MaxStart,
int II,
3605 SwingSchedulerDAG *DAG) {
3609 for (
int cycle = getFirstCycle(); cycle <= LastCycle; ++cycle) {
3612 for (
SUnit *I : getInstructions(cycle)) {
3615 for (
unsigned i = 0, e = (
unsigned)SU->
Preds.size(); i != e; ++i) {
3618 if (!DAG->isBackedge(SU, Dep)) {
3619 int EarlyStart = cycle + DAG->getLatency(SU, Dep) -
3620 DAG->getDistance(Dep.
getSUnit(), SU, Dep) * II;
3621 *MaxEarlyStart =
std::max(*MaxEarlyStart, EarlyStart);
3622 if (DAG->isLoopCarriedOrder(SU, Dep,
false)) {
3623 int End = earliestCycleInChain(Dep) + (II - 1);
3627 int LateStart = cycle - DAG->getLatency(SU, Dep) +
3628 DAG->getDistance(SU, Dep.
getSUnit(), Dep) * II;
3629 *MinLateStart =
std::min(*MinLateStart, LateStart);
3637 *MinLateStart =
std::min(*MinLateStart, cycle);
3639 for (
unsigned i = 0, e = (
unsigned)SU->
Succs.size(); i != e; ++i)
3640 if (SU->
Succs[i].getSUnit() ==
I) {
3642 if (!DAG->isBackedge(SU, Dep)) {
3643 int LateStart = cycle - DAG->getLatency(SU, Dep) +
3644 DAG->getDistance(SU, Dep.
getSUnit(), Dep) * II;
3645 *MinLateStart =
std::min(*MinLateStart, LateStart);
3646 if (DAG->isLoopCarriedOrder(SU, Dep)) {
3647 int Start = latestCycleInChain(Dep) + 1 - II;
3648 *MaxStart =
std::max(*MaxStart, Start);
3651 int EarlyStart = cycle + DAG->getLatency(SU, Dep) -
3652 DAG->getDistance(Dep.
getSUnit(), SU, Dep) * II;
3653 *MaxEarlyStart =
std::max(*MaxEarlyStart, EarlyStart);
3663 bool SMSchedule::orderDependence(SwingSchedulerDAG *SSD,
SUnit *SU,
3664 std::deque<SUnit *> &Insts) {
3666 bool OrderBeforeUse =
false;
3667 bool OrderAfterDef =
false;
3668 bool OrderBeforeDef =
false;
3669 unsigned MoveDef = 0;
3670 unsigned MoveUse = 0;
3671 int StageInst1 = stageScheduled(SU);
3674 for (std::deque<SUnit *>::iterator I = Insts.
begin(), E = Insts.end(); I !=
E;
3677 if (MI->
isPHI() && (*I)->getInstr()->isPHI())
3683 unsigned Reg = MO.
getReg();
3684 unsigned BasePos, OffsetPos;
3687 if (
unsigned NewReg = SSD->getInstrBaseReg(SU))
3690 std::tie(Reads, Writes) =
3691 (*I)->getInstr()->readsWritesVirtualRegister(Reg);
3692 if (MO.
isDef() && Reads && stageScheduled(*I) <= StageInst1) {
3693 OrderBeforeUse =
true;
3695 }
else if (MO.
isDef() && Reads && stageScheduled(*I) > StageInst1) {
3697 OrderAfterDef =
true;
3699 }
else if (MO.
isUse() && Writes && stageScheduled(*I) == StageInst1) {
3700 if (cycleScheduled(*I) == cycleScheduled(SU) && !(*I)->isSucc(SU)) {
3701 OrderBeforeUse =
true;
3704 OrderAfterDef =
true;
3707 }
else if (MO.
isUse() && Writes && stageScheduled(*I) > StageInst1) {
3708 OrderBeforeUse =
true;
3711 OrderAfterDef =
true;
3714 }
else if (MO.
isUse() && Writes && stageScheduled(*I) < StageInst1) {
3716 OrderBeforeUse =
true;
3718 }
else if (MO.
isUse() && stageScheduled(*I) == StageInst1 &&
3719 isLoopCarriedDefOfUse(SSD, (*I)->getInstr(), MO)) {
3720 OrderBeforeDef =
true;
3726 for (
auto &S : SU->
Succs)
3728 if (S.getSUnit() == *I && stageScheduled(*I) == StageInst1) {
3729 OrderBeforeUse =
true;
3733 if (cycleScheduled(SU) != cycleScheduled(S.getSUnit())) {
3734 if (S.isAssignedRegDep()) {
3735 OrderAfterDef =
true;
3739 OrderBeforeUse =
true;
3743 for (
auto &P : SU->
Preds)
3745 if (P.getSUnit() == *I && stageScheduled(*I) == StageInst1) {
3746 OrderAfterDef =
true;
3750 if (cycleScheduled(SU) != cycleScheduled(P.getSUnit())) {
3751 if (P.isAssignedRegDep()) {
3752 OrderBeforeUse =
true;
3756 OrderAfterDef =
true;
3763 if (OrderAfterDef && OrderBeforeUse && MoveUse == MoveDef)
3764 OrderBeforeUse =
false;
3769 OrderBeforeUse = !OrderAfterDef || (MoveUse > MoveDef);
3773 if (OrderBeforeUse && OrderAfterDef) {
3774 SUnit *UseSU = Insts.at(MoveUse);
3775 SUnit *DefSU = Insts.at(MoveDef);
3776 if (MoveUse > MoveDef) {
3777 Insts.erase(Insts.begin() + MoveUse);
3778 Insts.erase(Insts.begin() + MoveDef);
3780 Insts.erase(Insts.begin() + MoveDef);
3781 Insts.erase(Insts.begin() + MoveUse);
3783 if (orderDependence(SSD, UseSU, Insts)) {
3784 Insts.push_front(SU);
3785 orderDependence(SSD, DefSU, Insts);
3789 Insts.push_back(SU);
3790 Insts.push_back(UseSU);
3791 orderDependence(SSD, DefSU, Insts);
3797 Insts.push_front(SU);
3799 Insts.push_back(SU);
3800 return OrderBeforeUse;
3804 bool SMSchedule::isLoopCarried(SwingSchedulerDAG *SSD,
MachineInstr &Phi) {
3808 SUnit *DefSU = SSD->getSUnit(&Phi);
3809 unsigned DefCycle = cycleScheduled(DefSU);
3810 int DefStage = stageScheduled(DefSU);
3812 unsigned InitVal = 0;
3813 unsigned LoopVal = 0;
3818 if (UseSU->getInstr()->isPHI())
3820 unsigned LoopCycle = cycleScheduled(UseSU);
3821 int LoopStage = stageScheduled(UseSU);
3822 return (LoopCycle > DefCycle) || (LoopStage <= DefStage);
3832 bool SMSchedule::isLoopCarriedDefOfUse(SwingSchedulerDAG *SSD,
3841 if (!isLoopCarried(SSD, *Phi))
3848 if (DMO.
getReg() == LoopReg)
3858 bool SMSchedule::isValidSchedule(SwingSchedulerDAG *SSD) {
3859 for (
int i = 0, e = SSD->SUnits.size(); i < e; ++i) {
3860 SUnit &SU = SSD->SUnits[i];
3863 int StageDef = stageScheduled(&SU);
3864 assert(StageDef != -1 &&
"Instruction should have been scheduled.");
3865 for (
auto &SI : SU.
Succs)
3866 if (SI.isAssignedRegDep())
3868 if (stageScheduled(SI.getSUnit()) != StageDef)
3877 void SMSchedule::finalizeSchedule(SwingSchedulerDAG *SSD) {
3879 for (
int cycle = getFirstCycle(); cycle <= getFinalCycle(); ++cycle) {
3880 for (
int stage = 1, lastStage = getMaxStageCount(); stage <= lastStage;
3882 std::deque<SUnit *> &cycleInstrs =
3883 ScheduledInstrs[cycle + (stage * InitiationInterval)];
3884 for (std::deque<SUnit *>::reverse_iterator I = cycleInstrs.
rbegin(),
3885 E = cycleInstrs.rend();
3887 ScheduledInstrs[cycle].push_front(*I);
3892 for (
auto &I : InstrToCycle) {
3893 int DefStage = stageScheduled(I.first);
3900 unsigned Reg = Op.
getReg();
3901 unsigned MaxDiff = 0;
3902 bool PhiIsSwapped =
false;
3908 SUnit *SUnitUse = SSD->getSUnit(UseMI);
3909 int UseStage = stageScheduled(SUnitUse);
3911 if (UseStage != -1 && UseStage >= DefStage)
3912 Diff = UseStage - DefStage;
3914 if (isLoopCarried(SSD, *MI))
3917 PhiIsSwapped =
true;
3921 RegToStageDiff[
Reg] = std::make_pair(MaxDiff, PhiIsSwapped);
3927 for (
int cycle = getFinalCycle() + 1; cycle <= LastCycle; ++cycle)
3928 ScheduledInstrs.erase(cycle);
3932 for (
int i = 0, e = SSD->SUnits.size(); i != e; ++i) {
3933 SUnit *SU = &SSD->SUnits[i];
3934 SSD->applyInstrChange(SU->
getInstr(), *
this,
true);
3939 for (
int Cycle = getFirstCycle(), E = getFinalCycle(); Cycle <=
E; ++Cycle) {
3940 std::deque<SUnit *> &cycleInstrs = ScheduledInstrs[Cycle];
3941 std::deque<SUnit *> newOrderZC;
3943 for (
unsigned i = 0, e = cycleInstrs.size(); i < e; ++i) {
3944 SUnit *SU = cycleInstrs[i];
3946 orderDependence(SSD, SU, newOrderZC);
3948 std::deque<SUnit *> newOrderI;
3950 for (
unsigned i = 0, e = cycleInstrs.size(); i < e; ++i) {
3951 SUnit *SU = cycleInstrs[i];
3953 orderDependence(SSD, SU, newOrderI);
3956 cycleInstrs.swap(newOrderZC);
3957 cycleInstrs.insert(cycleInstrs.end(), newOrderI.begin(), newOrderI.end());
3966 for (
int cycle = getFirstCycle(); cycle <= getFinalCycle(); ++cycle) {
3968 const_sched_iterator cycleInstrs = ScheduledInstrs.find(cycle);
3969 for (
SUnit *CI : cycleInstrs->second) {
3970 os <<
"cycle " << cycle <<
" (" << stageScheduled(CI) <<
") ";
3971 os <<
"(" << CI->
NodeNum <<
") ";
3978 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Pass interface - Implemented by all 'passes'.
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
std::vector< int >::const_reverse_iterator const_reverse_iterator
A parsed version of the target data layout string in and methods for querying it. ...
const_iterator end(StringRef path)
Get end iterator over path.
static cl::opt< bool > SwpIgnoreRecMII("pipeliner-ignore-recmii", cl::ReallyHidden, cl::init(false), cl::ZeroOrMore, cl::desc("Ignore RecMII"))
virtual void finishBlock()
Cleans up after scheduling in the given block.
mop_iterator operands_end()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
instr_iterator instr_begin()
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
static cl::opt< bool > SwpPruneDeps("pipeliner-prune-deps", cl::desc("Prune dependences between unrelated Phi nodes."), cl::Hidden, cl::init(true))
A command line option to disable the pruning of chain dependences due to an unrelated Phi...
static void computeLiveOuts(MachineFunction &MF, RegPressureTracker &RPTracker, NodeSet &NS)
Compute the live-out registers for the instructions in a node-set.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
instr_iterator instr_end()
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
MachineBasicBlock * getMBB() const
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &STI) const override
Create machine specific model for scheduling.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
INITIALIZE_PASS_BEGIN(MachinePipeliner, DEBUG_TYPE,"Modulo Software Pipelining", false, false) INITIALIZE_PASS_END(MachinePipeliner
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
bool operator>(int64_t V1, const APSInt &V2)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
bool hasOrderedMemoryRef() const
Return true if this instruction may have an ordered or volatile memory reference, or if the informati...
static cl::opt< bool > EnableSWPOptSize("enable-pipeliner-opt-size", cl::desc("Enable SWP at Os."), cl::Hidden, cl::init(false))
A command line option to enable SWP at -Os.
static void getPhiRegs(MachineInstr &Phi, MachineBasicBlock *Loop, unsigned &InitVal, unsigned &LoopVal)
Return the register values for the operands of a Phi instruction.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
This class implements a map that also provides access to all stored values in a deterministic order...
static void dump(StringRef Title, SpillInfo const &Spills)
The two locations do not alias at all.
static bool computePath(SUnit *Cur, SetVector< SUnit * > &Path, SetVector< SUnit * > &DestNodes, SetVector< SUnit * > &Exclude, SmallPtrSet< SUnit *, 8 > &Visited)
Return true if there is a path from the specified node to any of the nodes in DestNodes.
void removePred(const SDep &D)
Removes the specified edge as a pred of the current node if it exists.
void GetUnderlyingObjects(Value *V, SmallVectorImpl< Value * > &Objects, const DataLayout &DL, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to GetUnderlyingObject except that it can look through phi and select instruct...
iterator_range< mmo_iterator > memoperands()
void print(raw_ostream &OS, bool SkipOpers=false, bool SkipDebugLoc=false, const TargetInstrInfo *TII=nullptr) const
Debugging supportPrint this MI to OS.
iterator_range< mop_iterator > operands()
iterator end()
Get an iterator to the end of the SetVector.
const std::vector< BlockT * > & getBlocks() const
Get a list of the basic blocks which make up this loop.
SmallVectorImpl< SDep >::iterator succ_iterator
size_type size() const
Determine the number of elements in the SetVector.
bool isArtificial() const
Tests if this is an Order dependence that is marked as "artificial", meaning it isn't necessary for...
BlockT * getHeader() const
SmallVector< SDep, 4 > Preds
All sunit predecessors.
A register anti-dependence (aka WAR).
bool isDereferenceableInvariantLoad(AliasAnalysis *AA) const
Return true if this load instruction never traps and points to a memory location whose value doesn't ...
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e...
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
A description of a memory reference used in the backend.
static use_iterator use_end()
SmallVectorImpl< SDep >::iterator pred_iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static bool isDependenceBarrier(MachineInstr &MI, AliasAnalysis *AA)
Return true if the instruction causes a chain between memory references before and after it...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
Kind getKind() const
Returns an enum value representing the kind of the dependence.
void setInstr(MachineInstr *MI)
Assigns the instruction for the SUnit.
static cl::opt< int > SwpMaxMii("pipeliner-max-mii", cl::desc("Size limit for the the MII."), cl::Hidden, cl::init(27))
A command line argument to limit minimum initial interval for pipelining.
SmallVectorImpl< SDep >::const_iterator const_pred_iterator
Modulo Software Pipelining
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Regular data dependence (aka true-dependence).
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
This file contains the simple types necessary to represent the attributes associated with functions a...
bool hasPhysRegDefs
Has physreg defs that are being used.
friend const_iterator begin(StringRef path, Style style)
Get begin iterator over path.
bool isPred(const SUnit *N) const
Tests if node N is a predecessor of this node.
LLVM_NODISCARD bool empty() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
static bool ignoreDependence(const SDep &D, bool isPred)
Return true for DAG nodes that we ignore when computing the cost functions.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
bool insert(const value_type &X)
Insert a new element into the SetVector.
virtual bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const
Return true if the instruction contains a base register and offset.
static void swapAntiDependences(std::vector< SUnit > &SUnits)
Swap all the anti dependences in the DAG.
static bool isSubset(S1Ty &Set1, S2Ty &Set2)
Return true if Set1 is a subset of Set2.
void dump(const ScheduleDAG *G) const
iterator begin()
Get an iterator to the beginning of the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Instructions::reverse_iterator reverse_instr_iterator
virtual void adjustSchedDependency(SUnit *def, SUnit *use, SDep &dep) const
Itinerary data supplied by a subtarget to be used by a target.
static cl::opt< bool > EnableSWP("enable-pipeliner", cl::Hidden, cl::init(true), cl::ZeroOrMore, cl::desc("Enable Software Pipelining"))
A command line option to turn software pipelining on or off.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
iterator find(const KeyT &Key)
static int getLatency(LLVMDisasmContext *DC, const MCInst &Inst)
Gets latency information for Inst, based on DC information.
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
reverse_iterator rbegin()
static void getUnderlyingObjects(MachineInstr *MI, SmallVectorImpl< Value * > &Objs, const DataLayout &DL)
Return the underlying objects for the memory references of an instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
static void removePhis(MachineBasicBlock *BB, MachineBasicBlock *Incoming)
Remove the incoming block from the Phis in a basic block.
mmo_iterator memoperands_end() const
static unsigned getInitPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB)
Return the Phi register value that comes from the incoming block.
void addLiveRegs(ArrayRef< RegisterMaskPair > Regs)
Force liveness of virtual registers or physical register units.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
friend const_iterator end(StringRef path)
Get end iterator over path.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
unsigned const MachineRegisterInfo * MRI
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
static bool hasUseAfterLoop(unsigned Reg, MachineBasicBlock *BB, MachineRegisterInfo &MRI)
Return true if the register has a use that occurs outside the specified loop.
bool getIncrementValue(const MachineInstr &MI, int &Value) const override
If the instruction is an increment of a constant value, return the amount.
unsigned short Latency
Node latency.
AAMDNodes getAAInfo() const
Return the AA tags for the memory reference.
static bool pred_L(SetVector< SUnit * > &NodeOrder, SmallSetVector< SUnit *, 8 > &Preds, const NodeSet *S=nullptr)
Compute the Pred_L(O) set, as defined in the paper.
MachineInstrBuilder & UseMI
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static int64_t computeDelta(SectionEntry *A, SectionEntry *B)
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
bool getBaseAndOffsetPosition(const MachineInstr &MI, unsigned &BasePos, unsigned &OffsetPos) const override
For instructions with a base and offset, return the position of the base register and offset operands...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx=nullptr) const
Given the index of a register def operand, check if the register def is tied to a source operand...
static bool isIntersect(SmallSetVector< SUnit *, 8 > &Set1, const NodeSet &Set2, SmallSetVector< SUnit *, 8 > &Result)
Return true if Set1 contains elements in Set2.
void setMBB(MachineBasicBlock *MBB)
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
unsigned getLatency() const
Returns the latency value for this edge, which roughly means the minimum number of cycles that must e...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static const unsigned End
Track the current register pressure at some position in the instruction stream, and remember the high...
void setImm(int64_t immVal)
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
LLVM_NODISCARD bool empty() const
succ_iterator succ_begin()
bool isZeroCost(unsigned Opcode) const
Return true for pseudo instructions that don't consume any machine resources in their current form...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Any other ordering dependency.
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
typename vector_type::const_iterator const_iterator
static void replaceRegUsesAfterLoop(unsigned FromReg, unsigned ToReg, MachineBasicBlock *MBB, MachineRegisterInfo &MRI, LiveIntervals &LIS)
Replace all uses of FromReg that appear outside the specified basic block with ToReg.
An unknown scheduling barrier.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
Representation for a specific memory location.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
unsigned reduceLoopCount(MachineBasicBlock &MBB, MachineInstr *IndVar, MachineInstr &Cmp, SmallVectorImpl< MachineOperand > &Cond, SmallVectorImpl< MachineInstr * > &PrevInsts, unsigned Iter, unsigned MaxIter) const override
Generate code to reduce the loop iteration by one and check if the loop is finished.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
typename vector_type::const_iterator iterator
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A SetVector that performs no allocations if smaller than a certain size.
print lazy value Lazy Value Info Printer Pass
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
unsigned countPopulation(T Value)
Count the number of set bits in a value.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
reverse_instr_iterator instr_rbegin()
static cl::opt< int > SwpLoopLimit("pipeliner-max", cl::Hidden, cl::init(-1))
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
static cl::opt< int > SwpMaxStages("pipeliner-max-stages", cl::desc("Maximum stages allowed in the generated scheduled."), cl::Hidden, cl::init(3))
A command line argument to limit the number of stages in the pipeline.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static LaneBitmask getNone()
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool canReserveResources(const MCInstrDesc *MID)
static bool succ_L(SetVector< SUnit * > &NodeOrder, SmallSetVector< SUnit *, 8 > &Succs, const NodeSet *S=nullptr)
Compute the Succ_L(O) set, as defined in the paper.
char & MachinePipelinerID
This pass performs software pipelining on machine instructions.
LLVM_NODISCARD T pop_back_val()
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const override
Insert branch code into the end of the specified MachineBasicBlock.
reverse_iterator rbegin()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool isSuccOrder(SUnit *SUa, SUnit *SUb)
Return true if SUb can be reached from SUa following the chain edges.
reverse_instr_iterator instr_rend()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
std::vector< int >::const_iterator const_iterator
void clear()
Completely clear the SetVector.
size_type count(const KeyT &Key) const
const Value * getValue() const
Return the base address of the memory access.
static bool hasDataDependence(SUnit *Inst1, SUnit *Inst2)
Return true if Inst1 defines a value that is used in Inst2.
std::set< NodeId > NodeSet
static SUnit * multipleIterations(SUnit *SU, SwingSchedulerDAG *DAG)
If an instruction has a use that spans multiple iterations, then return true.
typename SuperClass::iterator iterator
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const override
Remove the branching code at the end of the specific MBB.
SmallVectorImpl< SDep >::const_iterator const_succ_iterator
LiveInterval & createEmptyInterval(unsigned Reg)
Interval creation.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static void clear(coro::Shape &Shape)
bool isBoundaryNode() const
Boundary nodes are placeholders for the boundary of the scheduling region.
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
void setLatency(unsigned Lat)
Sets the latency for this edge.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
void initializeMachinePipelinerPass(PassRegistry &)
TargetSubtargetInfo - Generic base class for all target subtargets.
bool operator!=(uint64_t V1, const APInt &V2)
A ScheduleDAG for scheduling lists of MachineInstr.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
unsigned getSchedClass() const
Return the scheduling class for this instruction.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getNumBlocks() const
Get the number of blocks in this loop in constant time.
These values represent a non-pipelined step in the execution of an instruction.
Represents a single loop in the control flow graph.
use_iterator use_begin(unsigned RegNo) const
This file provides utility analysis objects describing memory locations.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
void push_back(MachineInstr *MI)
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool hasInterval(unsigned Reg) const
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Instructions::iterator instr_iterator
unsigned NodeNum
Entry # of node in the node vector.
unsigned getReg() const
getReg - Returns the register number.
Store the effects of a change in pressure on things that MI scheduler cares about.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
virtual const TargetInstrInfo * getInstrInfo() const
mop_iterator operands_begin()
int64_t getOffset() const
For normal values, this is a byte offset added to the base address.
A vector that has set insertion semantics.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
SmallVector< SDep, 4 > Succs
All sunit successors.
This class implements an extremely fast bulk output stream that can only output to a stream...
static cl::opt< bool > SwpPruneLoopCarried("pipeliner-prune-loop-carried", cl::desc("Prune loop carried order dependences."), cl::Hidden, cl::init(true))
A command line option to disable the pruning of loop carried order dependences.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
bool operator==(uint64_t V1, const APInt &V2)
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
bool getMemOpBaseRegImmOfs(MachineInstr &LdSt, unsigned &BaseReg, int64_t &Offset, const TargetRegisterInfo *TRI) const override
Get the base register and byte offset of a load/store instr.
PriorityQueue - This class behaves like std::priority_queue and provides a few additional convenience...
unsigned getReg() const
Returns the register associated with this edge.
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
bool analyzeLoop(MachineLoop &L, MachineInstr *&IndVarInst, MachineInstr *&CmpInst) const override
Analyze the loop code, return true if it cannot be understood.
static unsigned getLoopPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB)
Return the Phi register value that comes the the loop block.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd)
Assign this MachineInstr's memory reference descriptor list.
bool areMemAccessesTriviallyDisjoint(MachineInstr &MIa, MachineInstr &MIb, AliasAnalysis *AA=nullptr) const override
std::vector< MachineBasicBlock * >::iterator succ_iterator
Scheduling unit. This is a node in the scheduling DAG.
void reserveResources(const MCInstrDesc *MID)
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.