Skip to content

Commit 574abdb

Browse files
authored
[Script] Helper for dumping assembly with target-feature (#1080)
1 parent 8136608 commit 574abdb

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/debug/dump_assembly.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(realpath $(dirname $0)/..)
4+
source ${SCRIPT_DIR}/ci/common.sh
5+
6+
TMP_DIR=$(mktemp -d)
7+
ROOT_DIR=$(git_root)
8+
BIN_DIR=$ROOT_DIR/build/bin
9+
TPP_RUN="${BIN_DIR}/tpp-run"
10+
check_program ${TPP_RUN}
11+
OBJDUMP=llvm-objdump
12+
check_program ${OBJDUMP}
13+
DUMP_FILE="$(mktemp).o"
14+
15+
# "Parse" the command line arguments for clues about the asm name
16+
# Example:
17+
# $ dump_assembly.sh matmul.mlir -e entry -entry-point-result=void --target-feature=avx512
18+
for arg in "$@"; do
19+
if [[ "$arg" =~ \.mlir ]]; then
20+
MLIR_FILE=$(realpath "$arg")
21+
continue
22+
fi
23+
if [[ "$arg" =~ target-feature=(.*) ]]; then
24+
TARGET_FEATURE=${BASH_REMATCH[1]}
25+
continue
26+
fi
27+
done
28+
if [ -z "${MLIR_FILE}" ]; then
29+
echo "ERROR: No MLIR file specified!"
30+
exit 1
31+
fi
32+
if [ -z "${TARGET_FEATURE}" ]; then
33+
ASM_FILE=$(basename ${MLIR_FILE%.mlir}.s)
34+
else
35+
ASM_FILE=$(basename ${MLIR_FILE%.mlir}-${TARGET_FEATURE}.s)
36+
fi
37+
38+
# Compile and dump the assembly
39+
TPP_RUN_CMDLINE="${TPP_RUN} $@ --dump-object-file --object-filename=${DUMP_FILE}"
40+
41+
echo "Running the program:"
42+
echo " $ \"${TPP_RUN_CMDLINE}\""
43+
${TPP_RUN_CMDLINE} > /dev/null
44+
45+
if [ $? -ne 0 ]; then
46+
echo "Error while running the program!"
47+
exit 1
48+
fi
49+
50+
# Dump the assembly and remove the temporary object file
51+
OBJDUMP_COMMAND="${OBJDUMP} -d ${DUMP_FILE}"
52+
53+
echo "Dumping the assembly:"
54+
echo " $ \"${OBJDUMP_COMMAND} > ${ASM_FILE}\""
55+
${OBJDUMP_COMMAND} > ${ASM_FILE}
56+
57+
if [ $? -ne 0 ]; then
58+
echo "Error dumping the assembly!"
59+
echo "Object file: ${DUMP_FILE}"
60+
exit 1
61+
fi
62+
63+
rm -f ${DUMP_FILE}

0 commit comments

Comments
 (0)