Pipeline.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--------------------- Pipeline.h ---------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. ///
  15. /// This file implements an ordered container of stages that simulate the
  16. /// pipeline of a hardware backend.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_MCA_PIPELINE_H
  20. #define LLVM_MCA_PIPELINE_H
  21. #include "llvm/MCA/Stages/Stage.h"
  22. #include "llvm/Support/Error.h"
  23. namespace llvm {
  24. namespace mca {
  25. class HWEventListener;
  26. /// A pipeline for a specific subtarget.
  27. ///
  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
  31. /// then executed.
  32. ///
  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
  37. /// in flight.
  38. ///
  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.
  42. ///
  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
  45. /// has been retired.
  46. ///
  47. /// Internally, the Pipeline collects statistical information in the form of
  48. /// histograms. For example, it tracks how the dispatch group size changes
  49. /// over time.
  50. class Pipeline {
  51. Pipeline(const Pipeline &P) = delete;
  52. Pipeline &operator=(const Pipeline &P) = delete;
  53. /// An ordered list of stages that define this instruction pipeline.
  54. SmallVector<std::unique_ptr<Stage>, 8> Stages;
  55. std::set<HWEventListener *> Listeners;
  56. unsigned Cycles;
  57. Error runCycle();
  58. bool hasWorkToProcess();
  59. void notifyCycleBegin();
  60. void notifyCycleEnd();
  61. public:
  62. Pipeline() : Cycles(0) {}
  63. void appendStage(std::unique_ptr<Stage> S);
  64. /// Returns the total number of simulated cycles.
  65. Expected<unsigned> run();
  66. void addEventListener(HWEventListener *Listener);
  67. };
  68. } // namespace mca
  69. } // namespace llvm
  70. #endif // LLVM_MCA_PIPELINE_H
  71. #ifdef __GNUC__
  72. #pragma GCC diagnostic pop
  73. #endif