MLIR 24.0.0git
RemarkStreamer.h
Go to the documentation of this file.
1//===- RemarkStreamer.h - MLIR Optimization Remark ---------------*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines LLVMRemarkStreamer plugging class that uses LLVM's
10// streamer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_REMARK_REMARKSTREAMER_H
15#define MLIR_REMARK_REMARKSTREAMER_H
16
17#include "mlir/IR/Remarks.h"
18
19#include "llvm/Remarks/RemarkStreamer.h"
20#include "llvm/Support/Error.h"
21#include "llvm/Support/ToolOutputFile.h"
22
23#include <mutex>
24
25namespace mlir::remark::detail {
26
27/// Concrete streamer that writes LLVM optimization remarks to a file
28/// (YAML or Bitstream). Lives outside core.
29class LLVMRemarkStreamer final : public MLIRRemarkStreamerBase {
30public:
31 /// Open \p path and create the serializer for \p fmt.
33 createToFile(llvm::StringRef path, llvm::remarks::Format fmt);
34
35 void streamOptimizationRemark(const Remark &remark) override;
36 /// Finalize after all reporting threads have stopped.
37 void finalize() override;
38 ~LLVMRemarkStreamer() override;
39
40private:
41 LLVMRemarkStreamer() = default;
42
43 std::mutex mutex;
44 std::unique_ptr<class llvm::ToolOutputFile> file;
45 // RemarkStreamer must be destructed before file is destroyed!
46 std::unique_ptr<class llvm::remarks::RemarkStreamer> remarkStreamer;
47};
48} // namespace mlir::remark::detail
49
50namespace mlir::remark {
51/// Enable optimization remarks to a file with the given path and format.
52/// The remark categories are used to filter the remarks that are emitted.
53/// If the printAsEmitRemarks flag is set, remarks will also be printed using
54/// mlir::emitRemarks. If the file cannot be opened or the serializer cannot be
55/// created, an error is emitted on the context.
57 MLIRContext &ctx, StringRef filePath, llvm::remarks::Format fmt,
58 std::unique_ptr<detail::RemarkEmittingPolicyBase> remarkEmittingPolicy,
59 const RemarkCategories &cat, bool printAsEmitRemarks = false);
60
61} // namespace mlir::remark
62
63#endif // MLIR_REMARK_REMARKSTREAMER_H
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
void streamOptimizationRemark(const Remark &remark) override
Stream an optimization remark to the underlying remark streamer.
static llvm::Expected< std::unique_ptr< MLIRRemarkStreamerBase > > createToFile(llvm::StringRef path, llvm::remarks::Format fmt)
Open path and create the serializer for fmt.
void finalize() override
Finalize after all reporting threads have stopped.
Base class for MLIR remark streamers that is used to stream optimization remarks to the underlying re...
Definition Remarks.h:542
LogicalResult enableOptimizationRemarksWithLLVMStreamer(MLIRContext &ctx, StringRef filePath, llvm::remarks::Format fmt, std::unique_ptr< detail::RemarkEmittingPolicyBase > remarkEmittingPolicy, const RemarkCategories &cat, bool printAsEmitRemarks=false)
Enable optimization remarks to a file with the given path and format.
Define an the set of categories to accept.
Definition Remarks.h:69