[Mlir-commits] [mlir] [MLIR] Introduce RemarkEngine + pluggable remark streaming (YAML/Bitstream) (PR #152474)

Mehdi Amini llvmlistbot at llvm.org
Mon Aug 11 09:51:34 PDT 2025


================
@@ -0,0 +1,35 @@
+#include "mlir/IR/Remarks.h"
+
+#include "llvm/Remarks/RemarkStreamer.h"
+#include "llvm/Support/ToolOutputFile.h"
+
+using namespace llvm;
+namespace mlir::remark {
+
+/// Concrete streamer that writes LLVM optimization remarks to a file
+/// (YAML or Bitstream). Lives outside core.
+class LLVMRemarkStreamer final : public MLIRRemarkStreamerBase {
+public:
+  static FailureOr<std::unique_ptr<MLIRRemarkStreamerBase>>
+  createToFile(llvm::StringRef path, llvm::remarks::Format fmt);
+
+  void streamOptimizationRemark(const Remark &remark) override;
+  void finalize() override {}
+  ~LLVMRemarkStreamer() override;
+
+private:
+  LLVMRemarkStreamer() = default;
+
+  std::unique_ptr<class llvm::remarks::RemarkStreamer> remarkStreamer;
+  std::unique_ptr<class llvm::ToolOutputFile> file;
+};
+
+/// Enable optimization remarks to a file with the given path and format.
+/// The remark categories are used to filter the remarks that are emitted.
+/// If the printAsEmitRemarks flag is set, remarks will also be printed using
+/// mlir::emitRemarks.
+LogicalResult enableOptimizationRemarksToFile(
+    MLIRContext &ctx, StringRef path, llvm::remarks::Format fmt,
+    const MLIRContext::RemarkCategories &cat, bool printAsEmitRemarks = false);
+
+} // namespace mlir::remark
----------------
joker-eph wrote:

Nit: missing new line at the end of the file.

https://github.com/llvm/llvm-project/pull/152474


More information about the Mlir-commits mailing list