[Mlir-commits] [mlir] [MLIR] Introduce RemarkEngine + pluggable remark streaming (YAML/Bitstream) (PR #152474)
Mehdi Amini
llvmlistbot at llvm.org
Mon Aug 11 09:55:51 PDT 2025
================
@@ -0,0 +1,273 @@
+//===- 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/BuiltinAttributes.h"
+#include "mlir/IR/Diagnostics.h"
+#include "mlir/IR/Value.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+
+using namespace mlir::remark;
+
+//------------------------------------------------------------------------------
+// Remark
+//------------------------------------------------------------------------------
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, Value value)
+ : key(std::string(key)) {
+
+ llvm::raw_string_ostream rss(val);
+ rss << value;
+}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, Type type)
+ : key(std::string(key)) {
+ llvm::raw_string_ostream os(val);
+ os << type;
+}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, StringRef s)
+ : key(std::string(key)), val(s.str()) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, int n)
+ : key(std::string(key)), val(llvm::itostr(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, float n)
+ : key(std::string(key)), val(std::to_string(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, long n)
+ : key(std::string(key)), val(llvm::itostr(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, long long n)
+ : key(std::string(key)), val(llvm::itostr(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned n)
+ : key(std::string(key)), val(llvm::utostr(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned long n)
+ : key(std::string(key)), val(llvm::utostr(n)) {}
+
+Remark::RemarkKeyValue::RemarkKeyValue(StringRef key, unsigned long long n)
+ : key(std::string(key)), val(llvm::utostr(n)) {}
+
+void Remark::insert(StringRef s) { args.emplace_back(s); }
+
+void Remark::insert(RemarkKeyValue a) { args.push_back(std::move(a)); }
+
+// Simple helper to print key=val list.
+static void printArgs(llvm::raw_ostream &os,
+ llvm::ArrayRef<Remark::RemarkKeyValue> args) {
+ if (args.empty())
+ return;
+ os << " {\n";
+ for (size_t i = 0; i < args.size(); ++i) {
+ const auto &a = args[i];
+ os << a.key << "=" << a.val;
+ if (i + 1 < args.size())
+ os << ", ";
+ os << "\n";
+ }
+ os << "\n}";
+}
+
+void Remark::print(llvm::raw_ostream &os, bool printLocation) const {
+ os << getRemarkTypeString() << "\n";
+ os << getPassName() << ":" << getRemarkName() << "\n";
+
+ // Function (if any)
+ if (!getFunction().empty())
+ os << " func=" << getFunction() << "\n";
----------------
joker-eph wrote:
```suggestion
os << '[' << getRemarkTypeString() << "] ";
os << getPassName() << ':' << getRemarkName();
if (functionName)
os << " func=" << getFunction() << " ";
```
Do we need multiple lines here? That seems quite verbose? The nice things about fitting on single line is that you can more easily grep through a log for example.
Also you need to check on `if(functionName)` because `getFunction()` always return a non-empty string right now it seems (default to "<unknown func>" in the implementation).
https://github.com/llvm/llvm-project/pull/152474
More information about the Mlir-commits
mailing list