llvm.org GIT mirror llvm / 3b8950a
Rename OptimizationDiagnosticInfo.* to OptimizationRemarkEmitter.* Sync it up with the name of the class actually defined here. This has been bothering me for a while... git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315249 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 3 years ago
35 changed file(s) with 335 addition(s) and 335 deletion(s). Raw diff Collapse all Expand all
1515
1616 #include "llvm/Analysis/AssumptionCache.h"
1717 #include "llvm/Analysis/CallGraphSCCPass.h"
18 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
18 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
1919 #include
2020 #include
2121
+0
-168
include/llvm/Analysis/OptimizationDiagnosticInfo.h less more
None //===- OptimizationDiagnosticInfo.h - Optimization Diagnostic ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Optimization diagnostic interfaces. It's packaged as an analysis pass so
10 // that by using this service passes become dependent on BFI as well. BFI is
11 // used to compute the "hotness" of the diagnostic message.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
15 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
16
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/Analysis/BlockFrequencyInfo.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Pass.h"
23
24 namespace llvm {
25 class DebugLoc;
26 class Loop;
27 class Pass;
28 class Twine;
29 class Value;
30
31 /// The optimization diagnostic interface.
32 ///
33 /// It allows reporting when optimizations are performed and when they are not
34 /// along with the reasons for it. Hotness information of the corresponding
35 /// code region can be included in the remark if DiagnosticsHotnessRequested is
36 /// enabled in the LLVM context.
37 class OptimizationRemarkEmitter {
38 public:
39 OptimizationRemarkEmitter(const Function *F, BlockFrequencyInfo *BFI)
40 : F(F), BFI(BFI) {}
41
42 /// \brief This variant can be used to generate ORE on demand (without the
43 /// analysis pass).
44 ///
45 /// Note that this ctor has a very different cost depending on whether
46 /// F->getContext().getDiagnosticsHotnessRequested() is on or not. If it's off
47 /// the operation is free.
48 ///
49 /// Whereas if DiagnosticsHotnessRequested is on, it is fairly expensive
50 /// operation since BFI and all its required analyses are computed. This is
51 /// for example useful for CGSCC passes that can't use function analyses
52 /// passes in the old PM.
53 OptimizationRemarkEmitter(const Function *F);
54
55 OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
56 : F(Arg.F), BFI(Arg.BFI) {}
57
58 OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
59 F = RHS.F;
60 BFI = RHS.BFI;
61 return *this;
62 }
63
64 /// Handle invalidation events in the new pass manager.
65 bool invalidate(Function &F, const PreservedAnalyses &PA,
66 FunctionAnalysisManager::Invalidator &Inv);
67
68 /// \brief Output the remark via the diagnostic handler and to the
69 /// optimization record file.
70 void emit(DiagnosticInfoOptimizationBase &OptDiag);
71
72 /// \brief Take a lambda that returns a remark which will be emitted. Second
73 /// argument is only used to restrict this to functions.
74 template
75 void emit(T RemarkBuilder, decltype(RemarkBuilder()) * = nullptr) {
76 // Avoid building the remark unless we know there are at least *some*
77 // remarks enabled. We can't currently check whether remarks are requested
78 // for the calling pass since that requires actually building the remark.
79
80 if (F->getContext().getDiagnosticsOutputFile() ||
81 F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
82 auto R = RemarkBuilder();
83 emit((DiagnosticInfoOptimizationBase &)R);
84 }
85 }
86
87 /// \brief Whether we allow for extra compile-time budget to perform more
88 /// analysis to produce fewer false positives.
89 ///
90 /// This is useful when reporting missed optimizations. In this case we can
91 /// use the extra analysis (1) to filter trivial false positives or (2) to
92 /// provide more context so that non-trivial false positives can be quickly
93 /// detected by the user.
94 bool allowExtraAnalysis(StringRef PassName) const {
95 return (F->getContext().getDiagnosticsOutputFile() ||
96 F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
97 }
98
99 private:
100 const Function *F;
101
102 BlockFrequencyInfo *BFI;
103
104 /// If we generate BFI on demand, we need to free it when ORE is freed.
105 std::unique_ptr OwnedBFI;
106
107 /// Compute hotness from IR value (currently assumed to be a block) if PGO is
108 /// available.
109 Optional computeHotness(const Value *V);
110
111 /// Similar but use value from \p OptDiag and update hotness there.
112 void computeHotness(DiagnosticInfoIROptimization &OptDiag);
113
114 /// \brief Only allow verbose messages if we know we're filtering by hotness
115 /// (BFI is only set in this case).
116 bool shouldEmitVerbose() { return BFI != nullptr; }
117
118 OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
119 void operator=(const OptimizationRemarkEmitter &) = delete;
120 };
121
122 /// \brief Add a small namespace to avoid name clashes with the classes used in
123 /// the streaming interface. We want these to be short for better
124 /// write/readability.
125 namespace ore {
126 using NV = DiagnosticInfoOptimizationBase::Argument;
127 using setIsVerbose = DiagnosticInfoOptimizationBase::setIsVerbose;
128 using setExtraArgs = DiagnosticInfoOptimizationBase::setExtraArgs;
129 }
130
131 /// OptimizationRemarkEmitter legacy analysis pass
132 ///
133 /// Note that this pass shouldn't generally be marked as preserved by other
134 /// passes. It's holding onto BFI, so if the pass does not preserve BFI, BFI
135 /// could be freed.
136 class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
137 std::unique_ptr ORE;
138
139 public:
140 OptimizationRemarkEmitterWrapperPass();
141
142 bool runOnFunction(Function &F) override;
143
144 void getAnalysisUsage(AnalysisUsage &AU) const override;
145
146 OptimizationRemarkEmitter &getORE() {
147 assert(ORE && "pass not run yet");
148 return *ORE;
149 }
150
151 static char ID;
152 };
153
154 class OptimizationRemarkEmitterAnalysis
155 : public AnalysisInfoMixin {
156 friend AnalysisInfoMixin;
157 static AnalysisKey Key;
158
159 public:
160 /// \brief Provide the result typedef for this analysis pass.
161 typedef OptimizationRemarkEmitter Result;
162
163 /// \brief Run the analysis pass over a function and produce BFI.
164 Result run(Function &F, FunctionAnalysisManager &AM);
165 };
166 }
167 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
0 //===- OptimizationRemarkEmitter.h - Optimization Diagnostic ----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Optimization diagnostic interfaces. It's packaged as an analysis pass so
10 // that by using this service passes become dependent on BFI as well. BFI is
11 // used to compute the "hotness" of the diagnostic message.
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
15 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
16
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/Analysis/BlockFrequencyInfo.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/PassManager.h"
22 #include "llvm/Pass.h"
23
24 namespace llvm {
25 class DebugLoc;
26 class Loop;
27 class Pass;
28 class Twine;
29 class Value;
30
31 /// The optimization diagnostic interface.
32 ///
33 /// It allows reporting when optimizations are performed and when they are not
34 /// along with the reasons for it. Hotness information of the corresponding
35 /// code region can be included in the remark if DiagnosticsHotnessRequested is
36 /// enabled in the LLVM context.
37 class OptimizationRemarkEmitter {
38 public:
39 OptimizationRemarkEmitter(const Function *F, BlockFrequencyInfo *BFI)
40 : F(F), BFI(BFI) {}
41
42 /// \brief This variant can be used to generate ORE on demand (without the
43 /// analysis pass).
44 ///
45 /// Note that this ctor has a very different cost depending on whether
46 /// F->getContext().getDiagnosticsHotnessRequested() is on or not. If it's off
47 /// the operation is free.
48 ///
49 /// Whereas if DiagnosticsHotnessRequested is on, it is fairly expensive
50 /// operation since BFI and all its required analyses are computed. This is
51 /// for example useful for CGSCC passes that can't use function analyses
52 /// passes in the old PM.
53 OptimizationRemarkEmitter(const Function *F);
54
55 OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
56 : F(Arg.F), BFI(Arg.BFI) {}
57
58 OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
59 F = RHS.F;
60 BFI = RHS.BFI;
61 return *this;
62 }
63
64 /// Handle invalidation events in the new pass manager.
65 bool invalidate(Function &F, const PreservedAnalyses &PA,
66 FunctionAnalysisManager::Invalidator &Inv);
67
68 /// \brief Output the remark via the diagnostic handler and to the
69 /// optimization record file.
70 void emit(DiagnosticInfoOptimizationBase &OptDiag);
71
72 /// \brief Take a lambda that returns a remark which will be emitted. Second
73 /// argument is only used to restrict this to functions.
74 template
75 void emit(T RemarkBuilder, decltype(RemarkBuilder()) * = nullptr) {
76 // Avoid building the remark unless we know there are at least *some*
77 // remarks enabled. We can't currently check whether remarks are requested
78 // for the calling pass since that requires actually building the remark.
79
80 if (F->getContext().getDiagnosticsOutputFile() ||
81 F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
82 auto R = RemarkBuilder();
83 emit((DiagnosticInfoOptimizationBase &)R);
84 }
85 }
86
87 /// \brief Whether we allow for extra compile-time budget to perform more
88 /// analysis to produce fewer false positives.
89 ///
90 /// This is useful when reporting missed optimizations. In this case we can
91 /// use the extra analysis (1) to filter trivial false positives or (2) to
92 /// provide more context so that non-trivial false positives can be quickly
93 /// detected by the user.
94 bool allowExtraAnalysis(StringRef PassName) const {
95 return (F->getContext().getDiagnosticsOutputFile() ||
96 F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
97 }
98
99 private:
100 const Function *F;
101
102 BlockFrequencyInfo *BFI;
103
104 /// If we generate BFI on demand, we need to free it when ORE is freed.
105 std::unique_ptr OwnedBFI;
106
107 /// Compute hotness from IR value (currently assumed to be a block) if PGO is
108 /// available.
109 Optional computeHotness(const Value *V);
110
111 /// Similar but use value from \p OptDiag and update hotness there.
112 void computeHotness(DiagnosticInfoIROptimization &OptDiag);
113
114 /// \brief Only allow verbose messages if we know we're filtering by hotness
115 /// (BFI is only set in this case).
116 bool shouldEmitVerbose() { return BFI != nullptr; }
117
118 OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
119 void operator=(const OptimizationRemarkEmitter &) = delete;
120 };
121
122 /// \brief Add a small namespace to avoid name clashes with the classes used in
123 /// the streaming interface. We want these to be short for better
124 /// write/readability.
125 namespace ore {
126 using NV = DiagnosticInfoOptimizationBase::Argument;
127 using setIsVerbose = DiagnosticInfoOptimizationBase::setIsVerbose;
128 using setExtraArgs = DiagnosticInfoOptimizationBase::setExtraArgs;
129 }
130
131 /// OptimizationRemarkEmitter legacy analysis pass
132 ///
133 /// Note that this pass shouldn't generally be marked as preserved by other
134 /// passes. It's holding onto BFI, so if the pass does not preserve BFI, BFI
135 /// could be freed.
136 class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
137 std::unique_ptr ORE;
138
139 public:
140 OptimizationRemarkEmitterWrapperPass();
141
142 bool runOnFunction(Function &F) override;
143
144 void getAnalysisUsage(AnalysisUsage &AU) const override;
145
146 OptimizationRemarkEmitter &getORE() {
147 assert(ORE && "pass not run yet");
148 return *ORE;
149 }
150
151 static char ID;
152 };
153
154 class OptimizationRemarkEmitterAnalysis
155 : public AnalysisInfoMixin {
156 friend AnalysisInfoMixin;
157 static AnalysisKey Key;
158
159 public:
160 /// \brief Provide the result typedef for this analysis pass.
161 typedef OptimizationRemarkEmitter Result;
162
163 /// \brief Run the analysis pass over a function and produce BFI.
164 Result run(Function &F, FunctionAnalysisManager &AM);
165 };
166 }
167 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
1515 #ifndef LLVM_CODEGEN_MACHINEOPTIMIZATIONREMARKEMITTER_H
1616 #define LLVM_CODEGEN_MACHINEOPTIMIZATIONREMARKEMITTER_H
1717
18 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
18 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
1919 #include "llvm/CodeGen/MachineFunctionPass.h"
2020
2121 namespace llvm {
5656 #include "llvm/Analysis/DemandedBits.h"
5757 #include "llvm/Analysis/LoopAccessAnalysis.h"
5858 #include "llvm/Analysis/LoopInfo.h"
59 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
59 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
6060 #include "llvm/Analysis/ScalarEvolution.h"
6161 #include "llvm/Analysis/TargetTransformInfo.h"
6262 #include "llvm/IR/Function.h"
6060 ObjCARCAliasAnalysis.cpp
6161 ObjCARCAnalysisUtils.cpp
6262 ObjCARCInstKind.cpp
63 OptimizationDiagnosticInfo.cpp
63 OptimizationRemarkEmitter.cpp
6464 OrderedBasicBlock.cpp
6565 PHITransAddr.cpp
6666 PostDominators.cpp
2626 #include "llvm/Analysis/ConstantFolding.h"
2727 #include "llvm/Analysis/LoopAnalysisManager.h"
2828 #include "llvm/Analysis/MemoryBuiltins.h"
29 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
29 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3030 #include "llvm/Analysis/ValueTracking.h"
3131 #include "llvm/Analysis/VectorUtils.h"
3232 #include "llvm/IR/ConstantRange.h"
2828 #include "llvm/Analysis/LoopAnalysisManager.h"
2929 #include "llvm/Analysis/LoopInfo.h"
3030 #include "llvm/Analysis/MemoryLocation.h"
31 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
31 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3232 #include "llvm/Analysis/ScalarEvolution.h"
3333 #include "llvm/Analysis/ScalarEvolutionExpander.h"
3434 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
+0
-136
lib/Analysis/OptimizationDiagnosticInfo.cpp less more
None //===- OptimizationDiagnosticInfo.cpp - Optimization Diagnostic -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Optimization diagnostic interfaces. It's packaged as an analysis pass so
10 // that by using this service passes become dependent on BFI as well. BFI is
11 // used to compute the "hotness" of the diagnostic message.
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
15 #include "llvm/Analysis/BranchProbabilityInfo.h"
16 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/IR/DebugInfo.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/Dominators.h"
21 #include "llvm/IR/LLVMContext.h"
22
23 using namespace llvm;
24
25 OptimizationRemarkEmitter::OptimizationRemarkEmitter(const Function *F)
26 : F(F), BFI(nullptr) {
27 if (!F->getContext().getDiagnosticsHotnessRequested())
28 return;
29
30 // First create a dominator tree.
31 DominatorTree DT;
32 DT.recalculate(*const_cast(F));
33
34 // Generate LoopInfo from it.
35 LoopInfo LI;
36 LI.analyze(DT);
37
38 // Then compute BranchProbabilityInfo.
39 BranchProbabilityInfo BPI;
40 BPI.calculate(*F, LI);
41
42 // Finally compute BFI.
43 OwnedBFI = llvm::make_unique(*F, BPI, LI);
44 BFI = OwnedBFI.get();
45 }
46
47 bool OptimizationRemarkEmitter::invalidate(
48 Function &F, const PreservedAnalyses &PA,
49 FunctionAnalysisManager::Invalidator &Inv) {
50 // This analysis has no state and so can be trivially preserved but it needs
51 // a fresh view of BFI if it was constructed with one.
52 if (BFI && Inv.invalidate(F, PA))
53 return true;
54
55 // Otherwise this analysis result remains valid.
56 return false;
57 }
58
59 Optional OptimizationRemarkEmitter::computeHotness(const Value *V) {
60 if (!BFI)
61 return None;
62
63 return BFI->getBlockProfileCount(cast(V));
64 }
65
66 void OptimizationRemarkEmitter::computeHotness(
67 DiagnosticInfoIROptimization &OptDiag) {
68 const Value *V = OptDiag.getCodeRegion();
69 if (V)
70 OptDiag.setHotness(computeHotness(V));
71 }
72
73 void OptimizationRemarkEmitter::emit(
74 DiagnosticInfoOptimizationBase &OptDiagBase) {
75 auto &OptDiag = cast(OptDiagBase);
76 computeHotness(OptDiag);
77 // If a diagnostic has a hotness value, then only emit it if its hotness
78 // meets the threshold.
79 if (OptDiag.getHotness() &&
80 *OptDiag.getHotness() <
81 F->getContext().getDiagnosticsHotnessThreshold()) {
82 return;
83 }
84
85 F->getContext().diagnose(OptDiag);
86 }
87
88 OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
89 : FunctionPass(ID) {
90 initializeOptimizationRemarkEmitterWrapperPassPass(
91 *PassRegistry::getPassRegistry());
92 }
93
94 bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
95 BlockFrequencyInfo *BFI;
96
97 if (Fn.getContext().getDiagnosticsHotnessRequested())
98 BFI = &getAnalysis().getBFI();
99 else
100 BFI = nullptr;
101
102 ORE = llvm::make_unique(&Fn, BFI);
103 return false;
104 }
105
106 void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
107 AnalysisUsage &AU) const {
108 LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
109 AU.setPreservesAll();
110 }
111
112 AnalysisKey OptimizationRemarkEmitterAnalysis::Key;
113
114 OptimizationRemarkEmitter
115 OptimizationRemarkEmitterAnalysis::run(Function &F,
116 FunctionAnalysisManager &AM) {
117 BlockFrequencyInfo *BFI;
118
119 if (F.getContext().getDiagnosticsHotnessRequested())
120 BFI = &AM.getResult(F);
121 else
122 BFI = nullptr;
123
124 return OptimizationRemarkEmitter(&F, BFI);
125 }
126
127 char OptimizationRemarkEmitterWrapperPass::ID = 0;
128 static const char ore_name[] = "Optimization Remark Emitter";
129 #define ORE_NAME "opt-remark-emitter"
130
131 INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
132 false, true)
133 INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
134 INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
135 false, true)
0 //===- OptimizationRemarkEmitter.cpp - Optimization Diagnostic --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Optimization diagnostic interfaces. It's packaged as an analysis pass so
10 // that by using this service passes become dependent on BFI as well. BFI is
11 // used to compute the "hotness" of the diagnostic message.
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
15 #include "llvm/Analysis/BranchProbabilityInfo.h"
16 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/IR/DebugInfo.h"
19 #include "llvm/IR/DiagnosticInfo.h"
20 #include "llvm/IR/Dominators.h"
21 #include "llvm/IR/LLVMContext.h"
22
23 using namespace llvm;
24
25 OptimizationRemarkEmitter::OptimizationRemarkEmitter(const Function *F)
26 : F(F), BFI(nullptr) {
27 if (!F->getContext().getDiagnosticsHotnessRequested())
28 return;
29
30 // First create a dominator tree.
31 DominatorTree DT;
32 DT.recalculate(*const_cast(F));
33
34 // Generate LoopInfo from it.
35 LoopInfo LI;
36 LI.analyze(DT);
37
38 // Then compute BranchProbabilityInfo.
39 BranchProbabilityInfo BPI;
40 BPI.calculate(*F, LI);
41
42 // Finally compute BFI.
43 OwnedBFI = llvm::make_unique(*F, BPI, LI);
44 BFI = OwnedBFI.get();
45 }
46
47 bool OptimizationRemarkEmitter::invalidate(
48 Function &F, const PreservedAnalyses &PA,
49 FunctionAnalysisManager::Invalidator &Inv) {
50 // This analysis has no state and so can be trivially preserved but it needs
51 // a fresh view of BFI if it was constructed with one.
52 if (BFI && Inv.invalidate(F, PA))
53 return true;
54
55 // Otherwise this analysis result remains valid.
56 return false;
57 }
58
59 Optional OptimizationRemarkEmitter::computeHotness(const Value *V) {
60 if (!BFI)
61 return None;
62
63 return BFI->getBlockProfileCount(cast(V));
64 }
65
66 void OptimizationRemarkEmitter::computeHotness(
67 DiagnosticInfoIROptimization &OptDiag) {
68 const Value *V = OptDiag.getCodeRegion();
69 if (V)
70 OptDiag.setHotness(computeHotness(V));
71 }
72
73 void OptimizationRemarkEmitter::emit(
74 DiagnosticInfoOptimizationBase &OptDiagBase) {
75 auto &OptDiag = cast(OptDiagBase);
76 computeHotness(OptDiag);
77 // If a diagnostic has a hotness value, then only emit it if its hotness
78 // meets the threshold.
79 if (OptDiag.getHotness() &&
80 *OptDiag.getHotness() <
81 F->getContext().getDiagnosticsHotnessThreshold()) {
82 return;
83 }
84
85 F->getContext().diagnose(OptDiag);
86 }
87
88 OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
89 : FunctionPass(ID) {
90 initializeOptimizationRemarkEmitterWrapperPassPass(
91 *PassRegistry::getPassRegistry());
92 }
93
94 bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
95 BlockFrequencyInfo *BFI;
96
97 if (Fn.getContext().getDiagnosticsHotnessRequested())
98 BFI = &getAnalysis().getBFI();
99 else
100 BFI = nullptr;
101
102 ORE = llvm::make_unique(&Fn, BFI);
103 return false;
104 }
105
106 void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
107 AnalysisUsage &AU) const {
108 LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
109 AU.setPreservesAll();
110 }
111
112 AnalysisKey OptimizationRemarkEmitterAnalysis::Key;
113
114 OptimizationRemarkEmitter
115 OptimizationRemarkEmitterAnalysis::run(Function &F,
116 FunctionAnalysisManager &AM) {
117 BlockFrequencyInfo *BFI;
118
119 if (F.getContext().getDiagnosticsHotnessRequested())
120 BFI = &AM.getResult(F);
121 else
122 BFI = nullptr;
123
124 return OptimizationRemarkEmitter(&F, BFI);
125 }
126
127 char OptimizationRemarkEmitterWrapperPass::ID = 0;
128 static const char ore_name[] = "Optimization Remark Emitter";
129 #define ORE_NAME "opt-remark-emitter"
130
131 INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
132 false, true)
133 INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
134 INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
135 false, true)
2828 #include "llvm/Analysis/InstructionSimplify.h"
2929 #include "llvm/Analysis/Loads.h"
3030 #include "llvm/Analysis/LoopInfo.h"
31 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
31 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3232 #include "llvm/Analysis/TargetLibraryInfo.h"
3333 #include "llvm/IR/Argument.h"
3434 #include "llvm/IR/Attributes.h"
1414 #include "llvm/ADT/ScopeExit.h"
1515 #include "llvm/ADT/SmallSet.h"
1616 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
17 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
1818 #include "llvm/CodeGen/Analysis.h"
1919 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
2020 #include "llvm/CodeGen/LowLevelType.h"
2929 #include "llvm/ADT/Statistic.h"
3030 #include "llvm/ADT/StringRef.h"
3131 #include "llvm/Analysis/AliasAnalysis.h"
32 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
32 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3333 #include "llvm/CodeGen/CalcSpillWeights.h"
3434 #include "llvm/CodeGen/EdgeBundles.h"
3535 #include "llvm/CodeGen/LiveInterval.h"
2525 #include "llvm/Analysis/AliasAnalysis.h"
2626 #include "llvm/Analysis/BranchProbabilityInfo.h"
2727 #include "llvm/Analysis/CFG.h"
28 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
28 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2929 #include "llvm/Analysis/TargetLibraryInfo.h"
3030 #include "llvm/CodeGen/FastISel.h"
3131 #include "llvm/CodeGen/FunctionLoweringInfo.h"
1717 #include "llvm/ADT/Statistic.h"
1818 #include "llvm/Analysis/BranchProbabilityInfo.h"
1919 #include "llvm/Analysis/EHPersonalities.h"
20 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
20 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2121 #include "llvm/CodeGen/Passes.h"
2222 #include "llvm/CodeGen/StackProtector.h"
2323 #include "llvm/CodeGen/TargetPassConfig.h"
4040 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
4141 #include "llvm/Analysis/MemorySSA.h"
4242 #include "llvm/Analysis/ModuleSummaryAnalysis.h"
43 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
43 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
4444 #include "llvm/Analysis/PostDominators.h"
4545 #include "llvm/Analysis/ProfileSummaryInfo.h"
4646 #include "llvm/Analysis/RegionInfo.h"
2121 #include "llvm/Analysis/BlockFrequencyInfo.h"
2222 #include "llvm/Analysis/CallGraph.h"
2323 #include "llvm/Analysis/InlineCost.h"
24 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
24 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2525 #include "llvm/Analysis/ProfileSummaryInfo.h"
2626 #include "llvm/Analysis/TargetLibraryInfo.h"
2727 #include "llvm/IR/CallSite.h"
1818 #include "llvm/Analysis/CodeMetrics.h"
1919 #include "llvm/Analysis/InlineCost.h"
2020 #include "llvm/Analysis/LoopInfo.h"
21 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
21 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2222 #include "llvm/Analysis/ProfileSummaryInfo.h"
2323 #include "llvm/Analysis/TargetLibraryInfo.h"
2424 #include "llvm/Analysis/TargetTransformInfo.h"
2929 #include "llvm/Analysis/AssumptionCache.h"
3030 #include "llvm/Analysis/InlineCost.h"
3131 #include "llvm/Analysis/LoopInfo.h"
32 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
32 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3333 #include "llvm/Analysis/PostDominators.h"
3434 #include "llvm/Analysis/TargetTransformInfo.h"
3535 #include "llvm/IR/Constants.h"
5050 #include "llvm/ADT/iterator_range.h"
5151 #include "llvm/Analysis/AliasAnalysis.h"
5252 #include "llvm/Analysis/BasicAliasAnalysis.h"
53 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
53 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
5454 #include "llvm/Analysis/TypeMetadataUtils.h"
5555 #include "llvm/IR/CallSite.h"
5656 #include "llvm/IR/Constants.h"
4747 #include "llvm/Analysis/InstructionSimplify.h"
4848 #include "llvm/Analysis/LoopInfo.h"
4949 #include "llvm/Analysis/MemoryBuiltins.h"
50 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
50 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
5151 #include "llvm/Analysis/TargetLibraryInfo.h"
5252 #include "llvm/Analysis/ValueTracking.h"
5353 #include "llvm/IR/CFG.h"
2020 #include "llvm/Analysis/GlobalsModRef.h"
2121 #include "llvm/Analysis/IndirectCallPromotionAnalysis.h"
2222 #include "llvm/Analysis/IndirectCallSiteVisitor.h"
23 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
23 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2424 #include "llvm/Analysis/ProfileSummaryInfo.h"
2525 #include "llvm/IR/BasicBlock.h"
2626 #include "llvm/IR/CallSite.h"
5858 #include "llvm/Analysis/CFG.h"
5959 #include "llvm/Analysis/IndirectCallSiteVisitor.h"
6060 #include "llvm/Analysis/LoopInfo.h"
61 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
61 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
6262 #include "llvm/IR/CallSite.h"
6363 #include "llvm/IR/DiagnosticInfo.h"
6464 #include "llvm/IR/Dominators.h"
2020 #include "llvm/ADT/Twine.h"
2121 #include "llvm/Analysis/BlockFrequencyInfo.h"
2222 #include "llvm/Analysis/GlobalsModRef.h"
23 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
23 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2424 #include "llvm/IR/BasicBlock.h"
2525 #include "llvm/IR/CallSite.h"
2626 #include "llvm/IR/DerivedTypes.h"
3434 #include "llvm/Analysis/LoopInfo.h"
3535 #include "llvm/Analysis/MemoryBuiltins.h"
3636 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
37 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
37 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3838 #include "llvm/Analysis/PHITransAddr.h"
3939 #include "llvm/Analysis/TargetLibraryInfo.h"
4040 #include "llvm/IR/Attributes.h"
4141 #include "llvm/Analysis/LoopInfo.h"
4242 #include "llvm/Analysis/LoopPass.h"
4343 #include "llvm/Analysis/MemoryBuiltins.h"
44 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
44 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
4545 #include "llvm/Analysis/ScalarEvolution.h"
4646 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
4747 #include "llvm/Analysis/TargetLibraryInfo.h"
1919 #include "llvm/Analysis/CodeMetrics.h"
2020 #include "llvm/Analysis/InstructionSimplify.h"
2121 #include "llvm/Analysis/LoopInfo.h"
22 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
22 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2323 #include "llvm/Analysis/ScalarEvolution.h"
2424 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
2525 #include "llvm/Analysis/ScalarEvolutionExpander.h"
3030 #include "llvm/Analysis/GlobalsModRef.h"
3131 #include "llvm/Analysis/LoopAccessAnalysis.h"
3232 #include "llvm/Analysis/LoopInfo.h"
33 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
33 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
3434 #include "llvm/IR/DiagnosticInfo.h"
3535 #include "llvm/IR/Dominators.h"
3636 #include "llvm/Pass.h"
2121 #include "llvm/Analysis/LoopInfo.h"
2222 #include "llvm/Analysis/LoopIterator.h"
2323 #include "llvm/Analysis/LoopPass.h"
24 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
24 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2525 #include "llvm/Analysis/ScalarEvolution.h"
2626 #include "llvm/Analysis/ScalarEvolutionExpander.h"
2727 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
1919 #include "llvm/Analysis/InstructionSimplify.h"
2020 #include "llvm/Analysis/LoopPass.h"
2121 #include "llvm/Analysis/LoopUnrollAnalyzer.h"
22 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
22 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2323 #include "llvm/Analysis/ProfileSummaryInfo.h"
2424 #include "llvm/Analysis/ScalarEvolution.h"
2525 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
5959 #include "llvm/Analysis/InlineCost.h"
6060 #include "llvm/Analysis/InstructionSimplify.h"
6161 #include "llvm/Analysis/Loads.h"
62 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
62 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
6363 #include "llvm/Analysis/TargetTransformInfo.h"
6464 #include "llvm/IR/CFG.h"
6565 #include "llvm/IR/CallSite.h"
2121 #include "llvm/Analysis/InstructionSimplify.h"
2222 #include "llvm/Analysis/LoopIterator.h"
2323 #include "llvm/Analysis/LoopPass.h"
24 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
24 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2525 #include "llvm/Analysis/ScalarEvolution.h"
2626 #include "llvm/IR/BasicBlock.h"
2727 #include "llvm/IR/DataLayout.h"
1919 #include "llvm/ADT/Statistic.h"
2020 #include "llvm/Analysis/AssumptionCache.h"
2121 #include "llvm/Analysis/InstructionSimplify.h"
22 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
22 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2323 #include "llvm/Analysis/TargetLibraryInfo.h"
2424 #include "llvm/IR/DataLayout.h"
2525 #include "llvm/IR/Dominators.h"
1818 #include "llvm/ADT/StringMap.h"
1919 #include "llvm/ADT/Triple.h"
2020 #include "llvm/Analysis/ConstantFolding.h"
21 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
21 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
2222 #include "llvm/Analysis/TargetLibraryInfo.h"
2323 #include "llvm/Analysis/ValueTracking.h"
2424 #include "llvm/IR/DataLayout.h"
3838 #include "llvm/Analysis/LoopAccessAnalysis.h"
3939 #include "llvm/Analysis/LoopInfo.h"
4040 #include "llvm/Analysis/MemoryLocation.h"
41 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
41 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
4242 #include "llvm/Analysis/ScalarEvolution.h"
4343 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
4444 #include "llvm/Analysis/TargetLibraryInfo.h"