From 6c715e1483cc2a21dd9d2076107d07b544538c89 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 15 Jul 2016 20:16:03 +0000 Subject: [PATCH] [Hexagon] Make MI scheduler check for stalls in previous packet on v60 Patch by Ikhlas Ajbar. llvm-svn: 275606 --- .../lib/Target/Hexagon/HexagonMachineScheduler.cpp | 28 ++++++++++++++++++++++ llvm/lib/Target/Hexagon/HexagonMachineScheduler.h | 16 ++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp index 0cc0293..2ff1b53 100644 --- a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp +++ b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.cpp @@ -105,6 +105,11 @@ void HexagonCallMutation::apply(ScheduleDAGInstrs *DAG) { } +/// Save the last formed packet +void VLIWResourceModel::savePacket() { + OldPacket = Packet; +} + /// Check if scheduling of this SU is possible /// in the current packet. /// It is _not_ precise (statefull), it is more like @@ -155,6 +160,7 @@ bool VLIWResourceModel::reserveResources(SUnit *SU) { // Artificially reset state. if (!SU) { ResourcesModel->clearResources(); + savePacket(); Packet.clear(); TotalPackets++; return false; @@ -163,6 +169,7 @@ bool VLIWResourceModel::reserveResources(SUnit *SU) { // start a new one. if (!isResourceAvailable(SU)) { ResourcesModel->clearResources(); + savePacket(); Packet.clear(); TotalPackets++; startNewCycle = true; @@ -199,6 +206,7 @@ bool VLIWResourceModel::reserveResources(SUnit *SU) { // we start fresh. if (Packet.size() >= SchedModel->getIssueWidth()) { ResourcesModel->clearResources(); + savePacket(); Packet.clear(); TotalPackets++; startNewCycle = true; @@ -552,6 +560,8 @@ int ConvergingVLIWScheduler::SchedulingCost(ReadyQueue &Q, SUnit *SU, if (!SU || SU->isScheduled) return ResCount; + MachineInstr *Instr = SU->getInstr(); + // Forced priority is high. if (SU->isScheduleHigh) ResCount += PriorityOne; @@ -596,6 +606,24 @@ int ConvergingVLIWScheduler::SchedulingCost(ReadyQueue &Q, SUnit *SU, ResCount -= (Delta.Excess.getUnitInc()*PriorityTwo); ResCount -= (Delta.CriticalMax.getUnitInc()*PriorityTwo); + auto &QST = DAG->MF.getSubtarget(); + auto &QII = *QST.getInstrInfo(); + + // Give less preference to an instruction that will cause a stall with + // an instruction in the previous packet. + if (QII.isV60VectorInstruction(Instr)) { + // Check for stalls in the previous packet. + if (Q.getID() == TopQID) { + for (auto J : Top.ResourceModel->OldPacket) + if (QII.producesStall(J->getInstr(), Instr)) + ResCount -= PriorityOne; + } else { + for (auto J : Bot.ResourceModel->OldPacket) + if (QII.producesStall(Instr, J->getInstr())) + ResCount -= PriorityOne; + } + } + DEBUG(if (verbose) dbgs() << " Total(" << ResCount << ")"); return ResCount; diff --git a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.h b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.h index 1fe8d9d..611527e 100644 --- a/llvm/lib/Target/Hexagon/HexagonMachineScheduler.h +++ b/llvm/lib/Target/Hexagon/HexagonMachineScheduler.h @@ -53,9 +53,13 @@ class VLIWResourceModel { unsigned TotalPackets; public: + /// Save the last formed packet. + std::vector OldPacket; + +public: VLIWResourceModel(const TargetSubtargetInfo &STI, const TargetSchedModel *SM) : SchedModel(SM), TotalPackets(0) { - ResourcesModel = STI.getInstrInfo()->CreateTargetScheduleState(STI); + ResourcesModel = STI.getInstrInfo()->CreateTargetScheduleState(STI); // This hard requirement could be relaxed, // but for now do not let it proceed. @@ -63,6 +67,8 @@ public: Packet.resize(SchedModel->getIssueWidth()); Packet.clear(); + OldPacket.resize(SchedModel->getIssueWidth()); + OldPacket.clear(); ResourcesModel->clearResources(); } @@ -85,7 +91,12 @@ public: bool isResourceAvailable(SUnit *SU); bool reserveResources(SUnit *SU); + void savePacket(); unsigned getTotalPackets() const { return TotalPackets; } + + bool isInPacket(SUnit *SU) const { + return std::find(Packet.begin(), Packet.end(), SU) != Packet.end(); + } }; /// Extend the standard ScheduleDAGMI to provide more context and override the @@ -99,8 +110,6 @@ public: /// Schedule - This is called back from ScheduleDAGInstrs::Run() when it's /// time to do some work. void schedule() override; - /// Perform platform-specific DAG postprocessing. - void postprocessDAG(); }; /// ConvergingVLIWScheduler shrinks the unscheduled zone using heuristics @@ -166,6 +175,7 @@ class ConvergingVLIWScheduler : public MachineSchedStrategy { void init(VLIWMachineScheduler *dag, const TargetSchedModel *smodel) { DAG = dag; SchedModel = smodel; + IssueCount = 0; } bool isTop() const { -- 2.7.4