[llvm] d6a68d0 - [Hexagon] Refactor updateLatency() function

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 4 13:17:33 PST 2022


Author: Ikhlas Ajbar
Date: 2022-01-04T13:16:54-08:00
New Revision: d6a68d08f3845ca321d38243bb6595599ae9f93b

URL: https://github.com/llvm/llvm-project/commit/d6a68d08f3845ca321d38243bb6595599ae9f93b
DIFF: https://github.com/llvm/llvm-project/commit/d6a68d08f3845ca321d38243bb6595599ae9f93b.diff

LOG: [Hexagon] Refactor updateLatency() function

Co-authored-by: Sumanth Gundapaneni <sgundapa at quicinc.com>

Added: 
    

Modified: 
    llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
    llvm/lib/Target/Hexagon/HexagonSubtarget.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
index 047b2176c684..bdd2a2cfc5fa 100644
--- a/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.cpp
@@ -468,10 +468,8 @@ void HexagonSubtarget::adjustSchedDependency(SUnit *Src, int SrcOpIdx,
     return;
   }
 
-  if (!hasV60Ops())
-    return;
-
-  // Set the latency for a copy to zero since we hope that is will get removed.
+  // Set the latency for a copy to zero since we hope that is will get
+  // removed.
   if (DstInst->isCopy())
     Dep.setLatency(0);
 
@@ -485,7 +483,7 @@ void HexagonSubtarget::adjustSchedDependency(SUnit *Src, int SrcOpIdx,
     int DLatency = -1;
     for (const auto &DDep : Dst->Succs) {
       MachineInstr *DDst = DDep.getSUnit()->getInstr();
-      unsigned UseIdx = -1;
+      int UseIdx = -1;
       for (unsigned OpNum = 0; OpNum < DDst->getNumOperands(); OpNum++) {
         const MachineOperand &MO = DDst->getOperand(OpNum);
         if (MO.isReg() && MO.getReg() && MO.isUse() && MO.getReg() == DReg) {
@@ -493,6 +491,10 @@ void HexagonSubtarget::adjustSchedDependency(SUnit *Src, int SrcOpIdx,
           break;
         }
       }
+
+      if (UseIdx == -1)
+        continue;
+
       int Latency = (InstrInfo.getOperandLatency(&InstrItins, *SrcInst, 0,
                                                  *DDst, UseIdx));
       // Set DLatency for the first time.
@@ -518,8 +520,10 @@ void HexagonSubtarget::adjustSchedDependency(SUnit *Src, int SrcOpIdx,
     Dep.setLatency(0);
     return;
   }
-
-  updateLatency(*SrcInst, *DstInst, Dep);
+  int Latency = Dep.getLatency();
+  bool IsArtificial = Dep.isArtificial();
+  Latency = updateLatency(*SrcInst, *DstInst, IsArtificial, Latency);
+  Dep.setLatency(Latency);
 }
 
 void HexagonSubtarget::getPostRAMutations(
@@ -548,21 +552,19 @@ bool HexagonSubtarget::usePredicatedCalls() const {
   return EnablePredicatedCalls;
 }
 
-void HexagonSubtarget::updateLatency(MachineInstr &SrcInst,
-      MachineInstr &DstInst, SDep &Dep) const {
-  if (Dep.isArtificial()) {
-    Dep.setLatency(1);
-    return;
-  }
-
+int HexagonSubtarget::updateLatency(MachineInstr &SrcInst,
+                                    MachineInstr &DstInst, bool IsArtificial,
+                                    int Latency) const {
+  if (IsArtificial)
+    return 1;
   if (!hasV60Ops())
-    return;
-
-  auto &QII = static_cast<const HexagonInstrInfo&>(*getInstrInfo());
+    return Latency;
 
+  auto &QII = static_cast<const HexagonInstrInfo &>(*getInstrInfo());
   // BSB scheduling.
   if (QII.isHVXVec(SrcInst) || useBSBScheduling())
-    Dep.setLatency((Dep.getLatency() + 1) >> 1);
+    Latency = (Latency + 1) >> 1;
+  return Latency;
 }
 
 void HexagonSubtarget::restoreLatency(SUnit *Src, SUnit *Dst) const {
@@ -598,9 +600,9 @@ void HexagonSubtarget::restoreLatency(SUnit *Src, SUnit *Dst) const {
         // For some instructions (ex: COPY), we might end up with < 0 latency
         // as they don't have any Itinerary class associated with them.
         Latency = std::max(Latency, 0);
-
+        bool IsArtificial = I.isArtificial();
+        Latency = updateLatency(*SrcI, *DstI, IsArtificial, Latency);
         I.setLatency(Latency);
-        updateLatency(*SrcI, *DstI, I);
       }
     }
 

diff  --git a/llvm/lib/Target/Hexagon/HexagonSubtarget.h b/llvm/lib/Target/Hexagon/HexagonSubtarget.h
index e4f375440be1..db682676cf12 100644
--- a/llvm/lib/Target/Hexagon/HexagonSubtarget.h
+++ b/llvm/lib/Target/Hexagon/HexagonSubtarget.h
@@ -325,8 +325,8 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo {
 
 private:
   // Helper function responsible for increasing the latency only.
-  void updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst, SDep &Dep)
-      const;
+  int updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst,
+                    bool IsArtificial, int Latency) const;
   void restoreLatency(SUnit *Src, SUnit *Dst) const;
   void changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) const;
   bool isBestZeroLatency(SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,


        


More information about the llvm-commits mailing list