Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions llvm/test/tools/llvm-remarkutil/Inputs/filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- !Passed
Pass: pass1
Name: Remark1
DebugLoc: { File: 'path/to/func1.c', Line: 1, Column: 2 }
Function: func1
Args:
- String: ' text'
- arg1: argval1
...
--- !Missed
Pass: pass2
Name: Remark2
DebugLoc: { File: 'path/to/func2.c', Line: 1, Column: 2 }
Function: func2
Args:
- String: ' text'
- arg2: argval2
...
--- !Analysis
Pass: pass3
Name: Remark3
DebugLoc: { File: 'path/to/func3.c', Line: 1, Column: 2 }
Function: func3
Args:
- String: ' text'
- arg3: argval3
DebugLoc: { File: 'path/to/func3.c', Line: 2, Column: 2 }
...
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ RUN: not llvm-remarkutil instruction-count %p/Inputs/broken-remark-magic.bitstre
RUN: not llvm-remarkutil instruction-mix %p/Inputs/broken-remark-magic.bitstream -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil annotation-count --annotation-type=remark %p/Inputs/broken-remark-magic.bitstream -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil count %p/Inputs/broken-remark-magic.bitstream -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil filter %p/Inputs/broken-remark-magic.bitstream -o - 2>&1 | FileCheck %s

CHECK: error: Automatic detection of remark format failed. Unknown magic number: '1234'
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ RUN: not llvm-remarkutil bitstream2yaml %p/Inputs/broken-remark -o - 2>&1 | File
RUN: not llvm-remarkutil instruction-count --parser=bitstream %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil annotation-count --parser=bitstream --annotation-type=remark %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil count --parser=bitstream %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil filter --parser=bitstream %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s

CHECK: error: Unknown magic number: expecting RMRK, got --- .
1 change: 1 addition & 0 deletions llvm/test/tools/llvm-remarkutil/broken-yaml-remark.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ RUN: not llvm-remarkutil instruction-count --parser=yaml %p/Inputs/broken-remark
RUN: not llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil annotation-count --parser=yaml --annotation-type=remark %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil count --parser=yaml %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s
RUN: not llvm-remarkutil filter --parser=yaml %p/Inputs/broken-remark -o - 2>&1 | FileCheck %s

CHECK: error: Type, Pass, Name or Function missing
5 changes: 5 additions & 0 deletions llvm/test/tools/llvm-remarkutil/empty-file.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ RUN: not llvm-remarkutil instruction-count --parser=yaml %p/Inputs/empty-file -o
RUN: not llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --check-prefix=YAMLPARSER
RUN: not llvm-remarkutil annotation-count --parser=yaml --annotation-type=remark %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --check-prefix=YAMLPARSER
RUN: not llvm-remarkutil count --parser=yaml %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --check-prefix=YAMLPARSER
RUN: not llvm-remarkutil filter --parser=yaml %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --check-prefix=YAMLPARSER
RUN: llvm-remarkutil bitstream2yaml %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=BITSTREAM2YAML
RUN: llvm-remarkutil instruction-count --parser=bitstream %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=SIZEBITSTREAM
RUN: llvm-remarkutil instruction-mix --parser=bitstream %p/Inputs/empty-file --report_style=csv -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=MIXBITSTREAM
RUN: llvm-remarkutil annotation-count --parser=bitstream --annotation-type=remark %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=ANNOTATIONBITSTREAM
RUN: llvm-remarkutil count --parser=bitstream %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=COUNTBITSTREAM
RUN: llvm-remarkutil filter --parser=bitstream %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=FILTERBITSTREAM
; Parser format auto-detection should treat empty files as bitstream files
RUN: llvm-remarkutil instruction-count %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=SIZEBITSTREAM
RUN: llvm-remarkutil instruction-mix %p/Inputs/empty-file --report_style=csv -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=MIXBITSTREAM
RUN: llvm-remarkutil annotation-count --annotation-type=remark %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=ANNOTATIONBITSTREAM
RUN: llvm-remarkutil count %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=COUNTBITSTREAM
RUN: llvm-remarkutil filter %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow-empty --check-prefix=FILTERBITSTREAM

