Bug Summary

File:lib/CodeGen/GlobalISel/Legalizer.cpp
Warning:line 36, column 40
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Legalizer.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn325874/build-llvm/lib/CodeGen/GlobalISel -I /build/llvm-toolchain-snapshot-7~svn325874/lib/CodeGen/GlobalISel -I /build/llvm-toolchain-snapshot-7~svn325874/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn325874/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn325874/build-llvm/lib/CodeGen/GlobalISel -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-02-23-163436-368-1 -x c++ /build/llvm-toolchain-snapshot-7~svn325874/lib/CodeGen/GlobalISel/Legalizer.cpp

/build/llvm-toolchain-snapshot-7~svn325874/lib/CodeGen/GlobalISel/Legalizer.cpp

1//===-- llvm/CodeGen/GlobalISel/Legalizer.cpp -----------------------------===//
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//
10/// \file This file implements the LegalizerHelper class to legalize individual
11/// instructions and the LegalizePass wrapper pass for the primary
12/// legalization.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/CodeGen/GlobalISel/Legalizer.h"
17#include "llvm/ADT/PostOrderIterator.h"
18#include "llvm/ADT/SetVector.h"
19#include "llvm/CodeGen/GlobalISel/GISelWorkList.h"
20#include "llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h"
21#include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
22#include "llvm/CodeGen/GlobalISel/Utils.h"
23#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
24#include "llvm/CodeGen/MachineRegisterInfo.h"
25#include "llvm/CodeGen/TargetPassConfig.h"
26#include "llvm/CodeGen/TargetSubtargetInfo.h"
27#include "llvm/Support/Debug.h"
28
29#include <iterator>
30
31#define DEBUG_TYPE"legalizer" "legalizer"
32
33using namespace llvm;
34
35char Legalizer::ID = 0;
36INITIALIZE_PASS_BEGIN(Legalizer, DEBUG_TYPE,static void *initializeLegalizerPassOnce(PassRegistry &Registry
) {
37 "Legalize the Machine IR a function's Machine IR", false,static void *initializeLegalizerPassOnce(PassRegistry &Registry
) {
38 false)static void *initializeLegalizerPassOnce(PassRegistry &Registry
) {
39INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)initializeTargetPassConfigPass(Registry);
40INITIALIZE_PASS_END(Legalizer, DEBUG_TYPE,PassInfo *PI = new PassInfo( "Legalize the Machine IR a function's Machine IR"
, "legalizer", &Legalizer::ID, PassInfo::NormalCtor_t(callDefaultCtor
<Legalizer>), false, false); Registry.registerPass(*PI,
true); return PI; } static llvm::once_flag InitializeLegalizerPassFlag
; void llvm::initializeLegalizerPass(PassRegistry &Registry
) { llvm::call_once(InitializeLegalizerPassFlag, initializeLegalizerPassOnce
, std::ref(Registry)); }
41 "Legalize the Machine IR a function's Machine IR", false,PassInfo *PI = new PassInfo( "Legalize the Machine IR a function's Machine IR"
, "legalizer", &Legalizer::ID, PassInfo::NormalCtor_t(callDefaultCtor
<Legalizer>), false, false); Registry.registerPass(*PI,
true); return PI; } static llvm::once_flag InitializeLegalizerPassFlag
; void llvm::initializeLegalizerPass(PassRegistry &Registry
) { llvm::call_once(InitializeLegalizerPassFlag, initializeLegalizerPassOnce
, std::ref(Registry)); }
42 false)PassInfo *PI = new PassInfo( "Legalize the Machine IR a function's Machine IR"
, "legalizer", &Legalizer::ID, PassInfo::NormalCtor_t(callDefaultCtor
<Legalizer>), false, false); Registry.registerPass(*PI,
true); return PI; } static llvm::once_flag InitializeLegalizerPassFlag
; void llvm::initializeLegalizerPass(PassRegistry &Registry
) { llvm::call_once(InitializeLegalizerPassFlag, initializeLegalizerPassOnce
, std::ref(Registry)); }
43
44Legalizer::Legalizer() : MachineFunctionPass(ID) {
45 initializeLegalizerPass(*PassRegistry::getPassRegistry());
46}
47
48void Legalizer::getAnalysisUsage(AnalysisUsage &AU) const {
49 AU.addRequired<TargetPassConfig>();
50 MachineFunctionPass::getAnalysisUsage(AU);
51}
52
53void Legalizer::init(MachineFunction &MF) {
54}
55
56static bool isArtifact(const MachineInstr &MI) {
57 switch (MI.getOpcode()) {
58 default:
59 return false;
60 case TargetOpcode::G_TRUNC:
61 case TargetOpcode::G_ZEXT:
62 case TargetOpcode::G_ANYEXT:
63 case TargetOpcode::G_SEXT:
64 case TargetOpcode::G_MERGE_VALUES:
65 case TargetOpcode::G_UNMERGE_VALUES:
66 return true;
67 }
68}
69
70bool Legalizer::runOnMachineFunction(MachineFunction &MF) {
71 // If the ISel pipeline failed, do not bother running that pass.
72 if (MF.getProperties().hasProperty(
1
Taking false branch
73 MachineFunctionProperties::Property::FailedISel))
74 return false;
75 DEBUG(dbgs() << "Legalize Machine IR for: " << MF.getName() << '\n')do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("legalizer")) { dbgs() << "Legalize Machine IR for: " <<
MF.getName() << '\n'; } } while (false)
;
76 init(MF);
77 const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
78 MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr);
79 LegalizerHelper Helper(MF);
80
81 const size_t NumBlocks = MF.size();
82 MachineRegisterInfo &MRI = MF.getRegInfo();
83
84 // Populate Insts
85 GISelWorkList<256> InstList;
86 GISelWorkList<128> ArtifactList;
87 ReversePostOrderTraversal<MachineFunction *> RPOT(&MF);
88 // Perform legalization bottom up so we can DCE as we legalize.
89 // Traverse BB in RPOT and within each basic block, add insts top down,
90 // so when we pop_back_val in the legalization process, we traverse bottom-up.
91 for (auto *MBB : RPOT) {
92 if (MBB->empty())
2
Assuming the condition is false
3
Taking false branch
10
Assuming the condition is true
11
Taking true branch
13
Assuming the condition is true
14
Taking true branch
93 continue;
12
Execution continues on line 91
15
Execution continues on line 91
94 for (MachineInstr &MI : *MBB) {
95 // Only legalize pre-isel generic instructions: others don't have types
96 // and are assumed to be legal.
97 if (!isPreISelGenericOpcode(MI.getOpcode()))
4
Taking true branch
6
Taking true branch
8
Taking true branch
98 continue;
5
Execution continues on line 94
7
Execution continues on line 94
9
Execution continues on line 94
99 if (isArtifact(MI))
100 ArtifactList.insert(&MI);
101 else
102 InstList.insert(&MI);
103 }
104 }
105 Helper.MIRBuilder.recordInsertions([&](MachineInstr *MI) {
106 // Only legalize pre-isel generic instructions.
107 // Legalization process could generate Target specific pseudo
108 // instructions with generic types. Don't record them
109 if (isPreISelGenericOpcode(MI->getOpcode())) {
110 if (isArtifact(*MI))
111 ArtifactList.insert(MI);
112 else
113 InstList.insert(MI);
114 }
115 DEBUG(dbgs() << ".. .. New MI: " << *MI;)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("legalizer")) { dbgs() << ".. .. New MI: " << *MI
;; } } while (false)
;
116 });
117 const LegalizerInfo &LInfo(Helper.getLegalizerInfo());
118 LegalizationArtifactCombiner ArtCombiner(Helper.MIRBuilder, MF.getRegInfo(), LInfo);
119 auto RemoveDeadInstFromLists = [&InstList,
120 &ArtifactList](MachineInstr *DeadMI) {
121 InstList.remove(DeadMI);
122 ArtifactList.remove(DeadMI);
123 };
124 bool Changed = false;
125 do {
21
Loop condition is false. Exiting loop
126 while (!InstList.empty()) {
16
Assuming the condition is false
17
Loop condition is false. Execution continues on line 147
127 MachineInstr &MI = *InstList.pop_back_val();
128 assert(isPreISelGenericOpcode(MI.getOpcode()) && "Expecting generic opcode")(static_cast <bool> (isPreISelGenericOpcode(MI.getOpcode
()) && "Expecting generic opcode") ? void (0) : __assert_fail
("isPreISelGenericOpcode(MI.getOpcode()) && \"Expecting generic opcode\""
, "/build/llvm-toolchain-snapshot-7~svn325874/lib/CodeGen/GlobalISel/Legalizer.cpp"
, 128, __extension__ __PRETTY_FUNCTION__))
;
129 if (isTriviallyDead(MI, MRI)) {
130 DEBUG(dbgs() << MI << "Is dead; erasing.\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("legalizer")) { dbgs() << MI << "Is dead; erasing.\n"
; } } while (false)
;
131 MI.eraseFromParentAndMarkDBGValuesForRemoval();
132 continue;
133 }
134
135 // Do the legalization for this instruction.
136 auto Res = Helper.legalizeInstrStep(MI);
137 // Error out if we couldn't legalize this instruction. We may want to
138 // fall back to DAG ISel instead in the future.
139 if (Res == LegalizerHelper::UnableToLegalize) {
140 Helper.MIRBuilder.stopRecordingInsertions();
141 reportGISelFailure(MF, TPC, MORE, "gisel-legalize",
142 "unable to legalize instruction", MI);
143 return false;
144 }
145 Changed |= Res == LegalizerHelper::Legalized;
146 }
147 while (!ArtifactList.empty()) {
18
Assuming the condition is false
19
Loop condition is false. Execution continues on line 172
148 MachineInstr &MI = *ArtifactList.pop_back_val();
149 assert(isPreISelGenericOpcode(MI.getOpcode()) && "Expecting generic opcode")(static_cast <bool> (isPreISelGenericOpcode(MI.getOpcode
()) && "Expecting generic opcode") ? void (0) : __assert_fail
("isPreISelGenericOpcode(MI.getOpcode()) && \"Expecting generic opcode\""
, "/build/llvm-toolchain-snapshot-7~svn325874/lib/CodeGen/GlobalISel/Legalizer.cpp"
, 149, __extension__ __PRETTY_FUNCTION__))
;
150 if (isTriviallyDead(MI, MRI)) {
151 DEBUG(dbgs() << MI << "Is dead; erasing.\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("legalizer")) { dbgs() << MI << "Is dead; erasing.\n"
; } } while (false)
;
152 RemoveDeadInstFromLists(&MI);
153 MI.eraseFromParentAndMarkDBGValuesForRemoval();
154 continue;
155 }
156 SmallVector<MachineInstr *, 4> DeadInstructions;
157 if (ArtCombiner.tryCombineInstruction(MI, DeadInstructions)) {
158 for (auto *DeadMI : DeadInstructions) {
159 DEBUG(dbgs() << ".. Erasing Dead Instruction " << *DeadMI)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("legalizer")) { dbgs() << ".. Erasing Dead Instruction "
<< *DeadMI; } } while (false)
;
160 RemoveDeadInstFromLists(DeadMI);
161 DeadMI->eraseFromParentAndMarkDBGValuesForRemoval();
162 }
163 Changed = true;
164 continue;
165 }
166 // If this was not an artifact (that could be combined away), this might
167 // need special handling. Add it to InstList, so when it's processed
168 // there, it has to be legal or specially handled.
169 else
170 InstList.insert(&MI);
171 }
172 } while (!InstList.empty());
20
Assuming the condition is false
173
174 // For now don't support if new blocks are inserted - we would need to fix the
175 // outerloop for that.
176 if (MF.size() != NumBlocks) {
22
Taking true branch
177 MachineOptimizationRemarkMissed R("gisel-legalize", "GISelFailure",
24
Calling constructor for 'MachineOptimizationRemarkMissed'
178 MF.getFunction().getSubprogram(),
179 /*MBB=*/nullptr);
23
Passing null pointer value via 4th parameter 'MBB'
180 R << "inserting blocks is not supported yet";
181 reportGISelFailure(MF, TPC, MORE, R);
182 return false;
183 }
184
185 return Changed;
186}

