PipelinePrinter.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //===--------------------- PipelinePrinter.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 class PipelinePrinter.
  11. ///
  12. /// PipelinePrinter allows the customization of the performance report.
  13. ///
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
  16. #define LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/MC/MCSubtargetInfo.h"
  19. #include "llvm/MCA/Context.h"
  20. #include "llvm/MCA/Pipeline.h"
  21. #include "llvm/MCA/View.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #define DEBUG_TYPE "llvm-mca"
  24. namespace llvm {
  25. namespace mca {
  26. class CodeRegion;
  27. /// A printer class that knows how to collects statistics on the
  28. /// code analyzed by the llvm-mca tool.
  29. ///
  30. /// This class knows how to print out the analysis information collected
  31. /// during the execution of the code. Internally, it delegates to other
  32. /// classes the task of printing out timeline information as well as
  33. /// resource pressure.
  34. class PipelinePrinter {
  35. Pipeline &P;
  36. const CodeRegion &Region;
  37. unsigned RegionIdx;
  38. const MCSubtargetInfo &STI;
  39. const PipelineOptions &PO;
  40. llvm::SmallVector<std::unique_ptr<View>, 8> Views;
  41. void printRegionHeader(llvm::raw_ostream &OS) const;
  42. json::Object getJSONReportRegion() const;
  43. json::Object getJSONTargetInfo() const;
  44. json::Object getJSONSimulationParameters() const;
  45. public:
  46. PipelinePrinter(Pipeline &Pipe, const CodeRegion &R, unsigned Idx,
  47. const MCSubtargetInfo &STI, const PipelineOptions &PO)
  48. : P(Pipe), Region(R), RegionIdx(Idx), STI(STI), PO(PO) {}
  49. void addView(std::unique_ptr<View> V) {
  50. P.addEventListener(V.get());
  51. Views.emplace_back(std::move(V));
  52. }
  53. void printReport(llvm::raw_ostream &OS) const;
  54. void printReport(json::Object &JO) const;
  55. };
  56. } // namespace mca
  57. } // namespace llvm
  58. #endif // LLVM_TOOLS_LLVM_MCA_PIPELINEPRINTER_H