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/MCA/Stages/Stage.h"
19 #include "llvm/Support/Error.h"
24 class HWEventListener;
26 /// A pipeline for a specific subtarget.
28 /// It emulates an out-of-order execution of instructions. Instructions are
29 /// fetched from a MCInst sequence managed by an initial 'Fetch' stage.
30 /// Instructions are firstly fetched, then dispatched to the schedulers, and
33 /// This class tracks the lifetime of an instruction from the moment where
34 /// it gets dispatched to the schedulers, to the moment where it finishes
35 /// executing and register writes are architecturally committed.
36 /// In particular, it monitors changes in the state of every instruction
39 /// Instructions are executed in a loop of iterations. The number of iterations
40 /// is defined by the SourceMgr object, which is managed by the initial stage
41 /// of the instruction pipeline.
43 /// The Pipeline entry point is method 'run()' which executes cycles in a loop
44 /// until there are new instructions to dispatch, and not every instruction
47 /// Internally, the Pipeline collects statistical information in the form of
48 /// histograms. For example, it tracks how the dispatch group size changes
51 Pipeline(const Pipeline &P) = delete;
52 Pipeline &operator=(const Pipeline &P) = delete;
54 /// An ordered list of stages that define this instruction pipeline.
55 SmallVector<std::unique_ptr<Stage>, 8> Stages;
56 std::set<HWEventListener *> Listeners;
60 bool hasWorkToProcess();
61 void notifyCycleBegin();
62 void notifyCycleEnd();
65 Pipeline() : Cycles(0) {}
66 void appendStage(std::unique_ptr<Stage> S);
68 /// Returns the total number of simulated cycles.
69 Expected<unsigned> run();
71 void addEventListener(HWEventListener *Listener);
76 #endif // LLVM_MCA_PIPELINE_H