Skip to content

Commit 2bfad9b

Browse files
committed
-nosched-above
1 parent f0cbdd3 commit 2bfad9b

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ class MachineSchedStrategy {
241241
/// Tell the strategy that MBB is about to be processed.
242242
virtual void enterMBB(MachineBasicBlock *MBB) {};
243243

244+
virtual bool disableForRegionPreRA(MachineBasicBlock::iterator begin,
245+
MachineBasicBlock::iterator end,
246+
unsigned regioninstrs) const {
247+
return false;
248+
}
249+
244250
/// Tell the strategy that current MBB is done.
245251
virtual void leaveMBB() {};
246252

@@ -487,6 +493,13 @@ class ScheduleDAGMILive : public ScheduleDAGMI {
487493
MachineBasicBlock::iterator end,
488494
unsigned regioninstrs) override;
489495

496+
bool disableForRegion(MachineBasicBlock *bb,
497+
MachineBasicBlock::iterator begin,
498+
MachineBasicBlock::iterator end,
499+
unsigned regioninstrs) const override {
500+
return SchedImpl->disableForRegionPreRA(begin, end, regioninstrs);
501+
}
502+
490503
/// Implement ScheduleDAGInstrs interface for scheduling a sequence of
491504
/// reorderable instructions.
492505
void schedule() override;
@@ -1219,6 +1232,10 @@ class GenericScheduler : public GenericSchedulerBase {
12191232

12201233
void dumpPolicy() const override;
12211234

1235+
bool disableForRegionPreRA(MachineBasicBlock::iterator Begin,
1236+
MachineBasicBlock::iterator End,
1237+
unsigned NumRegionInstrs) const override;
1238+
12221239
bool shouldTrackPressure() const override {
12231240
return RegionPolicy.ShouldTrackPressure;
12241241
}

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ namespace llvm {
319319
MachineBasicBlock::iterator end,
320320
unsigned regioninstrs);
321321

322+
virtual bool disableForRegion(MachineBasicBlock *bb,
323+
MachineBasicBlock::iterator begin,
324+
MachineBasicBlock::iterator end,
325+
unsigned regioninstrs) const { return false; }
326+
322327
/// Called when the scheduler has finished scheduling the current region.
323328
virtual void exitRegion();
324329

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
19+
#include "llvm/CodeGen/MachineBasicBlock.h"
1920
#include "llvm/CodeGen/MacroFusion.h"
2021
#include "llvm/CodeGen/PBQPRAConstraint.h"
2122
#include "llvm/CodeGen/SchedulerRegistry.h"
@@ -229,6 +230,15 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
229230
virtual void overrideSchedPolicy(MachineSchedPolicy &Policy,
230231
unsigned NumRegionInstrs) const {}
231232

233+
/// Allow the subtarget to leave a region untouched. This has purposefully
234+
/// been left a bit untangled from other methods as this is hopefully
235+
/// just a temporary solution.
236+
virtual bool disableForRegionPreRA(MachineBasicBlock::iterator Begin,
237+
MachineBasicBlock::iterator End,
238+
unsigned NumRegionInstrs) const {
239+
return false;
240+
}
241+
232242
// Perform target-specific adjustments to the latency of a schedule
233243
// dependency.
234244
// If a pair of operands is associated with the schedule dependency, DefOpIdx

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ void MachineSchedulerBase::scheduleRegions(ScheduleDAGInstrs &Scheduler,
641641
Scheduler.enterRegion(&*MBB, I, RegionEnd, NumRegionInstrs);
642642

643643
// Skip empty scheduling regions (0 or 1 schedulable instructions).
644-
if (I == RegionEnd || I == std::prev(RegionEnd)) {
644+
if (I == RegionEnd || I == std::prev(RegionEnd) ||
645+
Scheduler.disableForRegion(&*MBB, I, RegionEnd, NumRegionInstrs)) {
645646
// Close the current region. Bundle the terminator if needed.
646647
// This invalidates 'RegionEnd' and 'I'.
647648
Scheduler.exitRegion();
@@ -3334,6 +3335,13 @@ void GenericScheduler::dumpPolicy() const {
33343335
#endif
33353336
}
33363337

3338+
bool GenericScheduler::disableForRegionPreRA(MachineBasicBlock::iterator Begin,
3339+
MachineBasicBlock::iterator End,
3340+
unsigned NumRegionInstrs) const {
3341+
const MachineFunction &MF = *Begin->getMF();
3342+
return MF.getSubtarget().disableForRegionPreRA(Begin, End, NumRegionInstrs);
3343+
}
3344+
33373345
/// Set IsAcyclicLatencyLimited if the acyclic path is longer than the cyclic
33383346
/// critical path by more cycles than it takes to drain the instruction buffer.
33393347
/// We estimate an upper bounds on in-flight instructions as:

llvm/lib/Target/SystemZ/SystemZSubtarget.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ SystemZSubtarget::SystemZSubtarget(const Triple &TT, const std::string &CPU,
7272
InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
7373
TLInfo(TM, *this), FrameLowering(SystemZFrameLowering::create(*this)) {}
7474

75+
76+
// EXPERIMENTAL
77+
cl::opt<unsigned> NoSchedAbove("nosched-above", cl::init(~0U));
78+
bool SystemZSubtarget::disableForRegionPreRA(MachineBasicBlock::iterator Begin,
79+
MachineBasicBlock::iterator End,
80+
unsigned NumRegionInstrs) const {
81+
// It seems that the generic scheduler currently can increase spilling heavily
82+
// with big / huge regions. Disable it until it is fixed.
83+
if (NumRegionInstrs > NoSchedAbove) {
84+
LLVM_DEBUG(dbgs() << "Disabling pre-ra mischeduling of region with "
85+
<< NumRegionInstrs << " instructions\n";);
86+
return true;
87+
}
88+
return false;
89+
}
90+
7591
bool SystemZSubtarget::enableSubRegLiveness() const {
7692
return UseSubRegLiveness;
7793
}

llvm/lib/Target/SystemZ/SystemZSubtarget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class SystemZSubtarget : public SystemZGenSubtargetInfo {
8989
// "source" order scheduler.
9090
bool enableMachineScheduler() const override { return true; }
9191

92+
// Don't use pre-ra mischeduler for huge regions where it creates a lot of
93+
// spilling (temporary solution).
94+
bool disableForRegionPreRA(MachineBasicBlock::iterator Begin,
95+
MachineBasicBlock::iterator End,
96+
unsigned NumRegionInstrs) const override;
97+
9298
// This is important for reducing register pressure in vector code.
9399
bool useAA() const override { return true; }
94100

0 commit comments

Comments
 (0)