InstructionInfoView.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===--------------------- InstructionInfoView.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 the instruction info view.
  11. ///
  12. /// The goal fo the instruction info view is to print the latency and reciprocal
  13. /// throughput information for every instruction in the input sequence.
  14. /// This section also reports extra information related to the number of micro
  15. /// opcodes, and opcode properties (i.e. 'MayLoad', 'MayStore', 'HasSideEffects)
  16. ///
  17. /// Example:
  18. ///
  19. /// Instruction Info:
  20. /// [1]: #uOps
  21. /// [2]: Latency
  22. /// [3]: RThroughput
  23. /// [4]: MayLoad
  24. /// [5]: MayStore
  25. /// [6]: HasSideEffects
  26. ///
  27. /// [1] [2] [3] [4] [5] [6] Instructions:
  28. /// 1 2 1.00 vmulps %xmm0, %xmm1, %xmm2
  29. /// 1 3 1.00 vhaddps %xmm2, %xmm2, %xmm3
  30. /// 1 3 1.00 vhaddps %xmm3, %xmm3, %xmm4
  31. //
  32. //===----------------------------------------------------------------------===//
  33. #ifndef LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
  34. #define LLVM_TOOLS_LLVM_MCA_INSTRUCTIONINFOVIEW_H
  35. #include "Views/InstructionView.h"
  36. #include "llvm/ADT/ArrayRef.h"
  37. #include "llvm/ADT/SmallVector.h"
  38. #include "llvm/MC/MCInst.h"
  39. #include "llvm/MC/MCInstPrinter.h"
  40. #include "llvm/MC/MCInstrInfo.h"
  41. #include "llvm/MC/MCSubtargetInfo.h"
  42. #include "llvm/MCA/CodeEmitter.h"
  43. #include "llvm/Support/raw_ostream.h"
  44. #define DEBUG_TYPE "llvm-mca"
  45. namespace llvm {
  46. namespace mca {
  47. /// A view that prints out generic instruction information.
  48. class InstructionInfoView : public InstructionView {
  49. const llvm::MCInstrInfo &MCII;
  50. CodeEmitter &CE;
  51. bool PrintEncodings;
  52. bool PrintBarriers;
  53. using UniqueInst = std::unique_ptr<Instruction>;
  54. ArrayRef<UniqueInst> LoweredInsts;
  55. struct InstructionInfoViewData {
  56. unsigned NumMicroOpcodes = 0;
  57. unsigned Latency = 0;
  58. std::optional<double> RThroughput = 0.0;
  59. bool mayLoad = false;
  60. bool mayStore = false;
  61. bool hasUnmodeledSideEffects = false;
  62. };
  63. using IIVDVec = SmallVector<InstructionInfoViewData, 16>;
  64. /// Place the data into the array of InstructionInfoViewData IIVD.
  65. void collectData(MutableArrayRef<InstructionInfoViewData> IIVD) const;
  66. public:
  67. InstructionInfoView(const llvm::MCSubtargetInfo &ST,
  68. const llvm::MCInstrInfo &II, CodeEmitter &C,
  69. bool ShouldPrintEncodings, llvm::ArrayRef<llvm::MCInst> S,
  70. llvm::MCInstPrinter &IP,
  71. ArrayRef<UniqueInst> LoweredInsts,
  72. bool ShouldPrintBarriers)
  73. : InstructionView(ST, IP, S), MCII(II), CE(C),
  74. PrintEncodings(ShouldPrintEncodings),
  75. PrintBarriers(ShouldPrintBarriers), LoweredInsts(LoweredInsts) {}
  76. void printView(llvm::raw_ostream &OS) const override;
  77. StringRef getNameAsString() const override { return "InstructionInfoView"; }
  78. json::Value toJSON() const override;
  79. json::Object toJSON(const InstructionInfoViewData &IIVD) const;
  80. };
  81. } // namespace mca
  82. } // namespace llvm
  83. #endif