LLVM  6.0.0svn
MachineOptimizationRemarkEmitter.cpp
Go to the documentation of this file.
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 
19 #include "llvm/IR/DebugInfo.h"
20 #include "llvm/IR/DiagnosticInfo.h"
21 #include "llvm/IR/LLVMContext.h"
22 
23 using namespace llvm;
24 
26  StringRef MKey, const MachineInstr &MI)
27  : Argument() {
28  Key = MKey;
29 
31  MI.print(OS, /*SkipOpers=*/false, /*SkipDebugLoc=*/true);
32 }
33 
35 MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
36  if (!MBFI)
37  return None;
38 
39  return MBFI->getBlockProfileCount(&MBB);
40 }
41 
42 void MachineOptimizationRemarkEmitter::computeHotness(
44  const MachineBasicBlock *MBB = Remark.getBlock();
45  if (MBB)
46  Remark.setHotness(computeHotness(*MBB));
47 }
48 
50  DiagnosticInfoOptimizationBase &OptDiagCommon) {
51  auto &OptDiag = cast<DiagnosticInfoMIROptimization>(OptDiagCommon);
52  computeHotness(OptDiag);
53 
54  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  if (OptDiag.getHotness() &&
59  *OptDiag.getHotness() < Ctx.getDiagnosticsHotnessThreshold()) {
60  return;
61  }
62 
63  Ctx.diagnose(OptDiag);
64 }
65 
70 }
71 
73  MachineFunction &MF) {
75 
77  MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
78  else
79  MBFI = nullptr;
80 
81  ORE = llvm::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
82  return false;
83 }
84 
86  AnalysisUsage &AU) const {
88  AU.setPreservesAll();
90 }
91 
93 static const char ore_name[] = "Machine Optimization Remark Emitter";
94 #define ORE_NAME "machine-opt-remark-emitter"
95 
97  false, true)
100  false, true)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
void emit(DiagnosticInfoOptimizationBase &OptDiag)
Emit an optimization remark.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
MachineArgument(StringRef Key, const MachineInstr &MI)
Print an entire MachineInstr.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
This is an alternative analysis pass to MachineBlockFrequencyInfo.
uint64_t getDiagnosticsHotnessThreshold() const
Return the minimum hotness value a diagnostic would need in order to be included in optimization diag...
bool getDiagnosticsHotnessRequested() const
Return if a code hotness metric should be included in optimization diagnostics.
Represent the analysis usage information of a pass.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
Used in the streaming interface as the general argument type.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
static const char ore_name[]
Common features for diagnostics dealing with optimization remarks that are used by both IR and MIR pa...
void setPreservesAll()
Set by analyses that do not transform their input at all.
Representation of each machine instruction.
Definition: MachineInstr.h:59
Basic Alias true
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void print(raw_ostream &OS, bool SkipOpers=false, bool SkipDebugLoc=false, const TargetInstrInfo *TII=nullptr) const
Debugging supportPrint this MI to OS.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:462
IRTranslator LLVM IR MI
void setHotness(Optional< uint64_t > H)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Common features for diagnostics dealing with optimization remarks that are used by machine passes...
void initializeMachineOptimizationRemarkEmitterPassPass(PassRegistry &)
INITIALIZE_PASS_BEGIN(MachineOptimizationRemarkEmitterPass, ORE_NAME, ore_name, false, true) INITIALIZE_PASS_END(MachineOptimizationRemarkEmitterPass