]> granicus.if.org Git - llvm/commitdiff
Revert "[Remarks] Refactor remark diagnostic emission in a RemarkStreamer"
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Wed, 6 Mar 2019 14:52:37 +0000 (14:52 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Wed, 6 Mar 2019 14:52:37 +0000 (14:52 +0000)
This reverts commit 2e8c4997a2089f8228c843fd81b148d903472e02.

Breaks bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355511 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
include/llvm/Analysis/OptimizationRemarkEmitter.h
include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
include/llvm/IR/LLVMContext.h
include/llvm/IR/RemarkStreamer.h [deleted file]
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/IR/CMakeLists.txt
lib/IR/DiagnosticInfo.cpp
lib/IR/LLVMContext.cpp
lib/IR/LLVMContextImpl.h
lib/IR/RemarkStreamer.cpp [deleted file]
lib/LTO/LTO.cpp
tools/llc/llc.cpp
tools/opt/opt.cpp

index 7b8404404ce7aab8ff4e543f1fc19982160160af..a2b29555ce5ad4585e74c6a36872197b1126984c 100644 (file)
@@ -77,7 +77,7 @@ public:
     // remarks enabled. We can't currently check whether remarks are requested
     // for the calling pass since that requires actually building the remark.
 
-    if (F->getContext().getRemarkStreamer() ||
+    if (F->getContext().getDiagnosticsOutputFile() ||
         F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
       auto R = RemarkBuilder();
       emit((DiagnosticInfoOptimizationBase &)R);
@@ -92,7 +92,7 @@ public:
   /// provide more context so that non-trivial false positives can be quickly
   /// detected by the user.
   bool allowExtraAnalysis(StringRef PassName) const {
-    return (F->getContext().getRemarkStreamer() ||
+    return (F->getContext().getDiagnosticsOutputFile() ||
             F->getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
   }
 
index a461a299917cbc8023eceb7556d913f0f600a733..9a0fd56253673b511586af17bd52bea3fa7ba14c 100644 (file)
@@ -158,10 +158,9 @@ public:
   /// (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().getRemarkStreamer() ||
-        MF.getFunction().getContext().getDiagHandlerPtr()->isAnyRemarkEnabled(
-            PassName));
+    return (MF.getFunction().getContext().getDiagnosticsOutputFile() ||
+            MF.getFunction().getContext()
+            .getDiagHandlerPtr()->isAnyRemarkEnabled(PassName));
   }
 
   /// Take a lambda that returns a remark which will be emitted.  Second
@@ -172,11 +171,8 @@ public:
     // remarks enabled. We can't currently check whether remarks are requested
     // for the calling pass since that requires actually building the remark.
 
-    if (MF.getFunction().getContext().getRemarkStreamer() ||
-        MF.getFunction()
-            .getContext()
-            .getDiagHandlerPtr()
-            ->isAnyRemarkEnabled()) {
+    if (MF.getFunction().getContext().getDiagnosticsOutputFile() ||
+        MF.getFunction().getContext().getDiagHandlerPtr()->isAnyRemarkEnabled()) {
       auto R = RemarkBuilder();
       emit((DiagnosticInfoOptimizationBase &)R);
     }
index f737801fffbb9b47333ff85922864488ed57f418..f28480ee4c6f60a278e00beb5eaa544045e8826a 100644 (file)
@@ -35,8 +35,12 @@ template <typename T> class SmallVectorImpl;
 class SMDiagnostic;
 class StringRef;
 class Twine;
-class RemarkStreamer;
-class raw_ostream;
+
+namespace yaml {
+
+class Output;
+
+} // end namespace yaml
 
 namespace SyncScope {
 
@@ -242,23 +246,16 @@ public:
   /// included in optimization diagnostics.
   void setDiagnosticsHotnessThreshold(uint64_t Threshold);
 
-  /// Return the streamer used by the backend to save remark diagnostics. If it
-  /// does not exist, diagnostics are not saved in a file but only emitted via
-  /// the diagnostic handler.
-  RemarkStreamer *getRemarkStreamer();
-  const RemarkStreamer *getRemarkStreamer() const;
-
-  /// Set the diagnostics output used for optimization diagnostics.
-  /// This filename may be embedded in a section for tools to find the
-  /// diagnostics whenever they're needed.
-  ///
-  /// If a remark streamer is already set, it will be replaced with
-  /// \p RemarkStreamer.
+  /// Return the YAML file used by the backend to save optimization
+  /// diagnostics.  If null, diagnostics are not saved in a file but only
+  /// emitted via the diagnostic handler.
+  yaml::Output *getDiagnosticsOutputFile();
+  /// Set the diagnostics output file used for optimization diagnostics.
   ///
-  /// By default, diagnostics are not saved in a file but only emitted via the
-  /// diagnostic handler.  Even if an output file is set, the handler is invoked
-  /// for each diagnostic message.
-  void setRemarkStreamer(std::unique_ptr<RemarkStreamer> RemarkStreamer);
+  /// By default or if invoked with null, diagnostics are not saved in a file
+  /// but only emitted via the diagnostic handler.  Even if an output file is
+  /// set, the handler is invoked for each diagnostic message.
+  void setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F);
 
   /// Get the prefix that should be printed in front of a diagnostic of
   ///        the given \p Severity
diff --git a/include/llvm/IR/RemarkStreamer.h b/include/llvm/IR/RemarkStreamer.h
deleted file mode 100644 (file)
index 38baa2b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-//===- llvm/IR/RemarkStreamer.h - 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 declares the main interface for outputting remarks.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_IR_REMARKSTREAMER_H
-#define LLVM_IR_REMARKSTREAMER_H
-
-#include "llvm/IR/DiagnosticInfo.h"
-#include "llvm/Support/YAMLTraits.h"
-#include "llvm/Support/raw_ostream.h"
-#include <string>
-#include <vector>
-
-namespace llvm {
-/// Streamer for remarks.
-class RemarkStreamer {
-  /// The filename that the remark diagnostics are emitted to.
-  const std::string Filename;
-  /// The open raw_ostream that the remark diagnostics are emitted to.
-  raw_ostream &OS;
-
-  /// The YAML streamer.
-  yaml::Output YAMLOutput;
-
-public:
-  RemarkStreamer(StringRef Filename, raw_ostream& OS);
-  /// Return the filename that the remark diagnostics are emitted to.
-  StringRef getFilename() const { return Filename; }
-  /// Return stream that the remark diagnostics are emitted to.
-  raw_ostream &getStream() { return OS; }
-  /// Emit a diagnostic through the streamer.
-  void emit(const DiagnosticInfoOptimizationBase &Diag);
-};
-} // end namespace llvm
-
-#endif // LLVM_IR_REMARKSTREAMER_H
index 7d95c4d7be7635bcb22e55941814cbce8f9edfcf..5319519ddc0d70d6d90a6edf682ccdcbd801191c 100644 (file)
@@ -78,7 +78,6 @@
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
-#include "llvm/IR/RemarkStreamer.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include "llvm/MC/MCAsmInfo.h"
index b12931948003bf0d9662644c1584855b0be5d657..2ea01b8a7679d74dcaff6ac34c8f464787b12847 100644 (file)
@@ -46,7 +46,6 @@ add_llvm_library(LLVMCore
   PassManager.cpp
   PassRegistry.cpp
   PassTimingInfo.cpp
-  RemarkStreamer.cpp
   SafepointIRVerifier.cpp
   ProfileSummary.cpp
   Statepoint.cpp
index 020305d76cb189e1440689861544aaa3e175b809..14bee35dc2929ec6060c63c8e6fdc1cdb44c8151 100644 (file)
@@ -27,7 +27,6 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
-#include "llvm/IR/RemarkStreamer.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/Casting.h"
index 75d0218bcc8a31a76af9692f64e6b2c9f5113ed3..1cea21461f46e40e166e4794d1bea1276ca9bc6a 100644 (file)
@@ -21,7 +21,6 @@
 #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"
@@ -161,15 +160,12 @@ uint64_t LLVMContext::getDiagnosticsHotnessThreshold() const {
   return pImpl->DiagnosticsHotnessThreshold;
 }
 
-RemarkStreamer *LLVMContext::getRemarkStreamer() {
-  return pImpl->RemarkStreamer.get();
+yaml::Output *LLVMContext::getDiagnosticsOutputFile() {
+  return pImpl->DiagnosticsOutputFile.get();
 }
-const RemarkStreamer *LLVMContext::getRemarkStreamer() const {
-  return const_cast<LLVMContext *>(this)->getRemarkStreamer();
-}
-void LLVMContext::setRemarkStreamer(
-    std::unique_ptr<RemarkStreamer> RemarkStreamer) {
-  pImpl->RemarkStreamer = std::move(RemarkStreamer);
+
+void LLVMContext::setDiagnosticsOutputFile(std::unique_ptr<yaml::Output> F) {
+  pImpl->DiagnosticsOutputFile = std::move(F);
 }
 
 DiagnosticHandler::DiagnosticHandlerTy
@@ -232,10 +228,14 @@ LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
 }
 
 void LLVMContext::diagnose(const DiagnosticInfo &DI) {
-  if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI))
-    if (RemarkStreamer *RS = getRemarkStreamer())
-      RS->emit(*OptDiagBase);
-
+  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 there is a report handler, use it.
   if (pImpl->DiagHandler &&
       (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
index b8974ef9767f24645cbe2cf5dcd6a90a08a77027..f7038ace035d6b4b1c958e026fe8d0dec099452e 100644 (file)
@@ -37,7 +37,6 @@
 #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"
@@ -1227,7 +1226,7 @@ public:
   bool RespectDiagnosticFilters = false;
   bool DiagnosticsHotnessRequested = false;
   uint64_t DiagnosticsHotnessThreshold = 0;
-  std::unique_ptr<RemarkStreamer> RemarkStreamer;
+  std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
 
   LLVMContext::YieldCallbackTy YieldCallback = nullptr;
   void *YieldOpaqueHandle = nullptr;
diff --git a/lib/IR/RemarkStreamer.cpp b/lib/IR/RemarkStreamer.cpp
deleted file mode 100644 (file)
index 0b98340..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//===- 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;
-}
index f6e34c5d0614ebd1dee4cf75221150d90e85c9ad..8e0d532fa7ecb56b078819eec0ddebde3ceeea59 100644 (file)
@@ -24,7 +24,6 @@
 #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"
@@ -1327,8 +1326,8 @@ lto::setupOptimizationRemarks(LLVMContext &Context,
       llvm::make_unique<ToolOutputFile>(Filename, EC, sys::fs::F_None);
   if (EC)
     return errorCodeToError(EC);
-  Context.setRemarkStreamer(
-      llvm::make_unique<RemarkStreamer>(Filename, DiagnosticFile->os()));
+  Context.setDiagnosticsOutputFile(
+      llvm::make_unique<yaml::Output>(DiagnosticFile->os()));
   DiagnosticFile->keep();
   return std::move(DiagnosticFile);
 }
index a566d15cd81ac7d5913e7a046715e7fc00ef4473..ae51eef9e9ccfa570237e313be55474872386e0a 100644 (file)
@@ -31,7 +31,6 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
-#include "llvm/IR/RemarkStreamer.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/MC/SubtargetFeature.h"
@@ -334,8 +333,8 @@ int main(int argc, char **argv) {
       WithColor::error(errs(), argv[0]) << EC.message() << '\n';
       return 1;
     }
-    Context.setRemarkStreamer(
-        llvm::make_unique<RemarkStreamer>(RemarksFilename, YamlFile->os()));
+    Context.setDiagnosticsOutputFile(
+        llvm::make_unique<yaml::Output>(YamlFile->os()));
   }
 
   if (InputLanguage != "" && InputLanguage != "ir" &&
index 06745b0cca078791091c3baf312d3a961d221e02..2d80b47973500fe3f60b56133579a5ffe9f9abf9 100644 (file)
@@ -33,7 +33,6 @@
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/LegacyPassNameParser.h"
 #include "llvm/IR/Module.h"
-#include "llvm/IR/RemarkStreamer.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/InitializePasses.h"
@@ -564,8 +563,8 @@ int main(int argc, char **argv) {
       errs() << EC.message() << '\n';
       return 1;
     }
-    Context.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
-        RemarksFilename, OptRemarkFile->os()));
+    Context.setDiagnosticsOutputFile(
+        llvm::make_unique<yaml::Output>(OptRemarkFile->os()));
   }
 
   // Load the input module...