[Mlir-commits] [mlir] [MLIR] Integrate LLVM Optimization Remarks Infrastructure (PR #152474)

River Riddle llvmlistbot at llvm.org
Thu Aug 7 13:22:22 PDT 2025


================
@@ -0,0 +1,453 @@
+//===- Remarks.h - MLIR Optimization Remark ----------------------*- 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 defines utilities for emitting optimization remarks.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_IR_REMARKS_H
+#define MLIR_IR_REMARKS_H
+
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/DiagnosticPrinter.h"
+#include "llvm/Remarks/Remark.h"
+#include "llvm/Remarks/RemarkStreamer.h"
+#include "llvm/Support/ToolOutputFile.h"
+
+#include "mlir/IR/Diagnostics.h"
+#include "mlir/IR/MLIRContext.h"
+
+namespace mlir {
+
+/// Defines different remark kinds that can be used to categorize remarks.
+enum class RemarkKind {
+  OptimizationRemarkUnknown = 0,
+  OptimizationRemarkPass,
+  OptimizationRemarkMissed,
+  OptimizationRemarkFailure,
+  OptimizationRemarkAnalysis,
+};
+
+//===----------------------------------------------------------------------===//
+// Remark Base Class
+//===----------------------------------------------------------------------===//
+class RemarkBase : public llvm::DiagnosticInfo {
+
+public:
+  RemarkBase(RemarkKind remarkKind, DiagnosticSeverity severity,
+             const char *passName, StringRef remarkName, Location loc,
+             std::optional<StringRef> functionName = std::nullopt)
+      : llvm::DiagnosticInfo(makeLLVMKind(remarkKind),
+                             makeLLVMSeverity(severity)),
+        remarkKind(remarkKind), functionName(functionName), loc(loc),
+        passName(passName), remarkName(remarkName) {}
+
+  struct SetIsVerbose {};
+
+  struct SetExtraArgs {};
+
+  struct RemarkKeyValue {
+    std::string key;
+    std::string val;
+
+    explicit RemarkKeyValue(StringRef str = "") : key("String"), val(str) {}
+    RemarkKeyValue(StringRef key, Value value);
----------------
River707 wrote:

The duplication here compared to MLIR diagnostics is unfortunate, is there no way to unify these things more?

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


More information about the Mlir-commits mailing list