[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"); ... }
This commit is contained in:
parent
34f59d7920
commit
8c14d3f44f
@ -65,7 +65,7 @@
|
|||||||
//
|
//
|
||||||
// void <SubTarget>Subtarget::
|
// void <SubTarget>Subtarget::
|
||||||
// overrideSchedPolicy(MachineSchedPolicy &Policy,
|
// overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
// unsigned NumRegionInstrs) const {
|
// const SchedRegion &Region) const {
|
||||||
// Policy.<Flag> = true;
|
// Policy.<Flag> = true;
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
@ -218,6 +218,22 @@ struct MachineSchedPolicy {
|
|||||||
MachineSchedPolicy() = default;
|
MachineSchedPolicy() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A region of an MBB for scheduling.
|
||||||
|
struct SchedRegion {
|
||||||
|
/// RegionBegin is the first instruction in the scheduling region, and
|
||||||
|
/// RegionEnd is either MBB->end() or the scheduling boundary after the
|
||||||
|
/// last instruction in the scheduling region. These iterators cannot refer
|
||||||
|
/// to instructions outside of the identified scheduling region because
|
||||||
|
/// those may be reordered before scheduling this region.
|
||||||
|
MachineBasicBlock::iterator RegionBegin;
|
||||||
|
MachineBasicBlock::iterator RegionEnd;
|
||||||
|
unsigned NumRegionInstrs;
|
||||||
|
|
||||||
|
SchedRegion(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E,
|
||||||
|
unsigned N)
|
||||||
|
: RegionBegin(B), RegionEnd(E), NumRegionInstrs(N) {}
|
||||||
|
};
|
||||||
|
|
||||||
/// MachineSchedStrategy - Interface to the scheduling algorithm used by
|
/// MachineSchedStrategy - Interface to the scheduling algorithm used by
|
||||||
/// ScheduleDAGMI.
|
/// ScheduleDAGMI.
|
||||||
///
|
///
|
||||||
|
@ -54,6 +54,7 @@ class TargetRegisterClass;
|
|||||||
class TargetRegisterInfo;
|
class TargetRegisterInfo;
|
||||||
class TargetSchedModel;
|
class TargetSchedModel;
|
||||||
class Triple;
|
class Triple;
|
||||||
|
struct SchedRegion;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
///
|
///
|
||||||
@ -231,7 +232,7 @@ public:
|
|||||||
/// scheduling heuristics (no custom MachineSchedStrategy) to make
|
/// scheduling heuristics (no custom MachineSchedStrategy) to make
|
||||||
/// changes to the generic scheduling policy.
|
/// changes to the generic scheduling policy.
|
||||||
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {}
|
const SchedRegion &Region) const {}
|
||||||
|
|
||||||
/// Override generic post-ra scheduling policy within a region.
|
/// Override generic post-ra scheduling policy within a region.
|
||||||
///
|
///
|
||||||
@ -241,7 +242,7 @@ public:
|
|||||||
/// Note that some options like tracking register pressure won't take effect
|
/// Note that some options like tracking register pressure won't take effect
|
||||||
/// in post-ra scheduling.
|
/// in post-ra scheduling.
|
||||||
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
|
virtual void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {}
|
const SchedRegion &Region) const {}
|
||||||
|
|
||||||
// Perform target-specific adjustments to the latency of a schedule
|
// Perform target-specific adjustments to the latency of a schedule
|
||||||
// dependency.
|
// dependency.
|
||||||
|
@ -771,24 +771,6 @@ static bool isSchedBoundary(MachineBasicBlock::iterator MI,
|
|||||||
MI->isFakeUse();
|
MI->isFakeUse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A region of an MBB for scheduling.
|
|
||||||
namespace {
|
|
||||||
struct SchedRegion {
|
|
||||||
/// RegionBegin is the first instruction in the scheduling region, and
|
|
||||||
/// RegionEnd is either MBB->end() or the scheduling boundary after the
|
|
||||||
/// last instruction in the scheduling region. These iterators cannot refer
|
|
||||||
/// to instructions outside of the identified scheduling region because
|
|
||||||
/// those may be reordered before scheduling this region.
|
|
||||||
MachineBasicBlock::iterator RegionBegin;
|
|
||||||
MachineBasicBlock::iterator RegionEnd;
|
|
||||||
unsigned NumRegionInstrs;
|
|
||||||
|
|
||||||
SchedRegion(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E,
|
|
||||||
unsigned N) :
|
|
||||||
RegionBegin(B), RegionEnd(E), NumRegionInstrs(N) {}
|
|
||||||
};
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
using MBBRegionsVector = SmallVector<SchedRegion, 16>;
|
using MBBRegionsVector = SmallVector<SchedRegion, 16>;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3725,7 +3707,8 @@ void GenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
|
|||||||
RegionPolicy.OnlyBottomUp = true;
|
RegionPolicy.OnlyBottomUp = true;
|
||||||
|
|
||||||
// Allow the subtarget to override default policy.
|
// Allow the subtarget to override default policy.
|
||||||
MF.getSubtarget().overrideSchedPolicy(RegionPolicy, NumRegionInstrs);
|
SchedRegion Region(Begin, End, NumRegionInstrs);
|
||||||
|
MF.getSubtarget().overrideSchedPolicy(RegionPolicy, Region);
|
||||||
|
|
||||||
// After subtarget overrides, apply command line options.
|
// After subtarget overrides, apply command line options.
|
||||||
if (!EnableRegPressure) {
|
if (!EnableRegPressure) {
|
||||||
@ -4338,7 +4321,8 @@ void PostGenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
|
|||||||
RegionPolicy.OnlyBottomUp = false;
|
RegionPolicy.OnlyBottomUp = false;
|
||||||
|
|
||||||
// Allow the subtarget to override default policy.
|
// Allow the subtarget to override default policy.
|
||||||
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, NumRegionInstrs);
|
SchedRegion Region(Begin, End, NumRegionInstrs);
|
||||||
|
MF.getSubtarget().overridePostRASchedPolicy(RegionPolicy, Region);
|
||||||
|
|
||||||
// After subtarget overrides, apply command line options.
|
// After subtarget overrides, apply command line options.
|
||||||
if (PostRADirection == MISched::TopDown) {
|
if (PostRADirection == MISched::TopDown) {
|
||||||
|
@ -534,7 +534,7 @@ unsigned AArch64Subtarget::classifyGlobalFunctionReference(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void AArch64Subtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {
|
const SchedRegion &Region) const {
|
||||||
// LNT run (at least on Cyclone) showed reasonably significant gains for
|
// LNT run (at least on Cyclone) showed reasonably significant gains for
|
||||||
// bi-directional scheduling. 253.perlbmk.
|
// bi-directional scheduling. 253.perlbmk.
|
||||||
Policy.OnlyTopDown = false;
|
Policy.OnlyTopDown = false;
|
||||||
|
@ -343,7 +343,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const override;
|
const SchedRegion &Region) const override;
|
||||||
|
|
||||||
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
|
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx,
|
||||||
SDep &Dep,
|
SDep &Dep,
|
||||||
const TargetSchedModel *SchedModel) const override;
|
const TargetSchedModel *SchedModel) const override;
|
||||||
|
@ -324,7 +324,7 @@ bool GCNSubtarget::zeroesHigh16BitsOfDest(unsigned Opcode) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {
|
const SchedRegion &Region) const {
|
||||||
// Track register pressure so the scheduler can try to decrease
|
// Track register pressure so the scheduler can try to decrease
|
||||||
// pressure once register usage is above the threshold defined by
|
// pressure once register usage is above the threshold defined by
|
||||||
// SIRegisterInfo::getRegPressureSetLimit()
|
// SIRegisterInfo::getRegPressureSetLimit()
|
||||||
|
@ -1022,7 +1022,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const override;
|
const SchedRegion &Region) const override;
|
||||||
|
|
||||||
void mirFileLoaded(MachineFunction &MF) const override;
|
void mirFileLoaded(MachineFunction &MF) const override;
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ void PPCSubtarget::getCriticalPathRCs(RegClassVector &CriticalPathRCs) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void PPCSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {
|
const SchedRegion &Region) const {
|
||||||
// The GenericScheduler that we use defaults to scheduling bottom up only.
|
// The GenericScheduler that we use defaults to scheduling bottom up only.
|
||||||
// We want to schedule from both the top and the bottom and so we set
|
// We want to schedule from both the top and the bottom and so we set
|
||||||
// OnlyBottomUp to false.
|
// OnlyBottomUp to false.
|
||||||
|
@ -240,7 +240,8 @@ public:
|
|||||||
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
|
void getCriticalPathRCs(RegClassVector &CriticalPathRCs) const override;
|
||||||
|
|
||||||
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const override;
|
const SchedRegion &Region) const override;
|
||||||
|
|
||||||
bool useAA() const override;
|
bool useAA() const override;
|
||||||
|
|
||||||
bool enableSubRegLiveness() const override;
|
bool enableSubRegLiveness() const override;
|
||||||
|
@ -216,7 +216,7 @@ unsigned RISCVSubtarget::getMinimumJumpTableEntries() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const {
|
const SchedRegion &Region) const {
|
||||||
// Do bidirectional scheduling since it provides a more balanced scheduling
|
// Do bidirectional scheduling since it provides a more balanced scheduling
|
||||||
// leading to better performance. This will increase compile time.
|
// leading to better performance. This will increase compile time.
|
||||||
Policy.OnlyTopDown = false;
|
Policy.OnlyTopDown = false;
|
||||||
@ -231,8 +231,8 @@ void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
|
|||||||
Policy.ShouldTrackPressure = true;
|
Policy.ShouldTrackPressure = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RISCVSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
|
void RISCVSubtarget::overridePostRASchedPolicy(
|
||||||
unsigned NumRegionInstrs) const {
|
MachineSchedPolicy &Policy, const SchedRegion &Region) const {
|
||||||
MISched::Direction PostRASchedDirection = getPostRASchedDirection();
|
MISched::Direction PostRASchedDirection = getPostRASchedDirection();
|
||||||
if (PostRASchedDirection == MISched::TopDown) {
|
if (PostRASchedDirection == MISched::TopDown) {
|
||||||
Policy.OnlyTopDown = true;
|
Policy.OnlyTopDown = true;
|
||||||
|
@ -395,11 +395,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
void overrideSchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const override;
|
const SchedRegion &Region) const override;
|
||||||
|
|
||||||
void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
|
void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
|
||||||
unsigned NumRegionInstrs) const override;
|
const SchedRegion &Region) const override;
|
||||||
};
|
};
|
||||||
} // End llvm namespace
|
} // namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user