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 | |
35 | #ifndef LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H |
36 | #define LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H |
37 | |
38 | #include "llvm/ADT/SmallVector.h" |
39 | #include "llvm/MC/MCSubtargetInfo.h" |
40 | #include "llvm/MCA/View.h" |
41 | |
42 | namespace llvm { |
43 | namespace mca { |
44 | |
45 | class RegisterFileStatistics : public View { |
46 | const llvm::MCSubtargetInfo &STI; |
47 | |
48 | // Used to track the number of physical registers used in a register file. |
49 | struct RegisterFileUsage { |
50 | unsigned TotalMappings; |
51 | unsigned MaxUsedMappings; |
52 | unsigned CurrentlyUsedMappings; |
53 | }; |
54 | |
55 | struct MoveEliminationInfo { |
56 | unsigned TotalMoveEliminationCandidates; |
57 | unsigned TotalMovesEliminated; |
58 | unsigned TotalMovesThatPropagateZero; |
59 | unsigned MaxMovesEliminatedPerCycle; |
60 | unsigned CurrentMovesEliminated; |
61 | }; |
62 | |
63 | // There is one entry for each register file implemented by the processor. |
64 | llvm::SmallVector<RegisterFileUsage, 4> PRFUsage; |
65 | llvm::SmallVector<MoveEliminationInfo, 4> MoveElimInfo; |
66 | |
67 | void updateRegisterFileUsage(ArrayRef<unsigned> UsedPhysRegs); |
68 | void updateMoveElimInfo(const Instruction &Inst); |
69 | |
70 | public: |
71 | RegisterFileStatistics(const llvm::MCSubtargetInfo &sti); |
72 | |
73 | void onCycleEnd() override; |
74 | void onEvent(const HWInstructionEvent &Event) override; |
75 | void printView(llvm::raw_ostream &OS) const override; |
76 | StringRef getNameAsString() const override { |
77 | return "RegisterFileStatistics" ; |
78 | } |
79 | bool isSerializable() const override { return false; } |
80 | }; |
81 | } // namespace mca |
82 | } // namespace llvm |
83 | |
84 | #endif |
85 | |