Skip to content

Commit a5a28f9

Browse files
committed
[llvm][CodeGen] Modifications made based on review comments 1
1 parent 40c675f commit a5a28f9

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

llvm/include/llvm/CodeGen/ModuloSchedule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ class ModuloScheduleExpander {
188188
/// Instructions to change when emitting the final schedule.
189189
InstrChangesTy InstrChanges;
190190

191-
/// Record newly created registers with empty live intervals.
192-
SmallVector<Register> EmptyIntervalRegs;
191+
/// Record the registers that need to compute live intervals.
192+
SmallVector<Register> NoIntervalRegs;
193193

194194
void generatePipelinedLoop();
195195
void generateProlog(unsigned LastStage, MachineBasicBlock *KernelBB,
@@ -214,7 +214,7 @@ class ModuloScheduleExpander {
214214
void addBranches(MachineBasicBlock &PreheaderBB, MBBVectorTy &PrologBBs,
215215
MachineBasicBlock *KernelBB, MBBVectorTy &EpilogBBs,
216216
ValueMapTy *VRMap);
217-
void recalcEmptyIntervals();
217+
void calculateIntervals();
218218
bool computeDelta(MachineInstr &MI, unsigned &Delta);
219219
void updateMemOperands(MachineInstr &NewMI, MachineInstr &OldMI,
220220
unsigned Num);

llvm/lib/CodeGen/ModuloSchedule.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)