LLVM  10.0.0svn
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 
18 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/MCA/Stages/Stage.h"
21 #include "llvm/Support/Error.h"
22 
23 namespace llvm {
24 namespace mca {
25 
26 class HWEventListener;
27 
28 /// A pipeline for a specific subtarget.
29 ///
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
33 /// then executed.
34 ///
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
39 /// in flight.
40 ///
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.
44 ///
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
47 /// has been retired.
48 ///
49 /// Internally, the Pipeline collects statistical information in the form of
50 /// histograms. For example, it tracks how the dispatch group size changes
51 /// over time.
52 class Pipeline {
53  Pipeline(const Pipeline &P) = delete;
54  Pipeline &operator=(const Pipeline &P) = delete;
55 
56  /// An ordered list of stages that define this instruction pipeline.
58  std::set<HWEventListener *> Listeners;
59  unsigned Cycles;
60 
61  Error runCycle();
62  bool hasWorkToProcess();
63  void notifyCycleBegin();
64  void notifyCycleEnd();
65 
66 public:
67  Pipeline() : Cycles(0) {}
68  void appendStage(std::unique_ptr<Stage> S);
69 
70  /// Returns the total number of simulated cycles.
72 
73  void addEventListener(HWEventListener *Listener);
74 };
75 } // namespace mca
76 } // namespace llvm
77 
78 #endif // LLVM_MCA_PIPELINE_H
void addEventListener(HWEventListener *Listener)
Definition: Pipeline.cpp:24
A pipeline for a specific subtarget.
Definition: Pipeline.h:52
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
#define P(N)
This file defines a stage.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Expected< unsigned > run()
Returns the total number of simulated cycles.
Definition: Pipeline.cpp:37
void appendStage(std::unique_ptr< Stage > S)
Definition: Pipeline.cpp:75
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
A scheduler for Processor Resource Units and Processor Resource Groups.