aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2023-08-20 08:32:02 -0700
committerGitHub <noreply@github.com>2023-08-20 11:32:02 -0400
commit4c613e9f70abbe53a9f139da770d99014bb97a5a (patch)
treef6ee7b757096afcfc75202ca2652f2f365835e6c
parent0c3ee7f547078d2aeccb070aecae9979252a1f7a (diff)
downloadcompiler-explorer-gh-8526.tar.gz
compiler-explorer-gh-8526.zip
Implement comment filtering in LlvmIrParser (#5389)gh-8526
This is arguably a bit pointless, since most if not all of the comments in LLVM IR are filtered out as part of directives or attributes, but it comes up for things like `opt` on LLVM IR with debug info and for DXC (which is DXIL, but that's LLVM 3.7-era IR). In any case, this makes things less confusing in those cases by making the comments filter actually do something, rather than be ignored.
-rw-r--r--lib/llvm-ir.ts9
-rw-r--r--static/panes/ir-view.interfaces.ts1
-rw-r--r--static/panes/ir-view.ts2
-rw-r--r--types/compilation/ir.interfaces.ts1
-rw-r--r--views/templates/panes/ir.pug1
5 files changed, 14 insertions, 0 deletions
diff --git a/lib/llvm-ir.ts b/lib/llvm-ir.ts
index 2dcec50ca..ca4780299 100644
--- a/lib/llvm-ir.ts
+++ b/lib/llvm-ir.ts
@@ -49,6 +49,8 @@ export class LlvmIrParser {
private attributeDirective: RegExp;
private moduleMetadata: RegExp;
private functionAttrs: RegExp;
+ private commentOnly: RegExp;
+ private commentAtEOL: RegExp;
constructor(
compilerProps,
@@ -72,6 +74,8 @@ export class LlvmIrParser {
this.attributeDirective = /^attributes #\d+ = { .+ }$/;
this.functionAttrs = /^; Function Attrs: .+$/;
this.moduleMetadata = /^((source_filename|target datalayout|target triple) = ".+"|; ModuleID = '.+')$/;
+ this.commentOnly = /^\s*;.*$/;
+ this.commentAtEOL = /\s*;.*$/;
}
getFileName(debugInfo, scope): string | null {
@@ -174,6 +178,10 @@ export class LlvmIrParser {
filters.push(this.functionAttrs);
lineFilters.push(this.attributeAnnotation);
}
+ if (options.filterComments) {
+ filters.push(this.commentOnly);
+ lineFilters.push(this.commentAtEOL);
+ }
for (const line of irLines) {
if (line.trim().length === 0) {
@@ -253,6 +261,7 @@ export class LlvmIrParser {
filterDebugInfo: !!filters.debugCalls,
filterIRMetadata: !!filters.directives,
filterAttributes: false,
+ filterComments: !!filters.commentOnly,
demangle: !!filters.demangle,
// discard value names is handled earlier
});
diff --git a/static/panes/ir-view.interfaces.ts b/static/panes/ir-view.interfaces.ts
index 640b9012a..a62045b93 100644
--- a/static/panes/ir-view.interfaces.ts
+++ b/static/panes/ir-view.interfaces.ts
@@ -31,4 +31,5 @@ export interface IrState {
'filter-debug-info'?: boolean;
'filter-instruction-metadata'?: boolean;
'filter-attributes'?: boolean;
+ 'filter-comments'?: boolean;
}
diff --git a/static/panes/ir-view.ts b/static/panes/ir-view.ts
index 65996d366..575842fc6 100644
--- a/static/panes/ir-view.ts
+++ b/static/panes/ir-view.ts
@@ -57,6 +57,7 @@ export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState>
filterDebugInfo: true,
filterIRMetadata: true,
filterAttributes: true,
+ filterComments: true,
noDiscardValueNames: true,
demangle: true,
};
@@ -183,6 +184,7 @@ export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState>
filterDebugInfo: filters['filter-debug-info'],
filterIRMetadata: filters['filter-instruction-metadata'],
filterAttributes: filters['filter-attributes'],
+ filterComments: filters['filter-comments'],
noDiscardValueNames: options['-fno-discard-value-names'],
demangle: options['demangle-symbols'],
};
diff --git a/types/compilation/ir.interfaces.ts b/types/compilation/ir.interfaces.ts
index 060422ae0..c39e21f7c 100644
--- a/types/compilation/ir.interfaces.ts
+++ b/types/compilation/ir.interfaces.ts
@@ -26,6 +26,7 @@ export type LLVMIrBackendOptions = {
filterDebugInfo: boolean;
filterIRMetadata: boolean;
filterAttributes: boolean;
+ filterComments: boolean;
noDiscardValueNames?: boolean;
demangle: boolean;
};
diff --git a/views/templates/panes/ir.pug b/views/templates/panes/ir.pug
index 80f3342ad..ff140dca4 100644
--- a/views/templates/panes/ir.pug
+++ b/views/templates/panes/ir.pug
@@ -22,6 +22,7 @@ mixin optionButton(bind, isActive, text, title)
+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("filter-attributes", true, "Filter Attribute Groups", "Filter attribute groups")
+ +optionButton("filter-comments", true, "Hide Comments", "Filter comments")
//- +optionButton("library-functions", true, "Filter Library Functions", "Filter library functions")
.btn-group.btn-group-sm(role="group")
button.btn.btn-sm.btn-light.cfg(title="Open Control Flow Graph")