Index: llvm/trunk/tools/llvm-mca/include/Stages/EntryStage.h =================================================================== --- llvm/trunk/tools/llvm-mca/include/Stages/EntryStage.h +++ llvm/trunk/tools/llvm-mca/include/Stages/EntryStage.h @@ -0,0 +1,52 @@ +//===---------------------- EntryStage.h ------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file defines the Entry stage of an instruction pipeline. Its sole +/// purpose in life is to pick instructions in sequence and move them to the +/// next pipeline stage. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVM_MCA_ENTRY_STAGE_H +#define LLVM_TOOLS_LLVM_MCA_ENTRY_STAGE_H + +#include "SourceMgr.h" +#include "Stages/Stage.h" +#include + +namespace llvm { +namespace mca { + +class EntryStage final : public Stage { + InstRef CurrentInstruction; + using InstMap = std::map>; + InstMap Instructions; + SourceMgr &SM; + + // Updates the program counter, and sets 'CurrentInstruction'. + void getNextInstruction(); + + EntryStage(const EntryStage &Other) = delete; + EntryStage &operator=(const EntryStage &Other) = delete; + +public: + EntryStage(SourceMgr &SM) : CurrentInstruction(), SM(SM) {} + + bool isAvailable(const InstRef &IR) const override; + bool hasWorkToComplete() const override; + Error execute(InstRef &IR) override; + Error cycleStart() override; + Error cycleEnd() override; +}; + +} // namespace mca +} // namespace llvm + +#endif // LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H Index: llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h =================================================================== --- llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h +++ llvm/trunk/tools/llvm-mca/include/Stages/FetchStage.h @@ -1,51 +0,0 @@ -//===---------------------- FetchStage.h ------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// \file -/// -/// This file defines the Fetch stage of an instruction pipeline. Its sole -/// purpose in life is to produce instructions for the rest of the pipeline. -/// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H -#define LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H - -#include "SourceMgr.h" -#include "Stages/Stage.h" -#include - -namespace llvm { -namespace mca { - -class FetchStage final : public Stage { - InstRef CurrentInstruction; - using InstMap = std::map>; - InstMap Instructions; - SourceMgr &SM; - - // Updates the program counter, and sets 'CurrentInstruction'. - void getNextInstruction(); - - FetchStage(const FetchStage &Other) = delete; - FetchStage &operator=(const FetchStage &Other) = delete; - -public: - FetchStage(SourceMgr &SM) : CurrentInstruction(), SM(SM) {} - - bool isAvailable(const InstRef &IR) const override; - bool hasWorkToComplete() const override; - Error execute(InstRef &IR) override; - Error cycleStart() override; - Error cycleEnd() override; -}; - -} // namespace mca -} // namespace llvm - -#endif // LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H Index: llvm/trunk/tools/llvm-mca/lib/CMakeLists.txt =================================================================== --- llvm/trunk/tools/llvm-mca/lib/CMakeLists.txt +++ llvm/trunk/tools/llvm-mca/lib/CMakeLists.txt @@ -14,8 +14,8 @@ Instruction.cpp Pipeline.cpp Stages/DispatchStage.cpp + Stages/EntryStage.cpp Stages/ExecuteStage.cpp - Stages/FetchStage.cpp Stages/InstructionTables.cpp Stages/RetireStage.cpp Stages/Stage.cpp Index: llvm/trunk/tools/llvm-mca/lib/Context.cpp =================================================================== --- llvm/trunk/tools/llvm-mca/lib/Context.cpp +++ llvm/trunk/tools/llvm-mca/lib/Context.cpp @@ -20,8 +20,8 @@ #include "HardwareUnits/RetireControlUnit.h" #include "HardwareUnits/Scheduler.h" #include "Stages/DispatchStage.h" +#include "Stages/EntryStage.h" #include "Stages/ExecuteStage.h" -#include "Stages/FetchStage.h" #include "Stages/RetireStage.h" namespace llvm { @@ -40,7 +40,7 @@ auto HWS = llvm::make_unique(SM, LSU.get()); // Create the pipeline stages. - auto Fetch = llvm::make_unique(SrcMgr); + auto Fetch = llvm::make_unique(SrcMgr); auto Dispatch = llvm::make_unique(STI, MRI, Opts.DispatchWidth, *RCU, *PRF); auto Execute = llvm::make_unique(*HWS); Index: llvm/trunk/tools/llvm-mca/lib/Stages/EntryStage.cpp =================================================================== --- llvm/trunk/tools/llvm-mca/lib/Stages/EntryStage.cpp +++ llvm/trunk/tools/llvm-mca/lib/Stages/EntryStage.cpp @@ -0,0 +1,73 @@ +//===---------------------- EntryStage.cpp ----------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This file defines the Fetch stage of an instruction pipeline. Its sole +/// purpose in life is to produce instructions for the rest of the pipeline. +/// +//===----------------------------------------------------------------------===// + +#include "Stages/EntryStage.h" +#include "Instruction.h" + +namespace llvm { +namespace mca { + +bool EntryStage::hasWorkToComplete() const { return CurrentInstruction; } + +bool EntryStage::isAvailable(const InstRef & /* unused */) const { + if (CurrentInstruction) + return checkNextStage(CurrentInstruction); + return false; +} + +void EntryStage::getNextInstruction() { + assert(!CurrentInstruction && "There is already an instruction to process!"); + if (!SM.hasNext()) + return; + SourceRef SR = SM.peekNext(); + std::unique_ptr Inst = llvm::make_unique(SR.second); + CurrentInstruction = InstRef(SR.first, Inst.get()); + Instructions[SR.first] = std::move(Inst); + SM.updateNext(); +} + +llvm::Error EntryStage::execute(InstRef & /*unused */) { + assert(CurrentInstruction && "There is no instruction to process!"); + if (llvm::Error Val = moveToTheNextStage(CurrentInstruction)) + return Val; + + // Move the program counter. + CurrentInstruction.invalidate(); + getNextInstruction(); + return llvm::ErrorSuccess(); +} + +llvm::Error EntryStage::cycleStart() { + if (!CurrentInstruction) + getNextInstruction(); + return llvm::ErrorSuccess(); +} + +llvm::Error EntryStage::cycleEnd() { + // Find the first instruction which hasn't been retired. + const InstMap::iterator It = + llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) { + return !KeyValuePair.second->isRetired(); + }); + + // Erase instructions up to the first that hasn't been retired. + if (It != Instructions.begin()) + Instructions.erase(Instructions.begin(), It); + + return llvm::ErrorSuccess(); +} + +} // namespace mca +} // namespace llvm Index: llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp =================================================================== --- llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp +++ llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp @@ -1,73 +0,0 @@ -//===---------------------- FetchStage.cpp ----------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -/// \file -/// -/// This file defines the Fetch stage of an instruction pipeline. Its sole -/// purpose in life is to produce instructions for the rest of the pipeline. -/// -//===----------------------------------------------------------------------===// - -#include "Stages/FetchStage.h" -#include "Instruction.h" - -namespace llvm { -namespace mca { - -bool FetchStage::hasWorkToComplete() const { return CurrentInstruction; } - -bool FetchStage::isAvailable(const InstRef & /* unused */) const { - if (CurrentInstruction) - return checkNextStage(CurrentInstruction); - return false; -} - -void FetchStage::getNextInstruction() { - assert(!CurrentInstruction && "There is already an instruction to process!"); - if (!SM.hasNext()) - return; - SourceRef SR = SM.peekNext(); - std::unique_ptr Inst = llvm::make_unique(SR.second); - CurrentInstruction = InstRef(SR.first, Inst.get()); - Instructions[SR.first] = std::move(Inst); - SM.updateNext(); -} - -llvm::Error FetchStage::execute(InstRef & /*unused */) { - assert(CurrentInstruction && "There is no instruction to process!"); - if (llvm::Error Val = moveToTheNextStage(CurrentInstruction)) - return Val; - - // Move the program counter. - CurrentInstruction.invalidate(); - getNextInstruction(); - return llvm::ErrorSuccess(); -} - -llvm::Error FetchStage::cycleStart() { - if (!CurrentInstruction) - getNextInstruction(); - return llvm::ErrorSuccess(); -} - -llvm::Error FetchStage::cycleEnd() { - // Find the first instruction which hasn't been retired. - const InstMap::iterator It = - llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) { - return !KeyValuePair.second->isRetired(); - }); - - // Erase instructions up to the first that hasn't been retired. - if (It != Instructions.begin()) - Instructions.erase(Instructions.begin(), It); - - return llvm::ErrorSuccess(); -} - -} // namespace mca -} // namespace llvm Index: llvm/trunk/tools/llvm-mca/llvm-mca.cpp =================================================================== --- llvm/trunk/tools/llvm-mca/llvm-mca.cpp +++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp @@ -24,7 +24,7 @@ #include "CodeRegion.h" #include "CodeRegionGenerator.h" #include "PipelinePrinter.h" -#include "Stages/FetchStage.h" +#include "Stages/EntryStage.h" #include "Stages/InstructionTables.h" #include "Views/DispatchStatistics.h" #include "Views/InstructionInfoView.h" @@ -434,7 +434,7 @@ if (PrintInstructionTables) { // Create a pipeline, stages, and a printer. auto P = make_unique(); - P->appendStage(make_unique(S)); + P->appendStage(make_unique(S)); P->appendStage(make_unique(SM)); mca::PipelinePrinter Printer(*P);