LLVM  8.0.1
DiagnosticHandler.cpp
Go to the documentation of this file.
1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -------------===//
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 //
11 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Regex.h"
15 
16 using namespace llvm;
17 
18 namespace {
19 
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;
27 
28  void operator=(const std::string &Val) {
29  // Create a regexp object to match pass names for emitOptimizationRemark.
30  if (!Val.empty()) {
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,
36  false);
37  }
38  }
39 };
40 
41 static PassRemarksOpt PassRemarksPassedOptLoc;
42 static PassRemarksOpt PassRemarksMissedOptLoc;
43 static PassRemarksOpt PassRemarksAnalysisOptLoc;
44 
45 // -pass-remarks
46 // Command line flag to enable emitOptimizationRemark()
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,
53 
54 // -pass-remarks-missed
55 // Command line flag to enable emitOptimizationRemarkMissed()
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,
62 
63 // -pass-remarks-analysis
64 // Command line flag to enable emitOptimizationRemarkAnalysis()
66  PassRemarksAnalysis(
67  "pass-remarks-analysis", cl::value_desc("pattern"),
68  cl::desc(
69  "Enable optimization analysis remarks from passes whose name match "
70  "the given regular expression"),
71  cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
73 }
74 
76  return (PassRemarksAnalysisOptLoc.Pattern &&
77  PassRemarksAnalysisOptLoc.Pattern->match(PassName));
78 }
80  return (PassRemarksMissedOptLoc.Pattern &&
81  PassRemarksMissedOptLoc.Pattern->match(PassName));
82 }
84  return (PassRemarksPassedOptLoc.Pattern &&
85  PassRemarksPassedOptLoc.Pattern->match(PassName));
86 }
87 
89  return (PassRemarksPassedOptLoc.Pattern || PassRemarksMissedOptLoc.Pattern ||
90  PassRemarksAnalysisOptLoc.Pattern);
91 }
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const
Return true if missed optimization remarks are enabled, override to provide different implementation...
virtual bool isPassedOptRemarkEnabled(StringRef PassName) const
Return true if passed optimization remarks are enabled, override to provide different implementation...
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
virtual bool isAnyRemarkEnabled() const
Return true if any type of remarks are enabled for any pass.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:439