[llvm] r345185 - [llvm-mca] Simplify the logic in FetchStage. NFCI

Andrea Di Biagio via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 24 12:37:45 PDT 2018


Author: adibiagio
Date: Wed Oct 24 12:37:45 2018
New Revision: 345185

URL: http://llvm.org/viewvc/llvm-project?rev=345185&view=rev
Log:
[llvm-mca] Simplify the logic in FetchStage. NFCI

Only method 'getNextInstruction()' needs to interact with the SourceMgr.

Modified:
    llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h
    llvm/trunk/tools/llvm-mca/lib/Pipeline.cpp
    llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp

Modified: llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h?rev=345185&r1=345184&r2=345185&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h (original)
+++ llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h Wed Oct 24 12:37:45 2018
@@ -24,7 +24,7 @@
 namespace mca {
 
 class FetchStage final : public Stage {
-  std::unique_ptr<Instruction> CurrentInstruction;
+  InstRef CurrentInstruction;
   using InstMap = std::map<unsigned, std::unique_ptr<Instruction>>;
   InstMap Instructions;
   InstrBuilder &IB;

Modified: llvm/trunk/tools/llvm-mca/lib/Pipeline.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/lib/Pipeline.cpp?rev=345185&r1=345184&r2=345185&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/lib/Pipeline.cpp (original)
+++ llvm/trunk/tools/llvm-mca/lib/Pipeline.cpp Wed Oct 24 12:37:45 2018
@@ -39,13 +39,14 @@ bool Pipeline::hasWorkToProcess() {
 Error Pipeline::run() {
   assert(!Stages.empty() && "Unexpected empty pipeline found!");
 
-  while (hasWorkToProcess()) {
+  do {
     notifyCycleBegin();
     if (Error Err = runCycle())
       return Err;
     notifyCycleEnd();
     ++Cycles;
-  }
+  } while (hasWorkToProcess());
+
   return ErrorSuccess();
 }
 

Modified: llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp?rev=345185&r1=345184&r2=345185&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp Wed Oct 24 12:37:45 2018
@@ -18,20 +18,18 @@
 namespace mca {
 
 bool FetchStage::hasWorkToComplete() const {
-  return CurrentInstruction.get() || SM.hasNext();
+  return CurrentInstruction.isValid();
 }
 
 bool FetchStage::isAvailable(const InstRef & /* unused */) const {
-  if (!CurrentInstruction)
-    return false;
-  assert(SM.hasNext() && "Unexpected internal state!");
-  const SourceRef SR = SM.peekNext();
-  InstRef IR(SR.first, CurrentInstruction.get());
-  return checkNextStage(IR);
+  if (CurrentInstruction.isValid())
+    return checkNextStage(CurrentInstruction);
+  return false;
 }
 
 llvm::Error FetchStage::getNextInstruction() {
-  assert(!CurrentInstruction && "There is already an instruction to process!");
+  assert(!CurrentInstruction.isValid() &&
+         "There is already an instruction to process!");
   if (!SM.hasNext())
     return llvm::ErrorSuccess();
   const SourceRef SR = SM.peekNext();
@@ -39,28 +37,25 @@ llvm::Error FetchStage::getNextInstructi
       IB.createInstruction(SR.second);
   if (!InstOrErr)
     return InstOrErr.takeError();
-  CurrentInstruction = std::move(InstOrErr.get());
+  std::unique_ptr<Instruction> Inst = std::move(InstOrErr.get());
+  CurrentInstruction = InstRef(SR.first, Inst.get());
+  Instructions[SR.first] = std::move(Inst);
+  SM.updateNext();
   return llvm::ErrorSuccess();
 }
 
 llvm::Error FetchStage::execute(InstRef & /*unused */) {
-  assert(CurrentInstruction && "There is no instruction to process!");
-  const SourceRef SR = SM.peekNext();
-  InstRef IR(SR.first, CurrentInstruction.get());
-  assert(checkNextStage(IR) && "Invalid fetch!");
-
-  Instructions[IR.getSourceIndex()] = std::move(CurrentInstruction);
-  if (llvm::Error Val = moveToTheNextStage(IR))
+  assert(CurrentInstruction.isValid() && "There is no instruction to process!");
+  if (llvm::Error Val = moveToTheNextStage(CurrentInstruction))
     return Val;
 
-  SM.updateNext();
-
   // Move the program counter.
+  CurrentInstruction.invalidate();
   return getNextInstruction();
 }
 
 llvm::Error FetchStage::cycleStart() {
-  if (!CurrentInstruction)
+  if (!CurrentInstruction.isValid())
     return getNextInstruction();
   return llvm::ErrorSuccess();
 }




More information about the llvm-commits mailing list