LLVM  8.0.1
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/DiagnosticInfo.h"
20 #include "llvm/IR/LLVMContext.h"
21 
22 using namespace llvm;
23 
25  StringRef MKey, const MachineInstr &MI)
26  : Argument() {
27  Key = MKey;
28 
30  MI.print(OS, /*IsStandalone=*/true, /*SkipOpers=*/false,
31  /*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  // Only emit it if its hotness meets the threshold.
57  if (OptDiag.getHotness().getValueOr(0) <
59  return;
60  }
61 
62  Ctx.diagnose(OptDiag);
63 }
64 
69 }
70 
72  MachineFunction &MF) {
74 
76  MBFI = &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI();
77  else
78  MBFI = nullptr;
79 
80  ORE = llvm::make_unique<MachineOptimizationRemarkEmitter>(MF, MBFI);
81  return false;
82 }
83 
85  AnalysisUsage &AU) const {
87  AU.setPreservesAll();
89 }
90 
92 static const char ore_name[] = "Machine Optimization Remark Emitter";
93 #define ORE_NAME "machine-opt-remark-emitter"
94 
96  false, true)
99  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:24
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: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.
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:193
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:64
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:483
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