[llvm] Introduce llvmremark util diff command (PR #85007)

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 24 18:49:10 PDT 2024


================
@@ -0,0 +1,298 @@
+//===- RemarkDiff.h -------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Generic tool to diff remarks based on properties
+//
+//===----------------------------------------------------------------------===//
+
+#include "RemarkUtilHelpers.h"
+#include "RemarkUtilRegistry.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/ScopedPrinter.h"
+
+namespace llvm {
+namespace remarks {
+
+enum ReportStyleOptions { human_output, json_output };
+/// copy of Argument class using std::string instead of StringRef.
+struct RemarkArgInfo {
+  std::string Key;
+  std::string Val;
+  RemarkArgInfo(StringRef Key, StringRef Val)
+      : Key(Key.str()), Val(Val.str()) {}
+  void print(raw_ostream &OS) const;
+};
+
+hash_code hash_value(const RemarkArgInfo &Arg) {
+  return hash_combine(Arg.Key, Arg.Val);
+}
+
+/// A wrapper for Remark class that can be used for generating remark diff.
+struct RemarkInfo {
+  std::string RemarkName;
+  std::string FunctionName;
+  std::string PassName;
+  Type RemarkType;
+  SmallVector<RemarkArgInfo, 4> Args;
+  RemarkInfo();
+  RemarkInfo(std::string RemarkName, std::string FunctionName,
+             std::string PassName, Type RemarkType,
+             SmallVector<RemarkArgInfo, 4> &Args)
+      : RemarkName(RemarkName), FunctionName(FunctionName), PassName(PassName),
+        RemarkType(RemarkType), Args(Args) {}
+  RemarkInfo(Remark &Remark)
+      : RemarkName(Remark.RemarkName.str()),
+        FunctionName(Remark.FunctionName.str()),
+        PassName(Remark.PassName.str()), RemarkType(Remark.RemarkType) {
+    for (const auto &Arg : Remark.Args)
+      Args.push_back({Arg.Key.str(), Arg.Val.str()});
+  }
+
+  /// Check if the remark has the same name, function name and pass name as \p
+  /// RHS
+  bool hasSameHeader(const RemarkInfo &RHS) const {
+    return RemarkName == RHS.RemarkName && FunctionName == RHS.FunctionName &&
----------------
ornata wrote:

Should `RemarkHeader` be a struct/class with an overloaded `==` ?

Then `RemarkInfo` can contain a `RemarkHeader`.

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


More information about the llvm-commits mailing list