Skip to content

Commit 021294e

Browse files
committed
llvm/utils/imisched.py: Accept input from stdin
This allows something like: `llc test.ll --debug-only=machine-scheduler 2>&1 | imisched.py -`
1 parent 6931806 commit 021294e

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

llvm/test/CodeGen/AIE/aie2/end-to-end/Conv2D-red.ll

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
;
77
; (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
88
; RUN: llc -O2 -mtriple=aie2 --enable-pipeliner=0 %s -o - | FileCheck %s --check-prefix=ASM
9+
; RUN: llc -O2 -mtriple=aie2 --enable-pipeliner=0 %s -o - --debug-only=machine-scheduler \
10+
; RUN: 2>&1 | %imisched -d - \
11+
; RUN: | FileCheck %s --check-prefix=SCHED-DUMP
912

1013

1114
; This is a reduced version of the Conv2D_0 MLLib benchmark which only contains
@@ -23,6 +26,13 @@
2326
; The test is meant as a quick way to spot QoR regressions, but if the ASM is
2427
; too unstable, we can use different FileCheck lines.
2528

29+
30+
; SCHED-DUMP: Region: conv2d.loop.nest:bb.2
31+
; SCHED-DUMP: Region: conv2d.loop.nest:bb.4
32+
; SCHED-DUMP: Region: conv2d.loop.nest:bb.3
33+
; SCHED-DUMP: Region: conv2d.loop.nest:bb.1
34+
; SCHED-DUMP: Region: conv2d.loop.nest:bb.0
35+
2636
define dso_local void @conv2d.loop.nest(ptr %add.ptr6.i51, ptr %add.ptr5, ptr %cond, ptr %cond.i50, <16 x i32> %0, i32 %cond67.i79, i20 %idx.ext.i.i81, i20 %idx.ext.i404.i, i20 %idx.ext.i410.i, i20 %idx.ext.i434.i85, i32 %1, i20 %2, i20 %3, i20 %4, i20 %5, i20 %6, i32 %7, i32 %8, i32 %or9.i.i.i.i.i96, i32 %9, i20 %idx.ext.i422.i82, i20 %10, i20 %11, i20 %12, i20 %13, i20 %14, i20 %15, i20 %16, i20 %17, i20 %18, i20 %19, i20 %20, i20 %21, i20 %22, i20 %23, i32 %conv192.i107, i20 %24, i20 %idx.ext.i428.i, i20 %25, i20 %26, i20 %27, i32 %28) #1 {
2737
; ASM-LABEL: conv2d.loop.nest:
2838
; ASM: .p2align 4

llvm/test/CodeGen/AIE/aie2/lit.local.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
#
77
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates
8+
import os
9+
810
config.substitutions.insert(0, ('%last-mi-pass', 'machinemoduleinfo'))
911
config.substitutions.insert(0, ('%topdown-single', '--issue-limit=1 --aie-bottomup-cycles=0'))
1012
config.substitutions.insert(0, ('%topdown-multi', '--issue-limit=6 --aie-bottomup-cycles=0'))
13+
14+
imisched_path = os.path.join(config.llvm_src_root, 'utils', 'imisched.py')
15+
config.substitutions.insert(0, ('%imisched', f"{config.python_executable} {imisched_path}"))

llvm/utils/imisched.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,35 @@
55
# (c) Copyright 2024 Advanced Micro Devices, Inc. or its affiliates
66

77
import argparse
8+
import io
9+
import os
10+
import sys
11+
812
from mischedutils import schedlogparser
913

1014

1115
def main():
1216
parser = argparse.ArgumentParser()
13-
parser.add_argument("sched_log")
14-
parser.add_argument("-d", "--dump", action="store_true")
17+
parser.add_argument("sched_log", help="Log file to parse, or '-' to read stdin")
18+
parser.add_argument(
19+
"-d", "--dump", action="store_true", help="dump the sched regions"
20+
)
1521
args = parser.parse_args()
1622

1723
regions = []
18-
with open(args.sched_log, "r") as file:
19-
regions = schedlogparser.process_log(file.read())
24+
if args.sched_log != "-":
25+
if not sys.__stdin__.isatty():
26+
print(
27+
"Error: cannot get data from stdin and a file at the same time",
28+
file=sys.stderr,
29+
)
30+
exit(1)
31+
print(f"Parsing '{args.sched_log}'...")
32+
with open(args.sched_log, "r") as file:
33+
regions = schedlogparser.process_log(file.read())
34+
else:
35+
print("Parsing stdin...")
36+
regions = schedlogparser.process_log(sys.__stdin__.read())
2037

2138
if args.dump:
2239
for region in regions:
@@ -29,6 +46,10 @@ def main():
2946
else:
3047
from mischedutils import interactive_sched
3148

49+
# Make sure Textual gets a fresh stdin for user keyboard inputs.
50+
sys.__stdin__.flush()
51+
sys.__stdin__ = io.TextIOWrapper(io.FileIO(os.open(os.ctermid(), os.O_RDONLY)))
52+
3253
app = interactive_sched.InteractiveMISchedApp(regions)
3354
app.run()
3455

0 commit comments

Comments
 (0)