From d9151b9d39405dcc23892f6bca54abc930e2dba2 Mon Sep 17 00:00:00 2001 From: Ben Barsdell Date: Thu, 26 May 2022 21:59:16 +1000 Subject: [PATCH] Fix unused label filter for CUDA PTX output (#3717) - Previously this filter did not correctly identify used labels in CUDA PTX output, which caused it to remove important labels. --- lib/parsers/asm-parser.js | 7 +++++-- .../nvcc-example.asm.directives.approved.txt | 11 ++++++++++- ...-example.asm.directives.comments.approved.txt | 11 ++++++++++- ...cc-example.asm.directives.labels.approved.txt | 16 +++++++++++++++- ...e.asm.directives.labels.comments.approved.txt | 16 +++++++++++++++- ...rectives.labels.comments.library.approved.txt | 16 +++++++++++++++- ...mments.library.dontMaskFilenames.approved.txt | 16 +++++++++++++++- ...c-example.asm.directives.library.approved.txt | 11 ++++++++++- 8 files changed, 95 insertions(+), 9 deletions(-) diff --git a/lib/parsers/asm-parser.js b/lib/parsers/asm-parser.js index 8c55e8c44..9e2549484 100644 --- a/lib/parsers/asm-parser.js +++ b/lib/parsers/asm-parser.js @@ -116,6 +116,7 @@ export class AsmParser extends AsmRegex { const startBlock = /\.cfi_startproc/; const endBlock = /\.cfi_endproc/; let inFunction = false; + let inNvccCode = false; // Scan through looking for definite label usages (ones used by opcodes), // and ones that are weakly used: that is, their use is conditional on another label. @@ -138,6 +139,8 @@ export class AsmParser extends AsmRegex { inFunction = true; } else if (endBlock.test(line)) { inFunction = false; + } else if (this.cudaBeginDef.test(line)) { + inNvccCode = true; } if (inCustomAssembly > 0) line = this.fixLabelIndentation(line); @@ -163,14 +166,14 @@ export class AsmParser extends AsmRegex { match = line.match(labelFind); if (!match) continue; - if (!filterDirectives || this.hasOpcode(line, false) || definesFunction) { + if (!filterDirectives || this.hasOpcode(line, inNvccCode) || definesFunction) { // Only count a label as used if it's used by an opcode, or else we're not filtering directives. for (const label of match) labelsUsed[label] = true; } else { // If we have a current label, then any subsequent opcode or data definition's labels are referred to // weakly by that label. const isDataDefinition = !!this.dataDefn.test(line); - const isOpcode = this.hasOpcode(line, false); + const isOpcode = this.hasOpcode(line, inNvccCode); if (isDataDefinition || isOpcode) { for (const currentLabel of currentLabelSet) { if (inFunction && isDataDefinition) { diff --git a/test/filters-cases/nvcc-example.asm.directives.approved.txt b/test/filters-cases/nvcc-example.asm.directives.approved.txt index 29bc86943..ac059a9a7 100644 --- a/test/filters-cases/nvcc-example.asm.directives.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.approved.txt @@ -156,7 +156,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -299,6 +307,7 @@ } ], "labelDefinitions": { + "BB0_2": 42, "entry": 11 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.comments.approved.txt b/test/filters-cases/nvcc-example.asm.directives.comments.approved.txt index 7832d67a7..7ec8259dd 100644 --- a/test/filters-cases/nvcc-example.asm.directives.comments.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.comments.approved.txt @@ -106,7 +106,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -249,6 +257,7 @@ } ], "labelDefinitions": { + "BB0_2": 32, "entry": 1 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.labels.approved.txt b/test/filters-cases/nvcc-example.asm.directives.labels.approved.txt index 0d0f1e04b..ac059a9a7 100644 --- a/test/filters-cases/nvcc-example.asm.directives.labels.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.labels.approved.txt @@ -156,7 +156,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -273,6 +281,11 @@ "source": null, "text": "" }, + { + "labels": [], + "source": null, + "text": "BB0_2:" + }, { "labels": [], "source": { @@ -294,6 +307,7 @@ } ], "labelDefinitions": { + "BB0_2": 42, "entry": 11 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.labels.comments.approved.txt b/test/filters-cases/nvcc-example.asm.directives.labels.comments.approved.txt index d497ddba6..7ec8259dd 100644 --- a/test/filters-cases/nvcc-example.asm.directives.labels.comments.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.labels.comments.approved.txt @@ -106,7 +106,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -223,6 +231,11 @@ "source": null, "text": "" }, + { + "labels": [], + "source": null, + "text": "BB0_2:" + }, { "labels": [], "source": { @@ -244,6 +257,7 @@ } ], "labelDefinitions": { + "BB0_2": 32, "entry": 1 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.approved.txt b/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.approved.txt index d497ddba6..7ec8259dd 100644 --- a/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.approved.txt @@ -106,7 +106,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -223,6 +231,11 @@ "source": null, "text": "" }, + { + "labels": [], + "source": null, + "text": "BB0_2:" + }, { "labels": [], "source": { @@ -244,6 +257,7 @@ } ], "labelDefinitions": { + "BB0_2": 32, "entry": 1 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt b/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt index ae32429b3..8322274e6 100644 --- a/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.labels.comments.library.dontMaskFilenames.approved.txt @@ -111,7 +111,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -240,6 +248,11 @@ "source": null, "text": "" }, + { + "labels": [], + "source": null, + "text": "BB0_2:" + }, { "labels": [], "source": { @@ -262,6 +275,7 @@ } ], "labelDefinitions": { + "BB0_2": 32, "entry": 1 } } diff --git a/test/filters-cases/nvcc-example.asm.directives.library.approved.txt b/test/filters-cases/nvcc-example.asm.directives.library.approved.txt index 29bc86943..ac059a9a7 100644 --- a/test/filters-cases/nvcc-example.asm.directives.library.approved.txt +++ b/test/filters-cases/nvcc-example.asm.directives.library.approved.txt @@ -156,7 +156,15 @@ "text": " setp.ge.s32 %p1, %r1, %r2;" }, { - "labels": [], + "labels": [ + { + "name": "BB0_2", + "range": { + "endCol": 30, + "startCol": 25 + } + } + ], "source": { "column": 5, "file": "/tmp/moo.cu", @@ -299,6 +307,7 @@ } ], "labelDefinitions": { + "BB0_2": 42, "entry": 11 } }