1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
12 #include "llvm/IR/DiagnosticHandler.h"
13 #include "llvm/Support/CommandLine.h"
14 #include "llvm/Support/Regex.h"
20 /// Regular expression corresponding to the value given in one of the
21 /// -pass-remarks* command line flags. Passes whose name matches this regexp
22 /// will emit a diagnostic when calling the associated diagnostic function
23 /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
24 /// emitOptimizationRemarkAnalysis).
25 struct PassRemarksOpt
{
26 std::shared_ptr
<Regex
> Pattern
;
28 void operator=(const std::string
&Val
) {
29 // Create a regexp object to match pass names for emitOptimizationRemark.
31 Pattern
= std::make_shared
<Regex
>(Val
);
32 std::string RegexError
;
33 if (!Pattern
->isValid(RegexError
))
34 report_fatal_error("Invalid regular expression '" + Val
+
35 "' in -pass-remarks: " + RegexError
,
41 static PassRemarksOpt PassRemarksPassedOptLoc
;
42 static PassRemarksOpt PassRemarksMissedOptLoc
;
43 static PassRemarksOpt PassRemarksAnalysisOptLoc
;
46 // Command line flag to enable emitOptimizationRemark()
47 static cl::opt
<PassRemarksOpt
, true, cl::parser
<std::string
>> PassRemarks(
48 "pass-remarks", cl::value_desc("pattern"),
49 cl::desc("Enable optimization remarks from passes whose name match "
50 "the given regular expression"),
51 cl::Hidden
, cl::location(PassRemarksPassedOptLoc
), cl::ValueRequired
,
54 // -pass-remarks-missed
55 // Command line flag to enable emitOptimizationRemarkMissed()
56 static cl::opt
<PassRemarksOpt
, true, cl::parser
<std::string
>> PassRemarksMissed(
57 "pass-remarks-missed", cl::value_desc("pattern"),
58 cl::desc("Enable missed optimization remarks from passes whose name match "
59 "the given regular expression"),
60 cl::Hidden
, cl::location(PassRemarksMissedOptLoc
), cl::ValueRequired
,
63 // -pass-remarks-analysis
64 // Command line flag to enable emitOptimizationRemarkAnalysis()
65 static cl::opt
<PassRemarksOpt
, true, cl::parser
<std::string
>>
67 "pass-remarks-analysis", cl::value_desc("pattern"),
69 "Enable optimization analysis remarks from passes whose name match "
70 "the given regular expression"),
71 cl::Hidden
, cl::location(PassRemarksAnalysisOptLoc
), cl::ValueRequired
,
75 bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName
) const {
76 return (PassRemarksAnalysisOptLoc
.Pattern
&&
77 PassRemarksAnalysisOptLoc
.Pattern
->match(PassName
));
79 bool DiagnosticHandler::isMissedOptRemarkEnabled(StringRef PassName
) const {
80 return (PassRemarksMissedOptLoc
.Pattern
&&
81 PassRemarksMissedOptLoc
.Pattern
->match(PassName
));
83 bool DiagnosticHandler::isPassedOptRemarkEnabled(StringRef PassName
) const {
84 return (PassRemarksPassedOptLoc
.Pattern
&&
85 PassRemarksPassedOptLoc
.Pattern
->match(PassName
));
88 bool DiagnosticHandler::isAnyRemarkEnabled() const {
89 return (PassRemarksPassedOptLoc
.Pattern
|| PassRemarksMissedOptLoc
.Pattern
||
90 PassRemarksAnalysisOptLoc
.Pattern
);