From: Andrea Di Biagio Date: Wed, 24 Oct 2018 19:37:45 +0000 (+0000) Subject: [llvm-mca] Simplify the logic in FetchStage. NFCI X-Git-Tag: llvmorg-8.0.0-rc1~5883 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd4deea1c4e84187c109349f5c34fd579932bb60;p=platform%2Fupstream%2Fllvm.git [llvm-mca] Simplify the logic in FetchStage. NFCI Only method 'getNextInstruction()' needs to interact with the SourceMgr. llvm-svn: 345185 --- diff --git a/llvm/tools/llvm-mca/include/Stages/FetchStage.h b/llvm/tools/llvm-mca/include/Stages/FetchStage.h index 10a89c9..45e30e1 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 CurrentInstruction; + InstRef CurrentInstruction; using InstMap = std::map>; InstMap Instructions; InstrBuilder &IB; diff --git a/llvm/tools/llvm-mca/lib/Pipeline.cpp b/llvm/tools/llvm-mca/lib/Pipeline.cpp index 2d9aa6b..ad49522 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 8bd0bd9..e607db9 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 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(); }