summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2018-10-24 19:37:45 +0000
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2018-10-24 19:37:45 +0000
commitcd4deea1c4e84187c109349f5c34fd579932bb60 (patch)
treea84beaa988054e1f7a26c3e59e0bd49bfd40627c
parent536916898388e10fdfe02d8f8ef61fe9b75f62a0 (diff)
downloadbcm5719-llvm-cd4deea1c4e84187c109349f5c34fd579932bb60.tar.gz
bcm5719-llvm-cd4deea1c4e84187c109349f5c34fd579932bb60.zip
[llvm-mca] Simplify the logic in FetchStage. NFCI
Only method 'getNextInstruction()' needs to interact with the SourceMgr. llvm-svn: 345185
-rw-r--r--llvm/tools/llvm-mca/include/Stages/FetchStage.h2
-rw-r--r--llvm/tools/llvm-mca/lib/Pipeline.cpp5
-rw-r--r--llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp33
3 files changed, 18 insertions, 22 deletions
diff --git a/llvm/tools/llvm-mca/include/Stages/FetchStage.h b/llvm/tools/llvm-mca/include/Stages/FetchStage.h
index 10a89c94469..45e30e17b4d 100644
--- a/llvm/tools/llvm-mca/include/Stages/FetchStage.h
+++ b/llvm/tools/llvm-mca/include/Stages/FetchStage.h
@@ -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;
diff --git a/llvm/tools/llvm-mca/lib/Pipeline.cpp b/llvm/tools/llvm-mca/lib/Pipeline.cpp
index 2d9aa6b2a31..ad49522ad79 100644
--- a/llvm/tools/llvm-mca/lib/Pipeline.cpp
+++ b/llvm/tools/llvm-mca/lib/Pipeline.cpp
@@ -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();
}
diff --git a/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp b/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp
index 8bd0bd9e3a7..e607db9c8f0 100644
--- a/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp
+++ b/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp
@@ -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::getNextInstruction() {
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();
}
OpenPOWER on IntegriCloud