Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/MachineOptimizationRemarkEmitter.cpp
Line
Count
Source
1
///===- MachineOptimizationRemarkEmitter.cpp - Opt Diagnostic -*- 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
/// Optimization diagnostic interfaces for machine passes.  It's packaged as an
10
/// analysis pass so that by using this service passes become dependent on MBFI
11
/// as well.  MBFI is used to compute the "hotness" of the diagnostic message.
12
///
13
///===---------------------------------------------------------------------===//
14
15
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
16
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
17
#include "llvm/CodeGen/MachineInstr.h"
18
#include "llvm/IR/DiagnosticInfo.h"
19
#include "llvm/IR/LLVMContext.h"
20
21
using namespace llvm;
22
23
DiagnosticInfoMIROptimization::MachineArgument::MachineArgument(
24
    StringRef MKey, const MachineInstr &MI)
25
305
    : Argument() {
26
305
  Key = MKey;
27
305
28
305
  raw_string_ostream OS(Val);
29
305
  MI.print(OS, /*IsStandalone=*/true, /*SkipOpers=*/false,
30
305
           /*SkipDebugLoc=*/true);
31
305
}
32
33
Optional<uint64_t>
34
516k
MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
35
516k
  if (!MBFI)
36
515k
    return None;
37
57
38
57
  return MBFI->getBlockProfileCount(&MBB);
39
57
}
40
41
void MachineOptimizationRemarkEmitter::computeHotness(
42
516k
    DiagnosticInfoMIROptimization &Remark) {
43
516k
  const MachineBasicBlock *MBB = Remark.getBlock();
44
516k
  if (MBB)
45
516k
    Remark.setHotness(computeHotness(*MBB));
46
516k
}
47
48
void MachineOptimizationRemarkEmitter::emit(
49
516k
    DiagnosticInfoOptimizationBase &OptDiagCommon) {
50
516k
  auto &OptDiag = cast<DiagnosticInfoMIROptimization>(OptDiagCommon);
51
516k
  computeHotness(OptDiag);
52
516k
53
516k
  LLVMContext &Ctx = MF.getFunction().getContext();
54
516k
55
516k
  // Only emit it if its hotness meets the threshold.
56
516k
  if (OptDiag.getHotness().getValueOr(0) <
57
516k
      Ctx.getDiagnosticsHotnessThreshold()) {
58
13
    return;
59
13
  }
60
516k
61
516k
  Ctx.diagnose(OptDiag);
62
516k
}
63
64
MachineOptimizationRemarkEmitterPass::MachineOptimizationRemarkEmitterPass()
65
105k
    : MachineFunctionPass(ID) {
66
105k
  initializeMachineOptimizationRemarkEmitterPassPass(
67
105k
      *PassRegistry::getPassRegistry());
68
105k
}
69
70
bool MachineOptimizationRemarkEmitterPass::runOnMachineFunction(
71
1.47M
    MachineFunction &MF) {
72
1.47M
  MachineBlockFrequencyInfo *MBFI;
73
1.47M
74
1.47M
  if (MF.getFunction().getContext().getDiagnosticsHotnessRequested())
75
60
    MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
76
1.47M
  else
77
1.47M
    MBFI = nullptr;
78
1.47M
79
1.47M
  ORE = llvm::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
80
1.47M
  return false;
81
1.47M
}
82
83
void MachineOptimizationRemarkEmitterPass::getAnalysisUsage(
84
105k
    AnalysisUsage &AU) const {
85
105k
  AU.addRequired<LazyMachineBlockFrequencyInfoPass>();
86
105k
  AU.setPreservesAll();
87
105k
  MachineFunctionPass::getAnalysisUsage(AU);
88
105k
}
89
90
char MachineOptimizationRemarkEmitterPass::ID = 0;
91
static const char ore_name[] = "Machine Optimization Remark Emitter";
92
#define ORE_NAME "machine-opt-remark-emitter"
93
94
42.3k
INITIALIZE_PASS_BEGIN(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
95
42.3k
                      false, true)
96
42.3k
INITIALIZE_PASS_DEPENDENCY(LazyMachineBlockFrequencyInfoPass)
97
42.3k
INITIALIZE_PASS_END(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name,
98
                    false, true)