22 #define DEBUG_TYPE "pipeliner" 37 unsigned &InitVal,
unsigned &LoopVal) {
48 assert(InitVal != 0 && LoopVal != 0 &&
"Unexpected Phi structure.");
68 BB = Schedule.getLoop()->getTopBlock();
69 Preheader = *BB->pred_begin();
71 Preheader = *std::next(BB->pred_begin());
76 int DefStage = Schedule.getStage(
MI);
77 for (
unsigned i = 0,
e =
MI->getNumOperands(); i <
e; ++i) {
84 bool PhiIsSwapped =
false;
90 int UseStage = Schedule.getStage(UseMI);
92 if (UseStage != -1 && UseStage >= DefStage)
93 Diff = UseStage - DefStage;
95 if (isLoopCarried(*
MI))
102 RegToStageDiff[
Reg] = std::make_pair(MaxDiff, PhiIsSwapped);
106 generatePipelinedLoop();
109 void ModuloScheduleExpander::generatePipelinedLoop() {
116 unsigned MaxStageCount = Schedule.getNumStages() - 1;
128 generateProlog(MaxStageCount, KernelBB, VRMap, PrologBBs);
129 MF.insert(BB->getIterator(), KernelBB);
136 unsigned StageNum = Schedule.getStage(CI);
137 MachineInstr *NewMI = cloneInstr(CI, MaxStageCount, StageNum);
138 updateInstruction(NewMI,
false, MaxStageCount, StageNum, VRMap);
140 InstrMap[NewMI] = CI;
149 updateInstruction(NewMI,
false, MaxStageCount, 0, VRMap);
151 InstrMap[NewMI] = &*
I;
154 NewKernel = KernelBB;
158 generateExistingPhis(KernelBB, PrologBBs.
back(), KernelBB, KernelBB, VRMap,
159 InstrMap, MaxStageCount, MaxStageCount,
false);
160 generatePhis(KernelBB, PrologBBs.
back(), KernelBB, KernelBB, VRMap, InstrMap,
161 MaxStageCount, MaxStageCount,
false);
167 generateEpilog(MaxStageCount, KernelBB, VRMap, EpilogBBs, PrologBBs);
171 splitLifetimes(KernelBB, EpilogBBs);
174 removeDeadInstructions(KernelBB, EpilogBBs);
177 addBranches(*Preheader, PrologBBs, KernelBB, EpilogBBs, VRMap);
185 LIS.RemoveMachineInstrFromMaps(
I);
187 BB->eraseFromParent();
191 void ModuloScheduleExpander::generateProlog(
unsigned LastStage,
201 for (
unsigned i = 0; i < LastStage; ++i) {
206 MF.insert(BB->getIterator(), NewBB);
213 for (
int StageNum = i; StageNum >= 0; --StageNum) {
215 BBE = BB->getFirstTerminator();
217 if (Schedule.getStage(&*BBI) == StageNum) {
221 cloneAndChangeInstr(&*BBI, i, (
unsigned)StageNum);
222 updateInstruction(NewMI,
false, i, (
unsigned)StageNum, VRMap);
224 InstrMap[NewMI] = &*BBI;
228 rewritePhiValues(NewBB, i, VRMap, InstrMap);
230 dbgs() <<
"prolog:\n";
249 void ModuloScheduleExpander::generateEpilog(
unsigned LastStage,
259 assert(!checkBranch &&
"generateEpilog must be able to analyze the branch");
264 if (*LoopExitI == KernelBB)
266 assert(LoopExitI != KernelBB->
succ_end() &&
"Expecting a successor");
276 int EpilogStage = LastStage + 1;
277 for (
unsigned i = LastStage; i >= 1; --i, ++EpilogStage) {
280 MF.insert(BB->getIterator(), NewBB);
285 if (EpilogStart == LoopExitBB)
290 for (
unsigned StageNum = i; StageNum <= LastStage; ++StageNum) {
291 for (
auto &BBI : *BB) {
295 if ((
unsigned)Schedule.getStage(In) == StageNum) {
299 updateInstruction(NewMI, i == 1, EpilogStage, 0, VRMap);
301 InstrMap[NewMI] =
In;
305 generateExistingPhis(NewBB, PrologBBs[i - 1], PredBB, KernelBB, VRMap,
306 InstrMap, LastStage, EpilogStage, i == 1);
307 generatePhis(NewBB, PrologBBs[i - 1], PredBB, KernelBB, VRMap, InstrMap,
308 LastStage, EpilogStage, i == 1);
312 dbgs() <<
"epilog:\n";
318 LoopExitBB->replacePhiUsesWith(BB, PredBB);
325 if (EpilogBBs.
size() > 0) {
357 if (
I->getParent()->getParent() != BB)
365 void ModuloScheduleExpander::generateExistingPhis(
368 unsigned LastStageNum,
unsigned CurStageNum,
bool IsLast) {
372 unsigned PrologStage = 0;
373 unsigned PrevStage = 0;
374 bool InKernel = (LastStageNum == CurStageNum);
376 PrologStage = LastStageNum - 1;
377 PrevStage = CurStageNum;
379 PrologStage = LastStageNum - (CurStageNum - LastStageNum);
380 PrevStage = LastStageNum + (CurStageNum - LastStageNum) - 1;
384 BBE = BB->getFirstNonPHI();
388 unsigned InitVal = 0;
389 unsigned LoopVal = 0;
395 unsigned PhiOp2 = LoopVal;
396 if (VRMap[LastStageNum].
count(LoopVal))
397 PhiOp2 = VRMap[LastStageNum][LoopVal];
399 int StageScheduled = Schedule.getStage(&*BBI);
400 int LoopValStage = Schedule.getStage(
MRI.getVRegDef(LoopVal));
401 unsigned NumStages = getStagesForReg(Def, CurStageNum);
402 if (NumStages == 0) {
405 unsigned NewReg = VRMap[PrevStage][LoopVal];
406 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, 0, &*BBI, Def,
408 if (VRMap[CurStageNum].
count(LoopVal))
409 VRMap[CurStageNum][
Def] = VRMap[CurStageNum][LoopVal];
415 unsigned MaxPhis = PrologStage + 2;
416 if (!InKernel && (
int)PrologStage <= LoopValStage)
417 MaxPhis =
std::max((
int)MaxPhis - (
int)LoopValStage, 1);
418 unsigned NumPhis = std::min(NumStages, MaxPhis);
421 unsigned AccessStage = (LoopValStage != -1) ? LoopValStage : StageScheduled;
428 if (!InKernel && StageScheduled >= LoopValStage && AccessStage == 0 &&
433 if (InKernel && LoopValStage != -1 && StageScheduled > LoopValStage)
434 StageDiff = StageScheduled - LoopValStage;
435 for (
unsigned np = 0; np < NumPhis; ++np) {
439 if (np > PrologStage || StageScheduled >= (
int)LastStageNum)
442 else if (PrologStage >= AccessStage + StageDiff + np &&
443 VRMap[PrologStage - StageDiff - np].
count(LoopVal) != 0)
444 PhiOp1 = VRMap[PrologStage - StageDiff - np][LoopVal];
447 else if (PrologStage >= AccessStage + StageDiff + np) {
453 while (InstOp1 && InstOp1->
isPHI() && InstOp1->
getParent() == BB) {
454 int PhiStage = Schedule.getStage(InstOp1);
455 if ((
int)(PrologStage - StageDiff - np) < PhiStage + Indirects)
459 InstOp1 =
MRI.getVRegDef(PhiOp1);
460 int PhiOpStage = Schedule.getStage(InstOp1);
461 int StageAdj = (PhiOpStage != -1 ? PhiStage - PhiOpStage : 0);
462 if (PhiOpStage != -1 && PrologStage - StageAdj >= Indirects + np &&
463 VRMap[PrologStage - StageAdj - Indirects - np].
count(PhiOp1)) {
464 PhiOp1 = VRMap[PrologStage - StageAdj - Indirects - np][PhiOp1];
474 if (InstOp1->isPHI() && InstOp1->getParent() == KernelBB)
478 bool LoopDefIsPhi = PhiInst && PhiInst->
isPHI();
483 int StageDiffAdj = 0;
484 if (LoopValStage != -1 && StageScheduled > LoopValStage)
485 StageDiffAdj = StageScheduled - LoopValStage;
488 if (np == 0 && PrevStage == LastStageNum &&
489 (StageScheduled != 0 || LoopValStage != 0) &&
490 VRMap[PrevStage - StageDiffAdj].
count(LoopVal))
491 PhiOp2 = VRMap[PrevStage - StageDiffAdj][LoopVal];
494 else if (np > 0 && PrevStage == LastStageNum &&
495 VRMap[PrevStage - np + 1].
count(Def))
496 PhiOp2 = VRMap[PrevStage - np + 1][
Def];
498 else if (static_cast<unsigned>(LoopValStage) > PrologStage + 1 &&
499 VRMap[PrevStage - StageDiffAdj - np].
count(LoopVal))
500 PhiOp2 = VRMap[PrevStage - StageDiffAdj - np][LoopVal];
503 else if (VRMap[PrevStage - np].
count(Def) &&
504 (!LoopDefIsPhi || (PrevStage != LastStageNum) ||
505 (LoopValStage == StageScheduled)))
506 PhiOp2 = VRMap[PrevStage - np][
Def];
514 if (static_cast<int>(PrologStage - np) >= StageScheduled) {
515 int LVNumStages = getStagesForPhi(LoopVal);
516 int StageDiff = (StageScheduled - LoopValStage);
517 LVNumStages -= StageDiff;
519 if (LVNumStages > (
int)np && VRMap[CurStageNum].
count(LoopVal)) {
521 unsigned ReuseStage = CurStageNum;
522 if (isLoopCarried(*PhiInst))
523 ReuseStage -= LVNumStages;
526 if (VRMap[ReuseStage - np].
count(LoopVal)) {
527 NewReg = VRMap[ReuseStage - np][LoopVal];
529 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI,
532 VRMap[CurStageNum - np][
Def] = NewReg;
534 if (VRMap[LastStageNum - np - 1].
count(LoopVal))
535 PhiOp2 = VRMap[LastStageNum - np - 1][LoopVal];
537 if (IsLast && np == NumPhis - 1)
543 if (InKernel && StageDiff > 0 &&
544 VRMap[CurStageNum - StageDiff - np].
count(LoopVal))
545 PhiOp2 = VRMap[CurStageNum - StageDiff - np][LoopVal];
549 NewReg =
MRI.createVirtualRegister(RC);
553 TII->get(TargetOpcode::PHI), NewReg);
557 InstrMap[NewPhi] = &*BBI;
562 unsigned PrevReg = 0;
563 if (InKernel && VRMap[PrevStage - np].
count(LoopVal))
564 PrevReg = VRMap[PrevStage - np][LoopVal];
565 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI, Def,
568 if (VRMap[CurStageNum - np].
count(Def)) {
569 unsigned R = VRMap[CurStageNum - np][
Def];
570 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI, R,
577 if (IsLast && np == NumPhis - 1)
585 VRMap[CurStageNum - np][
Def] = NewReg;
588 while (NumPhis++ < NumStages) {
589 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, NumPhis, &*BBI, Def,
595 if (NumStages == 0 && IsLast && VRMap[CurStageNum].
count(LoopVal))
603 void ModuloScheduleExpander::generatePhis(
606 unsigned LastStageNum,
unsigned CurStageNum,
bool IsLast) {
609 unsigned PrologStage = 0;
610 unsigned PrevStage = 0;
611 unsigned StageDiff = CurStageNum - LastStageNum;
612 bool InKernel = (StageDiff == 0);
614 PrologStage = LastStageNum - 1;
615 PrevStage = CurStageNum;
617 PrologStage = LastStageNum - StageDiff;
618 PrevStage = LastStageNum + StageDiff - 1;
622 BBE = BB->instr_end();
624 for (
unsigned i = 0,
e = BBI->getNumOperands(); i !=
e; ++i) {
630 int StageScheduled = Schedule.getStage(&*BBI);
631 assert(StageScheduled != -1 &&
"Expecting scheduled instruction.");
633 unsigned NumPhis = getStagesForReg(Def, CurStageNum);
637 if (!InKernel && NumPhis == 0 && StageScheduled == 0 &&
640 if (!InKernel && (
unsigned)StageScheduled > PrologStage)
643 unsigned PhiOp2 = VRMap[PrevStage][
Def];
645 if (InstOp2->isPHI() && InstOp2->getParent() == NewBB)
649 if (NumPhis > PrologStage + 1 - StageScheduled)
650 NumPhis = PrologStage + 1 - StageScheduled;
651 for (
unsigned np = 0; np < NumPhis; ++np) {
652 unsigned PhiOp1 = VRMap[PrologStage][
Def];
653 if (np <= PrologStage)
654 PhiOp1 = VRMap[PrologStage - np][
Def];
656 if (InstOp1->isPHI() && InstOp1->getParent() == KernelBB)
658 if (InstOp1->isPHI() && InstOp1->getParent() == NewBB)
662 PhiOp2 = VRMap[PrevStage - np][
Def];
669 TII->get(TargetOpcode::PHI), NewReg);
673 InstrMap[NewPhi] = &*BBI;
678 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI, PhiOp1,
680 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI, PhiOp2,
684 VRMap[PrevStage - np - 1][
Def] = NewReg;
686 VRMap[CurStageNum - np][
Def] = NewReg;
687 if (np == NumPhis - 1)
688 rewriteScheduledInstr(NewBB, InstrMap, CurStageNum, np, &*BBI, Def,
691 if (IsLast && np == NumPhis - 1)
703 MBBVectorTy &EpilogBBs) {
706 for (MBBVectorTy::reverse_iterator MBB = EpilogBBs.rbegin(),
707 MBE = EpilogBBs.rend();
710 ME = (*MBB)->instr_rend();
713 if (
MI->isInlineAsm()) {
717 bool SawStore =
false;
720 if (!
MI->isSafeToMove(
nullptr, SawStore) && !
MI->isPHI()) {
726 MOE =
MI->operands_end();
728 if (!MOI->isReg() || !MOI->isDef())
733 used = !MOI->isDead();
738 unsigned realUses = 0;
744 if (UI->getParent()->getParent() != BB) {
755 LIS.RemoveMachineInstrFromMaps(*
MI);
756 MI++->eraseFromParent();
769 if (
MRI.use_begin(reg) ==
MRI.use_end()) {
770 LIS.RemoveMachineInstrFromMaps(*MI);
787 MBBVectorTy &EpilogBBs) {
789 for (
auto &PHI : KernelBB->
phis()) {
794 E =
MRI.use_instr_end();
796 if (
I->isPHI() &&
I->getParent() == KernelBB) {
806 unsigned SplitReg = 0;
809 if (BBJ.readsRegister(Def)) {
812 SplitReg =
MRI.createVirtualRegister(
MRI.getRegClass(Def));
814 TII->get(TargetOpcode::COPY), SplitReg)
817 BBJ.substituteRegister(Def, SplitReg, 0, *TRI);
822 for (
auto &Epilog : EpilogBBs)
823 for (
auto &
I : *Epilog)
824 if (
I.readsRegister(Def))
825 I.substituteRegister(Def, SplitReg, 0, *TRI);
837 for (
unsigned i = 1,
e =
MI.getNumOperands(); i !=
e; i += 2)
838 if (
MI.getOperand(i + 1).getMBB() == Incoming) {
839 MI.RemoveOperand(i + 1);
850 MBBVectorTy &PrologBBs,
852 MBBVectorTy &EpilogBBs,
854 assert(PrologBBs.
size() == EpilogBBs.
size() &&
"Prolog/Epilog mismatch");
861 unsigned MaxIter = PrologBBs.
size() - 1;
862 for (
unsigned i = 0, j = MaxIter; i <= MaxIter; ++i, --j) {
870 LoopInfo->createTripCountGreaterCondition(j + 1, *Prolog, Cond);
871 unsigned numAdded = 0;
872 if (!StaticallyGreater.
hasValue()) {
875 }
else if (*StaticallyGreater ==
false) {
882 if (LastPro != LastEpi) {
886 if (LastPro == KernelBB) {
891 LastPro->eraseFromParent();
900 I !=
E && numAdded > 0; ++
I, --numAdded)
901 updateInstruction(&*
I,
false, j, 0, VRMap);
905 LoopInfo->setPreheader(PrologBBs[MaxIter]);
906 LoopInfo->adjustTripCount(-(MaxIter + 1));
912 bool ModuloScheduleExpander::computeDelta(
MachineInstr &
MI,
unsigned &Delta) {
919 if (!BaseOp->
isReg())
927 if (BaseDef && BaseDef->
isPHI()) {
945 void ModuloScheduleExpander::updateMemOperands(
MachineInstr &NewMI,
957 if (MMO->isVolatile() || MMO->isAtomic() ||
958 (MMO->isInvariant() && MMO->isDereferenceable()) ||
959 (!MMO->getValue())) {
965 int64_t AdjOffset = Delta * Num;
967 MF.getMachineMemOperand(MMO, AdjOffset, MMO->getSize()));
979 unsigned CurStageNum,
980 unsigned InstStageNum) {
987 if (MO.isReg() && MO.isUse())
993 updateMemOperands(*NewMI, *OldMI, CurStageNum - InstStageNum);
1000 MachineInstr *ModuloScheduleExpander::cloneAndChangeInstr(
1001 MachineInstr *OldMI,
unsigned CurStageNum,
unsigned InstStageNum) {
1003 auto It = InstrChanges.find(OldMI);
1004 if (It != InstrChanges.end()) {
1005 std::pair<unsigned, int64_t> RegAndOffset = It->second;
1006 unsigned BasePos, OffsetPos;
1010 MachineInstr *LoopDef = findDefInLoop(RegAndOffset.first);
1011 if (Schedule.getStage(LoopDef) > (signed)InstStageNum)
1012 NewOffset += RegAndOffset.second * (CurStageNum - InstStageNum);
1015 updateMemOperands(*NewMI, *OldMI, CurStageNum - InstStageNum);
1021 void ModuloScheduleExpander::updateInstruction(
MachineInstr *NewMI,
1023 unsigned CurStageNum,
1024 unsigned InstrStageNum,
1025 ValueMapTy *VRMap) {
1036 VRMap[CurStageNum][reg] = NewReg;
1039 }
else if (MO.
isUse()) {
1042 int DefStageNum = Schedule.getStage(Def);
1043 unsigned StageNum = CurStageNum;
1044 if (DefStageNum != -1 && (
int)InstrStageNum > DefStageNum) {
1046 unsigned StageDiff = (InstrStageNum - DefStageNum);
1048 StageNum -= StageDiff;
1050 if (VRMap[StageNum].
count(reg))
1051 MO.
setReg(VRMap[StageNum][reg]);
1062 while (Def->
isPHI()) {
1063 if (!Visited.
insert(Def).second)
1075 unsigned ModuloScheduleExpander::getPrevMapVal(
1076 unsigned StageNum,
unsigned PhiStage,
unsigned LoopVal,
unsigned LoopStage,
1078 unsigned PrevVal = 0;
1079 if (StageNum > PhiStage) {
1081 if (PhiStage == LoopStage && VRMap[StageNum - 1].
count(LoopVal))
1083 PrevVal = VRMap[StageNum - 1][LoopVal];
1084 else if (VRMap[StageNum].
count(LoopVal))
1087 PrevVal = VRMap[StageNum][LoopVal];
1091 else if (StageNum == PhiStage + 1)
1094 else if (StageNum > PhiStage + 1 && LoopInst->
getParent() == BB)
1097 getPrevMapVal(StageNum - 1, PhiStage,
getLoopPhiReg(*LoopInst, BB),
1098 LoopStage, VRMap, BB);
1110 InstrMapTy &InstrMap) {
1111 for (
auto &PHI : BB->
phis()) {
1112 unsigned InitVal = 0;
1113 unsigned LoopVal = 0;
1115 Register PhiDef = PHI.getOperand(0).getReg();
1117 unsigned PhiStage = (
unsigned)Schedule.getStage(
MRI.getVRegDef(PhiDef));
1118 unsigned LoopStage = (
unsigned)Schedule.getStage(
MRI.getVRegDef(LoopVal));
1119 unsigned NumPhis = getStagesForPhi(PhiDef);
1120 if (NumPhis > StageNum)
1122 for (
unsigned np = 0; np <= NumPhis; ++np) {
1124 getPrevMapVal(StageNum - np, PhiStage, LoopVal, LoopStage, VRMap, BB);
1127 rewriteScheduledInstr(NewBB, InstrMap, StageNum - np, np, &PHI, PhiDef,
1136 void ModuloScheduleExpander::rewriteScheduledInstr(
1138 unsigned PhiNum,
MachineInstr *Phi,
unsigned OldReg,
unsigned NewReg,
1140 bool InProlog = (CurStageNum < (
unsigned)Schedule.getNumStages() - 1);
1141 int StagePhi = Schedule.getStage(Phi) + PhiNum;
1152 if (UseMI->
isPHI()) {
1158 InstrMapTy::iterator OrigInstr = InstrMap.find(UseMI);
1159 assert(OrigInstr != InstrMap.end() &&
"Instruction not scheduled.");
1161 int StageSched = Schedule.getStage(OrigMI);
1162 int CycleSched = Schedule.getCycle(OrigMI);
1163 unsigned ReplaceReg = 0;
1165 if (StagePhi == StageSched && Phi->
isPHI()) {
1166 int CyclePhi = Schedule.getCycle(Phi);
1167 if (PrevReg && InProlog)
1168 ReplaceReg = PrevReg;
1169 else if (PrevReg && !isLoopCarried(*Phi) &&
1170 (CyclePhi <= CycleSched || OrigMI->isPHI()))
1171 ReplaceReg = PrevReg;
1173 ReplaceReg = NewReg;
1177 if (!InProlog && StagePhi + 1 == StageSched && !isLoopCarried(*Phi))
1178 ReplaceReg = NewReg;
1179 if (StagePhi > StageSched && Phi->
isPHI())
1180 ReplaceReg = NewReg;
1181 if (!InProlog && !Phi->
isPHI() && StagePhi < StageSched)
1182 ReplaceReg = NewReg;
1184 MRI.constrainRegClass(ReplaceReg,
MRI.getRegClass(OldReg));
1185 UseOp.
setReg(ReplaceReg);
1190 bool ModuloScheduleExpander::isLoopCarried(
MachineInstr &Phi) {
1193 int DefCycle = Schedule.getCycle(&Phi);
1194 int DefStage = Schedule.getStage(&Phi);
1196 unsigned InitVal = 0;
1197 unsigned LoopVal = 0;
1200 if (!Use || Use->isPHI())
1202 int LoopCycle = Schedule.getCycle(Use);
1203 int LoopStage = Schedule.getStage(Use);
1204 return (LoopCycle > DefCycle) || (LoopStage <= DefStage);
1219 bool Changed =
true;
1246 class KernelRewriter {
1286 if (PreheaderBB == BB)
1302 BB->
insert(InsertPt, MI);
1306 assert(FirstMI &&
"Failed to find first MI in schedule");
1313 (
I++)->eraseFromParent();
1321 if (!MO.isReg() || MO.getReg().isPhysical() || MO.isImplicit())
1327 EliminateDeadPhis(BB,
MRI, LIS);
1333 for (
auto MI = BB->getFirstNonPHI(); MI != BB->end(); ++
MI) {
1356 int ConsumerStage = S.
getStage(&MI);
1357 if (!Producer->
isPHI()) {
1363 int ProducerStage = S.
getStage(Producer);
1364 assert(ConsumerStage != -1 &&
1365 "In-loop consumer should always be scheduled!");
1366 assert(ConsumerStage >= ProducerStage);
1367 unsigned StageDiff = ConsumerStage - ProducerStage;
1369 for (
unsigned I = 0;
I < StageDiff; ++
I)
1378 auto LoopProducer = Producer;
1379 while (LoopProducer->isPHI() && LoopProducer->getParent() == BB) {
1382 LoopProducer =
MRI.getUniqueVRegDef(LoopReg);
1385 int LoopProducerStage = S.
getStage(LoopProducer);
1389 if (LoopProducerStage == -1) {
1391 }
else if (LoopProducerStage > ConsumerStage) {
1396 #ifndef NDEBUG // Silence unused variables in non-asserts mode. 1397 int LoopProducerCycle = S.
getCycle(LoopProducer);
1398 int ConsumerCycle = S.
getCycle(&MI);
1400 assert(LoopProducerCycle <= ConsumerCycle);
1401 assert(LoopProducerStage == ConsumerStage + 1);
1408 IllegalPhiDefault = Defaults.
front();
1411 assert(ConsumerStage >= LoopProducerStage);
1412 int StageDiff = ConsumerStage - LoopProducerStage;
1413 if (StageDiff > 0) {
1415 <<
" to " << (Defaults.
size() + StageDiff) <<
"\n");
1426 auto DefaultI = Defaults.
rbegin();
1427 while (DefaultI != Defaults.
rend())
1428 LoopReg =
phi(LoopReg, *DefaultI++,
MRI.getRegClass(Reg));
1430 if (IllegalPhiDefault.
hasValue()) {
1436 auto RC =
MRI.getRegClass(Reg);
1439 .addReg(IllegalPhiDefault.
getValue())
1440 .addMBB(PreheaderBB)
1453 auto I = Phis.find({LoopReg, InitReg.
getValue()});
1454 if (
I != Phis.end())
1457 for (
auto &KV : Phis) {
1458 if (KV.first.first == LoopReg)
1465 auto I = UndefPhis.find(LoopReg);
1466 if (
I != UndefPhis.end()) {
1475 Phis.insert({{LoopReg, InitReg.
getValue()}, R});
1483 RC =
MRI.getRegClass(LoopReg);
1486 MRI.constrainRegClass(R,
MRI.getRegClass(*InitReg));
1488 .addReg(InitReg.
hasValue() ? *InitReg : undef(RC))
1489 .addMBB(PreheaderBB)
1493 UndefPhis[LoopReg] = R;
1495 Phis[{LoopReg, *InitReg}] = R;
1505 R =
MRI.createVirtualRegister(RC);
1508 TII->get(TargetOpcode::IMPLICIT_DEF), R);
1517 class KernelOperandInfo {
1530 while (isRegInLoop(MO)) {
1539 if (IllegalPhis.
count(MI)) {
1553 return PhiDefaults.
size() == Other.PhiDefaults.size();
1557 OS <<
"use of " << *Source <<
": distance(" << PhiDefaults.
size() <<
") in " 1573 PeeledFront.push_back(NewBB);
1575 PeeledBack.push_front(NewBB);
1576 for (
auto I = BB->
begin(), NI = NewBB->
begin(); !
I->isTerminator();
1578 CanonicalMIs[&*
I] = &*
I;
1579 CanonicalMIs[&*NI] = &*
I;
1580 BlockMIs[{NewBB, &*
I}] = &*NI;
1581 BlockMIs[{BB, &*
I}] = &*
I;
1592 if (Stage == -1 || Stage >= MinStage)
1605 for (
auto &Sub : Subs)
1606 Sub.first->substituteRegister(DefMO.getReg(), Sub.second, 0,
1607 *
MRI.getTargetRegisterInfo());
1615 void PeelingModuloScheduleExpander::moveStageBetweenBlocks(
1625 auto RC =
MRI.getRegClass(PhiR);
1628 TII->get(TargetOpcode::PHI), NR)
1631 BlockMIs[{DestBB, CanonicalMIs[
MI]}] = NI;
1632 CanonicalMIs[NI] = CanonicalMIs[
MI];
1639 DestBB->
insert(InsertPt, MI);
1640 auto *KernelMI = CanonicalMIs[
MI];
1641 BlockMIs[{DestBB, KernelMI}] =
MI;
1642 BlockMIs.erase({SourceBB, KernelMI});
1653 Def->getOperand(0).getReg());
1658 for (
auto *
P : PhiToDelete)
1659 P->eraseFromParent();
1665 DestBB->
insert(InsertPt, NewMI);
1672 CanonicalMIs[NewMI] = CanonicalMIs[Phi];
1673 BlockMIs[{DestBB, CanonicalMIs[Phi]}] = NewMI;
1674 PhiNodeLoopIteration[NewMI] = PhiNodeLoopIteration[Phi];
1681 if (Remaps.
count(MO.getReg()))
1682 MO.setReg(Remaps[MO.getReg()]);
1697 PeelingModuloScheduleExpander::getPhiCanonicalReg(
MachineInstr *CanonicalPhi,
1699 unsigned distance = PhiNodeLoopIteration[Phi];
1701 for (
unsigned I = 0;
I < distance; ++
I) {
1704 unsigned LoopRegIdx = 3, InitRegIdx = 1;
1713 void PeelingModuloScheduleExpander::peelPrologAndEpilogs() {
1715 BitVector AS(Schedule.getNumStages(),
true);
1716 LiveStages[BB] =
LS;
1717 AvailableStages[BB] = AS;
1721 for (
int I = 0;
I < Schedule.getNumStages() - 1; ++
I) {
1723 Prologs.push_back(peelKernel(
LPD_Front));
1724 LiveStages[Prologs.back()] =
LS;
1725 AvailableStages[Prologs.back()] =
LS;
1735 EliminateDeadPhis(ExitingBB,
MRI, LIS,
true);
1752 for (
int I = 1;
I <= Schedule.getNumStages() - 1; ++
I) {
1753 Epilogs.push_back(peelKernel(
LPD_Back));
1755 filterInstructions(B, Schedule.getNumStages() -
I);
1758 EliminateDeadPhis(B,
MRI, LIS,
true);
1760 PhiNodeLoopIteration[&*Phi] = Schedule.getNumStages() -
I;
1762 for (
size_t I = 0;
I < Epilogs.size();
I++) {
1764 for (
size_t J =
I; J < Epilogs.size(); J++) {
1766 unsigned Stage = Schedule.getNumStages() - 1 +
I - J;
1768 for (
size_t K = Iteration; K >
I; K--)
1769 moveStageBetweenBlocks(Epilogs[K - 1], Epilogs[K], Stage);
1772 LiveStages[Epilogs[
I]] =
LS;
1773 AvailableStages[Epilogs[
I]] = AS;
1779 auto PI = Prologs.begin();
1780 auto EI = Epilogs.begin();
1781 assert(Prologs.size() == Epilogs.size());
1782 for (; PI != Prologs.end(); ++PI, ++EI) {
1784 (*PI)->addSuccessor(*EI);
1790 if (CanonicalUse->
isPHI()) {
1794 Reg = getPhiCanonicalReg(CanonicalUse, Use);
1796 Reg = getEquivalentRegisterIn(Reg, *PI);
1805 llvm::copy(PeeledFront, std::back_inserter(Blocks));
1807 llvm::copy(PeeledBack, std::back_inserter(Blocks));
1811 for (
auto I =
B->getFirstInstrTerminator()->getReverseIterator();
1812 I != std::next(
B->getFirstNonPHI()->getReverseIterator());) {
1817 for (
auto *MI : IllegalPhisToDelete) {
1822 IllegalPhisToDelete.clear();
1826 EliminateDeadPhis(
B,
MRI, LIS);
1827 EliminateDeadPhis(ExitingBB,
MRI, LIS);
1846 if (
Use.getParent() != BB)
1849 Use->substituteRegister(OldR, R, 0,
1850 *
MRI.getTargetRegisterInfo());
1854 BlockMIs[{NewBB, &MI}] = NI;
1855 CanonicalMIs[NI] = &
MI;
1859 NewBB->addSuccessor(Exit);
1865 assert(CanAnalyzeBr &&
"Must be able to analyze the loop branch!");
1867 TII->
insertBranch(*BB, TBB == Exit ? NewBB : TBB, FBB == Exit ? NewBB : FBB,
1869 TII->insertUnconditionalBranch(*NewBB, Exit,
DebugLoc());
1874 PeelingModuloScheduleExpander::getEquivalentRegisterIn(
Register Reg,
1878 return BlockMIs[{BB, CanonicalMIs[
MI]}]->getOperand(OpIdx).getReg();
1881 void PeelingModuloScheduleExpander::rewriteUsesOf(
MachineInstr *MI) {
1888 if (RMIStage != -1 && !AvailableStages[MI->
getParent()].test(RMIStage))
1890 MRI.setRegClass(R,
MRI.getRegClass(PhiR));
1891 MRI.replaceRegWith(PhiR, R);
1895 IllegalPhisToDelete.push_back(MI);
1900 if (Stage == -1 || LiveStages.count(MI->
getParent()) == 0 ||
1901 LiveStages[MI->
getParent()].test(Stage))
1915 for (
auto &Sub : Subs)
1916 Sub.first->substituteRegister(DefMO.getReg(), Sub.second, 0,
1917 *
MRI.getTargetRegisterInfo());
1924 void PeelingModuloScheduleExpander::fixupBranches() {
1926 bool KernelDisposed =
false;
1927 int TC = Schedule.getNumStages() - 1;
1928 for (
auto PI = Prologs.rbegin(), EI = Epilogs.rbegin(); PI != Prologs.rend();
1936 Info->createTripCountGreaterCondition(TC, *Prolog, Cond);
1937 if (!StaticallyGreater.
hasValue()) {
1941 }
else if (*StaticallyGreater ==
false) {
1950 TII->insertUnconditionalBranch(*Prolog, Epilog,
DebugLoc());
1951 KernelDisposed =
true;
1963 if (!KernelDisposed) {
1964 Info->adjustTripCount(-(Schedule.getNumStages() - 1));
1965 Info->setPreheader(Prologs.back());
1972 KernelRewriter KR(*Schedule.getLoop(), Schedule);
1977 BB = Schedule.getLoop()->getTopBlock();
1978 Preheader = Schedule.getLoop()->getLoopPreheader();
1984 peelPrologAndEpilogs();
1989 BB = Schedule.getLoop()->getTopBlock();
1990 Preheader = Schedule.getLoop()->getLoopPreheader();
1994 std::string ScheduleDump;
2001 assert(LIS &&
"Requires LiveIntervals!");
2006 if (!ExpandedKernel) {
2012 Preheader->addSuccessor(BB);
2015 KernelRewriter KR(*Schedule.getLoop(), Schedule);
2017 peelPrologAndEpilogs();
2024 IllegalPhis.
insert(&*NI);
2030 auto OI = ExpandedKernel->
begin();
2031 auto NI = BB->
begin();
2032 for (; !OI->isTerminator() && !NI->isTerminator(); ++OI, ++NI) {
2033 while (OI->isPHI() || OI->isFullCopy())
2035 while (NI->isPHI() || NI->isFullCopy())
2037 assert(OI->getOpcode() == NI->getOpcode() &&
"Opcodes don't match?!");
2039 for (
auto OOpI = OI->operands_begin(), NOpI = NI->operands_begin();
2040 OOpI != OI->operands_end(); ++OOpI, ++NOpI)
2042 KernelOperandInfo(&*NOpI,
MRI, IllegalPhis));
2046 for (
auto &OldAndNew : KOIs) {
2047 if (OldAndNew.first == OldAndNew.second)
2050 errs() <<
"Modulo kernel validation error: [\n";
2051 errs() <<
" [golden] ";
2052 OldAndNew.first.print(
errs());
2054 OldAndNew.second.print(
errs());
2059 errs() <<
"Golden reference kernel:\n";
2061 errs() <<
"New kernel:\n";
2063 errs() << ScheduleDump;
2065 "Modulo kernel validation (-pipeliner-experimental-cg) failed");
2070 Preheader->removeSuccessor(BB);
2110 "Modulo Schedule test pass",
false,
false)
2118 for (
auto *L : MLI) {
2128 std::pair<StringRef, StringRef> StageAndCycle =
getToken(S,
"_");
2129 std::pair<StringRef, StringRef> StageTokenAndValue =
2130 getToken(StageAndCycle.first,
"-");
2131 std::pair<StringRef, StringRef> CycleTokenAndValue =
2132 getToken(StageAndCycle.second,
"-");
2133 if (StageTokenAndValue.first !=
"Stage" ||
2134 CycleTokenAndValue.first !=
"_Cycle") {
2136 "Bad post-instr symbol syntax: see comment in ModuloScheduleTest");
2140 StageTokenAndValue.second.drop_front().getAsInteger(10, Stage);
2141 CycleTokenAndValue.second.drop_front().getAsInteger(10, Cycle);
2143 dbgs() <<
" Stage=" << Stage <<
", Cycle=" << Cycle <<
"\n";
2149 dbgs() <<
"--- ModuloScheduleTest running on BB#" << BB->getNumber() <<
"\n";
2152 std::vector<MachineInstr *> Instrs;
2156 Instrs.push_back(&MI);
2158 dbgs() <<
"Parsing post-instr symbol for " <<
MI;
LiveInterval & createEmptyInterval(Register Reg)
Interval creation.
void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
reference emplace_back(ArgTypes &&... Args)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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...
static void removePhis(MachineBasicBlock *BB, MachineBasicBlock *Incoming)
Remove the incoming block from the Phis in a basic block.
instr_iterator instr_begin()
instr_iterator instr_end()
MachineBasicBlock * getMBB() const
void RemoveMachineInstrFromMaps(MachineInstr &MI)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
The ModuloScheduleExpander takes a ModuloSchedule and expands it in-place, rewriting the old loop and...
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Register getReg(unsigned Idx) const
Get the register for the operand index.
Represents a schedule for a single-block loop.
instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
int findRegisterDefOperandIdx(Register Reg, bool isDead=false, bool Overlap=false, const TargetRegisterInfo *TRI=nullptr) const
Returns the operand index that is a def of the specified register or -1 if it is not found...
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
A raw_ostream that writes to an SmallVector or SmallString.
unsigned const TargetRegisterInfo * TRI
INITIALIZE_PASS_BEGIN(ModuloScheduleTest, "modulo-schedule-test", "Modulo Schedule test pass", false, false) INITIALIZE_PASS_END(ModuloScheduleTest
void validateAgainstModuloScheduleExpander()
Runs ModuloScheduleExpander and treats it as a golden input to validate aspects of the code generated...
Peel the first iteration of the loop.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
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...
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()
MachineBasicBlock * getTopBlock()
Return the "top" block in the loop, which is the first block in the linear layout, ignoring any parts of the loop not contiguous with the part that contains the header.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
void print(raw_ostream &OS)
A Use represents the edge between a Value definition and its users.
MachineBasicBlock * getBottomBlock()
Return the "bottom" block in the loop, which is the last block in the linear layout, ignoring any parts of the loop not contiguous with the part that contains the header.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
defusechain_iterator - This class provides iterator support for machine operands in the function that...
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
std::pair< StringRef, StringRef > getToken(StringRef Source, StringRef Delimiters=" \\\)
getToken - This function extracts one token from source, ignoring any leading characters that appear ...
void initializeModuloScheduleTestPass(PassRegistry &)
bool hasInterval(Register Reg) const
static unsigned getInitPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB)
Return the Phi register value that comes from the incoming block.
void expand()
Performs the actual expansion.
const T & getValue() const LLVM_LVALUE_FUNCTION
static bool hasUseAfterLoop(unsigned Reg, MachineBasicBlock *BB, MachineRegisterInfo &MRI)
Return true if the register has a use that occurs outside the specified loop.
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.
bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
void setReg(Register Reg)
Change the register this operand corresponds to.
void setPostInstrSymbol(MachineFunction &MF, MCSymbol *Symbol)
Set a symbol that will be emitted just after the instruction itself.
virtual const TargetInstrInfo * getInstrInfo() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
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...
Analysis containing CSE Info
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
TargetInstrInfo - Interface to description of machine instruction set.
void rewriteKernel()
Converts BB from the original loop body to the rewritten, pipelined steady-state. ...
MCContext & getContext() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
bool getIncrementValue(const MachineInstr &MI, int &Value) const override
If the instruction is an increment of a constant value, return the amount.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static int64_t computeDelta(SectionEntry *A, SectionEntry *B)
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...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void setMBB(MachineBasicBlock *MBB)
Represent the analysis usage information of a pass.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
void setImm(int64_t immVal)
void replacePhiUsesWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
void cleanup()
Performs final cleanup after expansion.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
ArrayRef< MachineInstr * > getInstructions()
Return the rescheduled instructions in order.
BlockT * getExitBlock() const
If getExitBlocks would return exactly one block, return that block.
succ_iterator succ_begin()
iterator erase(const_iterator CI)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
pred_iterator pred_begin()
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
MCSymbol * getPostInstrSymbol() const
Helper to extract a post-instruction symbol if one has been added.
int getCycle(MachineInstr *MI)
Return the cycle that MI is scheduled at, or -1.
MachineBasicBlock * getRewrittenKernel()
Returns the newly rewritten kernel block, or nullptr if this was optimized away.
static void getPhiRegs(MachineInstr &Phi, MachineBasicBlock *Loop, unsigned &InitVal, unsigned &LoopVal)
Return the register values for the operands of a Phi instruction.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
reverse_instr_iterator instr_rbegin()
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
Align max(MaybeAlign Lhs, Align Rhs)
testing::Matcher< const detail::ErrorHolder & > Failed()
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...
int getStage(MachineInstr *MI)
Return the stage that MI is scheduled in, or -1.
modulo schedule Modulo Schedule test pass
StringRef str()
Return a StringRef for the vector contents.
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.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Peel the last iteration of the loop.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
reverse_instr_iterator instr_rend()
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Target - Wrapper for Target specific information.
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.
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static unsigned getLoopPhiReg(MachineInstr &Phi, MachineBasicBlock *LoopBB)
Return the Phi register value that comes the loop block.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
use_iterator use_begin(unsigned RegNo) const
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
void push_back(MachineInstr *MI)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
static bool rewrite(Function &F)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
std::unique_ptr< PipelinerLoopInfo > analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const override
Analyze loop L, which must be a single-basic-block loop, and if the conditions can be understood enou...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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...
MachineInstr * removeFromParent()
Unlink 'this' from the containing basic block, and return it without deleting it. ...
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool memoperands_empty() const
Return true if we don't have any memory operands which described the memory access done by this instr...
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
void setMemRefs(MachineFunction &MF, ArrayRef< MachineMemOperand *> MemRefs)
Assign this MachineInstr's memory reference descriptor list.
A raw_ostream that writes to an std::string.
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool getMemOperandWithOffset(const MachineInstr &LdSt, const MachineOperand *&BaseOp, int64_t &Offset, const TargetRegisterInfo *TRI) const override
Get the base register and byte offset of a load/store instr.
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
static void parseSymbolString(StringRef S, int &Cycle, int &Stage)
bool operator==(uint64_t V1, const APInt &V2)
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
OutputIt copy(R &&Range, OutputIt Out)
void annotate()
Performs the annotation.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
std::vector< MachineBasicBlock * >::iterator succ_iterator
MachineBasicBlock * PeelSingleBlockLoop(LoopPeelDirection Direction, MachineBasicBlock *Loop, MachineRegisterInfo &MRI, const TargetInstrInfo *TII)
Peels a single block loop.
Wrapper class representing virtual and physical registers.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.