LLVM  10.0.0svn
MachineOptimizationRemarkEmitter.cpp
Go to the documentation of this file.
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 
18 #include "llvm/IR/DiagnosticInfo.h"
19 #include "llvm/IR/LLVMContext.h"
20 
21 using namespace llvm;
22 
24  StringRef MKey, const MachineInstr &MI)
25  : Argument() {
26  Key = MKey;
27 
29  MI.print(OS, /*IsStandalone=*/true, /*SkipOpers=*/false,
30  /*SkipDebugLoc=*/true);
31 }
32 
34 MachineOptimizationRemarkEmitter::computeHotness(const MachineBasicBlock &MBB) {
35  if (!MBFI)
36  return None;
37 
38  return MBFI->getBlockProfileCount(&MBB);
39 }
40 
41 void MachineOptimizationRemarkEmitter::computeHotness(
43  const MachineBasicBlock *MBB = Remark.getBlock();
44  if (MBB)
45  Remark.setHotness(computeHotness(*MBB));
46 }
47 
49  DiagnosticInfoOptimizationBase &OptDiagCommon) {
50  auto &OptDiag = cast<DiagnosticInfoMIROptimization>(OptDiagCommon);
51  computeHotness(OptDiag);
52 
53  LLVMContext &Ctx = MF.getFunction().getContext();
54 
55  // Only emit it if its hotness meets the threshold.
56  if (OptDiag.getHotness().getValueOr(0) <
58  return;
59  }
60 
61  Ctx.diagnose(OptDiag);
62 }
63 
68 }
69 
71  MachineFunction &MF) {
73 
75  MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
76  else
77  MBFI = nullptr;
78 
79  ORE = std::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
80  return false;
81 }
82 
84  AnalysisUsage &AU) const {
86  AU.setPreservesAll();
88 }
89 
91 static const char ore_name[] = "Machine Optimization Remark Emitter";
92 #define ORE_NAME "machine-opt-remark-emitter"
93 
95  false, true)
98  false, true)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
block Block Frequency true
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:50
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:64
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.
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:205
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...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
void setPreservesAll()
Set by analyses that do not transform their input at all.
Representation of each machine instruction.
Definition: MachineInstr.h:63
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:503
IRTranslator LLVM IR MI
void setHotness(Optional< uint64_t > H)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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