Home | History | Annotate | Download | only in llvm-mca
      1 //===--------------------- RegisterFileStatistics.h -------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 /// \file
     10 ///
     11 /// This view collects and prints register file usage statistics.
     12 ///
     13 /// Example  (-mcpu=btver2):
     14 /// ========================
     15 ///
     16 /// Register File statistics:
     17 /// Total number of mappings created:    6
     18 /// Max number of mappings used:         3
     19 ///
     20 /// *  Register File #1 -- FpuPRF:
     21 ///    Number of physical registers:     72
     22 ///    Total number of mappings created: 0
     23 ///    Max number of mappings used:      0
     24 ///
     25 /// *  Register File #2 -- IntegerPRF:
     26 ///    Number of physical registers:     64
     27 ///    Total number of mappings created: 6
     28 ///    Max number of mappings used:      3
     29 //
     30 //===----------------------------------------------------------------------===//
     31 
     32 #ifndef LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H
     33 #define LLVM_TOOLS_LLVM_MCA_REGISTERFILESTATISTICS_H
     34 
     35 #include "View.h"
     36 #include "llvm/ADT/SmallVector.h"
     37 #include "llvm/MC/MCSubtargetInfo.h"
     38 
     39 namespace mca {
     40 
     41 class RegisterFileStatistics : public View {
     42   const llvm::MCSubtargetInfo &STI;
     43 
     44   // Used to track the number of physical registers used in a register file.
     45   struct RegisterFileUsage {
     46     unsigned TotalMappings;
     47     unsigned MaxUsedMappings;
     48     unsigned CurrentlyUsedMappings;
     49   };
     50 
     51   // There is one entry for each register file implemented by the processor.
     52   llvm::SmallVector<RegisterFileUsage, 4> RegisterFiles;
     53 
     54   void initializeRegisterFileInfo();
     55 
     56 public:
     57   RegisterFileStatistics(const llvm::MCSubtargetInfo &sti) : STI(sti) {
     58     initializeRegisterFileInfo();
     59   }
     60 
     61   void onEvent(const HWInstructionEvent &Event) override;
     62 
     63   void printView(llvm::raw_ostream &OS) const override;
     64 };
     65 } // namespace mca
     66 
     67 #endif
     68