[PATCH] D45266: [PowerPC] Add a Memory Latency Mutation to the scheduler
Stefan Pintilie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 4 09:45:45 PDT 2018
stefanp created this revision.
stefanp added reviewers: kbarton, nemanjai, inouehrs, sfertile, lei, syzaara, hfinkel, echristo.
Loads and Stores that depend on the same address should be scheduled apart because we don't want a load that is waiting for a store to finish or a store that is waiting for a load to finish.
This patch depends on https://reviews.llvm.org/D45265 and so that patch would have to go in first.
https://reviews.llvm.org/D45266
Files:
lib/Target/PowerPC/PPCSubtarget.cpp
lib/Target/PowerPC/PPCSubtarget.h
lib/Target/PowerPC/PPCTargetMachine.cpp
Index: lib/Target/PowerPC/PPCTargetMachine.cpp
===================================================================
--- lib/Target/PowerPC/PPCTargetMachine.cpp
+++ lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -315,6 +315,20 @@
return getTM<PPCTargetMachine>();
}
+ ScheduleDAGInstrs *
+ createMachineScheduler(MachineSchedContext *C) const override {
+ ScheduleDAGMILive *DAG = createGenericSchedLive(C);
+ DAG->addMutation(llvm::make_unique<PPCSubtarget::MemLatencyMutation>());
+ return DAG;
+ }
+
+ ScheduleDAGInstrs *
+ createPostMachineScheduler(MachineSchedContext *C) const override {
+ ScheduleDAGMI *DAG = createGenericSchedPostRA(C);
+ DAG->addMutation(llvm::make_unique<PPCSubtarget::MemLatencyMutation>());
+ return DAG;
+ }
+
void addIRPasses() override;
bool addPreISel() override;
bool addILPOpts() override;
Index: lib/Target/PowerPC/PPCSubtarget.h
===================================================================
--- lib/Target/PowerPC/PPCSubtarget.h
+++ lib/Target/PowerPC/PPCSubtarget.h
@@ -192,6 +192,10 @@
/// so that we can use initializer lists for subtarget initialization.
PPCSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
+ struct MemLatencyMutation : public ScheduleDAGMutation {
+ void apply(ScheduleDAGInstrs *DAG) override;
+ };
+
private:
void initializeEnvironment();
void initSubtargetFeatures(StringRef CPU, StringRef FS);
Index: lib/Target/PowerPC/PPCSubtarget.cpp
===================================================================
--- lib/Target/PowerPC/PPCSubtarget.cpp
+++ lib/Target/PowerPC/PPCSubtarget.cpp
@@ -47,6 +47,25 @@
return *this;
}
+void PPCSubtarget::MemLatencyMutation::apply(ScheduleDAGInstrs *DAG) {
+ for (SUnit &SU : DAG->SUnits) {
+ // Looking for loads and stores.
+ if (SU.getInstr()->mayLoad() || SU.getInstr()->mayStore()) {
+ // If we have a memory dependency then set the latency to 4 cycles.
+ // The reason 4 is picked is because it is the best case scenario for a
+ // load when we get a cache hit.
+ for (SDep &Dep : SU.Succs) {
+ if (Dep.isNormalMemory())
+ Dep.setLatency(4);
+ }
+ for (SDep &Dep : SU.Preds) {
+ if (Dep.isNormalMemory())
+ Dep.setLatency(4);
+ }
+ }
+ }
+}
+
PPCSubtarget::PPCSubtarget(const Triple &TT, const std::string &CPU,
const std::string &FS, const PPCTargetMachine &TM)
: PPCGenSubtargetInfo(TT, CPU, FS), TargetTriple(TT),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45266.140979.patch
Type: text/x-patch
Size: 2530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180404/8a274deb/attachment.bin>
More information about the llvm-commits
mailing list