@@ -181,7 +181,9 @@ void ModuloScheduleExpander::generatePipelinedLoop() {
181
181
// Add branches between prolog and epilog blocks.
182
182
addBranches (*Preheader, PrologBBs, KernelBB, EpilogBBs, VRMap);
183
183
184
- recalcEmptyIntervals ();
184
+ // The intervals of newly created virtual registers are calculated after the
185
+ // kernel expansion.
186
+ calculateIntervals ();
185
187
186
188
delete[] VRMap;
187
189
delete[] VRMapPhi;
@@ -351,15 +353,15 @@ static void replaceRegUsesAfterLoop(Register FromReg, Register ToReg,
351
353
MachineBasicBlock *MBB,
352
354
MachineRegisterInfo &MRI,
353
355
LiveIntervals &LIS,
354
- SmallVector<Register> &EmptyIntervalRegs ) {
356
+ SmallVector<Register> &NoIntervalRegs ) {
355
357
for (MachineOperand &O :
356
358
llvm::make_early_inc_range (MRI.use_operands (FromReg)))
357
359
if (O.getParent ()->getParent () != MBB)
358
360
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);
363
365
}
364
366
365
367
// / Return true if the register has a use that occurs outside the
@@ -552,7 +554,7 @@ void ModuloScheduleExpander::generateExistingPhis(
552
554
553
555
if (IsLast && np == NumPhis - 1 )
554
556
replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS,
555
- EmptyIntervalRegs );
557
+ NoIntervalRegs );
556
558
continue ;
557
559
}
558
560
}
@@ -593,7 +595,7 @@ void ModuloScheduleExpander::generateExistingPhis(
593
595
// register to replace depends on whether the Phi is scheduled in the
594
596
// epilog.
595
597
if (IsLast && np == NumPhis - 1 )
596
- replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
598
+ replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, NoIntervalRegs );
597
599
598
600
// In the kernel, a dependent Phi uses the value from this Phi.
599
601
if (InKernel)
@@ -613,8 +615,7 @@ void ModuloScheduleExpander::generateExistingPhis(
613
615
if (NumStages == 0 && IsLast) {
614
616
auto It = VRMap[CurStageNum].find (LoopVal);
615
617
if (It != VRMap[CurStageNum].end ())
616
- replaceRegUsesAfterLoop (Def, It->second , BB, MRI, LIS,
617
- EmptyIntervalRegs);
618
+ replaceRegUsesAfterLoop (Def, It->second , BB, MRI, LIS, NoIntervalRegs);
618
619
}
619
620
}
620
621
}
@@ -735,7 +736,7 @@ void ModuloScheduleExpander::generatePhis(
735
736
NewReg);
736
737
}
737
738
if (IsLast && np == NumPhis - 1 )
738
- replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
739
+ replaceRegUsesAfterLoop (Def, NewReg, BB, MRI, LIS, NoIntervalRegs );
739
740
}
740
741
}
741
742
}
@@ -947,23 +948,24 @@ void ModuloScheduleExpander::addBranches(MachineBasicBlock &PreheaderBB,
947
948
}
948
949
}
949
950
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
954
955
// slot indexes.
955
- auto CanRecalculateInterval = [this ](unsigned Reg) -> bool {
956
+ auto CanCalculateInterval = [this ](Register Reg) -> bool {
956
957
for (auto &Opnd : this ->MRI .reg_nodbg_operands (Reg))
957
958
if (this ->LIS .isNotInMIMap (*Opnd.getParent ()))
958
959
return false ;
959
960
return true ;
960
961
};
961
- for (auto Reg : EmptyIntervalRegs)
962
- if (CanRecalculateInterval (Reg)) {
963
- LIS.removeInterval (Reg);
962
+ for (auto Reg : NoIntervalRegs) {
963
+ if (CanCalculateInterval (Reg))
964
964
LIS.createAndComputeVirtRegInterval (Reg);
965
- }
966
- EmptyIntervalRegs.clear ();
965
+ else
966
+ LIS.createEmptyInterval (Reg);
967
+ }
968
+ NoIntervalRegs.clear ();
967
969
}
968
970
969
971
// / Return true if we can compute the amount the instruction changes
@@ -1087,7 +1089,7 @@ void ModuloScheduleExpander::updateInstruction(MachineInstr *NewMI,
1087
1089
MO.setReg (NewReg);
1088
1090
VRMap[CurStageNum][reg] = NewReg;
1089
1091
if (LastDef)
1090
- replaceRegUsesAfterLoop (reg, NewReg, BB, MRI, LIS, EmptyIntervalRegs );
1092
+ replaceRegUsesAfterLoop (reg, NewReg, BB, MRI, LIS, NoIntervalRegs );
1091
1093
} else if (MO.isUse ()) {
1092
1094
MachineInstr *Def = MRI.getVRegDef (reg);
1093
1095
// Compute the stage that contains the last definition for instruction.
0 commit comments