LLVM  13.0.0git
DiagnosticHandler.cpp
Go to the documentation of this file.
1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/Regex.h"
14 
15 using namespace llvm;
16 
17 namespace {
18 
19 /// Regular expression corresponding to the value given in one of the
20 /// -pass-remarks* command line flags. Passes whose name matches this regexp
21 /// will emit a diagnostic when calling the associated diagnostic function
22 /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
23 /// emitOptimizationRemarkAnalysis).
24 struct PassRemarksOpt {
25  std::shared_ptr<Regex> Pattern;
26 
27  void operator=(const std::string &Val) {
28  // Create a regexp object to match pass names for emitOptimizationRemark.
29  if (!Val.empty()) {
30  Pattern = std::make_shared<Regex>(Val);
31  std::string RegexError;
32  if (!Pattern->isValid(RegexError))
33  report_fatal_error("Invalid regular expression '" + Val +
34  "' in -pass-remarks: " + RegexError,
35  false);
36  }
37  }
38 };
39 
40 static PassRemarksOpt PassRemarksPassedOptLoc;
41 static PassRemarksOpt PassRemarksMissedOptLoc;
42 static PassRemarksOpt PassRemarksAnalysisOptLoc;
43 
44 // -pass-remarks
45 // Command line flag to enable emitOptimizationRemark()
47  "pass-remarks", cl::value_desc("pattern"),
48  cl::desc("Enable optimization remarks from passes whose name match "
49  "the given regular expression"),
50  cl::Hidden, cl::location(PassRemarksPassedOptLoc), cl::ValueRequired,
52 
53 // -pass-remarks-missed
54 // Command line flag to enable emitOptimizationRemarkMissed()
56  "pass-remarks-missed", cl::value_desc("pattern"),
57  cl::desc("Enable missed optimization remarks from passes whose name match "
58  "the given regular expression"),
59  cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
61 
62 // -pass-remarks-analysis
63 // Command line flag to enable emitOptimizationRemarkAnalysis()
65  PassRemarksAnalysis(
66  "pass-remarks-analysis", cl::value_desc("pattern"),
67  cl::desc(
68  "Enable optimization analysis remarks from passes whose name match "
69  "the given regular expression"),
70  cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
72 }
73 
75  return (PassRemarksAnalysisOptLoc.Pattern &&
76  PassRemarksAnalysisOptLoc.Pattern->match(PassName));
77 }
79  return (PassRemarksMissedOptLoc.Pattern &&
80  PassRemarksMissedOptLoc.Pattern->match(PassName));
81 }
83  return (PassRemarksPassedOptLoc.Pattern &&
84  PassRemarksPassedOptLoc.Pattern->match(PassName));
85 }
86 
88  return (PassRemarksPassedOptLoc.Pattern || PassRemarksMissedOptLoc.Pattern ||
89  PassRemarksAnalysisOptLoc.Pattern);
90 }
llvm
Definition: AllocatorList.h:23
llvm::DiagnosticHandler::isMissedOptRemarkEnabled
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const
Return true if missed optimization remarks are enabled, override to provide different implementation.
Definition: DiagnosticHandler.cpp:78
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:459
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::cl::ValueRequired
@ ValueRequired
Definition: CommandLine.h:137
CommandLine.h
llvm::DiagnosticHandler::isAnyRemarkEnabled
virtual bool isAnyRemarkEnabled() const
Return true if any type of remarks are enabled for any pass.
Definition: DiagnosticHandler.cpp:87
DiagnosticHandler.h
llvm::report_fatal_error
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
llvm::cl::ZeroOrMore
@ ZeroOrMore
Definition: CommandLine.h:120
llvm::cl::opt
Definition: CommandLine.h:1422
Regex.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::DiagnosticHandler::isAnalysisRemarkEnabled
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
Definition: DiagnosticHandler.cpp:74
llvm::DiagnosticHandler::isPassedOptRemarkEnabled
virtual bool isPassedOptRemarkEnabled(StringRef PassName) const
Return true if passed optimization remarks are enabled, override to provide different implementation.
Definition: DiagnosticHandler.cpp:82
llvm::cl::value_desc
Definition: CommandLine.h:424
llvm::Pattern
Definition: FileCheckImpl.h:614
llvm::cl::desc
Definition: CommandLine.h:414
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669