; YAMLPARSER: error: document root is not of mapping type.

Expand All @@ -30,3 +33,5 @@ RUN: llvm-remarkutil count %p/Inputs/empty-file -o - 2>&1 | FileCheck %s --allow

; MIXBITSTREAM-LABEL: Instruction,Count
; MIXBITSTREAM-EMPTY:

; FILTERBITSTREAM-NOT: {{.}}
59 changes: 59 additions & 0 deletions llvm/test/tools/llvm-remarkutil/filter.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
RUN: llvm-remarkutil filter %p/Inputs/filter.yaml | diff %p/Inputs/filter.yaml -
RUN: llvm-remarkutil filter --rfunction=func %p/Inputs/filter.yaml | diff %p/Inputs/filter.yaml -
RUN: llvm-remarkutil filter --rremark-name=Remark %p/Inputs/filter.yaml | diff %p/Inputs/filter.yaml -
RUN: llvm-remarkutil filter --rpass-name=pass %p/Inputs/filter.yaml | diff %p/Inputs/filter.yaml -
RUN: llvm-remarkutil filter --rfilter-arg-by=argval %p/Inputs/filter.yaml | diff %p/Inputs/filter.yaml -

RUN: llvm-remarkutil filter --rfunction=unc1 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
RUN: llvm-remarkutil filter --rremark-name=ark3 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK3
RUN: llvm-remarkutil filter --rpass-name=s1 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
RUN: llvm-remarkutil filter --filter-arg-by=argval2 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK2
RUN: llvm-remarkutil filter --function=func1 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
RUN: llvm-remarkutil filter --pass-name=pass2 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK2
RUN: llvm-remarkutil filter --remark-name=Remark3 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK3
RUN: llvm-remarkutil filter --function=func1 --pass-name=pass1 --remark-name=Remark1 %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
RUN: llvm-remarkutil filter --remark-type=passed %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
RUN: llvm-remarkutil filter --remark-type=missed %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK2
RUN: llvm-remarkutil filter --remark-type=analysis %p/Inputs/filter.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK3

RUN: llvm-remarkutil yaml2bitstream -o %t.opt.bitstream %p/Inputs/filter.yaml
RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream | FileCheck %s --strict-whitespace --check-prefix=REMARK1

RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1.opt.bitstream
RUN: llvm-remarkutil bitstream2yaml %t.r1.opt.bitstream | FileCheck %s --strict-whitespace --check-prefix=REMARK1

RUN: llvm-remarkutil filter --function=func %p/Inputs/filter.yaml | FileCheck %s --allow-empty --strict-whitespace --check-prefix=EMPTY

; REMARK1: --- !Passed
; REMARK1-NEXT: Pass: pass1
; REMARK1-NEXT: Name: Remark1
; REMARK1-NEXT: DebugLoc: { File: 'path/to/func1.c', Line: 1, Column: 2 }
; REMARK1-NEXT: Function: func1
; REMARK1-NEXT: Args:
; REMARK1-NEXT: - String: ' text'
; REMARK1-NEXT: - arg1: argval1
; REMARK1-NEXT: ...
; REMARK1-NOT: {{.}}
; REMARK2: --- !Missed
; REMARK2-NEXT: Pass: pass2
; REMARK2-NEXT: Name: Remark2
; REMARK2-NEXT: DebugLoc: { File: 'path/to/func2.c', Line: 1, Column: 2 }
; REMARK2-NEXT: Function: func2
; REMARK2-NEXT: Args:
; REMARK2-NEXT: - String: ' text'
; REMARK2-NEXT: - arg2: argval2
; REMARK2-NEXT: ...
; REMARK2-NOT: {{.}}
; REMARK3: --- !Analysis
; REMARK3-NEXT: Pass: pass3
; REMARK3-NEXT: Name: Remark3
; REMARK3-NEXT: DebugLoc: { File: 'path/to/func3.c', Line: 1, Column: 2 }
; REMARK3-NEXT: Function: func3
; REMARK3-NEXT: Args:
; REMARK3-NEXT: - String: ' text'
; REMARK3-NEXT: - arg3: argval3
; REMARK3-NEXT: DebugLoc: { File: 'path/to/func3.c', Line: 2, Column: 2 }
; REMARK3-NEXT: ...
; REMARK3-NOT: {{.}}

