[llvm] r328198 - [llvm-mca] Minor refactoring. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 07:14:50 PDT 2018


Author: adibiagio
Date: Thu Mar 22 07:14:49 2018
New Revision: 328198

URL: http://llvm.org/viewvc/llvm-project?rev=328198&view=rev
Log:
[llvm-mca] Minor refactoring. NFCI

Also, removed a couple of unused methods from class Instruction.

Modified:
    llvm/trunk/tools/llvm-mca/Instruction.cpp
    llvm/trunk/tools/llvm-mca/Instruction.h
    llvm/trunk/tools/llvm-mca/LSUnit.cpp
    llvm/trunk/tools/llvm-mca/LSUnit.h
    llvm/trunk/tools/llvm-mca/Scheduler.cpp

Modified: llvm/trunk/tools/llvm-mca/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Instruction.cpp?rev=328198&r1=328197&r2=328198&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Instruction.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Instruction.cpp Thu Mar 22 07:14:49 2018
@@ -108,7 +108,7 @@ void Instruction::execute() {
   Stage = IS_EXECUTING;
 
   // Set the cycles left before the write-back stage.
-  setCyclesLeft(Desc.MaxLatency);
+  CyclesLeft = Desc.MaxLatency;
 
   for (UniqueDef &Def : Defs)
     Def->onInstructionIssued();

Modified: llvm/trunk/tools/llvm-mca/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Instruction.h?rev=328198&r1=328197&r2=328198&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Instruction.h (original)
+++ llvm/trunk/tools/llvm-mca/Instruction.h Thu Mar 22 07:14:49 2018
@@ -285,10 +285,7 @@ public:
   VecUses &getUses() { return Uses; }
   const VecUses &getUses() const { return Uses; }
   const InstrDesc &getDesc() const { return Desc; }
-
   unsigned getRCUTokenID() const { return RCUTokenID; }
-  int getCyclesLeft() const { return CyclesLeft; }
-  void setCyclesLeft(int Cycles) { CyclesLeft = Cycles; }
 
   // Transition to the dispatch stage, and assign a RCUToken to this
   // instruction. The RCUToken is used to track the completion of every

Modified: llvm/trunk/tools/llvm-mca/LSUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/LSUnit.cpp?rev=328198&r1=328197&r2=328198&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/LSUnit.cpp (original)
+++ llvm/trunk/tools/llvm-mca/LSUnit.cpp Thu Mar 22 07:14:49 2018
@@ -12,6 +12,7 @@
 ///
 //===----------------------------------------------------------------------===//
 
+#include "Instruction.h"
 #include "LSUnit.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -49,9 +50,31 @@ void LSUnit::assignSQSlot(unsigned Index
   StoreQueue.insert(Index);
 }
 
+bool LSUnit::reserve(unsigned Index, const InstrDesc &Desc) {
+  unsigned MayLoad = Desc.MayLoad;
+  unsigned MayStore = Desc.MayStore;
+  unsigned IsMemBarrier = Desc.HasSideEffects;
+  if (!MayLoad && !MayStore)
+    return false;
+
+  if (MayLoad) {
+    if (IsMemBarrier)
+      LoadBarriers.insert(Index);
+    assignLQSlot(Index);
+  }
+  if (MayStore) {
+    if (IsMemBarrier)
+      StoreBarriers.insert(Index);
+    assignSQSlot(Index);
+  }
+  return true;
+}
+
 bool LSUnit::isReady(unsigned Index) const {
   bool IsALoad = LoadQueue.count(Index) != 0;
   bool IsAStore = StoreQueue.count(Index) != 0;
+  assert((IsALoad || IsAStore) && "Instruction is not in queue!");
+
   unsigned LoadBarrierIndex = LoadBarriers.empty() ? 0 : *LoadBarriers.begin();
   unsigned StoreBarrierIndex = StoreBarriers.empty() ? 0 : *StoreBarriers.begin();
 

Modified: llvm/trunk/tools/llvm-mca/LSUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/LSUnit.h?rev=328198&r1=328197&r2=328198&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/LSUnit.h (original)
+++ llvm/trunk/tools/llvm-mca/LSUnit.h Thu Mar 22 07:14:49 2018
@@ -24,6 +24,8 @@
 
 namespace mca {
 
+struct InstrDesc;
+
 /// \brief A Load/Store Unit implementing a load and store queues.
 ///
 /// This class implements a load queue and a store queue to emulate the
@@ -129,20 +131,8 @@ public:
   bool isSQFull() const { return SQ_Size != 0 && StoreQueue.size() == SQ_Size; }
   bool isLQFull() const { return LQ_Size != 0 && LoadQueue.size() == LQ_Size; }
 
-  void reserve(unsigned Index, bool MayLoad, bool MayStore, bool IsMemBarrier) {
-    if (!MayLoad && !MayStore)
-      return;
-    if (MayLoad) {
-      if (IsMemBarrier)
-        LoadBarriers.insert(Index);
-      assignLQSlot(Index);
-    }
-    if (MayStore) {
-      if (IsMemBarrier)
-        StoreBarriers.insert(Index);
-      assignSQSlot(Index);
-    }
-  }
+  // Returns true if this instruction has been successfully enqueued.
+  bool reserve(unsigned Index, const InstrDesc &Desc);
 
   // The rules are:
   // 1. A store may not pass a previous store.

Modified: llvm/trunk/tools/llvm-mca/Scheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.cpp?rev=328198&r1=328197&r2=328198&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.cpp Thu Mar 22 07:14:49 2018
@@ -260,16 +260,9 @@ void Scheduler::scheduleInstruction(unsi
     notifyReservedBuffers(Desc.Buffers);
   }
 
-  bool MayLoad = Desc.MayLoad;
-  bool MayStore = Desc.MayStore;
-  if (MayLoad || MayStore)
-    LSU->reserve(Idx, MayLoad, MayStore, Desc.HasSideEffects);
-
-  bool IsReady = MCIS.isReady();
-  if (IsReady && (MayLoad || MayStore))
-    IsReady &= LSU->isReady(Idx);
-
-  if (!IsReady) {
+  // If necessary, reserve queue entries in the load-store unit (LSU).
+  bool Reserved = LSU->reserve(Idx, Desc);
+  if (!MCIS.isReady() || (Reserved && !LSU->isReady(Idx))) {
     DEBUG(dbgs() << "[SCHEDULER] Adding " << Idx << " to the Wait Queue\n");
     WaitQueue[Idx] = &MCIS;
     return;




More information about the llvm-commits mailing list