1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00
llvm-mirror/include/llvm/IR/DiagnosticHandler.h
Adam Nemet 8d2be3fa7c Allow ORE.emit to take a closure to delay building the remark object
In the lambda we are now returning the remark by value so we need to preserve
its type in the insertion operator.  This requires making the insertion
operator generic.

I've also converted a few cases to use the new API.  It seems to work pretty
well.  See the LoopUnroller for a slightly more interesting case.

llvm-svn: 313691
2017-09-19 23:00:55 +00:00

76 lines
2.9 KiB
C++

//===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -*- C++ ---*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Base DiagnosticHandler class declaration. Derive from this class to provide
// custom diagnostic reporting.
//===----------------------------------------------------------------------===//
#ifndef LLVM_IR_DIAGNOSTICHANDLER_H
#define LLVM_IR_DIAGNOSTICHANDLER_H
#include "llvm/ADT/StringRef.h"
namespace llvm {
class DiagnosticInfo;
/// \brief This is the base class for diagnostic handling in LLVM.
/// The handleDiagnostics method must be overriden by the subclasses to handle
/// diagnostic. The *RemarkEnabled methods can be overriden to control
/// which remarks are enabled.
struct DiagnosticHandler {
void *DiagnosticContext = nullptr;
DiagnosticHandler(void *DiagContext = nullptr)
: DiagnosticContext(DiagContext) {}
virtual ~DiagnosticHandler() = default;
using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
/// DiagHandlerCallback is settable from the C API and base implementation
/// of DiagnosticHandler will call it from handleDiagnostics(). Any derived
/// class of DiagnosticHandler should not use callback but
/// implement handleDiagnostics().
DiagnosticHandlerTy DiagHandlerCallback = nullptr;
/// Override handleDiagnostics to provide custom implementation.
/// Return true if it handles diagnostics reporting properly otherwise
/// return false to make LLVMContext::diagnose() to print the message
/// with a prefix based on the severity.
virtual bool handleDiagnostics(const DiagnosticInfo &DI) {
if (DiagHandlerCallback) {
DiagHandlerCallback(DI, DiagnosticContext);
return true;
}
return false;
}
/// Return true if analysis remarks are enabled, override
/// to provide different implementation.
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const;
/// Return true if missed optimization remarks are enabled, override
/// to provide different implementation.
virtual bool isMissedOptRemarkEnabled(StringRef PassName) const;
/// Return true if passed optimization remarks are enabled, override
/// to provide different implementation.
virtual bool isPassedOptRemarkEnabled(StringRef PassName) const;
/// Return true if any type of remarks are enabled for this pass.
bool isAnyRemarkEnabled(StringRef PassName) const {
return (isMissedOptRemarkEnabled(PassName) ||
isPassedOptRemarkEnabled(PassName) ||
isAnalysisRemarkEnabled(PassName));
}
/// Return true if any type of remarks are enabled for any pass.
virtual bool isAnyRemarkEnabled() const;
};
} // namespace llvm
#endif // LLVM_IR_DIAGNOSTICHANDLER_H