llvm.org GIT mirror llvm / b665487
[llvm-mca] PR39261: Rename FetchStage to EntryStage. This fixes PR39261. FetchStage is a misnomer. It causes confusion with the frontend fetch stage, which we don't currently simulate. I decided to rename it into EntryStage mainly because this is meant to be a "source" stage for all pipelines. Differential Revision: https://reviews.llvm.org/D54268 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346419 91177308-0d34-0410-b5e6-96231b3b80d8 Andrea Di Biagio 10 months ago
7 changed file(s) with 130 addition(s) and 129 deletion(s). Raw diff Collapse all Expand all
0 //===---------------------- EntryStage.h ------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file defines the Entry stage of an instruction pipeline. Its sole
11 /// purpose in life is to pick instructions in sequence and move them to the
12 /// next pipeline stage.
13 ///
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TOOLS_LLVM_MCA_ENTRY_STAGE_H
17 #define LLVM_TOOLS_LLVM_MCA_ENTRY_STAGE_H
18
19 #include "SourceMgr.h"
20 #include "Stages/Stage.h"
21 #include
22
23 namespace llvm {
24 namespace mca {
25
26 class EntryStage final : public Stage {
27 InstRef CurrentInstruction;
28 using InstMap = std::map>;
29 InstMap Instructions;
30 SourceMgr &SM;
31
32 // Updates the program counter, and sets 'CurrentInstruction'.
33 void getNextInstruction();
34
35 EntryStage(const EntryStage &Other) = delete;
36 EntryStage &operator=(const EntryStage &Other) = delete;
37
38 public:
39 EntryStage(SourceMgr &SM) : CurrentInstruction(), SM(SM) {}
40
41 bool isAvailable(const InstRef &IR) const override;
42 bool hasWorkToComplete() const override;
43 Error execute(InstRef &IR) override;
44 Error cycleStart() override;
45 Error cycleEnd() override;
46 };
47
48 } // namespace mca
49 } // namespace llvm
50
51 #endif // LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H
+0
-51
tools/llvm-mca/include/Stages/FetchStage.h less more
None //===---------------------- FetchStage.h ------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file defines the Fetch stage of an instruction pipeline. Its sole
11 /// purpose in life is to produce instructions for the rest of the pipeline.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H
16 #define LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H
17
18 #include "SourceMgr.h"
19 #include "Stages/Stage.h"
20 #include
21
22 namespace llvm {
23 namespace mca {
24
25 class FetchStage final : public Stage {
26 InstRef CurrentInstruction;
27 using InstMap = std::map>;
28 InstMap Instructions;
29 SourceMgr &SM;
30
31 // Updates the program counter, and sets 'CurrentInstruction'.
32 void getNextInstruction();
33
34 FetchStage(const FetchStage &Other) = delete;
35 FetchStage &operator=(const FetchStage &Other) = delete;
36
37 public:
38 FetchStage(SourceMgr &SM) : CurrentInstruction(), SM(SM) {}
39
40 bool isAvailable(const InstRef &IR) const override;
41 bool hasWorkToComplete() const override;
42 Error execute(InstRef &IR) override;
43 Error cycleStart() override;
44 Error cycleEnd() override;
45 };
46
47 } // namespace mca
48 } // namespace llvm
49
50 #endif // LLVM_TOOLS_LLVM_MCA_FETCH_STAGE_H
1313 Instruction.cpp
1414 Pipeline.cpp
1515 Stages/DispatchStage.cpp
16 Stages/EntryStage.cpp
1617 Stages/ExecuteStage.cpp
17 Stages/FetchStage.cpp
1818 Stages/InstructionTables.cpp
1919 Stages/RetireStage.cpp
2020 Stages/Stage.cpp
1919 #include "HardwareUnits/RetireControlUnit.h"
2020 #include "HardwareUnits/Scheduler.h"
2121 #include "Stages/DispatchStage.h"
22 #include "Stages/EntryStage.h"
2223 #include "Stages/ExecuteStage.h"
23 #include "Stages/FetchStage.h"
2424 #include "Stages/RetireStage.h"
2525
2626 namespace llvm {
3939 auto HWS = llvm::make_unique(SM, LSU.get());
4040
4141 // Create the pipeline stages.
42 auto Fetch = llvm::make_unique<FetchStage>(SrcMgr);
42 auto Fetch = llvm::make_unique<EntryStage>(SrcMgr);
4343 auto Dispatch = llvm::make_unique(STI, MRI, Opts.DispatchWidth,
4444 *RCU, *PRF);
4545 auto Execute = llvm::make_unique(*HWS);
0 //===---------------------- EntryStage.cpp ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file defines the Fetch stage of an instruction pipeline. Its sole
11 /// purpose in life is to produce instructions for the rest of the pipeline.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "Stages/EntryStage.h"
16 #include "Instruction.h"
17
18 namespace llvm {
19 namespace mca {
20
21 bool EntryStage::hasWorkToComplete() const { return CurrentInstruction; }
22
23 bool EntryStage::isAvailable(const InstRef & /* unused */) const {
24 if (CurrentInstruction)
25 return checkNextStage(CurrentInstruction);
26 return false;
27 }
28
29 void EntryStage::getNextInstruction() {
30 assert(!CurrentInstruction && "There is already an instruction to process!");
31 if (!SM.hasNext())
32 return;
33 SourceRef SR = SM.peekNext();
34 std::unique_ptr Inst = llvm::make_unique(SR.second);
35 CurrentInstruction = InstRef(SR.first, Inst.get());
36 Instructions[SR.first] = std::move(Inst);
37 SM.updateNext();
38 }
39
40 llvm::Error EntryStage::execute(InstRef & /*unused */) {
41 assert(CurrentInstruction && "There is no instruction to process!");
42 if (llvm::Error Val = moveToTheNextStage(CurrentInstruction))
43 return Val;
44
45 // Move the program counter.
46 CurrentInstruction.invalidate();
47 getNextInstruction();
48 return llvm::ErrorSuccess();
49 }
50
51 llvm::Error EntryStage::cycleStart() {
52 if (!CurrentInstruction)
53 getNextInstruction();
54 return llvm::ErrorSuccess();
55 }
56
57 llvm::Error EntryStage::cycleEnd() {
58 // Find the first instruction which hasn't been retired.
59 const InstMap::iterator It =
60 llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) {
61 return !KeyValuePair.second->isRetired();
62 });
63
64 // Erase instructions up to the first that hasn't been retired.
65 if (It != Instructions.begin())
66 Instructions.erase(Instructions.begin(), It);
67
68 return llvm::ErrorSuccess();
69 }
70
71 } // namespace mca
72 } // namespace llvm
+0
-73
tools/llvm-mca/lib/Stages/FetchStage.cpp less more
None //===---------------------- FetchStage.cpp ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file defines the Fetch stage of an instruction pipeline. Its sole
11 /// purpose in life is to produce instructions for the rest of the pipeline.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "Stages/FetchStage.h"
16 #include "Instruction.h"
17
18 namespace llvm {
19 namespace mca {
20
21 bool FetchStage::hasWorkToComplete() const { return CurrentInstruction; }
22
23 bool FetchStage::isAvailable(const InstRef & /* unused */) const {
24 if (CurrentInstruction)
25 return checkNextStage(CurrentInstruction);
26 return false;
27 }
28
29 void FetchStage::getNextInstruction() {
30 assert(!CurrentInstruction && "There is already an instruction to process!");
31 if (!SM.hasNext())
32 return;
33 SourceRef SR = SM.peekNext();
34 std::unique_ptr Inst = llvm::make_unique(SR.second);
35 CurrentInstruction = InstRef(SR.first, Inst.get());
36 Instructions[SR.first] = std::move(Inst);
37 SM.updateNext();
38 }
39
40 llvm::Error FetchStage::execute(InstRef & /*unused */) {
41 assert(CurrentInstruction && "There is no instruction to process!");
42 if (llvm::Error Val = moveToTheNextStage(CurrentInstruction))
43 return Val;
44
45 // Move the program counter.
46 CurrentInstruction.invalidate();
47 getNextInstruction();
48 return llvm::ErrorSuccess();
49 }
50
51 llvm::Error FetchStage::cycleStart() {
52 if (!CurrentInstruction)
53 getNextInstruction();
54 return llvm::ErrorSuccess();
55 }
56
57 llvm::Error FetchStage::cycleEnd() {
58 // Find the first instruction which hasn't been retired.
59 const InstMap::iterator It =
60 llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) {
61 return !KeyValuePair.second->isRetired();
62 });
63
64 // Erase instructions up to the first that hasn't been retired.
65 if (It != Instructions.begin())
66 Instructions.erase(Instructions.begin(), It);
67
68 return llvm::ErrorSuccess();
69 }
70
71 } // namespace mca
72 } // namespace llvm
2323 #include "CodeRegion.h"
2424 #include "CodeRegionGenerator.h"
2525 #include "PipelinePrinter.h"
26 #include "Stages/FetchStage.h"
26 #include "Stages/EntryStage.h"
2727 #include "Stages/InstructionTables.h"
2828 #include "Views/DispatchStatistics.h"
2929 #include "Views/InstructionInfoView.h"
433433 if (PrintInstructionTables) {
434434 // Create a pipeline, stages, and a printer.
435435 auto P = make_unique();
436 P->appendStage(make_uniqueFetchStage>(S));
436 P->appendStage(make_uniqueEntryStage>(S));
437437 P->appendStage(make_unique(SM));
438438 mca::PipelinePrinter Printer(*P);
439439