]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/MCA/Pipeline.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / MCA / Pipeline.h
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"
20 #include "llvm/MCA/HardwareUnits/Scheduler.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.
58   SmallVector<std::unique_ptr<Stage>, 8> Stages;
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.
72   Expected<unsigned> run();
73
74   void addEventListener(HWEventListener *Listener);
75 };
76 } // namespace mca
77 } // namespace llvm
78
79 #endif // LLVM_MCA_PIPELINE_H