[llvm] [RISCV] Add tune info for postra scheduling direction (PR #115864)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 20:24:27 PST 2024
https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/115864
>From 4989eb0b8c213f248d0903e129f47b7ec6db6713 Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Wed, 13 Nov 2024 15:11:18 +0800
Subject: [PATCH] [RISCV] Add tune info for postra scheduling direction
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.
---
llvm/lib/Target/RISCV/RISCVProcessors.td | 11 ++++++++++-
llvm/lib/Target/RISCV/RISCVSubtarget.cpp | 16 +++++++++++++++-
llvm/lib/Target/RISCV/RISCVSubtarget.h | 11 +++++++++++
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVProcessors.td b/llvm/lib/Target/RISCV/RISCVProcessors.td
index c4e19c515b155b..1f5f5b02220776 100644
--- a/llvm/lib/Target/RISCV/RISCVProcessors.td
+++ b/llvm/lib/Target/RISCV/RISCVProcessors.td
@@ -10,6 +10,11 @@
// RISC-V processors supported.
//===----------------------------------------------------------------------===//
+// Predefined scheduling direction.
+defvar TopDown = [{ MISched::TopDown }];
+defvar BottomUp = [{ MISched::BottomUp }];
+defvar Bidirectional = [{ MISched::Bidirectional }];
+
class RISCVTuneInfo {
bits<8> PrefFunctionAlignment = 1;
bits<8> PrefLoopAlignment = 1;
@@ -37,6 +42,9 @@ class RISCVTuneInfo {
bits<32> MaxLoadsPerMemcmpOptSize = 4;
bits<32> MaxLoadsPerMemcmp = 8;
+
+ // The direction of PostRA scheduling.
+ code PostRASchedDirection = TopDown;
}
def RISCVTuneInfoTable : GenericTable {
@@ -49,7 +57,8 @@ def RISCVTuneInfoTable : GenericTable {
"MaxStoresPerMemset", "MaxGluedStoresPerMemcpy",
"MaxStoresPerMemcpyOptSize", "MaxStoresPerMemcpy",
"MaxStoresPerMemmoveOptSize", "MaxStoresPerMemmove",
- "MaxLoadsPerMemcmpOptSize", "MaxLoadsPerMemcmp"];
+ "MaxLoadsPerMemcmpOptSize", "MaxLoadsPerMemcmp",
+ "PostRASchedDirection"];
}
def getRISCVTuneInfo : SearchIndex {
diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
index 38443e8646de40..bb448995ad6ed5 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -16,7 +16,6 @@
#include "RISCV.h"
#include "RISCVFrameLowering.h"
#include "RISCVTargetMachine.h"
-#include "llvm/CodeGen/MachineScheduler.h"
#include "llvm/CodeGen/MacroFusion.h"
#include "llvm/CodeGen/ScheduleDAGMutation.h"
#include "llvm/MC/TargetRegistry.h"
@@ -211,3 +210,18 @@ void RISCVSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
// register-pressure tracking. This will increase compile time.
Policy.ShouldTrackPressure = true;
}
+
+void RISCVSubtarget::overridePostRASchedPolicy(MachineSchedPolicy &Policy,
+ unsigned NumRegionInstrs) const {
+ MISched::Direction PostRASchedDirection = getPostRASchedDirection();
+ if (PostRASchedDirection == MISched::TopDown) {
+ Policy.OnlyTopDown = true;
+ Policy.OnlyBottomUp = false;
+ } else if (PostRASchedDirection == MISched::BottomUp) {
+ Policy.OnlyTopDown = false;
+ Policy.OnlyBottomUp = true;
+ } else if (PostRASchedDirection == MISched::Bidirectional) {
+ Policy.OnlyTopDown = false;
+ Policy.OnlyBottomUp = false;
+ }
+}
diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.h b/llvm/lib/Target/RISCV/RISCVSubtarget.h
index 9a1881c2d39837..f83125c35b388d 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -21,6 +21,7 @@
#include "llvm/CodeGen/GlobalISel/CallLowering.h"
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
+#include "llvm/CodeGen/MachineScheduler.h"
#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/DataLayout.h"
@@ -66,6 +67,9 @@ struct RISCVTuneInfo {
unsigned MaxLoadsPerMemcmpOptSize;
unsigned MaxLoadsPerMemcmp;
+
+ // The direction of PostRA scheduling.
+ MISched::Direction PostRASchedDirection;
};
#define GET_RISCVTuneInfoTable_DECL
@@ -365,8 +369,15 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
: TuneInfo->MaxLoadsPerMemcmp;
}
+ MISched::Direction getPostRASchedDirection() const {
+ return TuneInfo->PostRASchedDirection;
+ }
+
void overrideSchedPolicy(MachineSchedPolicy &Policy,
unsigned NumRegionInstrs) const override;
+
+ void overridePostRASchedPolicy(MachineSchedPolicy &Policy,
+ unsigned NumRegionInstrs) const override;
};
} // End llvm namespace
More information about the llvm-commits
mailing list