Skip to content

Commit aeed954

Browse files
committed
Allow scheduling of regions with single MI
1 parent 2b340c1 commit aeed954

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ namespace llvm {
124124
/// rescheduling).
125125
bool RemoveKillFlags;
126126

127+
/// True if regions with a single MI should be scheduled.
128+
bool ScheduleSingleMIRegions = false;
129+
127130
/// The standard DAG builder does not normally include terminators as DAG
128131
/// nodes because it does not create the necessary dependencies to prevent
129132
/// reordering. A specialized scheduler can override
@@ -288,6 +291,11 @@ namespace llvm {
288291
return Topo.IsReachable(SU, TargetSU);
289292
}
290293

294+
/// Whether regions with a single MI should be scheduled.
295+
bool shouldScheduleSingleMIRegions() const {
296+
return ScheduleSingleMIRegions;
297+
}
298+
291299
/// Returns an iterator to the top of the current scheduling region.
292300
MachineBasicBlock::iterator begin() const { return RegionBegin; }
293301

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
770770

771771
MBBRegionsVector MBBRegions;
772772
getSchedRegions(&*MBB, MBBRegions, Scheduler.doMBBSchedRegionsTopDown());
773+
bool ScheduleSingleMI = Scheduler.shouldScheduleSingleMIRegions();
773774
for (const SchedRegion &R : MBBRegions) {
774775
MachineBasicBlock::iterator I = R.RegionBegin;
775776
MachineBasicBlock::iterator RegionEnd = R.RegionEnd;
@@ -780,7 +781,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
780781
Scheduler.enterRegion(&*MBB, I, RegionEnd, NumRegionInstrs);
781782

782783
// Skip empty scheduling regions (0 or 1 schedulable instructions).
783-
if (I == RegionEnd || I == std::prev(RegionEnd)) {
784+
if (I == RegionEnd || (!ScheduleSingleMI && I == std::prev(RegionEnd))) {
784785
// Close the current region. Bundle the terminator if needed.
785786
// This invalidates 'RegionEnd' and 'I'.
786787
Scheduler.exitRegion();

llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
116116
bool RemoveKillFlags)
117117
: ScheduleDAG(mf), MLI(mli), MFI(mf.getFrameInfo()),
118118
RemoveKillFlags(RemoveKillFlags),
119-
UnknownValue(UndefValue::get(
120-
Type::getVoidTy(mf.getFunction().getContext()))), Topo(SUnits, &ExitSU) {
119+
UnknownValue(
120+
UndefValue::get(Type::getVoidTy(mf.getFunction().getContext()))),
121+
Topo(SUnits, &ExitSU) {
121122
DbgValues.clear();
122123

123124
const TargetSubtargetInfo &ST = mf.getSubtarget();

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,10 @@ GCNScheduleDAGMILive::GCNScheduleDAGMILive(
759759
MFI(*MF.getInfo<SIMachineFunctionInfo>()),
760760
StartingOccupancy(MFI.getOccupancy()), MinOccupancy(StartingOccupancy),
761761
RegionLiveOuts(this, /*IsLiveOut=*/true) {
762-
762+
// We want regions with a single MI to be scheduled so that we can reason on
763+
// them correctlt during scheduling stages that move MIs between regions (e.g.
764+
// rematerialization).
765+
ScheduleSingleMIRegions = true;
763766
LLVM_DEBUG(dbgs() << "Starting occupancy is " << StartingOccupancy << ".\n");
764767
if (RelaxedOcc) {
765768
MinOccupancy = std::min(MFI.getMinAllowedOccupancy(), StartingOccupancy);

llvm/test/CodeGen/AMDGPU/debug-value-scheduler-liveins.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: llc -mtriple=amdgcn -mcpu=gfx908 -passes=machine-scheduler %s -o - -debug-only=machine-scheduler 2>&1 | FileCheck %s
33
# REQUIRES: asserts
44

5+
# CHECK: ********** MI Scheduling **********
6+
# CHECK-NEXT: test_get_liveins:%bb.0
57
# CHECK: ********** MI Scheduling **********
68
# CHECK-NEXT: test_get_liveins:%bb.1
79
# CHECK: Region live-in pressure: VGPRs: 1 AGPRs: 0, SGPRs: 0, LVGPR WT: 0, LSGPR WT: 0

0 commit comments

Comments
 (0)