RegisterFileStatistics.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //===--------------------- RegisterFileStatistics.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 view collects and prints register file usage statistics.
  11. ///
  12. /// Example (-mcpu=btver2):
  13. /// ========================
  14. ///
  15. /// Register File statistics:
  16. /// Total number of mappings created: 6
  17. /// Max number of mappings used: 3
  18. ///
  19. /// * Register File #1 -- FpuPRF:
  20. /// Number of physical registers: 72
  21. /// Total number of mappings created: 0
  22. /// Max number of mappings used: 0
  23. /// Number of optimizable moves: 200
  24. /// Number of moves eliminated: 200 (100.0%)
  25. /// Number of zero moves: 200 (100.0%)
  26. /// Max moves eliminated per cycle: 2
  27. ///
  28. /// * Register File #2 -- IntegerPRF:
  29. /// Number of physical registers: 64
  30. /// Total number of mappings created: 6
  31. /// Max number of mappings used: 3
  32. //
  33. //===----------------------------------------------------------------------===//
  34. #ifndef LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H
  35. #define LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H
  36. #include "Views/View.h"
  37. #include "llvm/ADT/SmallVector.h"
  38. #include "llvm/MC/MCSubtargetInfo.h"
  39. namespace llvm {
  40. namespace mca {
  41. class RegisterFileStatistics : public View {
  42. const llvm::MCSubtargetInfo &STI;
  43. // Used to track the number of physical registers used in a register file.
  44. struct RegisterFileUsage {
  45. unsigned TotalMappings;
  46. unsigned MaxUsedMappings;
  47. unsigned CurrentlyUsedMappings;
  48. };
  49. struct MoveEliminationInfo {
  50. unsigned TotalMoveEliminationCandidates;
  51. unsigned TotalMovesEliminated;
  52. unsigned TotalMovesThatPropagateZero;
  53. unsigned MaxMovesEliminatedPerCycle;
  54. unsigned CurrentMovesEliminated;
  55. };
  56. // There is one entry for each register file implemented by the processor.
  57. llvm::SmallVector<RegisterFileUsage, 4> PRFUsage;
  58. llvm::SmallVector<MoveEliminationInfo, 4> MoveElimInfo;
  59. void updateRegisterFileUsage(ArrayRef<unsigned> UsedPhysRegs);
  60. void updateMoveElimInfo(const Instruction &Inst);
  61. public:
  62. RegisterFileStatistics(const llvm::MCSubtargetInfo &sti);
  63. void onCycleEnd() override;
  64. void onEvent(const HWInstructionEvent &Event) override;
  65. void printView(llvm::raw_ostream &OS) const override;
  66. StringRef getNameAsString() const override {
  67. return "RegisterFileStatistics";
  68. }
  69. };
  70. } // namespace mca
  71. } // namespace llvm
  72. #endif