LLVM 22.0.0git
Pipeline.h
Go to the documentation of this file.
1//===--------------------- Pipeline.h ---------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file implements an ordered container of stages that simulate the
11/// pipeline of a hardware backend.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MCA_PIPELINE_H
16#define LLVM_MCA_PIPELINE_H
17
20#include "llvm/Support/Error.h"
21
22namespace llvm {
23namespace mca {
24
25class HWEventListener;
26
27/// A pipeline for a specific subtarget.
28///
29/// It emulates an out-of-order execution of instructions. Instructions are
30/// fetched from a MCInst sequence managed by an initial 'Fetch' stage.
31/// Instructions are firstly fetched, then dispatched to the schedulers, and
32/// then executed.
33///
34/// This class tracks the lifetime of an instruction from the moment where
35/// it gets dispatched to the schedulers, to the moment where it finishes
36/// executing and register writes are architecturally committed.
37/// In particular, it monitors changes in the state of every instruction
38/// in flight.
39///
40/// Instructions are executed in a loop of iterations. The number of iterations
41/// is defined by the SourceMgr object, which is managed by the initial stage
42/// of the instruction pipeline.
43///
44/// The Pipeline entry point is method 'run()' which executes cycles in a loop
45/// until there are new instructions to dispatch, and not every instruction
46/// has been retired.
47///
48/// Internally, the Pipeline collects statistical information in the form of
49/// histograms. For example, it tracks how the dispatch group size changes
50/// over time.
51class Pipeline {
52 Pipeline(const Pipeline &P) = delete;
53 Pipeline &operator=(const Pipeline &P) = delete;
54
55 enum class State {
56 Created, // Pipeline was just created. The default state.
57 Started, // Pipeline has started running.
58 Paused // Pipeline is paused.
59 };
60 State CurrentState = State::Created;
61
62 /// An ordered list of stages that define this instruction pipeline.
64 std::set<HWEventListener *> Listeners;
65 unsigned Cycles = 0;
66
67 Error runCycle();
68 bool hasWorkToProcess();
69 void notifyCycleBegin();
70 void notifyCycleEnd();
71
72public:
73 Pipeline() = default;
74 LLVM_ABI void appendStage(std::unique_ptr<Stage> S);
75
76 /// Returns the total number of simulated cycles.
78
80
81 /// Returns whether the pipeline is currently paused.
82 bool isPaused() const { return CurrentState == State::Paused; }
83};
84} // namespace mca
85} // namespace llvm
86
87#endif // LLVM_MCA_PIPELINE_H
#define LLVM_ABI
Definition Compiler.h:213
#define P(N)
This file defines a stage.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM_ABI void addEventListener(HWEventListener *Listener)
Definition Pipeline.cpp:24
bool isPaused() const
Returns whether the pipeline is currently paused.
Definition Pipeline.h:82
LLVM_ABI void appendStage(std::unique_ptr< Stage > S)
Definition Pipeline.cpp:86
LLVM_ABI Expected< unsigned > run()
Returns the total number of simulated cycles.
Definition Pipeline.cpp:37
This is an optimization pass for GlobalISel generic memory operations.