LCOV - code coverage report
Current view: top level - lib/CodeGen - MachineOptimizationRemarkEmitter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 45 45 100.0 %
Date: 2017-09-14 15:23:50 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : ///===- MachineOptimizationRemarkEmitter.cpp - Opt Diagnostic -*- 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             : /// Optimization diagnostic interfaces for machine passes.  It's packaged as an
      11             : /// analysis pass so that by using this service passes become dependent on MBFI
      12             : /// as well.  MBFI is used to compute the "hotness" of the diagnostic message.
      13             : ///
      14             : ///===---------------------------------------------------------------------===//
      15             : 
      16             : #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
      17             : #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
      18             : #include "llvm/CodeGen/MachineInstr.h"
      19             : #include "llvm/IR/DebugInfo.h"
      20             : #include "llvm/IR/DiagnosticInfo.h"
      21             : #include "llvm/IR/LLVMContext.h"
      22             : 
      23             : using namespace llvm;
      24             : 
      25          21 : DiagnosticInfoMIROptimization::MachineArgument::MachineArgument(
      26          21 :     StringRef MKey, const MachineInstr &MI)
      27          42 :     : Argument() {
      28          42 :   Key = MKey;
      29             : 
      30          63 :   raw_string_ostream OS(Val);
      31          21 :   MI.print(OS, /*SkipOpers=*/false, /*SkipDebugLoc=*/true);
      32          21 : }
      33             : 
      34             : Optional<uint64_t>
      35      285008 : MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
      36      285008 :   if (!MBFI)
      37             :     return None;
      38             : 
      39          38 :   return MBFI->getBlockProfileCount(&MBB);
      40             : }
      41             : 
      42      285008 : void MachineOptimizationRemarkEmitter::computeHotness(
      43             :     DiagnosticInfoMIROptimization &Remark) {
      44      285008 :   const MachineBasicBlock *MBB = Remark.getBlock();
      45      285008 :   if (MBB)
      46      855024 :     Remark.setHotness(computeHotness(*MBB));
      47      285008 : }
      48             : 
      49      285008 : void MachineOptimizationRemarkEmitter::emit(
      50             :     DiagnosticInfoOptimizationBase &OptDiagCommon) {
      51      285008 :   auto &OptDiag = cast<DiagnosticInfoMIROptimization>(OptDiagCommon);
      52      285008 :   computeHotness(OptDiag);
      53             : 
      54      285008 :   LLVMContext &Ctx = MF.getFunction()->getContext();
      55             : 
      56             :   // If a diagnostic has a hotness value, then only emit it if its hotness
      57             :   // meets the threshold.
      58     1140096 :   if (OptDiag.getHotness() &&
      59      570104 :       *OptDiag.getHotness() < Ctx.getDiagnosticsHotnessThreshold()) {
      60             :     return;
      61             :   }
      62             : 
      63      285000 :   yaml::Output *Out = Ctx.getDiagnosticsOutputFile();
      64      285000 :   if (Out) {
      65          80 :     auto *P = &const_cast<DiagnosticInfoOptimizationBase &>(OptDiagCommon);
      66          80 :     *Out << P;
      67             :   }
      68             :   // FIXME: now that IsVerbose is part of DI, filtering for this will be moved
      69             :   // from here to clang.
      70      285000 :   if (!OptDiag.isVerbose() || shouldEmitVerbose())
      71      285000 :     Ctx.diagnose(OptDiag);
      72             : }
      73             : 
      74       48791 : MachineOptimizationRemarkEmitterPass::MachineOptimizationRemarkEmitterPass()
      75       97582 :     : MachineFunctionPass(ID) {
      76       48791 :   initializeMachineOptimizationRemarkEmitterPassPass(
      77       48791 :       *PassRegistry::getPassRegistry());
      78       48791 : }
      79             : 
      80      418615 : bool MachineOptimizationRemarkEmitterPass::runOnMachineFunction(
      81             :     MachineFunction &MF) {
      82             :   MachineBlockFrequencyInfo *MBFI;
      83             : 
      84      418615 :   if (MF.getFunction()->getContext().getDiagnosticsHotnessRequested())
      85          78 :     MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
      86             :   else
      87             :     MBFI = nullptr;
      88             : 
      89     1674460 :   ORE = llvm::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
      90      418615 :   return false;
      91             : }
      92             : 
      93       48791 : void MachineOptimizationRemarkEmitterPass::getAnalysisUsage(
      94             :     AnalysisUsage &AU) const {
      95       48791 :   AU.addRequired<LazyMachineBlockFrequencyInfoPass>();
      96       48791 :   AU.setPreservesAll();
      97       48791 :   MachineFunctionPass::getAnalysisUsage(AU);
      98       48791 : }
      99             : 
     100             : char MachineOptimizationRemarkEmitterPass::ID = 0;
     101             : static const char ore_name[] = "Machine Optimization Remark Emitter";
     102             : #define ORE_NAME "machine-opt-remark-emitter"
     103             : 
     104       20212 : INITIALIZE_PASS_BEGIN(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
     105             :                       false, true)
     106       20212 : INITIALIZE_PASS_DEPENDENCY(LazyMachineBlockFrequencyInfoPass)
     107      418844 : INITIALIZE_PASS_END(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
     108             :                     false, true)

Generated by: LCOV version 1.13