Skip to content

Commit 9571d20

Browse files
authored
[RISCV] Add tune info for postra scheduling direction (#115864)
The results differ on different platforms so it is really hard to determine a common default value. Tune info for postra scheduling direction is added and CPUs can set their own preferable postra scheduling direction.
1 parent 4746395 commit 9571d20

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
// RISC-V processors supported.
1111
//===----------------------------------------------------------------------===//
1212

13+
// Predefined scheduling direction.
14+
defvar TopDown = [{ MISched::TopDown }];
15+
defvar BottomUp = [{ MISched::BottomUp }];
16+
defvar Bidirectional = [{ MISched::Bidirectional }];
17+
1318
class RISCVTuneInfo {
1419
bits<8> PrefFunctionAlignment = 1;
1520
bits<8> PrefLoopAlignment = 1;
@@ -37,6 +42,9 @@ class RISCVTuneInfo {
3742

3843
bits<32> MaxLoadsPerMemcmpOptSize = 4;
3944
bits<32> MaxLoadsPerMemcmp = 8;
45+
46+
// The direction of PostRA scheduling.
47+
code PostRASchedDirection = TopDown;
4048
}
4149

4250
def RISCVTuneInfoTable : GenericTable {
@@ -49,7 +57,8 @@ def RISCVTuneInfoTable : GenericTable {
4957
"MaxStoresPerMemset", "MaxGluedStoresPerMemcpy",
5058
"MaxStoresPerMemcpyOptSize", "MaxStoresPerMemcpy",
5159
"MaxStoresPerMemmoveOptSize", "MaxStoresPerMemmove",
52-
"MaxLoadsPerMemcmpOptSize", "MaxLoadsPerMemcmp"];
60+
"MaxLoadsPerMemcmpOptSize", "MaxLoadsPerMemcmp",
61+
"PostRASchedDirection"];
5362
}
5463

5564
def getRISCVTuneInfo : SearchIndex {

llvm/lib/Target/RISCV/RISCVSubtarget.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "RISCV.h"
1717
#include "RISCVFrameLowering.h"
1818
#include "RISCVTargetMachine.h"
19-
#include "llvm/CodeGen/MachineScheduler.h"
2019
#include "llvm/CodeGen/MacroFusion.h"
2120
#include "llvm/CodeGen/ScheduleDAGMutation.h"
2221
#include "llvm/MC/TargetRegistry.h"
@@ -211,3 +210,18 @@ void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
211210
// register-pressure tracking. This will increase compile time.
212211
Policy.ShouldTrackPressure = true;
213212
}
213+
214+
void RISCVSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
215+
unsigned NumRegionInstrs) const {
216+
MISched::Direction PostRASchedDirection = getPostRASchedDirection();
217+
if (PostRASchedDirection == MISched::TopDown) {
218+
Policy.OnlyTopDown = true;
219+
Policy.OnlyBottomUp = false;
220+
} else if (PostRASchedDirection == MISched::BottomUp) {
221+
Policy.OnlyTopDown = false;
222+
Policy.OnlyBottomUp = true;
223+
} else if (PostRASchedDirection == MISched::Bidirectional) {
224+
Policy.OnlyTopDown = false;
225+
Policy.OnlyBottomUp = false;
226+
}
227+
}

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
2222
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
2323
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
24+
#include "llvm/CodeGen/MachineScheduler.h"
2425
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
2526
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2627
#include "llvm/IR/DataLayout.h"
@@ -66,6 +67,9 @@ struct RISCVTuneInfo {
6667

6768
unsigned MaxLoadsPerMemcmpOptSize;
6869
unsigned MaxLoadsPerMemcmp;
70+
71+
// The direction of PostRA scheduling.
72+
MISched::Direction PostRASchedDirection;
6973
};
7074

7175
#define GET_RISCVTuneInfoTable_DECL
@@ -365,8 +369,15 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
365369
: TuneInfo->MaxLoadsPerMemcmp;
366370
}
367371

372+
MISched::Direction getPostRASchedDirection() const {
373+
return TuneInfo->PostRASchedDirection;
374+
}
375+
368376
void overrideSchedPolicy(MachineSchedPolicy &Policy,
369377
unsigned NumRegionInstrs) const override;
378+
379+
void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
380+
unsigned NumRegionInstrs) const override;
370381
};
371382
} // End llvm namespace
372383

0 commit comments

Comments
 (0)