Skip to content

Commit

Permalink
Fix unused label filter for CUDA PTX output (#3717)
Browse files Browse the repository at this point in the history
- Previously this filter did not correctly identify used labels in
  CUDA PTX output, which caused it to remove important labels.
  • Loading branch information
benbarsdell committed May 26, 2022
1 parent bf061d8 commit d9151b9
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/parsers/asm-parser.js
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion test/filters-cases/nvcc-example.asm.directives.approved.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9151b9

Please sign in to comment.