[llvm] Remark Util introduce remark count (PR #66214)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 17:26:27 PDT 2023


================
@@ -0,0 +1,339 @@
+//===- RemarkCounter.cpp --------------------------------------------------===//
+//
+// 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 count remarks based on properties
+//
+//===----------------------------------------------------------------------===//
+#include "RemarkCounter.h"
+#include "RemarkUtilRegistry.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Regex.h"
+
+using namespace llvm;
+using namespace remarks;
+using namespace llvm::remarkutil;
+
+static cl::SubCommand CountSub("count",
+                               "Collect remarks based on specified criteria.");
+
+INPUT_FORMAT_COMMAND_LINE_OPTIONS(CountSub)
+INPUT_OUTPUT_COMMAND_LINE_OPTIONS(CountSub)
+
+static cl::list<std::string>
+    Keys("args", cl::desc("Specify remark argument/s to count by."),
+         cl::value_desc("arguments"), cl::sub(CountSub), cl::ValueOptional);
+static cl::list<std::string> RKeys(
+    "rargs",
+    cl::desc(
+        "Specify remark argument/s to count by. using regular expressions"),
+    cl::value_desc("arguments"), cl::sub(CountSub), cl::ValueOptional);
+static cl::opt<std::string>
+    RemarkNameOpt("remark-name",
+                  cl::desc("optional remark name to filter collection by."),
+                  cl::ValueOptional, cl::sub(CountSub));
+static cl::opt<std::string>
+    PassNameOpt("pass-name", cl::ValueOptional,
+                cl::desc("optional remark pass name to filter collection by."),
+                cl::sub(CountSub));
+
+static cl::opt<std::string> RemarkFilterArgByOpt(
+    "filter-arg-by", cl::desc("optional remark arg to filter collection by."),
+    cl::ValueOptional, cl::sub(CountSub));
+static cl::opt<std::string>
+    RemarkNameOptRE("rremark-name",
+                    cl::desc("optional remark name to filter collection by "
+                             "(accepts regular expressions)."),
+                    cl::ValueOptional, cl::sub(CountSub));
+static cl::opt<std::string>
+    RemarkArgFilterOptRE("rfilter-arg-by",
+                         cl::desc("optional remark arg to filter collection by "
+                                  "(accepts regular expressions)."),
+                         cl::sub(CountSub), cl::ValueOptional);
+static cl::opt<std::string>
+    PassNameOptRE("rpass-name", cl::ValueOptional,
+                  cl::desc("optional remark pass name to filter collection "
+                           "by (accepts regular expressions)."),
+                  cl::sub(CountSub));
+static cl::opt<Type> RemarkTypeOpt(
+    "remark-type", cl::desc("filter collection by remark type."),
+    cl::values(clEnumValN(Type::Unknown, "unknown", "UNKOWN"),
+               clEnumValN(Type::Passed, "passed", "PASSED"),
+               clEnumValN(Type::Missed, "missed", "MISSED"),
+               clEnumValN(Type::Analysis, "analysis", "ANALYSIS"),
+               clEnumValN(Type::AnalysisFPCommute, "analysis-fp-commute",
+                          "ANALYSIS_FP_COMMUTE"),
+               clEnumValN(Type::AnalysisAliasing, "analysis-aliasing",
+                          "ANALYSIS_ALIASING"),
+               clEnumValN(Type::Failure, "failure", "FAILURE")),
+    cl::init(Type::Failure), cl::sub(CountSub));
+static cl::opt<CountBy> CountByOpt(
+    "count-by", cl::desc("Specify the property to collect remarks by"),
+    cl::values(
+        clEnumValN(
+            CountBy::REMARK, "remark-name",
+            "Counts individual remarks based on how many of the remark exists"),
+        clEnumValN(CountBy::ARGUMENT, "arg",
+                   "Counts based on the value each specified argument has. The "
+                   "argument has to have a number value to be considered.")),
+    cl::init(CountBy::REMARK), cl::sub(CountSub));
+static cl::opt<GroupBy> GroupByOpt(
+    "group-by", cl::desc("Specify the property to group remarks by."),
+    cl::values(
+        clEnumValN(
+            GroupBy::PER_SOURCE, "source",
+            "Display the count broken down by the filepath of each remark "
+            "emitted. Requires remarks to have DebugLoc information."),
+        clEnumValN(GroupBy::PER_FUNCTION, "function",
+                   "Breakdown the count by function name."),
+        clEnumValN(
+            GroupBy::PER_FUNCTION_WITH_DEBUG_LOC, "function-with-loc",
+            "Breakdown the count by function name taking into consideration "
+            "the filepath info from the DebugLoc of the remark."),
+        clEnumValN(GroupBy::TOTAL, "total",
+                   "Output the total number corresponding to the count for the "
+                   "provided input file.")),
+    cl::init(GroupBy::PER_SOURCE), cl::sub(CountSub));
+
+/// Look for matching argument for \p Key in \p Remark and return the parsed
+/// integer value.
+static unsigned getValForKey(StringRef Key, const Remark &Remark) {
+  auto *RemarkArg = find_if(Remark.Args, [&Key](const Argument &Arg) {
+    return Arg.Key == Key && Arg.isValInt();
+  });
+  if (RemarkArg == Remark.Args.end())
+    return 0;
+  return *RemarkArg->getValAsInt();
+}
+
+Error Filters::regexArgumentsValid() {
+  if (RemarkNameFilter.has_value() && RemarkNameFilter->IsRegex)
+    if (auto E = checkRegex(std::get<Regex>(RemarkNameFilter->FilterRE)))
----------------
fhahn wrote:

Got it, thanks!

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


More information about the llvm-commits mailing list