summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVivek Pandya <vivekvpandya@gmail.com>2017-09-15 19:53:54 +0000
committerVivek Pandya <vivekvpandya@gmail.com>2017-09-15 19:53:54 +0000
commit4abccff981adfaddf2a26bc1a6a8bce374f01574 (patch)
treef9cf7a8ab83f3e3f8413b767f045bfa77ecf32c6
parent885ad98e060cd960531fd534ab850babd715d65e (diff)
This reverts r313381
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313387 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/OptimizationDiagnosticInfo.h7
-rw-r--r--include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h20
-rw-r--r--include/llvm/IR/DiagnosticHandler.h67
-rw-r--r--include/llvm/IR/DiagnosticInfo.h14
-rw-r--r--include/llvm/IR/LLVMContext.h41
-rw-r--r--include/llvm/LTO/Config.h17
-rw-r--r--include/llvm/LTO/legacy/LTOCodeGenerator.h5
-rw-r--r--lib/IR/CMakeLists.txt1
-rw-r--r--lib/IR/Core.cpp6
-rw-r--r--lib/IR/DiagnosticHandler.cpp86
-rw-r--r--lib/IR/DiagnosticInfo.cpp78
-rw-r--r--lib/IR/LLVMContext.cpp38
-rw-r--r--lib/IR/LLVMContextImpl.cpp3
-rw-r--r--lib/IR/LLVMContextImpl.h3
-rw-r--r--lib/LTO/LTOCodeGenerator.cpp24
-rw-r--r--lib/Transforms/Scalar/GVN.cpp3
-rw-r--r--lib/Transforms/Vectorize/LoopVectorize.cpp21
-rw-r--r--test/Transforms/GVN/opt-remarks.ll2
-rw-r--r--tools/llc/llc.cpp40
-rw-r--r--tools/llvm-dis/llvm-dis.cpp43
-rw-r--r--tools/llvm-link/llvm-link.cpp45
-rw-r--r--tools/llvm-lto/llvm-lto.cpp66
-rw-r--r--tools/lto/lto.cpp35
23 files changed, 248 insertions, 417 deletions
diff --git a/include/llvm/Analysis/OptimizationDiagnosticInfo.h b/include/llvm/Analysis/OptimizationDiagnosticInfo.h
index 5d71b94e19e..a99514133e5 100644
--- a/include/llvm/Analysis/OptimizationDiagnosticInfo.h
+++ b/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/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h b/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
index 6b11c7aea4f..6ad5de533d1 100644
--- a/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
+++ b/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/include/llvm/IR/DiagnosticHandler.h b/include/llvm/IR/DiagnosticHandler.h
deleted file mode 100644
index 031298a1b74..00000000000
--- a/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/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h
index a2023554a89..fc6a8b214db 100644
--- a/include/llvm/IR/DiagnosticInfo.h
+++ b/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/include/llvm/IR/LLVMContext.h b/include/llvm/IR/LLVMContext.h
index 2de3e5f651a..4cb77701f76 100644
--- a/include/llvm/IR/LLVMContext.h
+++ b/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/include/llvm/LTO/Config.h b/include/llvm/LTO/Config.h
index 4bd981c090b..60a5fa6eb36 100644
--- a/include/llvm/LTO/Config.h
+++ b/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/include/llvm/LTO/legacy/LTOCodeGenerator.h b/include/llvm/LTO/legacy/LTOCodeGenerator.h
index 4add6724557..952875fc854 100644
--- a/include/llvm/LTO/legacy/LTOCodeGenerator.h
+++ b/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);
diff --git a/lib/IR/CMakeLists.txt b/lib/IR/CMakeLists.txt
index eb4b9143090..1cc229d68bf 100644
--- a/lib/IR/CMakeLists.txt
+++ b/lib/IR/CMakeLists.txt
@@ -17,7 +17,6 @@ add_llvm_library(LLVMCore
DebugInfo.cpp
DebugInfoMetadata.cpp
DebugLoc.cpp
- DiagnosticHandler.cpp
DiagnosticInfo.cpp
DiagnosticPrinter.cpp
Dominators.cpp
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index abb83e01e0c..aba770457e2 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -85,15 +85,15 @@ LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); }
void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
LLVMDiagnosticHandler Handler,
void *DiagnosticContext) {
- unwrap(C)->setDiagnosticHandlerCallBack(
- LLVM_EXTENSION reinterpret_cast<DiagnosticHandler::DiagnosticHandlerTy>(
+ unwrap(C)->setDiagnosticHandler(
+ LLVM_EXTENSION reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(
Handler),
DiagnosticContext);
}
LLVMDiagnosticHandler LLVMContextGetDiagnosticHandler(LLVMContextRef C) {
return LLVM_EXTENSION reinterpret_cast<LLVMDiagnosticHandler>(
- unwrap(C)->getDiagnosticHandlerCallBack());
+ unwrap(C)->getDiagnosticHandler());
}
void *LLVMContextGetDiagnosticContext(LLVMContextRef C) {
diff --git a/lib/IR/DiagnosticHandler.cpp b/lib/IR/DiagnosticHandler.cpp
deleted file mode 100644
index cc3969349bb..00000000000
--- a/lib/IR/DiagnosticHandler.cpp
+++ /dev/null
@@ -1,86 +0,0 @@
-//===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//
-//===----------------------------------------------------------------------===//
-#include "llvm/IR/DiagnosticHandler.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/RegEx.h"
-
-using namespace llvm;
-
-namespace {
-
-/// \brief Regular expression corresponding to the value given in one of the
-/// -pass-remarks* command line flags. Passes whose name matches this regexp
-/// will emit a diagnostic when calling the associated diagnostic function
-/// (emitOptimizationRemark, emitOptimizationRemarkMissed or
-/// emitOptimizationRemarkAnalysis).
-struct PassRemarksOpt {
- std::shared_ptr<Regex> Pattern;
-
- void operator=(const std::string &Val) {
- // Create a regexp object to match pass names for emitOptimizationRemark.
- if (!Val.empty()) {
- Pattern = std::make_shared<Regex>(Val);
- std::string RegexError;
- if (!Pattern->isValid(RegexError))
- report_fatal_error("Invalid regular expression '" + Val +
- "' in -pass-remarks: " + RegexError,
- false);
- }
- }
-};
-
-static PassRemarksOpt PassRemarksPassedOptLoc;
-static PassRemarksOpt PassRemarksMissedOptLoc;
-static PassRemarksOpt PassRemarksAnalysisOptLoc;
-
-// -pass-remarks
-// Command line flag to enable emitOptimizationRemark()
-static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarks(
- "pass-remarks", cl::value_desc("pattern"),
- cl::desc("Enable optimization remarks from passes whose name match "
- "the given regular expression"),
- cl::Hidden, cl::location(PassRemarksPassedOptLoc), cl::ValueRequired,
- cl::ZeroOrMore);
-
-// -pass-remarks-missed
-// Command line flag to enable emitOptimizationRemarkMissed()
-static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarksMissed(
- "pass-remarks-missed", cl::value_desc("pattern"),
- cl::desc("Enable missed optimization remarks from passes whose name match "
- "the given regular expression"),
- cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
- cl::ZeroOrMore);
-
-// -pass-remarks-analysis
-// Command line flag to enable emitOptimizationRemarkAnalysis()
-static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
- PassRemarksAnalysis(
- "pass-remarks-analysis", cl::value_desc("pattern"),
- cl::desc(
- "Enable optimization analysis remarks from passes whose name match "
- "the given regular expression"),
- cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
- cl::ZeroOrMore);
-}
-
-bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName) const {
- return (PassRemarksAnalysisOptLoc.Pattern &&
- PassRemarksAnalysisOptLoc.Pattern->match(PassName));
-}
-bool DiagnosticHandler::isMissedOptRemarkEnabled(StringRef PassName) const {
- return (PassRemarksMissedOptLoc.Pattern &&
- PassRemarksMissedOptLoc.Pattern->match(PassName));
-}
-bool DiagnosticHandler::isPassedOptRemarkEnabled(StringRef PassName) const {
- return (PassRemarksPassedOptLoc.Pattern &&
- PassRemarksPassedOptLoc.Pattern->match(PassName));
-}
diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp
index bb9e52abe53..3f1a2879b33 100644
--- a/lib/IR/DiagnosticInfo.cpp
+++ b/lib/IR/DiagnosticInfo.cpp
@@ -13,7 +13,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/IR/DiagnosticInfo.h"
-#include "LLVMContextImpl.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
@@ -42,6 +41,61 @@
using namespace llvm;
+namespace {
+
+/// \brief Regular expression corresponding to the value given in one of the
+/// -pass-remarks* command line flags. Passes whose name matches this regexp
+/// will emit a diagnostic via ORE->emit(...);
+struct PassRemarksOpt {
+ std::shared_ptr<Regex> Pattern;
+
+ void operator=(const std::string &Val) {
+ if (!Val.empty()) {
+ Pattern = std::make_shared<Regex>(Val);
+ std::string RegexError;
+ if (!Pattern->isValid(RegexError))
+ report_fatal_error("Invalid regular expression '" + Val +
+ "' in -pass-remarks: " + RegexError,
+ false);
+ }
+ }
+};
+
+} // end anonymous namespace
+
+static PassRemarksOpt PassRemarksOptLoc;
+static PassRemarksOpt PassRemarksMissedOptLoc;
+static PassRemarksOpt PassRemarksAnalysisOptLoc;
+
+// -pass-remarks
+// Command line flag to enable optimization remarks
+static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
+PassRemarks("pass-remarks", cl::value_desc("pattern"),
+ cl::desc("Enable optimization remarks from passes whose name match "
+ "the given regular expression"),
+ cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired,
+ cl::ZeroOrMore);
+
+// -pass-remarks-missed
+// Command line flag to enable missed optimization remarks
+static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarksMissed(
+ "pass-remarks-missed", cl::value_desc("pattern"),
+ cl::desc("Enable missed optimization remarks from passes whose name match "
+ "the given regular expression"),
+ cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
+ cl::ZeroOrMore);
+
+// -pass-remarks-analysis
+// Command line flag to enable optimization analysis remarks
+static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
+PassRemarksAnalysis(
+ "pass-remarks-analysis", cl::value_desc("pattern"),
+ cl::desc(
+ "Enable optimization analysis remarks from passes whose name match "
+ "the given regular expression"),
+ cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
+ cl::ZeroOrMore);
+
int llvm::getNextAvailablePluginDiagnosticKind() {
static std::atomic<int> PluginKindID(DK_FirstPluginKind);
return ++PluginKindID;
@@ -229,10 +283,9 @@ OptimizationRemark::OptimizationRemark(const char *PassName,
RemarkName, *Func, Func->getSubprogram(),
&getFirstFunctionBlock(Func)) {}
-bool OptimizationRemark::isEnabled() const {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isPassedOptRemarkEnabled(getPassName());
+bool OptimizationRemark::isEnabled(StringRef PassName) {
+ return PassRemarksOptLoc.Pattern &&
+ PassRemarksOptLoc.Pattern->match(PassName);
}
OptimizationRemarkMissed::OptimizationRemarkMissed(
@@ -250,10 +303,9 @@ OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
*Inst->getParent()->getParent(),
Inst->getDebugLoc(), Inst->getParent()) {}
-bool OptimizationRemarkMissed::isEnabled() const {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isMissedOptRemarkEnabled(getPassName());
+bool OptimizationRemarkMissed::isEnabled(StringRef PassName) {
+ return PassRemarksMissedOptLoc.Pattern &&
+ PassRemarksMissedOptLoc.Pattern->match(PassName);
}
OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
@@ -278,11 +330,9 @@ OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(
*cast<BasicBlock>(CodeRegion)->getParent(),
Loc, CodeRegion) {}
-bool OptimizationRemarkAnalysis::isEnabled() const {
- const Function &Fn = getFunction();
- LLVMContext &Ctx = Fn.getContext();
- return Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(getPassName()) ||
- shouldAlwaysPrint();
+bool OptimizationRemarkAnalysis::isEnabled(StringRef PassName) {
+ return PassRemarksAnalysisOptLoc.Pattern &&
+ PassRemarksAnalysisOptLoc.Pattern->match(PassName);
}
void DiagnosticInfoMIRParser::print(DiagnosticPrinter &DP) const {
diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp
index 6569695c996..c58459d6d5f 100644
--- a/lib/IR/LLVMContext.cpp
+++ b/lib/IR/LLVMContext.cpp
@@ -129,17 +129,11 @@ void *LLVMContext::getInlineAsmDiagnosticContext() const {
return pImpl->InlineAsmDiagContext;
}
-void LLVMContext::setDiagnosticHandlerCallBack(
- DiagnosticHandler::DiagnosticHandlerTy DiagnosticHandler,
- void *DiagnosticContext, bool RespectFilters) {
- pImpl->DiagHandler->DiagHandlerCallback = DiagnosticHandler;
- pImpl->DiagHandler->DiagnosticContext = DiagnosticContext;
- pImpl->RespectDiagnosticFilters = RespectFilters;
-}
-
-void LLVMContext::setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH,
- bool RespectFilters) {
- pImpl->DiagHandler = std::move(DH);
+void LLVMContext::setDiagnosticHandler(DiagnosticHandlerTy DiagnosticHandler,
+ void *DiagnosticContext,
+ bool RespectFilters) {
+ pImpl->DiagnosticHandler = DiagnosticHandler;
+ pImpl->DiagnosticContext = DiagnosticContext;
pImpl->RespectDiagnosticFilters = RespectFilters;
}
@@ -165,13 +159,12 @@ void LLVMContext::setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F) {
pImpl->DiagnosticsOutputFile = std::move(F);
}
-DiagnosticHandler::DiagnosticHandlerTy
-LLVMContext::getDiagnosticHandlerCallBack() const {
- return pImpl->DiagHandler->DiagHandlerCallback;
+LLVMContext::DiagnosticHandlerTy LLVMContext::getDiagnosticHandler() const {
+ return pImpl->DiagnosticHandler;
}
void *LLVMContext::getDiagnosticContext() const {
- return pImpl->DiagHandler->DiagnosticContext;
+ return pImpl->DiagnosticContext;
}
void LLVMContext::setYieldCallback(YieldCallbackTy Callback, void *OpaqueHandle)
@@ -222,10 +215,11 @@ LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
void LLVMContext::diagnose(const DiagnosticInfo &DI) {
// If there is a report handler, use it.
- if (pImpl->DiagHandler &&
- (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
- pImpl->DiagHandler->handleDiagnostics(DI))
+ if (pImpl->DiagnosticHandler) {
+ if (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI))
+ pImpl->DiagnosticHandler(DI, pImpl->DiagnosticContext);
return;
+ }
if (!isDiagnosticEnabled(DI))
return;
@@ -321,11 +315,3 @@ void LLVMContext::setDiscardValueNames(bool Discard) {
OptBisect &LLVMContext::getOptBisect() {
return pImpl->getOptBisect();
}
-
-const DiagnosticHandler *LLVMContext::getDiagHandlerPtr() const {
- return pImpl->DiagHandler.get();
-}
-
-std::unique_ptr<DiagnosticHandler> LLVMContext::getDiagnosticHandler() {
- return std::move(pImpl->DiagHandler);
-}
diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp
index 4b44a6b69ca..57dd08b36fe 100644
--- a/lib/IR/LLVMContextImpl.cpp
+++ b/lib/IR/LLVMContextImpl.cpp
@@ -22,8 +22,7 @@
using namespace llvm;
LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
- : DiagHandler(llvm::make_unique<DiagnosticHandler>()),
- VoidTy(C, Type::VoidTyID),
+ : VoidTy(C, Type::VoidTyID),
LabelTy(C, Type::LabelTyID),
HalfTy(C, Type::HalfTyID),
FloatTy(C, Type::FloatTyID),
diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h
index f41acfa8ea9..bea2c7ae8ff 100644
--- a/lib/IR/LLVMContextImpl.h
+++ b/lib/IR/LLVMContextImpl.h
@@ -1168,7 +1168,8 @@ public:
LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
void *InlineAsmDiagContext = nullptr;
- std::unique_ptr<DiagnosticHandler> DiagHandler;
+ LLVMContext::DiagnosticHandlerTy DiagnosticHandler = nullptr;
+ void *DiagnosticContext = nullptr;
bool RespectDiagnosticFilters = false;
bool DiagnosticsHotnessRequested = false;
uint64_t DiagnosticsHotnessThreshold = 0;
diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp
index ee9c70126b8..8ad3cccf8d4 100644
--- a/lib/LTO/LTOCodeGenerator.cpp
+++ b/lib/LTO/LTOCodeGenerator.cpp
@@ -622,8 +622,12 @@ void LTOCodeGenerator::parseCodeGenDebugOptions() {
}
}
+void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI,
+ void *Context) {
+ ((LTOCodeGenerator *)Context)->DiagnosticHandler2(DI);
+}
-void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI) {
+void LTOCodeGenerator::DiagnosticHandler2(const DiagnosticInfo &DI) {
// Map the LLVM internal diagnostic severity to the LTO diagnostic severity.
lto_codegen_diagnostic_severity_t Severity;
switch (DI.getSeverity()) {
@@ -653,29 +657,17 @@ void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI) {
(*DiagHandler)(Severity, MsgStorage.c_str(), DiagContext);
}
-namespace {
-struct LTODiagnosticHandler : public DiagnosticHandler {
- LTOCodeGenerator *CodeGenerator;
- LTODiagnosticHandler(LTOCodeGenerator *CodeGenPtr)
- : CodeGenerator(CodeGenPtr) {}
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- CodeGenerator->DiagnosticHandler(DI);
- return true;
- }
-};
-}
-
void
LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler,
void *Ctxt) {
this->DiagHandler = DiagHandler;
this->DiagContext = Ctxt;
if (!DiagHandler)
- return Context.setDiagnosticHandler(nullptr);
+ return Context.setDiagnosticHandler(nullptr, nullptr);
// Register the LTOCodeGenerator stub in the LLVMContext to forward the
// diagnostic to the external DiagHandler.
- Context.setDiagnosticHandler(llvm::make_unique<LTODiagnosticHandler>(this),
- true);
+ Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this,
+ /* RespectFilters */ true);
}
namespace {
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 593aad74bd1..497e1d3eb37 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -920,7 +920,8 @@ bool GVN::AnalyzeLoadAvailability(LoadInst *LI, MemDepResult DepInfo,
Instruction *I = DepInfo.getInst();
dbgs() << " is clobbered by " << *I << '\n';
);
- if (ORE->allowExtraAnalysis(DEBUG_TYPE))
+
+ if (ORE->allowExtraAnalysis())
reportMayClobberedLoad(LI, DepInfo, DT, ORE);
return false;
diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp
index d339143bf64..a37c877db1e 100644
--- a/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4957,15 +4957,12 @@ bool LoopVectorizationLegality::canVectorize() {
// Store the result and return it at the end instead of exiting early, in case
// allowExtraAnalysis is used to report multiple reasons for not vectorizing.
bool Result = true;
-
- bool DoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
- if (DoExtraAnalysis)
// We must have a loop in canonical form. Loops with indirectbr in them cannot
// be canonicalized.
if (!TheLoop->getLoopPreheader()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -4978,7 +4975,7 @@ bool LoopVectorizationLegality::canVectorize() {
if (!TheLoop->empty()) {
ORE->emit(createMissedAnalysis("NotInnermostLoop")
<< "loop is not the innermost loop");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -4988,7 +4985,7 @@ bool LoopVectorizationLegality::canVectorize() {
if (TheLoop->getNumBackEdges() != 1) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -4998,7 +4995,7 @@ bool LoopVectorizationLegality::canVectorize() {
if (!TheLoop->getExitingBlock()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -5010,7 +5007,7 @@ bool LoopVectorizationLegality::canVectorize() {
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) {
ORE->emit(createMissedAnalysis("CFGNotUnderstood")
<< "loop control flow is not understood by vectorizer");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -5024,7 +5021,7 @@ bool LoopVectorizationLegality::canVectorize() {
unsigned NumBlocks = TheLoop->getNumBlocks();
if (NumBlocks != 1 && !canVectorizeWithIfConvert()) {
DEBUG(dbgs() << "LV: Can't if-convert the loop.\n");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -5033,7 +5030,7 @@ bool LoopVectorizationLegality::canVectorize() {
// Check if we can vectorize the instructions and CFG in this loop.
if (!canVectorizeInstrs()) {
DEBUG(dbgs() << "LV: Can't vectorize the instructions or CFG\n");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -5042,7 +5039,7 @@ bool LoopVectorizationLegality::canVectorize() {
// Go over each instruction and look at memory deps.
if (!canVectorizeMemory()) {
DEBUG(dbgs() << "LV: Can't vectorize due to memory conflicts\n");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
@@ -5073,7 +5070,7 @@ bool LoopVectorizationLegality::canVectorize() {
<< "Too many SCEV assumptions need to be made and checked "
<< "at runtime");
DEBUG(dbgs() << "LV: Too many SCEV checks needed.\n");
- if (DoExtraAnalysis)
+ if (ORE->allowExtraAnalysis())
Result = false;
else
return false;
diff --git a/test/Transforms/GVN/opt-remarks.ll b/test/Transforms/GVN/opt-remarks.ll
index 4f1fb9f4012..f9425618443 100644
--- a/test/Transforms/GVN/opt-remarks.ll
+++ b/test/Transforms/GVN/opt-remarks.ll
@@ -11,7 +11,7 @@
; CHECK: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
; CHECK-NEXT: remark: <unknown>:0:0: load of type i32 eliminated{{$}}
-; CHECK-NEXT: remark: /tmp/s.c:3:3: load of type i32 not eliminated
+; CHECK-NOT: remark:
; YAML: --- !Passed
; YAML-NEXT: Pass: gvn
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index bbbec221208..aad237c42dc 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -235,24 +235,20 @@ GetOutputStream(const char *TargetName, Triple::OSType OS,
return FDOut;
}
-struct LLCDiagnosticHandler : public DiagnosticHandler {
- bool *HasError;
- LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- if (DI.getSeverity() == DS_Error)
- *HasError = true;
-
- if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
- if (!Remark->isEnabled())
- return true;
-
- DiagnosticPrinterRawOStream DP(errs());
- errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
- DI.print(DP);
- errs() << "\n";
- return true;
- }
-};
+static void DiagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ bool *HasError = static_cast<bool *>(Context);
+ if (DI.getSeverity() == DS_Error)
+ *HasError = true;
+
+ if (auto *Remark = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
+ if (!Remark->isEnabled())
+ return;
+
+ DiagnosticPrinterRawOStream DP(errs());
+ errs() << LLVMContext::getDiagnosticMessagePrefix(DI.getSeverity()) << ": ";
+ DI.print(DP);
+ errs() << "\n";
+}
static void InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context,
unsigned LocCookie) {
@@ -312,8 +308,7 @@ int main(int argc, char **argv) {
// Set a diagnostic handler that doesn't exit on the first error
bool HasError = false;
- Context.setDiagnosticHandler(
- llvm::make_unique<LLCDiagnosticHandler>(&HasError));
+ Context.setDiagnosticHandler(DiagnosticHandler, &HasError);
Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
if (PassRemarksWithHotness)
@@ -569,9 +564,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
PM.run(*M);
- auto HasError =
- ((const LLCDiagnosticHandler *)(Context.getDiagHandlerPtr()))->HasError;
- if (*HasError)
+ auto HasError = *static_cast<bool *>(Context.getDiagnosticContext());
+ if (HasError)
return 1;
// Compare the two outputs and make sure they're the same
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 6828b69abe8..82dbaa5e3c6 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -122,29 +122,25 @@ public:
}
};
-struct LLVMDisDiagnosticHandler : public DiagnosticHandler {
- char *Prefix;
- LLVMDisDiagnosticHandler(char *PrefixPtr) : Prefix(PrefixPtr) {}
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- raw_ostream &OS = errs();
- OS << Prefix << ": ";
- switch (DI.getSeverity()) {
- case DS_Error: OS << "error: "; break;
- case DS_Warning: OS << "warning: "; break;
- case DS_Remark: OS << "remark: "; break;
- case DS_Note: OS << "note: "; break;
- }
-
- DiagnosticPrinterRawOStream DP(OS);
- DI.print(DP);
- OS << '\n';
+} // end anon namespace
- if (DI.getSeverity() == DS_Error)
- exit(1);
- return true;
+static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ raw_ostream &OS = errs();
+ OS << (char *)Context << ": ";
+ switch (DI.getSeverity()) {
+ case DS_Error: OS << "error: "; break;
+ case DS_Warning: OS << "warning: "; break;
+ case DS_Remark: OS << "remark: "; break;
+ case DS_Note: OS << "note: "; break;
}
-};
-} // end anon namespace
+
+ DiagnosticPrinterRawOStream DP(OS);
+ DI.print(DP);
+ OS << '\n';
+
+ if (DI.getSeverity() == DS_Error)
+ exit(1);
+}
static ExitOnError ExitOnErr;
@@ -170,8 +166,9 @@ int main(int argc, char **argv) {
LLVMContext Context;
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
- Context.setDiagnosticHandler(
- llvm::make_unique<LLVMDisDiagnosticHandler>(argv[0]));
+
+ Context.setDiagnosticHandler(diagnosticHandler, argv[0]);
+
cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
std::unique_ptr<Module> M = openInputFile(Context);
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp
index 805ea73b3f6..568e5f8d2d5 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -182,30 +182,25 @@ Module &ModuleLazyLoaderCache::operator()(const char *argv0,
}
} // anonymous namespace
-namespace {
-struct LLVMLinkDiagnosticHandler : public DiagnosticHandler {
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- unsigned Severity = DI.getSeverity();
- switch (Severity) {
- case DS_Error:
- errs() << "ERROR: ";
- break;
- case DS_Warning:
- if (SuppressWarnings)
- return true;
- errs() << "WARNING: ";
- break;
- case DS_Remark:
- case DS_Note:
- llvm_unreachable("Only expecting warnings and errors");
- }
-
- DiagnosticPrinterRawOStream DP(errs());
- DI.print(DP);
- errs() << '\n';
- return true;
+static void diagnosticHandler(const DiagnosticInfo &DI, void *C) {
+ unsigned Severity = DI.getSeverity();
+ switch (Severity) {
+ case DS_Error:
+ errs() << "ERROR: ";
+ break;
+ case DS_Warning:
+ if (SuppressWarnings)
+ return;
+ errs() << "WARNING: ";
+ break;
+ case DS_Remark:
+ case DS_Note:
+ llvm_unreachable("Only expecting warnings and errors");
}
-};
+
+ DiagnosticPrinterRawOStream DP(errs());
+ DI.print(DP);
+ errs() << '\n';
}
/// Import any functions requested via the -import option.
@@ -352,8 +347,8 @@ int main(int argc, char **argv) {
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
LLVMContext Context;
- Context.setDiagnosticHandler(
- llvm::make_unique<LLVMLinkDiagnosticHandler>(), true);
+ Context.setDiagnosticHandler(diagnosticHandler, nullptr, true);
+
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
diff --git a/tools/llvm-lto/llvm-lto.cpp b/tools/llvm-lto/llvm-lto.cpp
index bbd0edac108..dd4199112ee 100644
--- a/tools/llvm-lto/llvm-lto.cpp
+++ b/tools/llvm-lto/llvm-lto.cpp
@@ -235,40 +235,34 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity,
}
static std::string CurrentActivity;
-
-namespace {
- struct LLVMLTODiagnosticHandler : public DiagnosticHandler {
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- raw_ostream &OS = errs();
- OS << "llvm-lto: ";
- switch (DI.getSeverity()) {
- case DS_Error:
- OS << "error";
- break;
- case DS_Warning:
- OS << "warning";
- break;
- case DS_Remark:
- OS << "remark";
- break;
- case DS_Note:
- OS << "note";
- break;
- }
- if (!CurrentActivity.empty())
- OS << ' ' << CurrentActivity;
- OS << ": ";
-
- DiagnosticPrinterRawOStream DP(OS);
- DI.print(DP);
- OS << '\n';
-
- if (DI.getSeverity() == DS_Error)
- exit(1);
- return true;
- }
- };
+static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ raw_ostream &OS = errs();
+ OS << "llvm-lto: ";
+ switch (DI.getSeverity()) {
+ case DS_Error:
+ OS << "error";
+ break;
+ case DS_Warning:
+ OS << "warning";
+ break;
+ case DS_Remark:
+ OS << "remark";
+ break;
+ case DS_Note:
+ OS << "note";
+ break;
}
+ if (!CurrentActivity.empty())
+ OS << ' ' << CurrentActivity;
+ OS << ": ";
+
+ DiagnosticPrinterRawOStream DP(OS);
+ DI.print(DP);
+ OS << '\n';
+
+ if (DI.getSeverity() == DS_Error)
+ exit(1);
+}
static void error(const Twine &Msg) {
errs() << "llvm-lto: " << Msg << '\n';
@@ -299,8 +293,7 @@ getLocalLTOModule(StringRef Path, std::unique_ptr<MemoryBuffer> &Buffer,
Buffer = std::move(BufferOrErr.get());
CurrentActivity = ("loading file '" + Path + "'").str();
std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>();
- Context->setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(),
- true);
+ Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext(
std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(),
Options, Path);
@@ -844,8 +837,7 @@ int main(int argc, char **argv) {
unsigned BaseArg = 0;
LLVMContext Context;
- Context.setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(),
- true);
+ Context.setDiagnosticHandler(diagnosticHandler, nullptr, true);
LTOCodeGenerator CodeGen(Context);
diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp
index 11885211797..1b218a64cbf 100644
--- a/tools/lto/lto.cpp
+++ b/tools/lto/lto.cpp
@@ -75,23 +75,20 @@ static bool parsedOptions = false;
static LLVMContext *LTOContext = nullptr;
-struct LTOToolDiagnosticHandler : public DiagnosticHandler {
- bool handleDiagnostics(const DiagnosticInfo &DI) override {
- if (DI.getSeverity() != DS_Error) {
- DiagnosticPrinterRawOStream DP(errs());
- DI.print(DP);
- errs() << '\n';
- return true;
- }
- sLastErrorString = "";
- {
- raw_string_ostream Stream(sLastErrorString);
- DiagnosticPrinterRawOStream DP(Stream);
- DI.print(DP);
- }
- return true;
+static void diagnosticHandler(const DiagnosticInfo &DI, void *Context) {
+ if (DI.getSeverity() != DS_Error) {
+ DiagnosticPrinterRawOStream DP(errs());
+ DI.print(DP);
+ errs() << '\n';
+ return;
}
-};
+ sLastErrorString = "";
+ {
+ raw_string_ostream Stream(sLastErrorString);
+ DiagnosticPrinterRawOStream DP(Stream);
+ DI.print(DP);
+ }
+}
// Initialize the configured targets if they have not been initialized.
static void lto_initialize() {
@@ -111,8 +108,7 @@ static void lto_initialize() {
static LLVMContext Context;
LTOContext = &Context;
- LTOContext->setDiagnosticHandler(
- llvm::make_unique<LTOToolDiagnosticHandler>(), true);
+ LTOContext->setDiagnosticHandler(diagnosticHandler, nullptr, true);
initialized = true;
}
}
@@ -278,8 +274,7 @@ lto_module_t lto_module_create_in_local_context(const void *mem, size_t length,
// Create a local context. Ownership will be transferred to LTOModule.
std::unique_ptr<LLVMContext> Context = llvm::make_unique<LLVMContext>();
- Context->setDiagnosticHandler(llvm::make_unique<LTOToolDiagnosticHandler>(),
- true);
+ Context->setDiagnosticHandler(diagnosticHandler, nullptr, true);
ErrorOr<std::unique_ptr<LTOModule>> M = LTOModule::createInLocalContext(
std::move(Context), mem, length, Options, StringRef(path));