ResourcePressureView.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===--------------------- ResourcePressureView.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 define class ResourcePressureView.
  11. /// Class ResourcePressureView observes hardware events generated by
  12. /// the Pipeline object and collects statistics related to resource usage at
  13. /// instruction granularity.
  14. /// Resource pressure information is then printed out to a stream in the
  15. /// form of a table like the one from the example below:
  16. ///
  17. /// Resources:
  18. /// [0] - JALU0
  19. /// [1] - JALU1
  20. /// [2] - JDiv
  21. /// [3] - JFPM
  22. /// [4] - JFPU0
  23. /// [5] - JFPU1
  24. /// [6] - JLAGU
  25. /// [7] - JSAGU
  26. /// [8] - JSTC
  27. /// [9] - JVIMUL
  28. ///
  29. /// Resource pressure per iteration:
  30. /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
  31. /// 0.00 0.00 0.00 0.00 2.00 2.00 0.00 0.00 0.00 0.00
  32. ///
  33. /// Resource pressure by instruction:
  34. /// [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions:
  35. /// - - - - - 1.00 - - - - vpermilpd $1, %xmm0,
  36. /// %xmm1
  37. /// - - - - 1.00 - - - - - vaddps %xmm0, %xmm1,
  38. /// %xmm2
  39. /// - - - - - 1.00 - - - - vmovshdup %xmm2, %xmm3
  40. /// - - - - 1.00 - - - - - vaddss %xmm2, %xmm3,
  41. /// %xmm4
  42. ///
  43. /// In this example, we have AVX code executed on AMD Jaguar (btver2).
  44. /// Both shuffles and vector floating point add operations on XMM registers have
  45. /// a reciprocal throughput of 1cy.
  46. /// Each add is issued to pipeline JFPU0, while each shuffle is issued to
  47. /// pipeline JFPU1. The overall pressure per iteration is reported by two
  48. /// tables: the first smaller table is the resource pressure per iteration;
  49. /// the second table reports resource pressure per instruction. Values are the
  50. /// average resource cycles consumed by an instruction.
  51. /// Every vector add from the example uses resource JFPU0 for an average of 1cy
  52. /// per iteration. Consequently, the resource pressure on JFPU0 is of 2cy per
  53. /// iteration.
  54. ///
  55. //===----------------------------------------------------------------------===//
  56. #ifndef LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
  57. #define LLVM_TOOLS_LLVM_MCA_RESOURCEPRESSUREVIEW_H
  58. #include "Views/InstructionView.h"
  59. #include "llvm/ADT/ArrayRef.h"
  60. #include "llvm/ADT/DenseMap.h"
  61. #include "llvm/MC/MCInst.h"
  62. #include "llvm/MC/MCInstPrinter.h"
  63. #include "llvm/MC/MCSubtargetInfo.h"
  64. #include "llvm/Support/JSON.h"
  65. namespace llvm {
  66. namespace mca {
  67. /// This class collects resource pressure statistics and it is able to print
  68. /// out all the collected information as a table to an output stream.
  69. class ResourcePressureView : public InstructionView {
  70. unsigned LastInstructionIdx;
  71. // Map to quickly obtain the ResourceUsage column index from a processor
  72. // resource ID.
  73. llvm::DenseMap<unsigned, unsigned> Resource2VecIndex;
  74. // Table of resources used by instructions.
  75. std::vector<ResourceCycles> ResourceUsage;
  76. unsigned NumResourceUnits;
  77. void printResourcePressurePerIter(llvm::raw_ostream &OS) const;
  78. void printResourcePressurePerInst(llvm::raw_ostream &OS) const;
  79. public:
  80. ResourcePressureView(const llvm::MCSubtargetInfo &sti,
  81. llvm::MCInstPrinter &Printer,
  82. llvm::ArrayRef<llvm::MCInst> S);
  83. void onEvent(const HWInstructionEvent &Event) override;
  84. void printView(llvm::raw_ostream &OS) const override {
  85. printResourcePressurePerIter(OS);
  86. printResourcePressurePerInst(OS);
  87. }
  88. StringRef getNameAsString() const override { return "ResourcePressureView"; }
  89. json::Value toJSON() const override;
  90. };
  91. } // namespace mca
  92. } // namespace llvm
  93. #endif