diff options
| author | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-03-06 15:20:13 +0000 |
|---|---|---|
| committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2019-03-06 15:20:13 +0000 |
| commit | b8a847c0a3edc4165afce9e2449737751bd34f78 (patch) | |
| tree | 8d5735d92301df39ea8f43e415d85ce99bf6e19d /llvm/lib | |
| parent | 94fccc93dec54bfc7d810870aa965c4e6fb9bdfa (diff) | |
| download | bcm5719-llvm-b8a847c0a3edc4165afce9e2449737751bd34f78.tar.gz bcm5719-llvm-b8a847c0a3edc4165afce9e2449737751bd34f78.zip | |
Reland "[Remarks] Refactor remark diagnostic emission in a RemarkStreamer"
This allows us to store more info about where we're emitting the remarks
without cluttering LLVMContext. This is needed for future support for
the remark section.
Differential Revision: https://reviews.llvm.org/D58996
Original llvm-svn: 355507
llvm-svn: 355514
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/lib/IR/LLVMContext.cpp | 26 | ||||
| -rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 3 | ||||
| -rw-r--r-- | llvm/lib/IR/RemarkStreamer.cpp | 28 | ||||
| -rw-r--r-- | llvm/lib/LTO/LTO.cpp | 5 |
5 files changed, 47 insertions, 16 deletions
diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt index 2ea01b8a767..b1293194800 100644 --- a/llvm/lib/IR/CMakeLists.txt +++ b/llvm/lib/IR/CMakeLists.txt @@ -46,6 +46,7 @@ add_llvm_library(LLVMCore PassManager.cpp PassRegistry.cpp PassTimingInfo.cpp + RemarkStreamer.cpp SafepointIRVerifier.cpp ProfileSummary.cpp Statepoint.cpp diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp index 1cea21461f4..0fff76c7c9a 100644 --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -21,6 +21,7 @@ #include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" +#include "llvm/IR/RemarkStreamer.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -160,12 +161,15 @@ uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const { return pImpl->DiagnosticsHotnessThreshold; } -yaml::Output *LLVMContext::getDiagnosticsOutputFile() { - return pImpl->DiagnosticsOutputFile.get(); +RemarkStreamer *LLVMContext::getRemarkStreamer() { + return pImpl->RemarkDiagStreamer.get(); } - -void LLVMContext::setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F) { - pImpl->DiagnosticsOutputFile = std::move(F); +const RemarkStreamer *LLVMContext::getRemarkStreamer() const { + return const_cast<LLVMContext *>(this)->getRemarkStreamer(); +} +void LLVMContext::setRemarkStreamer( + std::unique_ptr<RemarkStreamer> RemarkStreamer) { + pImpl->RemarkDiagStreamer = std::move(RemarkStreamer); } DiagnosticHandler::DiagnosticHandlerTy @@ -228,14 +232,10 @@ LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) { } void LLVMContext::diagnose(const DiagnosticInfo &DI) { - if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) { - yaml::Output *Out = getDiagnosticsOutputFile(); - if (Out) { - // For remarks the << operator takes a reference to a pointer. - auto *P = const_cast<DiagnosticInfoOptimizationBase *>(OptDiagBase); - *Out << P; - } - } + if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) + if (RemarkStreamer *RS = getRemarkStreamer()) + RS->emit(*OptDiagBase); + // If there is a report handler, use it. if (pImpl->DiagHandler && (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) && diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index f7038ace035..42dd471af9e 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -37,6 +37,7 @@ #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" +#include "llvm/IR/RemarkStreamer.h" #include "llvm/IR/TrackingMDRef.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" @@ -1226,7 +1227,7 @@ public: bool RespectDiagnosticFilters = false; bool DiagnosticsHotnessRequested = false; uint64_t DiagnosticsHotnessThreshold = 0; - std::unique_ptr<yaml::Output> DiagnosticsOutputFile; + std::unique_ptr<RemarkStreamer> RemarkDiagStreamer; LLVMContext::YieldCallbackTy YieldCallback = nullptr; void *YieldOpaqueHandle = nullptr; diff --git a/llvm/lib/IR/RemarkStreamer.cpp b/llvm/lib/IR/RemarkStreamer.cpp new file mode 100644 index 00000000000..0b983408e46 --- /dev/null +++ b/llvm/lib/IR/RemarkStreamer.cpp @@ -0,0 +1,28 @@ +//===- llvm/IR/RemarkStreamer.cpp - Remark Streamer -*- C++ -------------*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file contains the implementation of the remark outputting as part of +// LLVMContext. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/RemarkStreamer.h" + +using namespace llvm; + +RemarkStreamer::RemarkStreamer(StringRef Filename, raw_ostream &OS) + : Filename(Filename), OS(OS), + YAMLOutput(OS, reinterpret_cast<void *>(this)) { + assert(!Filename.empty() && "This needs to be a real filename."); +} + +void RemarkStreamer::emit(const DiagnosticInfoOptimizationBase &Diag) { + DiagnosticInfoOptimizationBase *DiagPtr = + const_cast<DiagnosticInfoOptimizationBase *>(&Diag); + YAMLOutput << DiagPtr; +} diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 8e0d532fa7e..f6e34c5d061 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -24,6 +24,7 @@ #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Metadata.h" +#include "llvm/IR/RemarkStreamer.h" #include "llvm/LTO/LTOBackend.h" #include "llvm/LTO/SummaryBasedOptimizations.h" #include "llvm/Linker/IRMover.h" @@ -1326,8 +1327,8 @@ lto::setupOptimizationRemarks(LLVMContext &Context, llvm::make_unique<ToolOutputFile>(Filename, EC, sys::fs::F_None); if (EC) return errorCodeToError(EC); - Context.setDiagnosticsOutputFile( - llvm::make_unique<yaml::Output>(DiagnosticFile->os())); + Context.setRemarkStreamer( + llvm::make_unique<RemarkStreamer>(Filename, DiagnosticFile->os())); DiagnosticFile->keep(); return std::move(DiagnosticFile); } |

