Skip to content

Commit 03677f6

Browse files
authored
[MachineScheduler] Optional scheduling of single-MI regions (#129704)
Following 15e295d the machine scheduler no longer filters-out single-MI regions when emitting regions to schedule. While this has no functional impact at the moment, it generally has a negative compile-time impact (see #128739). Since all targets but AMDGPU do not care for this behavior, this introduces an off-by-default flag to `ScheduleDAGInstrs` to control whether such regions are going to be scheduled, effectively reverting 15e295d for all targets but AMDGPU (currently the only target enabling this flag).
1 parent 43a1a33 commit 03677f6

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
769769

770770
MBBRegionsVector MBBRegions;
771771
getSchedRegions(&*MBB, MBBRegions, Scheduler.doMBBSchedRegionsTopDown());
772+
bool ScheduleSingleMI = Scheduler.shouldScheduleSingleMIRegions();
772773
for (const SchedRegion &R : MBBRegions) {
773774
MachineBasicBlock::iterator I = R.RegionBegin;
774775
MachineBasicBlock::iterator RegionEnd = R.RegionEnd;
@@ -778,11 +779,9 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
778779
// it. Perhaps it still needs to be bundled.
779780
Scheduler.enterRegion(&*MBB, I, RegionEnd, NumRegionInstrs);
780781

781-
// Skip empty scheduling regions but include single-MI regions; we want
782-
// those to be scheduled so that backends which move MIs across regions
783-
// during scheduling can reason about and schedule those regions
784-
// correctly.
785-
if (I == RegionEnd) {
782+
// Skip empty scheduling regions and, conditionally, regions with a single
783+
// MI.
784+
if (I == RegionEnd || (!ScheduleSingleMI && I == std::prev(RegionEnd))) {
786785
// Close the current region. Bundle the terminator if needed.
787786
// This invalidates 'RegionEnd' and 'I'.
788787
Scheduler.exitRegion();

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ GCNScheduleDAGMILive::GCNScheduleDAGMILive(
760760
StartingOccupancy(MFI.getOccupancy()), MinOccupancy(StartingOccupancy),
761761
RegionLiveOuts(this, /*IsLiveOut=*/true) {
762762

763+
// We want regions with a single MI to be scheduled so that we can reason
764+
// about them correctly during scheduling stages that move MIs between regions
765+
// (e.g., rematerialization).
766+
ScheduleSingleMIRegions = true;
763767
LLVM_DEBUG(dbgs() << "Starting occupancy is " << StartingOccupancy << ".\n");
764768
if (RelaxedOcc) {
765769
MinOccupancy = std::min(MFI.getMinAllowedOccupancy(), StartingOccupancy);

llvm/test/CodeGen/ARM/misched-branch-targets.mir

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# RUN: llc -o - -run-pass=machine-scheduler -misched=shuffle %s | FileCheck -check-prefixes=CHECK,CHECK-MISCHED %s
2-
# RUN: llc -o - -passes=machine-scheduler -misched=shuffle %s | FileCheck -check-prefixes=CHECK,CHECK-MISCHED %s
3-
# RUN: llc -o - -run-pass=postmisched %s | FileCheck -check-prefixes=CHECK,CHECK-POSTMISCHED %s
4-
# RUN: llc -o - -passes=postmisched %s | FileCheck -check-prefixes=CHECK,CHECK-POSTMISCHED %s
1+
# RUN: llc -o - -run-pass=machine-scheduler -misched=shuffle %s | FileCheck %s
2+
# RUN: llc -o - -passes=machine-scheduler -misched=shuffle %s | FileCheck %s
3+
# RUN: llc -o - -run-pass=postmisched %s | FileCheck %s
4+
# RUN: llc -o - -passes=postmisched %s | FileCheck %s
55

66
# REQUIRES: asserts
77
# -misched=shuffle is only available with assertions enabled
@@ -147,8 +147,7 @@ body: |
147147

148148
# CHECK-LABEL: name: foo_setjmp
149149
# CHECK: body:
150-
# CHECK-MISCHED: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit $r0, implicit-def $sp, implicit-def $r0
151-
# CHECK-POSTMISCHED: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def $r0
150+
# CHECK: tBL 14 /* CC::al */, $noreg, @setjmp, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $r0, implicit-def $sp, implicit-def $r0
152151
# CHECK-NEXT: t2BTI
153152

154153
---

llvm/test/CodeGen/X86/fake-use-scheduler.mir

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99
#
1010
# CHECK: ********** MI Scheduling **********
1111
# CHECK-NEXT: foo:%bb.0 entry
12-
# CHECK-NEXT: From: $rax = COPY %5:gr64
13-
# CHECK-NEXT: To: RET 0, killed $rax
14-
# CHECK-NEXT: RegionInstrs: 1
15-
#
16-
# CHECK: ********** MI Scheduling **********
17-
# CHECK-NEXT: foo:%bb.0 entry
1812
# CHECK-NEXT: From: %0:gr64 = COPY $rdi
1913
# CHECK-NEXT: To: FAKE_USE %5:gr64
2014
# CHECK-NEXT: RegionInstrs: 7

0 commit comments

Comments
 (0)