summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h7
-rw-r--r--llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h20
-rw-r--r--llvm/include/llvm/IR/DiagnosticHandler.h67
-rw-r--r--llvm/include/llvm/IR/DiagnosticInfo.h14
-rw-r--r--llvm/include/llvm/IR/LLVMContext.h41
-rw-r--r--llvm/include/llvm/LTO/Config.h17
-rw-r--r--llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h5
7 files changed, 45 insertions, 126 deletions
diff --git a/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h b/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h
index 5d71b94e19e..a99514133e5 100644
--- a/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h
+++ b/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h
@@ -78,9 +78,10 @@ public:
/// use the extra analysis (1) to filter trivial false positives or (2) to
/// provide more context so that non-trivial false positives can be quickly
/// detected by the user.
- bool allowExtraAnalysis(StringRef PassName) const {
- return (F->getContext().getDiagnosticsOutputFile() ||
- F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
+ bool allowExtraAnalysis() const {
+ // For now, only allow this with -fsave-optimization-record since the -Rpass
+ // options are handled in the front-end.
+ return F->getContext().getDiagnosticsOutputFile();
}
private:
diff --git a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
index 6b11c7aea4f..6ad5de533d1 100644
--- a/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
+++ b/llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
@@ -73,9 +73,7 @@ public:
/// \see DiagnosticInfoOptimizationBase::isEnabled.
bool isEnabled() const override {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName());
+ return OptimizationRemark::isEnabled(getPassName());
}
};
@@ -99,9 +97,7 @@ public:
/// \see DiagnosticInfoOptimizationBase::isEnabled.
bool isEnabled() const override {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName());
+ return OptimizationRemarkMissed::isEnabled(getPassName());
}
};
@@ -125,9 +121,7 @@ public:
/// \see DiagnosticInfoOptimizationBase::isEnabled.
bool isEnabled() const override {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(getPassName());
+ return OptimizationRemarkAnalysis::isEnabled(getPassName());
}
};
@@ -158,10 +152,10 @@ public:
/// that are normally too noisy. In this mode, we can use the extra analysis
/// (1) to filter trivial false positives or (2) to provide more context so
/// that non-trivial false positives can be quickly detected by the user.
- bool allowExtraAnalysis(StringRef PassName) const {
- return (MF.getFunction()->getContext().getDiagnosticsOutputFile() ||
- MF.getFunction()->getContext()
- .getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
+ bool allowExtraAnalysis() const {
+ // For now, only allow this with -fsave-optimization-record since the -Rpass
+ // options are handled in the front-end.
+ return MF.getFunction()->getContext().getDiagnosticsOutputFile();
}
private:
diff --git a/llvm/include/llvm/IR/DiagnosticHandler.h b/llvm/include/llvm/IR/DiagnosticHandler.h
deleted file mode 100644
index 031298a1b74..00000000000
--- a/llvm/include/llvm/IR/DiagnosticHandler.h
+++ /dev/null
@@ -1,67 +0,0 @@
-//===- 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.
-//===----------------------------------------------------------------------===//
-
-#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.
- bool isAnyRemarkEnabled(StringRef PassName) const {
- return (isMissedOptRemarkEnabled(PassName) ||
- isPassedOptRemarkEnabled(PassName) ||
- isAnalysisRemarkEnabled(PassName));
- }
-};
-}
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index a2023554a89..fc6a8b214db 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -604,8 +604,10 @@ public:
return DI->getKind() == DK_OptimizationRemark;
}
+ static bool isEnabled(StringRef PassName);
+
/// \see DiagnosticInfoOptimizationBase::isEnabled.
- bool isEnabled() const override;
+ bool isEnabled() const override { return isEnabled(getPassName()); }
private:
/// This is deprecated now and only used by the function API below.
@@ -645,8 +647,10 @@ public:
return DI->getKind() == DK_OptimizationRemarkMissed;
}
+ static bool isEnabled(StringRef PassName);
+
/// \see DiagnosticInfoOptimizationBase::isEnabled.
- bool isEnabled() const override;
+ bool isEnabled() const override { return isEnabled(getPassName()); }
private:
/// This is deprecated now and only used by the function API below.
@@ -697,8 +701,12 @@ public:
return DI->getKind() == DK_OptimizationRemarkAnalysis;
}
+ static bool isEnabled(StringRef PassName);
+
/// \see DiagnosticInfoOptimizationBase::isEnabled.
- bool isEnabled() const override;
+ bool isEnabled() const override {
+ return shouldAlwaysPrint() || isEnabled(getPassName());
+ }
static const char *AlwaysPrint;
diff --git a/llvm/include/llvm/IR/LLVMContext.h b/llvm/include/llvm/IR/LLVMContext.h
index 2de3e5f651a..4cb77701f76 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -16,7 +16,6 @@
#define LLVM_IR_LLVMCONTEXT_H
#include "llvm-c/Types.h"
-#include "llvm/IR/DiagnosticHandler.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Options.h"
#include <cstdint>
@@ -168,6 +167,11 @@ public:
using InlineAsmDiagHandlerTy = void (*)(const SMDiagnostic&, void *Context,
unsigned LocCookie);
+ /// Defines the type of a diagnostic handler.
+ /// \see LLVMContext::setDiagnosticHandler.
+ /// \see LLVMContext::diagnose.
+ using DiagnosticHandlerTy = void (*)(const DiagnosticInfo &DI, void *Context);
+
/// Defines the type of a yield callback.
/// \see LLVMContext::setYieldCallback.
using YieldCallbackTy = void (*)(LLVMContext *Context, void *OpaqueHandle);
@@ -190,43 +194,26 @@ public:
/// setInlineAsmDiagnosticHandler.
void *getInlineAsmDiagnosticContext() const;
- /// setDiagnosticHandlerCallBack - This method sets a handler call back
- /// that is invoked when the backend needs to report anything to the user.
- /// The first argument is a function pointer and the second is a context pointer
- /// that gets passed into the DiagHandler. The third argument should be set to
+ /// setDiagnosticHandler - This method sets a handler that is invoked
+ /// when the backend needs to report anything to the user. The first
+ /// argument is a function pointer and the second is a context pointer that
+ /// gets passed into the DiagHandler. The third argument should be set to
/// true if the handler only expects enabled diagnostics.
///
/// LLVMContext doesn't take ownership or interpret either of these
/// pointers.
- void setDiagnosticHandlerCallBack(
- DiagnosticHandler::DiagnosticHandlerTy DiagHandler,
- void *DiagContext = nullptr, bool RespectFilters = false);
-
- /// setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler
- /// to provide custom diagnostic handling. The first argument is unique_ptr of object
- /// of type DiagnosticHandler or a derived of that. The third argument should be
- /// set to true if the handler only expects enabled diagnostics.
- ///
- /// Ownership of this pointer is moved to LLVMContextImpl.
- void setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
+ void setDiagnosticHandler(DiagnosticHandlerTy DiagHandler,
+ void *DiagContext = nullptr,
bool RespectFilters = false);
- /// getDiagnosticHandlerCallBack - Return the diagnostic handler call back set by
- /// setDiagnosticHandlerCallBack.
- DiagnosticHandler::DiagnosticHandlerTy getDiagnosticHandlerCallBack() const;
+ /// getDiagnosticHandler - Return the diagnostic handler set by
+ /// setDiagnosticHandler.
+ DiagnosticHandlerTy getDiagnosticHandler() const;
/// getDiagnosticContext - Return the diagnostic context set by
/// setDiagnosticContext.
void *getDiagnosticContext() const;
- /// getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by
- /// setDiagnosticHandler.
- const DiagnosticHandler *getDiagHandlerPtr() const;
-
- /// getDiagnosticHandler - transfers owenership of DiagnosticHandler unique_ptr
- /// to caller.
- std::unique_ptr<DiagnosticHandler> getDiagnosticHandler();
-
/// \brief Return if a code hotness metric should be included in optimization
/// diagnostics.
bool getDiagnosticsHotnessRequested() const;
diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h
index 4bd981c090b..60a5fa6eb36 100644
--- a/llvm/include/llvm/LTO/Config.h
+++ b/llvm/include/llvm/LTO/Config.h
@@ -171,27 +171,20 @@ struct Config {
bool UseInputModulePath = false);
};
-struct LTOLLVMDiagnosticHandler : public DiagnosticHandler {
- DiagnosticHandlerFunction *Fn;
- LTOLLVMDiagnosticHandler(DiagnosticHandlerFunction *DiagHandlerFn)
- : Fn(DiagHandlerFn) {}
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- (*Fn)(DI);
- return true;
- }
-};
/// A derived class of LLVMContext that initializes itself according to a given
/// Config object. The purpose of this class is to tie ownership of the
/// diagnostic handler to the context, as opposed to the Config object (which
/// may be ephemeral).
-// FIXME: This should not be required as diagnostic handler is not callback.
struct LTOLLVMContext : LLVMContext {
+ static void funcDiagHandler(const DiagnosticInfo &DI, void *Context) {
+ auto *Fn = static_cast<DiagnosticHandlerFunction *>(Context);
+ (*Fn)(DI);
+ }
LTOLLVMContext(const Config &C) : DiagHandler(C.DiagHandler) {
setDiscardValueNames(C.ShouldDiscardValueNames);
enableDebugTypeODRUniquing();
- setDiagnosticHandler(
- llvm::make_unique<LTOLLVMDiagnosticHandler>(&DiagHandler), true);
+ setDiagnosticHandler(funcDiagHandler, &DiagHandler, true);
}
DiagnosticHandlerFunction DiagHandler;
};
diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
index 4add6724557..952875fc854 100644
--- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -184,7 +184,6 @@ struct LTOCodeGenerator {
LLVMContext &getContext() { return Context; }
void resetMergedModule() { MergedModule.reset(); }
- void DiagnosticHandler(const DiagnosticInfo &DI);
private:
void initializeLTOPasses();
@@ -205,6 +204,10 @@ private:
bool determineTarget();
std::unique_ptr<TargetMachine> createTargetMachine();
+ static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context);
+
+ void DiagnosticHandler2(const DiagnosticInfo &DI);
+
void emitError(const std::string &ErrMsg);
void emitWarning(const std::string &ErrMsg);
OpenPOWER on IntegriCloud