Skip to content

Commit 074c3c3

Browse files
committed
[RISCV] Override default sched policy
This is based on other targets like PPC/AArch64 and some experiments. Disclaimer: I haven't tested it on many cores, maybe we should make some options being features. I believe downstreams must have tried this before, so feedbacks are welcome.
1 parent 4f3bf1c commit 074c3c3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "RISCV.h"
1717
#include "RISCVFrameLowering.h"
1818
#include "RISCVTargetMachine.h"
19+
#include "llvm/CodeGen/MachineScheduler.h"
1920
#include "llvm/CodeGen/MacroFusion.h"
2021
#include "llvm/CodeGen/ScheduleDAGMutation.h"
2122
#include "llvm/MC/TargetRegistry.h"
@@ -199,3 +200,25 @@ unsigned RISCVSubtarget::getMinimumJumpTableEntries() const {
199200
? RISCVMinimumJumpTableEntries
200201
: TuneInfo->MinimumJumpTableEntries;
201202
}
203+
204+
void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
205+
unsigned NumRegionInstrs) const {
206+
// Do bidirectional scheduling since it provides a more balanced scheduling
207+
// leading to better performance. This will increase compile time.
208+
Policy.OnlyTopDown = false;
209+
Policy.OnlyBottomUp = false;
210+
211+
// Enabling or Disabling the latency heuristic is a close call: It seems to
212+
// help nearly no benchmark on out-of-order architectures, on the other hand
213+
// it regresses register pressure on a few benchmarking.
214+
// FIXME: This is from AArch64, but we haven't evaluated it on RISC-V.
215+
Policy.DisableLatencyHeuristic = true;
216+
217+
// Spilling is generally expensive on all RISC-V cores, so always enable
218+
// register-pressure tracking. This will increase compile time.
219+
Policy.ShouldTrackPressure = true;
220+
221+
// Enabling ShouldTrackLaneMasks when vector instructions are supported.
222+
// TODO: Add extensions that need register pairs as well?
223+
Policy.ShouldTrackLaneMasks = hasVInstructions();
224+
}

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
327327
unsigned getTailDupAggressiveThreshold() const {
328328
return TuneInfo->TailDupAggressiveThreshold;
329329
}
330+
331+
void overrideSchedPolicy(MachineSchedPolicy &Policy,
332+
unsigned NumRegionInstrs) const override;
330333
};
331334
} // End llvm namespace
332335

0 commit comments

Comments
 (0)