LCOV - code coverage report
Current view: top level - lib/CodeGen - MachineOptimizationRemarkEmitter.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 36 36 100.0 %
Date: 2018-06-17 00:07:59 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/DiagnosticInfo.h"
      20             : #include "llvm/IR/LLVMContext.h"
      21             : 
      22             : using namespace llvm;
      23             : 
      24          24 : DiagnosticInfoMIROptimization::MachineArgument::MachineArgument(
      25          24 :     StringRef MKey, const MachineInstr &MI)
      26          48 :     : Argument() {
      27          48 :   Key = MKey;
      28             : 
      29          48 :   raw_string_ostream OS(Val);
      30          24 :   MI.print(OS, /*IsStandalone=*/true, /*SkipOpers=*/false,
      31             :            /*SkipDebugLoc=*/true);
      32          24 : }
      33             : 
      34             : Optional<uint64_t>
      35      227453 : MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
      36      227453 :   if (!MBFI)
      37             :     return None;
      38             : 
      39          62 :   return MBFI->getBlockProfileCount(&MBB);
      40             : }
      41             : 
      42      227453 : void MachineOptimizationRemarkEmitter::computeHotness(
      43             :     DiagnosticInfoMIROptimization &Remark) {
      44      227453 :   const MachineBasicBlock *MBB = Remark.getBlock();
      45      227453 :   if (MBB)
      46      454906 :     Remark.setHotness(computeHotness(*MBB));
      47      227453 : }
      48             : 
      49      227453 : void MachineOptimizationRemarkEmitter::emit(
      50             :     DiagnosticInfoOptimizationBase &OptDiagCommon) {
      51             :   auto &OptDiag = cast<DiagnosticInfoMIROptimization>(OptDiagCommon);
      52      227453 :   computeHotness(OptDiag);
      53             : 
      54      227453 :   LLVMContext &Ctx = MF.getFunction().getContext();
      55             : 
      56             :   // Only emit it if its hotness meets the threshold.
      57      227453 :   if (OptDiag.getHotness().getValueOr(0) <
      58      227453 :       Ctx.getDiagnosticsHotnessThreshold()) {
      59             :     return;
      60             :   }
      61             : 
      62      227440 :   Ctx.diagnose(OptDiag);
      63             : }
      64             : 
      65       63494 : MachineOptimizationRemarkEmitterPass::MachineOptimizationRemarkEmitterPass()
      66       63494 :     : MachineFunctionPass(ID) {
      67       63494 :   initializeMachineOptimizationRemarkEmitterPassPass(
      68       63494 :       *PassRegistry::getPassRegistry());
      69       63494 : }
      70             : 
      71      631849 : bool MachineOptimizationRemarkEmitterPass::runOnMachineFunction(
      72             :     MachineFunction &MF) {
      73             :   MachineBlockFrequencyInfo *MBFI;
      74             : 
      75      631849 :   if (MF.getFunction().getContext().getDiagnosticsHotnessRequested())
      76          66 :     MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
      77             :   else
      78             :     MBFI = nullptr;
      79             : 
      80             :   ORE = llvm::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
      81      631849 :   return false;
      82             : }
      83             : 
      84       63494 : void MachineOptimizationRemarkEmitterPass::getAnalysisUsage(
      85             :     AnalysisUsage &AU) const {
      86             :   AU.addRequired<LazyMachineBlockFrequencyInfoPass>();
      87             :   AU.setPreservesAll();
      88       63494 :   MachineFunctionPass::getAnalysisUsage(AU);
      89       63494 : }
      90             : 
      91             : char MachineOptimizationRemarkEmitterPass::ID = 0;
      92             : static const char ore_name[] = "Machine Optimization Remark Emitter";
      93             : #define ORE_NAME "machine-opt-remark-emitter"
      94             : 
      95       26770 : INITIALIZE_PASS_BEGIN(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
      96             :                       false, true)
      97       26770 : INITIALIZE_PASS_DEPENDENCY(LazyMachineBlockFrequencyInfoPass)
      98      435720 : INITIALIZE_PASS_END(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
      99             :                     false, true)

Generated by: LCOV version 1.13