llvm.org GIT mirror llvm / c647710
Remove LLVMContextImpl::optimizationRemarkEnabledFor. Summary: This patch moves the handling of -pass-remarks* over to lib/DiagnosticInfo.cpp. This allows the removal of the optimizationRemarkEnabledFor functions from LLVMContextImpl, as they're not needed anymore. Reviewers: qcolombet Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3878 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209453 91177308-0d34-0410-b5e6-96231b3b80d8 Diego Novillo 6 years ago
5 changed file(s) with 75 addition(s) and 105 deletion(s). Raw diff Collapse all Expand all
270270 /// or -pass-remarks-analysis). Note that this only handles the LLVM
271271 /// flags. We cannot access Clang flags from here (they are handled
272272 /// in BackendConsumer::OptimizationRemarkHandler).
273 ///
274 /// \p pImpl points to the current LLVM context. It is needed to query the
275 /// value of the command line flag associated with this remark.
276 virtual bool isEnabled(LLVMContextImpl *pImpl) const = 0;
273 virtual bool isEnabled() const = 0;
277274
278275 /// Return true if location information is available for this diagnostic.
279276 bool isLocationAvailable() const;
331328 }
332329
333330 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
334 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
331 virtual bool isEnabled() const override;
335332 };
336333
337334 /// Diagnostic information for missed-optimization remarks.
358355 }
359356
360357 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
361 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
358 virtual bool isEnabled() const override;
362359 };
363360
364361 /// Diagnostic information for optimization analysis remarks.
386383 }
387384
388385 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
389 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
386 virtual bool isEnabled() const override;
390387 };
391388
392389 // Create wrappers for C Binding types (see CBindingWrapping.h).
2222 #include "llvm/IR/Metadata.h"
2323 #include "llvm/IR/Module.h"
2424 #include "llvm/Support/Atomic.h"
25 #include "llvm/Support/CommandLine.h"
26 #include "llvm/Support/Regex.h"
2527 #include
2628
2729 using namespace llvm;
30
31 namespace {
32
33 /// \brief Regular expression corresponding to the value given in one of the
34 /// -pass-remarks* command line flags. Passes whose name matches this regexp
35 /// will emit a diagnostic when calling the associated diagnostic function
36 /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
37 /// emitOptimizationRemarkAnalysis).
38 struct PassRemarksOpt {
39 std::shared_ptr Pattern;
40
41 void operator=(const std::string &Val) {
42 // Create a regexp object to match pass names for emitOptimizationRemark.
43 if (!Val.empty()) {
44 Pattern = std::make_shared(Val);
45 std::string RegexError;
46 if (!Pattern->isValid(RegexError))
47 report_fatal_error("Invalid regular expression '" + Val +
48 "' in -pass-remarks: " + RegexError,
49 false);
50 }
51 };
52 };
53
54 static PassRemarksOpt PassRemarksOptLoc;
55 static PassRemarksOpt PassRemarksMissedOptLoc;
56 static PassRemarksOpt PassRemarksAnalysisOptLoc;
57
58 // -pass-remarks
59 // Command line flag to enable emitOptimizationRemark()
60 static cl::opt>
61 PassRemarks("pass-remarks", cl::value_desc("pattern"),
62 cl::desc("Enable optimization remarks from passes whose name match "
63 "the given regular expression"),
64 cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired,
65 cl::ZeroOrMore);
66
67 // -pass-remarks-missed
68 // Command line flag to enable emitOptimizationRemarkMissed()
69 static cl::opt> PassRemarksMissed(
70 "pass-remarks-missed", cl::value_desc("pattern"),
71 cl::desc("Enable missed optimization remarks from passes whose name match "
72 "the given regular expression"),
73 cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
74 cl::ZeroOrMore);
75
76 // -pass-remarks-analysis
77 // Command line flag to enable emitOptimizationRemarkAnalysis()
78 static cl::opt>
79 PassRemarksAnalysis(
80 "pass-remarks-analysis", cl::value_desc("pattern"),
81 cl::desc(
82 "Enable optimization analysis remarks from passes whose name match "
83 "the given regular expression"),
84 cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
85 cl::ZeroOrMore);
86 }
2887
2988 int llvm::getNextAvailablePluginDiagnosticKind() {
3089 static sys::cas_flag PluginKindID = DK_FirstPluginKind;
93152 DP << getLocationStr() << ": " << getMsg();
94153 }
95154
96 bool
97 DiagnosticInfoOptimizationRemark::isEnabled(LLVMContextImpl *pImpl) const {
98 return pImpl->optimizationRemarkEnabledFor(this);
155 bool DiagnosticInfoOptimizationRemark::isEnabled() const {
156 return PassRemarksOptLoc.Pattern &&
157 PassRemarksOptLoc.Pattern->match(getPassName());
99158 }
100159
101 bool DiagnosticInfoOptimizationRemarkMissed::isEnabled(
102 LLVMContextImpl *pImpl) const {
103 return pImpl->optimizationRemarkEnabledFor(this);
160 bool DiagnosticInfoOptimizationRemarkMissed::isEnabled() const {
161 return PassRemarksMissedOptLoc.Pattern &&
162 PassRemarksMissedOptLoc.Pattern->match(getPassName());
104163 }
105164
106 bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled(
107 LLVMContextImpl *pImpl) const {
108 return pImpl->optimizationRemarkEnabledFor(this);
165 bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled() const {
166 return PassRemarksAnalysisOptLoc.Pattern &&
167 PassRemarksAnalysisOptLoc.Pattern->match(getPassName());
109168 }
110169
111170 void llvm::emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
147147 // diagnostic and return.
148148 switch (DI.getKind()) {
149149 case llvm::DK_OptimizationRemark:
150 if (!cast(DI).isEnabled(pImpl))
150 if (!cast(DI).isEnabled())
151151 return;
152152 break;
153153 case llvm::DK_OptimizationRemarkMissed:
154 if (!cast(DI).isEnabled(pImpl))
154 if (!cast(DI).isEnabled())
155155 return;
156156 break;
157157 case llvm::DK_OptimizationRemarkAnalysis:
158 if (!cast(DI).isEnabled(pImpl))
158 if (!cast(DI).isEnabled())
159159 return;
160160 break;
161161 default:
1515 #include "llvm/IR/Attributes.h"
1616 #include "llvm/IR/DiagnosticInfo.h"
1717 #include "llvm/IR/Module.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/Regex.h"
2018 #include
2119 using namespace llvm;
2220
4442 YieldCallback = nullptr;
4543 YieldOpaqueHandle = nullptr;
4644 NamedStructTypesUniqueID = 0;
47 }
48
49 namespace {
50
51 /// \brief Regular expression corresponding to the value given in one of the
52 /// -pass-remarks* command line flags. Passes whose name matches this regexp
53 /// will emit a diagnostic when calling the associated diagnostic function
54 /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
55 /// emitOptimizationRemarkAnalysis).
56 struct PassRemarksOpt {
57 std::shared_ptr Pattern;
58
59 void operator=(const std::string &Val) {
60 // Create a regexp object to match pass names for emitOptimizationRemark.
61 if (!Val.empty()) {
62 Pattern = std::make_shared(Val);
63 std::string RegexError;
64 if (!Pattern->isValid(RegexError))
65 report_fatal_error("Invalid regular expression '" + Val +
66 "' in -pass-remarks: " + RegexError,
67 false);
68 }
69 };
70 };
71
72 static PassRemarksOpt PassRemarksOptLoc;
73 static PassRemarksOpt PassRemarksMissedOptLoc;
74 static PassRemarksOpt PassRemarksAnalysisOptLoc;
75
76 // -pass-remarks
77 // Command line flag to enable emitOptimizationRemark()
78 static cl::opt>
79 PassRemarks("pass-remarks", cl::value_desc("pattern"),
80 cl::desc("Enable optimization remarks from passes whose name match "
81 "the given regular expression"),
82 cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired,
83 cl::ZeroOrMore);
84
85 // -pass-remarks-missed
86 // Command line flag to enable emitOptimizationRemarkMissed()
87 static cl::opt> PassRemarksMissed(
88 "pass-remarks-missed", cl::value_desc("pattern"),
89 cl::desc("Enable missed optimization remarks from passes whose name match "
90 "the given regular expression"),
91 cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
92 cl::ZeroOrMore);
93
94 // -pass-remarks-analysis
95 // Command line flag to enable emitOptimizationRemarkAnalysis()
96 static cl::opt>
97 PassRemarksAnalysis(
98 "pass-remarks-analysis", cl::value_desc("pattern"),
99 cl::desc(
100 "Enable optimization analysis remarks from passes whose name match "
101 "the given regular expression"),
102 cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
103 cl::ZeroOrMore);
104 }
105
106 bool LLVMContextImpl::optimizationRemarkEnabledFor(
107 const DiagnosticInfoOptimizationRemark *DI) const {
108 return PassRemarksOptLoc.Pattern &&
109 PassRemarksOptLoc.Pattern->match(DI->getPassName());
110 }
111
112 bool LLVMContextImpl::optimizationRemarkEnabledFor(
113 const DiagnosticInfoOptimizationRemarkMissed *DI) const {
114 return PassRemarksMissedOptLoc.Pattern &&
115 PassRemarksMissedOptLoc.Pattern->match(DI->getPassName());
116 }
117
118 bool LLVMContextImpl::optimizationRemarkEnabledFor(
119 const DiagnosticInfoOptimizationRemarkAnalysis *DI) const {
120 return PassRemarksAnalysisOptLoc.Pattern &&
121 PassRemarksAnalysisOptLoc.Pattern->match(DI->getPassName());
12245 }
12346
12447 namespace {
373373 typedef DenseMap PrefixDataMapTy;
374374 PrefixDataMapTy PrefixDataMap;
375375
376 /// \brief Return true if the given pass name should emit optimization
377 /// remarks.
378 bool optimizationRemarkEnabledFor(
379 const DiagnosticInfoOptimizationRemark *DI) const;
380 bool optimizationRemarkEnabledFor(
381 const DiagnosticInfoOptimizationRemarkMissed *DI) const;
382 bool optimizationRemarkEnabledFor(
383 const DiagnosticInfoOptimizationRemarkAnalysis *DI) const;
384
385376 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
386377 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
387378