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

Guray Ozen llvmlistbot at llvm.org
Fri Aug 8 12:05:11 PDT 2025


================
@@ -0,0 +1,294 @@
+//===- Remarks.cpp - MLIR Remarks ---------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/IR/Remarks.h"
+
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Diagnostics.h"
+#include "mlir/IR/Value.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/IR/LLVMRemarkStreamer.h"
+#include "llvm/Remarks/RemarkFormat.h"
+#include "llvm/Support/FileSystem.h"
+
+using namespace mlir;
+
+//------------------------------------------------------------------------------
+// RemarkBase
+//------------------------------------------------------------------------------
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, Value value)
+    : key(std::string(key)) {
+
+  llvm::raw_string_ostream rss(val);
+  rss << value;
+}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, Type type)
+    : key(std::string(key)) {
+  llvm::raw_string_ostream os(val);
+  os << type;
+}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, StringRef s)
+    : key(std::string(key)), val(s.str()) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, int n)
+    : key(std::string(key)), val(llvm::itostr(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, float n)
+    : key(std::string(key)), val(std::to_string(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, long n)
+    : key(std::string(key)), val(llvm::itostr(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, long long n)
+    : key(std::string(key)), val(llvm::itostr(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned n)
+    : key(std::string(key)), val(llvm::utostr(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned long n)
+    : key(std::string(key)), val(llvm::utostr(n)) {}
+
+RemarkBase::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned long long n)
+    : key(std::string(key)), val(llvm::utostr(n)) {}
+
+void RemarkBase::print(llvm::DiagnosticPrinter &dp) const {
+  std::string str;
+  llvm::raw_string_ostream os(str);
+  getLocation()->print(os);
+  os.flush();
+  dp << str << ": " << getMsg();
+}
+
+void RemarkBase::print() const { emitError(getLocation(), getMsg()); }
+
+void RemarkBase::insert(StringRef s) { args.emplace_back(s); }
+
+void RemarkBase::insert(RemarkKeyValue a) { args.push_back(std::move(a)); }
+
+void RemarkBase::insert(SetIsVerbose v) { isVerboseRemark = true; }
+
+std::string RemarkBase::getMsg() const {
+  std::string str;
+  llvm::raw_string_ostream rss(str);
+  for (const RemarkBase::RemarkKeyValue &arg :
+       llvm::make_range(args.begin(), args.end()))
+    rss << arg.val;
+  return str;
+}
----------------
grypp wrote:

Yes, that's why I didn't resolve this case. I am still working on this PR. 

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


More information about the Mlir-commits mailing list