[llvm-branch-commits] [llvm] [llvm-remarkutil] Introduce filter command (PR #159784)
Florian Hahn via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Sep 24 04:12:27 PDT 2025
================
@@ -0,0 +1,84 @@
+//===- RemarkFilter.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 filter remarks
+//
+//===----------------------------------------------------------------------===//
+
+#include "RemarkUtilHelpers.h"
+#include "RemarkUtilRegistry.h"
+
+#include "llvm/Support/Error.h"
+#include "llvm/Support/Regex.h"
+
+using namespace llvm;
+using namespace remarks;
+using namespace llvm::remarkutil;
+
+namespace filter {
+
+static cl::SubCommand FilterSub("filter",
+ "Filter remarks based on specified criteria.");
+
+INPUT_FORMAT_COMMAND_LINE_OPTIONS(FilterSub)
+OUTPUT_FORMAT_COMMAND_LINE_OPTIONS(FilterSub)
+INPUT_OUTPUT_COMMAND_LINE_OPTIONS(FilterSub)
+REMARK_FILTER_COMMAND_LINE_OPTIONS(FilterSub)
+
+REMARK_FILTER_SETUP_FUNC()
+
+static Error tryFilter() {
+ auto MaybeFilter = getRemarkFilters();
+ if (!MaybeFilter)
+ return MaybeFilter.takeError();
+ Filters &Filter = *MaybeFilter;
+
+ auto MaybeBuf = getInputMemoryBuffer(InputFileName);
+ if (!MaybeBuf)
+ return MaybeBuf.takeError();
+ auto MaybeParser = createRemarkParser(InputFormat, (*MaybeBuf)->getBuffer());
+ if (!MaybeParser)
+ return MaybeParser.takeError();
+ auto &Parser = **MaybeParser;
+
+ Format SerializerFormat = OutputFormat;
+ if (SerializerFormat == Format::Auto) {
+ SerializerFormat = Parser.ParserFormat;
+ if (OutputFileName.empty() || OutputFileName == "-")
+ SerializerFormat = Format::YAML;
+ }
+
+ auto MaybeOF = getOutputFileForRemarks(OutputFileName, SerializerFormat);
+ if (!MaybeOF)
+ return MaybeOF.takeError();
+ auto OF = std::move(*MaybeOF);
+
+ auto MaybeSerializer = createRemarkSerializer(SerializerFormat, OF->os());
+ if (!MaybeSerializer)
+ return MaybeSerializer.takeError();
+ auto &Serializer = **MaybeSerializer;
+
+ auto MaybeRemark = Parser.next();
+ for (; MaybeRemark; MaybeRemark = Parser.next()) {
+ Remark &Remark = **MaybeRemark;
+ if (!Filter.filterRemark(Remark))
+ continue;
+ Serializer.emit(Remark);
+ }
----------------
fhahn wrote:
Yeah that's OK, although this might be worth more thought in the future, to avoid duplicating the logic in every remarks tool
https://github.com/llvm/llvm-project/pull/159784
More information about the llvm-branch-commits
mailing list