[Alignment][NFC] Convert StoreInst to MaybeAlign
[llvm-complete.git] / include / llvm / IR / DiagnosticHandler.h
blob55e5e5975808d97b8711f265063d4f4f220c1a33
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 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_IR_DIAGNOSTICHANDLER_H
13 #define LLVM_IR_DIAGNOSTICHANDLER_H
15 #include "llvm/ADT/StringRef.h"
17 namespace llvm {
18 class DiagnosticInfo;
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.
24 struct DiagnosticHandler {
25 void *DiagnosticContext = nullptr;
26 DiagnosticHandler(void *DiagContext = nullptr)
27 : DiagnosticContext(DiagContext) {}
28 virtual ~DiagnosticHandler() = default;
30 using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
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().
36 DiagnosticHandlerTy DiagHandlerCallback = nullptr;
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) {
44 DiagHandlerCallback(DI, DiagnosticContext);
45 return true;
47 return false;
50 /// Return true if analysis remarks are enabled, override
51 /// to provide different implementation.
52 virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
54 /// Return true if missed optimization remarks are enabled, override
55 /// to provide different implementation.
56 virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
58 /// Return true if passed optimization remarks are enabled, override
59 /// to provide different implementation.
60 virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
62 /// Return true if any type of remarks are enabled for this pass.
63 bool isAnyRemarkEnabled(StringRef PassName) const {
64 return (isMissedOptRemarkEnabled(PassName) ||
65 isPassedOptRemarkEnabled(PassName) ||
66 isAnalysisRemarkEnabled(PassName));
69 /// Return true if any type of remarks are enabled for any pass.
70 virtual bool isAnyRemarkEnabled() const;
72 } // namespace llvm
74 #endif // LLVM_IR_DIAGNOSTICHANDLER_H