LLVM  13.0.0git
DiagnosticHandler.h
Go to the documentation of this file.
1 //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM ---*- C++ -*-===//
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 // Base DiagnosticHandler class declaration. Derive from this class to provide
9 // custom diagnostic reporting.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
13 #define LLVM_IR_DIAGNOSTICHANDLER_H
14 
15 #include "llvm/ADT/StringRef.h"
16 
17 namespace llvm {
18 class DiagnosticInfo;
19 
20 /// This is the base class for diagnostic handling in LLVM.
21 /// The handleDiagnostics method must be overriden by the subclasses to handle
22 /// diagnostic. The *RemarkEnabled methods can be overriden to control
23 /// which remarks are enabled.
25  void *DiagnosticContext = nullptr;
26  DiagnosticHandler(void *DiagContext = nullptr)
27  : DiagnosticContext(DiagContext) {}
28  virtual ~DiagnosticHandler() = default;
29 
30  using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
31 
32  /// DiagHandlerCallback is settable from the C API and base implementation
33  /// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
34  /// class of DiagnosticHandler should not use callback but
35  /// implement handleDiagnostics().
37 
38  /// Override handleDiagnostics to provide custom implementation.
39  /// Return true if it handles diagnostics reporting properly otherwise
40  /// return false to make LLVMContext::diagnose() to print the message
41  /// with a prefix based on the severity.
42  virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
43  if (DiagHandlerCallback) {
45  return true;
46  }
47  return false;
48  }
49 
50  /// Return true if analysis remarks are enabled, override
51  /// to provide different implementation.
52  virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
53 
54  /// Return true if missed optimization remarks are enabled, override
55  /// to provide different implementation.
56  virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
57 
58  /// Return true if passed optimization remarks are enabled, override
59  /// to provide different implementation.
60  virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
61 
62  /// Return true if any type of remarks are enabled for this pass.
67  }
68 
69  /// Return true if any type of remarks are enabled for any pass.
70  virtual bool isAnyRemarkEnabled() const;
71 };
72 } // namespace llvm
73 
74 #endif // LLVM_IR_DIAGNOSTICHANDLER_H
llvm::DiagnosticHandler::DiagHandlerCallback
DiagnosticHandlerTy DiagHandlerCallback
DiagHandlerCallback is settable from the C API and base implementation of DiagnosticHandler will call...
Definition: DiagnosticHandler.h:36
llvm::DiagnosticHandler::DiagnosticHandler
DiagnosticHandler(void *DiagContext=nullptr)
Definition: DiagnosticHandler.h:26
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
StringRef.h
llvm::DiagnosticHandler
This is the base class for diagnostic handling in LLVM.
Definition: DiagnosticHandler.h:24
llvm::DiagnosticHandler::DiagnosticHandlerTy
void(*)(const DiagnosticInfo &DI, void *Context) DiagnosticHandlerTy
Definition: DiagnosticHandler.h:30
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::DiagnosticHandler::handleDiagnostics
virtual bool handleDiagnostics(const DiagnosticInfo &DI)
Override handleDiagnostics to provide custom implementation.
Definition: DiagnosticHandler.h:42
llvm::DiagnosticHandler::isAnyRemarkEnabled
virtual bool isAnyRemarkEnabled() const
Return true if any type of remarks are enabled for any pass.
Definition: DiagnosticHandler.cpp:87
llvm::DiagnosticInfo
This is the base abstract class for diagnostic reporting in the backend.
Definition: DiagnosticInfo.h:101
llvm::DiagnosticHandler::DiagnosticContext
void * DiagnosticContext
Definition: DiagnosticHandler.h:25
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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::DiagnosticHandler::isAnyRemarkEnabled
bool isAnyRemarkEnabled(StringRef PassName) const
Return true if any type of remarks are enabled for this pass.
Definition: DiagnosticHandler.h:63
llvm::DiagnosticHandler::~DiagnosticHandler
virtual ~DiagnosticHandler()=default
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:666