; EMPTY-NOT: {{.}}
1 change: 1 addition & 0 deletions llvm/tools/llvm-remarkutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_llvm_tool(llvm-remarkutil
RemarkConvert.cpp
RemarkCount.cpp
RemarkCounter.cpp
RemarkFilter.cpp
RemarkInstructionMix.cpp
RemarkSizeDiff.cpp
RemarkUtil.cpp
Expand Down
85 changes: 4 additions & 81 deletions llvm/tools/llvm-remarkutil/RemarkCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ static cl::SubCommand CountSub("count",

INPUT_FORMAT_COMMAND_LINE_OPTIONS(CountSub)
INPUT_OUTPUT_COMMAND_LINE_OPTIONS(CountSub)
REMARK_FILTER_COMMAND_LINE_OPTIONS(CountSub)

REMARK_FILTER_SETUP_FUNC()

static cl::list<std::string>
Keys("args", cl::desc("Specify remark argument/s to count by."),
Expand All @@ -34,45 +37,7 @@ static cl::list<std::string> RKeys(
cl::desc(
"Specify remark argument/s to count (accepts 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("Optional remark type to filter collection by."),
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(
Expand Down Expand Up @@ -112,21 +77,6 @@ static unsigned getValForKey(StringRef Key, const Remark &Remark) {
return *RemarkArg->getValAsInt();
}

bool Filters::filterRemark(const Remark &Remark) {
if (RemarkNameFilter && !RemarkNameFilter->match(Remark.RemarkName))
return false;
if (PassNameFilter && !PassNameFilter->match(Remark.PassName))
return false;
if (RemarkTypeFilter)
return *RemarkTypeFilter == Remark.RemarkType;
if (ArgFilter) {
if (!any_of(Remark.Args,
[this](Argument Arg) { return ArgFilter->match(Arg.Val); }))
return false;
}
return true;
}

Error ArgumentCounter::getAllMatchingArgumentsInRemark(
StringRef Buffer, ArrayRef<FilterMatcher> Arguments, Filters &Filter) {
auto MaybeParser = createRemarkParser(InputFormat, Buffer);
Expand Down Expand Up @@ -223,33 +173,6 @@ Error RemarkCounter::print(StringRef OutputFileName) {
return Error::success();
}

Expected<Filters> getRemarkFilter() {
// Create Filter properties.
auto MaybeRemarkNameFilter =
FilterMatcher::createExactOrRE(RemarkNameOpt, RemarkNameOptRE);
if (!MaybeRemarkNameFilter)
return MaybeRemarkNameFilter.takeError();

auto MaybePassNameFilter =
FilterMatcher::createExactOrRE(PassNameOpt, PassNameOptRE);
if (!MaybePassNameFilter)
return MaybePassNameFilter.takeError();

auto MaybeRemarkArgFilter = FilterMatcher::createExactOrRE(
RemarkFilterArgByOpt, RemarkArgFilterOptRE);
if (!MaybeRemarkArgFilter)
return MaybeRemarkArgFilter.takeError();

std::optional<Type> RemarkType;
if (RemarkTypeOpt != Type::Failure)
RemarkType = RemarkTypeOpt;

// Create RemarkFilter.
return Filters{std::move(*MaybeRemarkNameFilter),
std::move(*MaybePassNameFilter),
std::move(*MaybeRemarkArgFilter), RemarkType};
}

Error useCollectRemark(StringRef Buffer, Counter &Counter, Filters &Filter) {
// Create Parser.
auto MaybeParser = createRemarkParser(InputFormat, Buffer);
Expand Down Expand Up @@ -278,7 +201,7 @@ static Error collectRemarks() {
if (!MaybeBuf)
return MaybeBuf.takeError();
StringRef Buffer = (*MaybeBuf)->getBuffer();
auto MaybeFilter = getRemarkFilter();
auto MaybeFilter = getRemarkFilters();
if (!MaybeFilter)
return MaybeFilter.takeError();
auto &Filter = *MaybeFilter;
Expand Down
13 changes: 1 addition & 12 deletions llvm/tools/llvm-remarkutil/RemarkCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "RemarkUtilHelpers.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/Support/Regex.h"
#include <map>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to pull this in here now?

Copy link
Contributor Author

@tobias-stadler tobias-stadler Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unnecessary includes from RemarkUtilHelpers. Previously this was pulled in by YAMLRemarkSerializer.h thru YAMLTraits.h in RemarkUtilHelpers.


namespace llvm {
namespace remarks {
Expand Down Expand Up @@ -45,18 +46,6 @@ inline std::string groupByToStr(GroupBy GroupBy) {
}
}

/// Filter out remarks based on remark properties based on name, pass name,
/// argument and type.
struct Filters {
std::optional<FilterMatcher> RemarkNameFilter;
std::optional<FilterMatcher> PassNameFilter;
std::optional<FilterMatcher> ArgFilter;
std::optional<Type> RemarkTypeFilter;

/// Returns true if \p Remark satisfies all the provided filters.
bool filterRemark(const Remark &Remark);
};

/// Abstract counter class used to define the general required methods for
/// counting a remark.
struct Counter {
Expand Down
84 changes: 84 additions & 0 deletions llvm/tools/llvm-remarkutil/RemarkFilter.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
Comment on lines +67 to +72
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to create a iterator adopter that takes a parser and returns an iterator over filtered remarks and use it here and in RemarkCounter.cpp

Copy link
Contributor Author

@tobias-stadler tobias-stadler Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iterator/range needs to be fallible and must be able to take ownership of the unique_ptr<Remark> . This means we can't use a combination of iterator_range and fallible_iterator to implement this. We would have to roll this from scratch. My prototype is the same amount of code as the entire filter command. I don't think that's worth it, at least it's out of scope for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's OK, although this might be worth more thought in the future, to avoid duplicating the logic in every remarks tool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobias-stadler @fhahn I'm seeing failures in some external modules builds due to reuse of the filter identifier here. E.g.

 llvm-project/llvm/tools/llvm-remarkutil/RemarkFilter.cpp:23:11: error: redefinition of 'filter' as different kind of symbol
05:35:57     23 | namespace filter {
05:35:57        |           ^
05:35:57  /<sdk>/usr/include/curses.h:686:29: note: previous definition is here
05:35:57    686 | extern NCURSES_EXPORT(void) filter (void);

Is there a reasonable alternative name that we could use for this namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


auto E = MaybeRemark.takeError();
if (!E.isA<EndOfFileError>())
return E;
consumeError(std::move(E));
OF->keep();
return Error::success();
}

static CommandRegistration FilterReg(&FilterSub, tryFilter);

} // namespace filter
17 changes: 17 additions & 0 deletions llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,22 @@ FilterMatcher::createExactOrRE(const llvm::cl::opt<std::string> &ExactArg,
return std::nullopt;
}

bool Filters::filterRemark(const Remark &Remark) {
if (FunctionFilter && !FunctionFilter->match(Remark.FunctionName))
return false;
if (RemarkNameFilter && !RemarkNameFilter->match(Remark.RemarkName))
return false;
if (PassNameFilter && !PassNameFilter->match(Remark.PassName))
return false;
if (RemarkTypeFilter)
return *RemarkTypeFilter == Remark.RemarkType;
if (ArgFilter) {
if (!any_of(Remark.Args,
[this](Argument Arg) { return ArgFilter->match(Arg.Val); }))
return false;
}
return true;
}

} // namespace remarks
} // namespace llvm
Loading