-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[llvm-remarkutil] Introduce filter command #159784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6819c32
d97fe62
b27faa2
eff6b51
7ee6eae
626eb4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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: {{.}} |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Is there a reasonable alternative name that we could use for this namespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
thruYAMLTraits.h
in RemarkUtilHelpers.