Skip to content

Commit 8c14d3f

Browse files
authored
[MISched] Use SchedRegion in overrideSchedPolicy and overridePostRASchedPolicy (#149297)
This patch updates `overrideSchedPolicy` and `overridePostRASchedPolicy` to take a `SchedRegion` parameter instead of just `NumRegionInstrs`. This provides access to both the instruction range and the parent `MachineBasicBlock`, which enables looking up function-level attributes. With this change, targets can select post-RA scheduling direction per function using a function attribute. For example: ```cpp void overridePostRASchedPolicy(MachineSchedPolicy &Policy, const SchedRegion &Region) const { const Function &F = Region.RegionBegin->getMF()->getFunction(); Attribute Attr = F.getFnAttribute("amdgpu-post-ra-direction"); ... }
1 parent 34f59d7 commit 8c14d3f

File tree

11 files changed

+38
-35
lines changed

11 files changed

+38
-35
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
//
6666
// void <SubTarget>Subtarget::
6767
// overrideSchedPolicy(MachineSchedPolicy &Policy,
68-
// unsigned NumRegionInstrs) const {
68+
// const SchedRegion &Region) const {
6969
// Policy.<Flag> = true;
7070
// }
7171
//
@@ -218,6 +218,22 @@ struct MachineSchedPolicy {
218218
MachineSchedPolicy() = default;
219219
};
220220

221+
/// A region of an MBB for scheduling.
222+
struct SchedRegion {
223+
/// RegionBegin is the first instruction in the scheduling region, and
224+
/// RegionEnd is either MBB->end() or the scheduling boundary after the
225+
/// last instruction in the scheduling region. These iterators cannot refer
226+
/// to instructions outside of the identified scheduling region because
227+
/// those may be reordered before scheduling this region.
228+
MachineBasicBlock::iterator RegionBegin;
229+
MachineBasicBlock::iterator RegionEnd;
230+
unsigned NumRegionInstrs;
231+
232+
SchedRegion(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E,
233+
unsigned N)
234+
: RegionBegin(B), RegionEnd(E), NumRegionInstrs(N) {}
235+
};
236+
221237
/// MachineSchedStrategy - Interface to the scheduling algorithm used by
222238
/// ScheduleDAGMI.
223239
///

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TargetRegisterClass;
5454
class TargetRegisterInfo;
5555
class TargetSchedModel;
5656
class Triple;
57+
struct SchedRegion;
5758

5859
//===----------------------------------------------------------------------===//
5960
///
@@ -231,7 +232,7 @@ class LLVM_ABI TargetSubtargetInfo : public MCSubtargetInfo {
231232
/// scheduling heuristics (no custom MachineSchedStrategy) to make
232233
/// changes to the generic scheduling policy.
233234
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
234-
unsigned NumRegionInstrs) const {}
235+
const SchedRegion &Region) const {}
235236

236237
/// Override generic post-ra scheduling policy within a region.
237238
///
@@ -241,7 +242,7 @@ class LLVM_ABI TargetSubtargetInfo : public MCSubtargetInfo {
241242
/// Note that some options like tracking register pressure won't take effect
242243
/// in post-ra scheduling.
243244
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
244-
unsigned NumRegionInstrs) const {}
245+
const SchedRegion &Region) const {}
245246

246247
// Perform target-specific adjustments to the latency of a schedule
247248
// dependency.

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -771,24 +771,6 @@ static bool isSchedBoundary(MachineBasicBlock::iterator MI,
771771
MI->isFakeUse();
772772
}
773773

774-
/// A region of an MBB for scheduling.
775-
namespace {
776-
struct SchedRegion {
777-
/// RegionBegin is the first instruction in the scheduling region, and
778-
/// RegionEnd is either MBB->end() or the scheduling boundary after the
779-
/// last instruction in the scheduling region. These iterators cannot refer
780-
/// to instructions outside of the identified scheduling region because
781-
/// those may be reordered before scheduling this region.
782-
MachineBasicBlock::iterator RegionBegin;
783-
MachineBasicBlock::iterator RegionEnd;
784-
unsigned NumRegionInstrs;
785-
786-
SchedRegion(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E,
787-
unsigned N) :
788-
RegionBegin(B), RegionEnd(E), NumRegionInstrs(N) {}
789-
};
790-
} // end anonymous namespace
791-
792774
using MBBRegionsVector = SmallVector<SchedRegion, 16>;
793775

794776
static void
@@ -3725,7 +3707,8 @@ void GenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
37253707
RegionPolicy.OnlyBottomUp = true;
37263708

37273709
// Allow the subtarget to override default policy.
3728-
MF.getSubtarget().overrideSchedPolicy(RegionPolicy, NumRegionInstrs);
3710+
SchedRegion Region(Begin, End, NumRegionInstrs);
3711+
MF.getSubtarget().overrideSchedPolicy(RegionPolicy, Region);
37293712

37303713
// After subtarget overrides, apply command line options.
37313714
if (!EnableRegPressure) {
@@ -4338,7 +4321,8 @@ void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
43384321
RegionPolicy.OnlyBottomUp = false;
43394322

43404323
// Allow the subtarget to override default policy.
4341-
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, NumRegionInstrs);
4324+
SchedRegion Region(Begin, End, NumRegionInstrs);
4325+
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, Region);
43424326

43434327
// After subtarget overrides, apply command line options.
43444328
if (PostRADirection == MISched::TopDown) {

llvm/lib/Target/AArch64/AArch64Subtarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ unsigned AArch64Subtarget::classifyGlobalFunctionReference(
534534
}
535535

536536
void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
537-
unsigned NumRegionInstrs) const {
537+
const SchedRegion &Region) const {
538538
// LNT run (at least on Cyclone) showed reasonably significant gains for
539539
// bi-directional scheduling. 253.perlbmk.
540540
Policy.OnlyTopDown = false;

llvm/lib/Target/AArch64/AArch64Subtarget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo {
343343
}
344344

345345
void overrideSchedPolicy(MachineSchedPolicy &Policy,
346-
unsigned NumRegionInstrs) const override;
346+
const SchedRegion &Region) const override;
347+
347348
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
348349
SDep &Dep,
349350
const TargetSchedModel *SchedModel) const override;

llvm/lib/Target/AMDGPU/GCNSubtarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ bool GCNSubtarget::zeroesHigh16BitsOfDest(unsigned Opcode) const {
324324
}
325325

326326
void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
327-
unsigned NumRegionInstrs) const {
327+
const SchedRegion &Region) const {
328328
// Track register pressure so the scheduler can try to decrease
329329
// pressure once register usage is above the threshold defined by
330330
// SIRegisterInfo::getRegPressureSetLimit()

llvm/lib/Target/AMDGPU/GCNSubtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
10221022
}
10231023

10241024
void overrideSchedPolicy(MachineSchedPolicy &Policy,
1025-
unsigned NumRegionInstrs) const override;
1025+
const SchedRegion &Region) const override;
10261026

10271027
void mirFileLoaded(MachineFunction &MF) const override;
10281028

llvm/lib/Target/PowerPC/PPCSubtarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
171171
}
172172

173173
void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
174-
unsigned NumRegionInstrs) const {
174+
const SchedRegion &Region) const {
175175
// The GenericScheduler that we use defaults to scheduling bottom up only.
176176
// We want to schedule from both the top and the bottom and so we set
177177
// OnlyBottomUp to false.

llvm/lib/Target/PowerPC/PPCSubtarget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
240240
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
241241

242242
void overrideSchedPolicy(MachineSchedPolicy &Policy,
243-
unsigned NumRegionInstrs) const override;
243+
const SchedRegion &Region) const override;
244+
244245
bool useAA() const override;
245246

246247
bool enableSubRegLiveness() const override;

llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ unsigned RISCVSubtarget::getMinimumJumpTableEntries() const {
216216
}
217217

218218
void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
219-
unsigned NumRegionInstrs) const {
219+
const SchedRegion &Region) const {
220220
// Do bidirectional scheduling since it provides a more balanced scheduling
221221
// leading to better performance. This will increase compile time.
222222
Policy.OnlyTopDown = false;
@@ -231,8 +231,8 @@ void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
231231
Policy.ShouldTrackPressure = true;
232232
}
233233

234-
void RISCVSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
235-
unsigned NumRegionInstrs) const {
234+
void RISCVSubtarget::overridePostRASchedPolicy(
235+
MachineSchedPolicy &Policy, const SchedRegion &Region) const {
236236
MISched::Direction PostRASchedDirection = getPostRASchedDirection();
237237
if (PostRASchedDirection == MISched::TopDown) {
238238
Policy.OnlyTopDown = true;

0 commit comments

Comments
 (0)