diff options
author | Vivek Pandya <vivekvpandya@gmail.com> | 2017-09-15 19:30:59 +0000 |
---|---|---|
committer | Vivek Pandya <vivekvpandya@gmail.com> | 2017-09-15 19:30:59 +0000 |
commit | 00d887447b05bd41ec77a897978bace2af287154 (patch) | |
tree | 7cbf2055a7483fff1223c6c911d64c2a0a9c704b /llvm/tools/llvm-lto | |
parent | aff1c4df2573db4c21143c990db268d85350fd54 (diff) | |
download | bcm5719-llvm-00d887447b05bd41ec77a897978bace2af287154.tar.gz bcm5719-llvm-00d887447b05bd41ec77a897978bace2af287154.zip |
This patch fixes https://bugs.llvm.org/show_bug.cgi?id=32352
It enables OptimizationRemarkEmitter::allowExtraAnalysis and MachineOptimizationRemarkEmitter::allowExtraAnalysis to return true not only for -fsave-optimization-record but when specific remarks are requested with
command line options.
The diagnostic handler used to be callback now this patch adds a class
DiagnosticHandler. It has virtual method to provide custom diagnostic handler
and methods to control which particular remarks are enabled.
However LLVM-C API users can still provide callback function for diagnostic handler.
llvm-svn: 313382
Diffstat (limited to 'llvm/tools/llvm-lto')
-rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index dd4199112ee..bbd0edac108 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -235,34 +235,40 @@ static void handleDiagnostics(lto_codegen_diagnostic_severity_t Severity, } static std::string CurrentActivity; -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); -} +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 error(const Twine &Msg) { errs() << "llvm-lto: " << Msg << '\n'; @@ -293,7 +299,8 @@ 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(diagnosticHandler, nullptr, true); + Context->setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), + true); ErrorOr<std::unique_ptr<LTOModule>> Ret = LTOModule::createInLocalContext( std::move(Context), Buffer->getBufferStart(), Buffer->getBufferSize(), Options, Path); @@ -837,7 +844,8 @@ int main(int argc, char **argv) { unsigned BaseArg = 0; LLVMContext Context; - Context.setDiagnosticHandler(diagnosticHandler, nullptr, true); + Context.setDiagnosticHandler(llvm::make_unique<LLVMLTODiagnosticHandler>(), + true); LTOCodeGenerator CodeGen(Context); |