From 9be66737c134f655a585961671c4b3ff801190bf Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 15 Jul 2016 17:48:09 +0000 Subject: [PATCH] [Hexagon] Add a scheduling DAG mutation - Remove output dependencies on USR_OVF register. - Update chain edge latencies between v60 vector loads/stores. llvm-svn: 275586 --- .../lib/Target/Hexagon/HexagonMachineScheduler.cpp | 4 ++ llvm/lib/Target/Hexagon/HexagonSubtarget.cpp | 53 ++++++++++++++++++++++ llvm/lib/Target/Hexagon/HexagonSubtarget.h | 10 +++- llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp | 2 + 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp index 035cea3..c3fca85 100644 --- a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp +++ b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp @@ -13,7 +13,9 @@ //===----------------------------------------------------------------------===// #include "HexagonMachineScheduler.h" +#include "HexagonSubtarget.h" #include "llvm/CodeGen/MachineLoopInfo.h" +#include "llvm/CodeGen/ScheduleDAGMutation.h" #include "llvm/IR/Function.h" using namespace llvm; @@ -223,6 +225,8 @@ void ConvergingVLIWScheduler::initialize(ScheduleDAGMI *dag) { assert((!llvm::ForceTopDown || !llvm::ForceBottomUp) && "-misched-topdown incompatible with -misched-bottomup"); + + DAG->addMutation(make_unique()); } void ConvergingVLIWScheduler::releaseTopNode(SUnit *SU) { diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp index 842b715..0771cbebb 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp @@ -14,6 +14,8 @@ #include "HexagonSubtarget.h" #include "Hexagon.h" #include "HexagonRegisterInfo.h" +#include "llvm/CodeGen/ScheduleDAG.h" +#include "llvm/CodeGen/ScheduleDAGInstrs.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include @@ -119,6 +121,57 @@ HexagonSubtarget::HexagonSubtarget(const Triple &TT, StringRef CPU, UseBSBScheduling = hasV60TOps() && EnableBSBSched; } + +void HexagonSubtarget::HexagonDAGMutation::apply(ScheduleDAGInstrs *DAG) { + for (auto &SU : DAG->SUnits) { + if (!SU.isInstr()) + continue; + SmallVector Erase; + for (auto &D : SU.Preds) + if (D.getKind() == SDep::Output && D.getReg() == Hexagon::USR_OVF) + Erase.push_back(D); + for (auto &E : Erase) + SU.removePred(E); + } + + for (auto &SU : DAG->SUnits) { + // Update the latency of chain edges between v60 vector load or store + // instructions to be 1. These instructions cannot be scheduled in the + // same packet. + MachineInstr *MI1 = SU.getInstr(); + auto *QII = static_cast(DAG->TII); + bool IsStoreMI1 = MI1->mayStore(); + bool IsLoadMI1 = MI1->mayLoad(); + if (!QII->isV60VectorInstruction(MI1) || !(IsStoreMI1 || IsLoadMI1)) + continue; + for (auto &SI : SU.Succs) { + if (SI.getKind() != SDep::Order || SI.getLatency() != 0) + continue; + MachineInstr *MI2 = SI.getSUnit()->getInstr(); + if (!QII->isV60VectorInstruction(MI2)) + continue; + if ((IsStoreMI1 && MI2->mayStore()) || (IsLoadMI1 && MI2->mayLoad())) { + SI.setLatency(1); + SU.setHeightDirty(); + // Change the dependence in the opposite direction too. + for (auto &PI : SI.getSUnit()->Preds) { + if (PI.getSUnit() != &SU || PI.getKind() != SDep::Order) + continue; + PI.setLatency(1); + SI.getSUnit()->setDepthDirty(); + } + } + } + } +} + + +void HexagonSubtarget::getPostRAMutations( + std::vector> &Mutations) const { + Mutations.push_back(make_unique()); +} + + // Pin the vtable to this file. void HexagonSubtarget::anchor() {} diff --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.h b/llvm/lib/Target/Hexagon/HexagonSubtarget.h index 134b823..1922df1 100644 --- a/llvm/lib/Target/Hexagon/HexagonSubtarget.h +++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.h @@ -18,7 +18,6 @@ #include "HexagonISelLowering.h" #include "HexagonInstrInfo.h" #include "HexagonSelectionDAGInfo.h" -#include "llvm/IR/DataLayout.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetSubtargetInfo.h" #include @@ -47,6 +46,11 @@ public: /// default for V60. bool UseBSBScheduling; + class HexagonDAGMutation : public ScheduleDAGMutation { + public: + void apply(ScheduleDAGInstrs *DAG) override; + }; + private: std::string CPUString; HexagonInstrInfo InstrInfo; @@ -119,6 +123,10 @@ public: const HexagonArchEnum &getHexagonArchVersion() const { return HexagonArchVersion; } + + void getPostRAMutations( + std::vector> &Mutations) + const override; }; } // end namespace llvm diff --git a/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp b/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp index 0b3aea1..d326b94 100644 --- a/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp +++ b/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.cpp @@ -108,6 +108,8 @@ HexagonPacketizerList::HexagonPacketizerList(MachineFunction &MF, : VLIWPacketizerList(MF, MLI, AA), MBPI(MBPI), MLI(&MLI) { HII = MF.getSubtarget().getInstrInfo(); HRI = MF.getSubtarget().getRegisterInfo(); + + addMutation(make_unique()); } // Check if FirstI modifies a register that SecondI reads. -- 2.7.4