Skip to content

Commit

Permalink
Handle ir and machine functions separately in OptPipeline (#5902)
Browse files Browse the repository at this point in the history
This patch makes a small change in how functions are handled while
parsing LLVM opt pipeline output. Specifically, it differentiates
between IR function and machine function, and while checking for the
close of function, it only checks if the corresponding function is open.

This was needed because in some targets like hexagon, the machine
functions could contain `BUNDLE`s as part of the dump and `BUNDLE`s are
also represented with opening and closing braces ({}). This was causing
assertion because the close brace for a BUNDLE was considered to be a IR
function close statement.
  • Loading branch information
quic-sanirudh committed Jan 8, 2024
1 parent d811013 commit c3f8f86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ From oldest to newest contributor, we would like to thank:
- [Rupert Tombs](https://github.com/Rupt)
- [Andrew Brey](https://github.com/andrewbrey)
- [Weile Wei](https://github.com/weilewei)
- [Anirudh Sundar Subramaniam](https://github.com/quic-sanirudh)
14 changes: 11 additions & 3 deletions lib/parsers/llvm-pass-dump-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class LlvmPassDumpParser {
functionDefine: RegExp;
machineFunctionBegin: RegExp;
functionEnd: RegExp;
machineFunctionEnd: RegExp;
//label: RegExp;
//instruction: RegExp;

Expand Down Expand Up @@ -126,8 +127,10 @@ export class LlvmPassDumpParser {
// `define internal void @__cxx_global_var_init.1() #0 section ".text.startup" {`
this.functionDefine = /^define .+ @([\w.]+|"[^"]+")\(.+$/;
this.machineFunctionBegin = /^# Machine code for function ([\w$.]+):.*$/;
// Functions end with either a closing brace or "# End machine code for function _Z3fooi."
this.functionEnd = /^(?:}|# End machine code for function ([\w$.]+).)$/;
// IR Functions end with either a closing brace
this.functionEnd = /^}$/;
// Machine functions end like "# End machine code for function _Z3fooi."
this.machineFunctionEnd = /^# End machine code for function ([\w$.]+).$/;
// Either "123:" with a possible comment or something like "bb.3 (%ir-block.13):"
//this.label = /^(?:\d+:(\s+;.+)?|\w+.+:)$/;
//this.instruction = /^\s+.+$/;
Expand Down Expand Up @@ -194,6 +197,7 @@ export class LlvmPassDumpParser {
name: string;
lines: ResultLine[];
} | null = null;
let isMachineFunctionOpen: boolean = false;
for (const line of dump.lines) {
const irFnMatch = line.text.match(this.functionDefine);
const machineFnMatch = line.text.match(this.machineFunctionBegin);
Expand All @@ -206,6 +210,7 @@ export class LlvmPassDumpParser {
name: (irFnMatch || machineFnMatch)![1],
lines: [line], // include the current line
};
isMachineFunctionOpen = !!machineFnMatch;
} else if (line.text.startsWith('; Preheader:')) {
// loop dump
// every line in this dump should be part of the loop, exit condition will be end of the for loop
Expand All @@ -216,7 +221,10 @@ export class LlvmPassDumpParser {
};
} else {
// close function
if (this.functionEnd.test(line.text.trim())) {
if (
(!isMachineFunctionOpen && this.functionEnd.test(line.text.trim())) ||
(isMachineFunctionOpen && this.machineFunctionEnd.test(line.text.trim()))
) {
// if not currently in a function
assert(func);
const {name, lines} = func;
Expand Down

0 comments on commit c3f8f86

Please sign in to comment.