/build/llvm-toolchain-snapshot-7~svn325874/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h

1///===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- 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#ifndef LLVM_CODEGEN_MACHINEOPTIMIZATIONREMARKEMITTER_H
17#define LLVM_CODEGEN_MACHINEOPTIMIZATIONREMARKEMITTER_H
18
19#include "llvm/Analysis/OptimizationRemarkEmitter.h"
20#include "llvm/CodeGen/MachineFunctionPass.h"
21
22namespace llvm {
23class MachineBasicBlock;
24class MachineBlockFrequencyInfo;
25class MachineInstr;
26
27/// \brief Common features for diagnostics dealing with optimization remarks
28/// that are used by machine passes.
29class DiagnosticInfoMIROptimization : public DiagnosticInfoOptimizationBase {
30public:
31 DiagnosticInfoMIROptimization(enum DiagnosticKind Kind, const char *PassName,
32 StringRef RemarkName,
33 const DiagnosticLocation &Loc,
34 const MachineBasicBlock *MBB)
35 : DiagnosticInfoOptimizationBase(Kind, DS_Remark, PassName, RemarkName,
36 MBB->getParent()->getFunction(), Loc),
27
Called C++ object pointer is null
37 MBB(MBB) {}
38
39 /// MI-specific kinds of diagnostic Arguments.
40 struct MachineArgument : public DiagnosticInfoOptimizationBase::Argument {
41 /// Print an entire MachineInstr.
42 MachineArgument(StringRef Key, const MachineInstr &MI);
43 };
44
45 static bool classof(const DiagnosticInfo *DI) {
46 return DI->getKind() >= DK_FirstMachineRemark &&
47 DI->getKind() <= DK_LastMachineRemark;
48 }
49
50 const MachineBasicBlock *getBlock() const { return MBB; }
51
52private:
53 const MachineBasicBlock *MBB;
54};
55
56/// Diagnostic information for applied optimization remarks.
57class MachineOptimizationRemark : public DiagnosticInfoMIROptimization {
58public:
59 /// \p PassName is the name of the pass emitting this diagnostic. If this name
60 /// matches the regular expression given in -Rpass=, then the diagnostic will
61 /// be emitted. \p RemarkName is a textual identifier for the remark. \p
62 /// Loc is the debug location and \p MBB is the block that the optimization
63 /// operates in.
64 MachineOptimizationRemark(const char *PassName, StringRef RemarkName,
65 const DiagnosticLocation &Loc,
66 const MachineBasicBlock *MBB)
67 : DiagnosticInfoMIROptimization(DK_MachineOptimizationRemark, PassName,
68 RemarkName, Loc, MBB) {}
69
70 static bool classof(const DiagnosticInfo *DI) {
71 return DI->getKind() == DK_MachineOptimizationRemark;
72 }
73
74 /// \see DiagnosticInfoOptimizationBase::isEnabled.
75 bool isEnabled() const override {
76 const Function &Fn = getFunction();
77 LLVMContext &Ctx = Fn.getContext();
78 return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName());
79 }
80};
81
82/// Diagnostic information for missed-optimization remarks.
83class MachineOptimizationRemarkMissed : public DiagnosticInfoMIROptimization {
84public:
85 /// \p PassName is the name of the pass emitting this diagnostic. If this name
86 /// matches the regular expression given in -Rpass-missed=, then the
87 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
88 /// remark. \p Loc is the debug location and \p MBB is the block that the
89 /// optimization operates in.
90 MachineOptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
91 const DiagnosticLocation &Loc,
92 const MachineBasicBlock *MBB)
93 : DiagnosticInfoMIROptimization(DK_MachineOptimizationRemarkMissed,
26
Calling constructor for 'DiagnosticInfoMIROptimization'
94 PassName, RemarkName, Loc, MBB) {}
25
Passing null pointer value via 5th parameter 'MBB'
95
96 static bool classof(const DiagnosticInfo *DI) {
97 return DI->getKind() == DK_MachineOptimizationRemarkMissed;
98 }
99
100 /// \see DiagnosticInfoOptimizationBase::isEnabled.
101 bool isEnabled() const override {
102 const Function &Fn = getFunction();
103 LLVMContext &Ctx = Fn.getContext();
104 return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName());
105 }
106};
107
108/// Diagnostic information for optimization analysis remarks.
109class MachineOptimizationRemarkAnalysis : public DiagnosticInfoMIROptimization {
110public:
111 /// \p PassName is the name of the pass emitting this diagnostic. If this name
112 /// matches the regular expression given in -Rpass-analysis=, then the
113 /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
114 /// remark. \p Loc is the debug location and \p MBB is the block that the
115 /// optimization operates in.
116 MachineOptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
117 const DiagnosticLocation &Loc,
118 const MachineBasicBlock *MBB)
119 : DiagnosticInfoMIROptimization(DK_MachineOptimizationRemarkAnalysis,
120 PassName, RemarkName, Loc, MBB) {}
121
122 static bool classof(const DiagnosticInfo *DI) {
123 return DI->getKind() == DK_MachineOptimizationRemarkAnalysis;
124 }
125
126 /// \see DiagnosticInfoOptimizationBase::isEnabled.
127 bool isEnabled() const override {
128 const Function &Fn = getFunction();
129 LLVMContext &Ctx = Fn.getContext();
130 return Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(getPassName());
131 }
132};
133
134/// Extend llvm::ore:: with MI-specific helper names.
135namespace ore {
136using MNV = DiagnosticInfoMIROptimization::MachineArgument;
137}
138
139/// The optimization diagnostic interface.
140///
141/// It allows reporting when optimizations are performed and when they are not
142/// along with the reasons for it. Hotness information of the corresponding
143/// code region can be included in the remark if DiagnosticsHotnessRequested is
144/// enabled in the LLVM context.
145class MachineOptimizationRemarkEmitter {
146public:
147 MachineOptimizationRemarkEmitter(MachineFunction &MF,
148 MachineBlockFrequencyInfo *MBFI)
149 : MF(MF), MBFI(MBFI) {}
150
151 /// Emit an optimization remark.
152 void emit(DiagnosticInfoOptimizationBase &OptDiag);
153
154 /// \brief Whether we allow for extra compile-time budget to perform more
155 /// analysis to be more informative.
156 ///
157 /// This is useful to enable additional missed optimizations to be reported
158 /// that are normally too noisy. In this mode, we can use the extra analysis
159 /// (1) to filter trivial false positives or (2) to provide more context so
160 /// that non-trivial false positives can be quickly detected by the user.
161 bool allowExtraAnalysis(StringRef PassName) const {
162 return (MF.getFunction().getContext().getDiagnosticsOutputFile() ||
163 MF.getFunction().getContext()
164 .getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
165 }
166
167 /// \brief Take a lambda that returns a remark which will be emitted. Second
168 /// argument is only used to restrict this to functions.
169 template <typename T>
170 void emit(T RemarkBuilder, decltype(RemarkBuilder()) * = nullptr) {
171 // Avoid building the remark unless we know there are at least *some*
172 // remarks enabled. We can't currently check whether remarks are requested
173 // for the calling pass since that requires actually building the remark.
174
175 if (MF.getFunction().getContext().getDiagnosticsOutputFile() ||
176 MF.getFunction().getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
177 auto R = RemarkBuilder();
178 emit((DiagnosticInfoOptimizationBase &)R);
179 }
180 }
181
182private:
183 MachineFunction &MF;
184
185 /// MBFI is only set if hotness is requested.
186 MachineBlockFrequencyInfo *MBFI;
187
188 /// Compute hotness from IR value (currently assumed to be a block) if PGO is
189 /// available.
190 Optional<uint64_t> computeHotness(const MachineBasicBlock &MBB);
191
192 /// Similar but use value from \p OptDiag and update hotness there.
193 void computeHotness(DiagnosticInfoMIROptimization &Remark);
194
195 /// \brief Only allow verbose messages if we know we're filtering by hotness
196 /// (BFI is only set in this case).
197 bool shouldEmitVerbose() { return MBFI != nullptr; }
198};
199
200/// The analysis pass
201///
202/// Note that this pass shouldn't generally be marked as preserved by other
203/// passes. It's holding onto BFI, so if the pass does not preserve BFI, BFI
204/// could be freed.
205class MachineOptimizationRemarkEmitterPass : public MachineFunctionPass {
206 std::unique_ptr<MachineOptimizationRemarkEmitter> ORE;
207
208public:
209 MachineOptimizationRemarkEmitterPass();
210
211 bool runOnMachineFunction(MachineFunction &MF) override;
212
213 void getAnalysisUsage(AnalysisUsage &AU) const override;
214
215 MachineOptimizationRemarkEmitter &getORE() {
216 assert(ORE && "pass not run yet")(static_cast <bool> (ORE && "pass not run yet")
? void (0) : __assert_fail ("ORE && \"pass not run yet\""
, "/build/llvm-toolchain-snapshot-7~svn325874/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
, 216, __extension__ __PRETTY_FUNCTION__))
;
217 return *ORE;
218 }
219
220 static char ID;
221};
222}
223
224#endif