10b57cec5SDimitry Andric //===--------------------- RegisterFileStatistics.h -------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric /// \file 90b57cec5SDimitry Andric /// 100b57cec5SDimitry Andric /// This view collects and prints register file usage statistics. 110b57cec5SDimitry Andric /// 120b57cec5SDimitry Andric /// Example (-mcpu=btver2): 130b57cec5SDimitry Andric /// ======================== 140b57cec5SDimitry Andric /// 150b57cec5SDimitry Andric /// Register File statistics: 160b57cec5SDimitry Andric /// Total number of mappings created: 6 170b57cec5SDimitry Andric /// Max number of mappings used: 3 180b57cec5SDimitry Andric /// 190b57cec5SDimitry Andric /// * Register File #1 -- FpuPRF: 200b57cec5SDimitry Andric /// Number of physical registers: 72 210b57cec5SDimitry Andric /// Total number of mappings created: 0 220b57cec5SDimitry Andric /// Max number of mappings used: 0 230b57cec5SDimitry Andric /// Number of optimizable moves: 200 240b57cec5SDimitry Andric /// Number of moves eliminated: 200 (100.0%) 250b57cec5SDimitry Andric /// Number of zero moves: 200 (100.0%) 260b57cec5SDimitry Andric /// Max moves eliminated per cycle: 2 270b57cec5SDimitry Andric /// 280b57cec5SDimitry Andric /// * Register File #2 -- IntegerPRF: 290b57cec5SDimitry Andric /// Number of physical registers: 64 300b57cec5SDimitry Andric /// Total number of mappings created: 6 310b57cec5SDimitry Andric /// Max number of mappings used: 3 320b57cec5SDimitry Andric // 330b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric #ifndef LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H 360b57cec5SDimitry Andric #define LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 390b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h" 40*349cc55cSDimitry Andric #include "llvm/MCA/View.h" 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric namespace llvm { 430b57cec5SDimitry Andric namespace mca { 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric class RegisterFileStatistics : public View { 460b57cec5SDimitry Andric const llvm::MCSubtargetInfo &STI; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric // Used to track the number of physical registers used in a register file. 490b57cec5SDimitry Andric struct RegisterFileUsage { 500b57cec5SDimitry Andric unsigned TotalMappings; 510b57cec5SDimitry Andric unsigned MaxUsedMappings; 520b57cec5SDimitry Andric unsigned CurrentlyUsedMappings; 530b57cec5SDimitry Andric }; 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric struct MoveEliminationInfo { 560b57cec5SDimitry Andric unsigned TotalMoveEliminationCandidates; 570b57cec5SDimitry Andric unsigned TotalMovesEliminated; 580b57cec5SDimitry Andric unsigned TotalMovesThatPropagateZero; 590b57cec5SDimitry Andric unsigned MaxMovesEliminatedPerCycle; 600b57cec5SDimitry Andric unsigned CurrentMovesEliminated; 610b57cec5SDimitry Andric }; 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric // There is one entry for each register file implemented by the processor. 640b57cec5SDimitry Andric llvm::SmallVector<RegisterFileUsage, 4> PRFUsage; 650b57cec5SDimitry Andric llvm::SmallVector<MoveEliminationInfo, 4> MoveElimInfo; 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric void updateRegisterFileUsage(ArrayRef<unsigned> UsedPhysRegs); 680b57cec5SDimitry Andric void updateMoveElimInfo(const Instruction &Inst); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric public: 710b57cec5SDimitry Andric RegisterFileStatistics(const llvm::MCSubtargetInfo &sti); 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric void onCycleEnd() override; 740b57cec5SDimitry Andric void onEvent(const HWInstructionEvent &Event) override; 750b57cec5SDimitry Andric void printView(llvm::raw_ostream &OS) const override; getNameAsString()76e8d8bef9SDimitry Andric StringRef getNameAsString() const override { 77e8d8bef9SDimitry Andric return "RegisterFileStatistics"; 78e8d8bef9SDimitry Andric } isSerializable()79fe6060f1SDimitry Andric bool isSerializable() const override { return false; } 800b57cec5SDimitry Andric }; 810b57cec5SDimitry Andric } // namespace mca 820b57cec5SDimitry Andric } // namespace llvm 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric #endif 85