Skip to content

Commit

Permalink
Add Hide metadata option to LLVM pipeline (#4243)
Browse files Browse the repository at this point in the history
  • Loading branch information
OfekShilon committed Nov 6, 2022
1 parent d57274d commit db9b4f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
12 changes: 11 additions & 1 deletion lib/parsers/llvm-pass-dump-parser.ts
Expand Up @@ -84,6 +84,7 @@ export class LlvmPassDumpParser {
lineFilters: RegExp[];
debugInfoFilters: RegExp[];
debugInfoLineFilters: RegExp[];
metadataLineFilters: RegExp[];
irDumpHeader: RegExp;
machineCodeDumpHeader: RegExp;
functionDefine: RegExp;
Expand Down Expand Up @@ -119,6 +120,12 @@ export class LlvmPassDumpParser {
];
this.debugInfoLineFilters = [
/,? !dbg !\d+/, // instruction/function debug metadata
/,? debug-location !\d+/, // Direct source locations like 'example.cpp:8:1' not filtered
];

// Conditionally enabled by `filterIRMetadata`
this.metadataLineFilters = [
/,?(?: ![\d.A-Za-z]+){2}/, // any instruction metadata
];

// Ir dump headers look like "*** IR Dump After XYZ ***"
Expand Down Expand Up @@ -454,13 +461,16 @@ export class LlvmPassDumpParser {
}

applyIrFilters(ir: ResultLine[], llvmOptPipelineOptions: LLVMOptPipelineBackendOptions) {
// Additional filters conditionally enabled by `filterDebugInfo`
// Additional filters conditionally enabled by `filterDebugInfo`/`filterIRMetadata`
let filters = this.filters;
let lineFilters = this.lineFilters;
if (llvmOptPipelineOptions.filterDebugInfo) {
filters = filters.concat(this.debugInfoFilters);
lineFilters = lineFilters.concat(this.debugInfoLineFilters);
}
if (llvmOptPipelineOptions.filterIRMetadata) {
lineFilters = lineFilters.concat(this.metadataLineFilters);
}

return (
ir
Expand Down
2 changes: 2 additions & 0 deletions static/panes/llvm-opt-pipeline.ts
Expand Up @@ -64,6 +64,7 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneDiffEdi
state: LLVMOptPipelineViewState;
lastOptions: LLVMOptPipelineBackendOptions = {
filterDebugInfo: true,
filterIRMetadata: false,
fullModule: false,
noDiscardValueNames: true,
demangle: true,
Expand Down Expand Up @@ -195,6 +196,7 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneDiffEdi
const newOptions: LLVMOptPipelineBackendOptions = {
//'filter-inconsequential-passes': options['filter-inconsequential-passes'],
filterDebugInfo: filters['filter-debug-info'],
filterIRMetadata: filters['filter-instruction-metadata'],
fullModule: options['dump-full-module'],
noDiscardValueNames: options['-fno-discard-value-names'],
demangle: options['demangle-symbols'],
Expand Down
26 changes: 26 additions & 0 deletions test/llvm-pass-dump-parser-tests.js
Expand Up @@ -66,4 +66,30 @@ describe('llvm-pass-dump-parser filter', function () {
{text: ' ret void'},
]);
});

it('should filter out instruction metadata and object attribute group, leave debug instructions in place', function () {
// 'hide IR metadata' aims to decrease more visual noise than `hide debug info`
const options = {filterDebugInfo: false, filterIRMetadata: true};
// prettier-ignore
llvmPassDumpParser
.applyIrFilters(deepCopy(rawFuncIR), options)
.should.deep.equal([
{text: ' # Machine code for function f(S1&, S2 const&): NoPHIs, TracksLiveness, TiedOpsRewritten'},
{text: 'define dso_local void @f(S1&, S2 const&)(%struct.S1* noundef nonnull align 8 dereferenceable(16) %s1, %struct.S2* noundef nonnull align 8 dereferenceable(16) %s2) {'},
{text: 'entry:'},
{text: ' %s1.addr = alloca %struct.S1*, align 8'},
{text: ' store %struct.S1* %s1, %struct.S1** %s1.addr, align 8'},
{text: ' call void @llvm.dbg.declare(metadata %struct.S1** %s1.addr, metadata !30, metadata !DIExpression())'},
{text: ' call void @llvm.dbg.value(metadata %struct.S1* %s1, metadata !30, metadata !DIExpression())'},
{text: ' DBG_VALUE $rdi, $noreg, !"s1", !DIExpression(), debug-location !32; example.cpp:0 line no:7'},
{text: ' store %struct.S2* %s2, %struct.S2** %s2.addr, align 8'},
{text: ' %0 = load %struct.S2*, %struct.S2** %s2.addr, align 8'},
{text: ' %a = getelementptr inbounds %struct.S2, %struct.S2* %0, i32 0, i32 0'},
{text: ' %1 = load i64, i64* %t, align 8'},
{text: ' %2 = load %struct.S1*, %struct.S1** %s1.addr, align 8'},
{text: ' store i64 %1, i64* %t2, align 8'},
{text: ' %t3 = getelementptr inbounds %struct.Wrapper2, %struct.Wrapper2* %b, i32 0, i32 0'},
{text: ' ret void'},
]);
});
});
1 change: 1 addition & 0 deletions types/compilation/llvm-opt-pipeline-output.interfaces.ts
Expand Up @@ -42,6 +42,7 @@ export type LLVMOptPipelineOutput = {

export type LLVMOptPipelineBackendOptions = {
filterDebugInfo: boolean;
filterIRMetadata: boolean;
fullModule: boolean;
noDiscardValueNames: boolean;
demangle: boolean;
Expand Down
5 changes: 3 additions & 2 deletions views/templates/panes/llvm-opt-pipeline.pug
Expand Up @@ -20,8 +20,9 @@ mixin optionButton(bind, isActive, text, title)
span.fas.fa-filter
span.hideable Filters
.dropdown-menu
+optionButton("filter-inconsequential-passes", false, "Filter Inconsequential Passes", "Filter passes which do not make changes")
+optionButton("filter-debug-info", true, "Filter Debug Info", "Filter debug info intrinsics")
+optionButton("filter-inconsequential-passes", false, "Hide Inconsequential Passes", "Filter passes which do not make changes")
+optionButton("filter-debug-info", true, "Hide Debug Info", "Filter debug info intrinsics")
+optionButton("filter-instruction-metadata", true, "Hide Instruction Metadata", "Filter all IR metadata")
//- +optionButton("library-functions", true, "Filter Library Functions", "Filter library functions")
.btn-group.btn-group-sm
.input-group.input-group-sm.mb-auto
Expand Down

0 comments on commit db9b4f4

Please sign in to comment.