1 //===--------------------- Pipeline.h ---------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file implements an ordered container of stages that simulate the
11 /// pipeline of a hardware backend.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MCA_PIPELINE_H
16 #define LLVM_MCA_PIPELINE_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/MCA/HardwareUnits/Scheduler.h"
20 #include "llvm/MCA/Stages/Stage.h"
21 #include "llvm/Support/Error.h"
26 class HWEventListener
;
28 /// A pipeline for a specific subtarget.
30 /// It emulates an out-of-order execution of instructions. Instructions are
31 /// fetched from a MCInst sequence managed by an initial 'Fetch' stage.
32 /// Instructions are firstly fetched, then dispatched to the schedulers, and
35 /// This class tracks the lifetime of an instruction from the moment where
36 /// it gets dispatched to the schedulers, to the moment where it finishes
37 /// executing and register writes are architecturally committed.
38 /// In particular, it monitors changes in the state of every instruction
41 /// Instructions are executed in a loop of iterations. The number of iterations
42 /// is defined by the SourceMgr object, which is managed by the initial stage
43 /// of the instruction pipeline.
45 /// The Pipeline entry point is method 'run()' which executes cycles in a loop
46 /// until there are new instructions to dispatch, and not every instruction
49 /// Internally, the Pipeline collects statistical information in the form of
50 /// histograms. For example, it tracks how the dispatch group size changes
53 Pipeline(const Pipeline
&P
) = delete;
54 Pipeline
&operator=(const Pipeline
&P
) = delete;
56 /// An ordered list of stages that define this instruction pipeline.
57 SmallVector
<std::unique_ptr
<Stage
>, 8> Stages
;
58 std::set
<HWEventListener
*> Listeners
;
62 bool hasWorkToProcess();
63 void notifyCycleBegin();
64 void notifyCycleEnd();
67 Pipeline() : Cycles(0) {}
68 void appendStage(std::unique_ptr
<Stage
> S
);
70 /// Returns the total number of simulated cycles.
71 Expected
<unsigned> run();
73 void addEventListener(HWEventListener
*Listener
);
78 #endif // LLVM_MCA_PIPELINE_H