Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:25

0001 //===- llvm/Remarks/RemarkStreamer.h ----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the main interface for streaming remarks.
0010 //
0011 // This is used to stream any llvm::remarks::Remark to an open file taking
0012 // advantage of all the serialization capabilities developed for remarks (e.g.
0013 // metadata in a section, bitstream format, etc.).
0014 //
0015 // Typically, a specialized remark emitter should hold a reference to the main
0016 // remark streamer set up in the LLVMContext, and should convert specialized
0017 // diagnostics to llvm::remarks::Remark objects as they get emitted.
0018 //
0019 // Specialized remark emitters can be components like:
0020 // * Remarks from LLVM (M)IR passes
0021 // * Remarks from the frontend
0022 // * Remarks from an intermediate IR
0023 //
0024 // This allows for composition between specialized remark emitters throughout
0025 // the compilation pipeline, that end up in the same file, using the same format
0026 // and serialization techniques.
0027 //
0028 //===----------------------------------------------------------------------===//
0029 
0030 #ifndef LLVM_REMARKS_REMARKSTREAMER_H
0031 #define LLVM_REMARKS_REMARKSTREAMER_H
0032 
0033 #include "llvm/Remarks/RemarkSerializer.h"
0034 #include "llvm/Support/Error.h"
0035 #include "llvm/Support/Regex.h"
0036 #include <memory>
0037 #include <optional>
0038 
0039 namespace llvm {
0040 
0041 class raw_ostream;
0042 
0043 namespace remarks {
0044 class RemarkStreamer final {
0045   /// The regex used to filter remarks based on the passes that emit them.
0046   std::optional<Regex> PassFilter;
0047   /// The object used to serialize the remarks to a specific format.
0048   std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
0049   /// The filename that the remark diagnostics are emitted to.
0050   const std::optional<std::string> Filename;
0051 
0052 public:
0053   RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
0054                  std::optional<StringRef> Filename = std::nullopt);
0055 
0056   /// Return the filename that the remark diagnostics are emitted to.
0057   std::optional<StringRef> getFilename() const {
0058     return Filename ? std::optional<StringRef>(*Filename) : std::nullopt;
0059   }
0060   /// Return stream that the remark diagnostics are emitted to.
0061   raw_ostream &getStream() { return RemarkSerializer->OS; }
0062   /// Return the serializer used for this stream.
0063   remarks::RemarkSerializer &getSerializer() { return *RemarkSerializer; }
0064   /// Set a pass filter based on a regex \p Filter.
0065   /// Returns an error if the regex is invalid.
0066   Error setFilter(StringRef Filter);
0067   /// Check wether the string matches the filter.
0068   bool matchesFilter(StringRef Str);
0069   /// Check if the remarks also need to have associated metadata in a section.
0070   bool needsSection() const;
0071 };
0072 } // end namespace remarks
0073 } // end namespace llvm
0074 
0075 #endif // LLVM_REMARKS_REMARKSTREAMER_H