@@ -181,7 +181,9 @@ void ModuloScheduleExpander::generatePipelinedLoop() {
181181 // Add branches between prolog and epilog blocks.
182182 addBranches (*Preheader, PrologBBs, KernelBB, EpilogBBs, VRMap);
183183
184- recalcEmptyIntervals ();
184+ // The intervals of newly created virtual registers are calculated after the
185+ // kernel expansion.
186+ calculateIntervals ();
185187
186188 delete[] VRMap;
187189 delete[] VRMapPhi;
@@ -351,15 +353,15 @@ static void replaceRegUsesAfterLoop(Register FromReg, Register ToReg,
351353 MachineBasicBlock *MBB,
352354 MachineRegisterInfo &MRI,
353355 LiveIntervals &LIS,
354- SmallVector<Register> &EmptyIntervalRegs ) {
356+ SmallVector<Register> &NoIntervalRegs ) {
355357 for (MachineOperand &O :
356358 llvm::make_early_inc_range (MRI.use_operands (FromReg)))
357359 if (O.getParent ()->getParent () != MBB)
358360 O.setReg (ToReg);
359- if (!LIS. hasInterval (ToReg)) {
360- LIS. createEmptyInterval (ToReg);
361- EmptyIntervalRegs. push_back (ToReg);
362- }
361+ // The interval will be calculated after the kernel expansion in
362+ // calculateIntervals().
363+ if (!LIS. hasInterval (ToReg))
364+ NoIntervalRegs. push_back (ToReg);
363365}
364366
365367// / Return true if the register has a use that occurs outside the
@@ -552,7 +554,7 @@ void ModuloScheduleExpander::generateExistingPhis(
552554
553555 if (IsLast && np == NumPhis - 1 )
554556 replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS,
555- EmptyIntervalRegs );
557+ NoIntervalRegs );
556558 continue ;
557559 }
558560 }
@@ -593,7 +595,7 @@ void ModuloScheduleExpander::generateExistingPhis(
593595 // register to replace depends on whether the Phi is scheduled in the
594596 // epilog.
595597 if (IsLast && np == NumPhis - 1 )
596- replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
598+ replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, NoIntervalRegs );
597599
598600 // In the kernel, a dependent Phi uses the value from this Phi.
599601 if (InKernel)
@@ -613,8 +615,7 @@ void ModuloScheduleExpander::generateExistingPhis(
613615 if (NumStages == 0 && IsLast) {
614616 auto It = VRMap[CurStageNum].find (LoopVal);
615617 if (It != VRMap[CurStageNum].end ())
616- replaceRegUsesAfterLoop (Def, It->second , BB, MRI, LIS,
617- EmptyIntervalRegs);
618+ replaceRegUsesAfterLoop (Def, It->second , BB, MRI, LIS, NoIntervalRegs);
618619 }
619620 }
620621}
@@ -735,7 +736,7 @@ void ModuloScheduleExpander::generatePhis(
735736 NewReg);
736737 }
737738 if (IsLast && np == NumPhis - 1 )
738- replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
739+ replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, NoIntervalRegs );
739740 }
740741 }
741742 }
@@ -947,23 +948,24 @@ void ModuloScheduleExpander::addBranches(MachineBasicBlock &PreheaderBB,
947948 }
948949}
949950
950- // / Some new registers are generated during the kernel expansion. We recalculate
951- // / the live intervals of these registers after the expansion.
952- void ModuloScheduleExpander::recalcEmptyIntervals () {
953- // The interval can be computed if the register's non-debug users have
951+ // / Some registers are generated during the kernel expansion. We calculate the
952+ // / live intervals of these registers after the expansion.
953+ void ModuloScheduleExpander::calculateIntervals () {
954+ // The interval can be computed if all the register's non-debug users have
954955 // slot indexes.
955- auto CanRecalculateInterval = [this ](unsigned Reg) -> bool {
956+ auto CanCalculateInterval = [this ](Register Reg) -> bool {
956957 for (auto &Opnd : this ->MRI .reg_nodbg_operands (Reg))
957958 if (this ->LIS .isNotInMIMap (*Opnd.getParent ()))
958959 return false ;
959960 return true ;
960961 };
961- for (auto Reg : EmptyIntervalRegs)
962- if (CanRecalculateInterval (Reg)) {
963- LIS.removeInterval (Reg);
962+ for (auto Reg : NoIntervalRegs) {
963+ if (CanCalculateInterval (Reg))
964964 LIS.createAndComputeVirtRegInterval (Reg);
965- }
966- EmptyIntervalRegs.clear ();
965+ else
966+ LIS.createEmptyInterval (Reg);
967+ }
968+ NoIntervalRegs.clear ();
967969}
968970
969971// / Return true if we can compute the amount the instruction changes
@@ -1087,7 +1089,7 @@ void ModuloScheduleExpander::updateInstruction(MachineInstr *NewMI,
10871089 MO.setReg (NewReg);
10881090 VRMap[CurStageNum][reg] = NewReg;
10891091 if (LastDef)
1090- replaceRegUsesAfterLoop (reg, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
1092+ replaceRegUsesAfterLoop (reg, NewReg, BB, MRI, LIS, NoIntervalRegs );
10911093 } else if (MO.isUse ()) {
10921094 MachineInstr *Def = MRI.getVRegDef (reg);
10931095 // Compute the stage that contains the last definition for instruction.
0 commit comments