LLVM  8.0.1
Pipeline.h
Go to the documentation of this file.
1 //===--------------------- Pipeline.h ---------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file implements an ordered container of stages that simulate the
12 /// pipeline of a hardware backend.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_MCA_PIPELINE_H
17 #define LLVM_MCA_PIPELINE_H
18 
19 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/MCA/Stages/Stage.h"
22 #include "llvm/Support/Error.h"
23 
24 namespace llvm {
25 namespace mca {
26 
27 class HWEventListener;
28 
29 /// A pipeline for a specific subtarget.
30 ///
31 /// It emulates an out-of-order execution of instructions. Instructions are
32 /// fetched from a MCInst sequence managed by an initial 'Fetch' stage.
33 /// Instructions are firstly fetched, then dispatched to the schedulers, and
34 /// then executed.
35 ///
36 /// This class tracks the lifetime of an instruction from the moment where
37 /// it gets dispatched to the schedulers, to the moment where it finishes
38 /// executing and register writes are architecturally committed.
39 /// In particular, it monitors changes in the state of every instruction
40 /// in flight.
41 ///
42 /// Instructions are executed in a loop of iterations. The number of iterations
43 /// is defined by the SourceMgr object, which is managed by the initial stage
44 /// of the instruction pipeline.
45 ///
46 /// The Pipeline entry point is method 'run()' which executes cycles in a loop
47 /// until there are new instructions to dispatch, and not every instruction
48 /// has been retired.
49 ///
50 /// Internally, the Pipeline collects statistical information in the form of
51 /// histograms. For example, it tracks how the dispatch group size changes
52 /// over time.
53 class Pipeline {
54  Pipeline(const Pipeline &P) = delete;
55  Pipeline &operator=(const Pipeline &P) = delete;
56 
57  /// An ordered list of stages that define this instruction pipeline.
59  std::set<HWEventListener *> Listeners;
60  unsigned Cycles;
61 
62  Error runCycle();
63  bool hasWorkToProcess();
64  void notifyCycleBegin();
65  void notifyCycleEnd();
66 
67 public:
68  Pipeline() : Cycles(0) {}
69  void appendStage(std::unique_ptr<Stage> S);
70 
71  /// Returns the total number of simulated cycles.
73 
74  void addEventListener(HWEventListener *Listener);
75 };
76 } // namespace mca
77 } // namespace llvm
78 
79 #endif // LLVM_MCA_PIPELINE_H
void addEventListener(HWEventListener *Listener)
Definition: Pipeline.cpp:25
A pipeline for a specific subtarget.
Definition: Pipeline.h:53
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
#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:847
Expected< unsigned > run()
Returns the total number of simulated cycles.
Definition: Pipeline.cpp:38
void appendStage(std::unique_ptr< Stage > S)
Definition: Pipeline.cpp:75
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
A scheduler for Processor Resource Units and Processor Resource Groups.