Files
arti 739e48d8dd M9.4: document the final M9 state and full gate sweep
Record the two-tier counts, 22 flips, four-phase divide evidence, DWARF v5/rnglists gate and the M9/M10 boundary. The Generic sweep now classifies target asm-parser 'invalid instruction mnemonic' errors as unsupported for two x86-asm tests exposed by the inline-asm r support.
2026-11-17 07:26:49 +00:00

286 lines
11 KiB
Bash
Executable File

#!/bin/sh
# M5 CodeGen/Generic compile-only no-crash sweep.
#
# scripts/tests/m5/generic.sh
#
# Phase 1 (allowlist gate): compile each file in generic-allowlist.txt with
# llc -march=tms34010 -filetype=asm -O0
# and require exit 0 and a non-empty asm file. The allowlist is a small,
# curated integer/control/load-store/call/PHI set; it is not a claim that every
# Generic test is runnable, only that these compile cleanly.
#
# Phase 2 (broad sweep): compile every .ll file under the LLVM
# test/CodeGen/Generic tree and classify each result:
#
# pass exit 0 and a non-empty .s
# unsupported a clear LLVM/target diagnostic (Cannot select, an explicit
# M2/TMS34010 rejection, a missing libcall, an inline-asm
# constraint failure), even when LLVM exits through
# report_fatal_error()
# crash signal/abort/assertion/timeout, or any failure without a
# recognized diagnostic
#
# Every `unsupported` row must be recorded with a reason in
# generic-expected-fail.txt. A crash is a regression and is never a skip:
# it fails this gate even if the manifest names the test. The report is
# written to build/m5-generic/generic-report.txt.
#
# This is a compile-only sweep. Hand-written Generic IR GEPs are
# byte-oriented and the target tms-clang bit-address scaling does not apply,
# so executing the output is out of scope.
#
# Overridable: TMS_LLC LLVM_BIN GENERIC_SRC M5_WORK GENERIC_TIMEOUT
# GENERIC_ALLOWLIST GENERIC_MANIFEST
set -eu
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
HERE=$(cd "$(dirname "$0")" && pwd)
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
GENERIC_SRC=${GENERIC_SRC:-$ROOT/build/llvm-clean/llvm/test/CodeGen/Generic}
M5_WORK=${M5_WORK:-$ROOT/build/m5-generic}
# M5_WORK is removed below; reject paths that could escape their intended
# build directory or name the filesystem root.
case $M5_WORK in
'' | / | . | ..)
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK'" >&2
exit 1
;;
*/../* | */.. | ../* | */./* | */.)
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK' (contains . or ..)" >&2
exit 1
;;
esac
# 2010-11-04-BigByval is intentionally expensive upstream (a 128 KiB byval
# copy; PR7170). It takes ~6 minutes here but does finish, so the timeout is
# generous enough not to misclassify it while still catching a real hang.
GENERIC_TIMEOUT=${GENERIC_TIMEOUT:-900}
ALLOWLIST=${GENERIC_ALLOWLIST:-$HERE/generic-allowlist.txt}
MANIFEST=${GENERIC_MANIFEST:-$HERE/generic-expected-fail.txt}
REPORT=$M5_WORK/generic-report.txt
fail() {
echo "M5 generic: FAIL: $*" >&2
exit 1
}
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
[ -d "$GENERIC_SRC" ] || fail "missing Generic test tree: $GENERIC_SRC"
GENERIC_SRC=$(cd "$GENERIC_SRC" && pwd)
command -v timeout >/dev/null 2>&1 || fail "timeout(1) is required"
rm -rf "$M5_WORK"
mkdir -p "$M5_WORK/allowlist" "$M5_WORK/sweep"
# The first stderr line, with CRs stripped and long diagnostics truncated, is
# enough for a report row.
detail() {
sed -n '1{s/\r$//;p;}' "$1" 2>/dev/null | cut -c1-200
}
# Print the classification reason for a non-passing result, or nothing when
# stderr has no recognized diagnostic.
failure_reason() {
err=$1
line=$(detail "$err")
if grep -Eq 'LLVM ERROR: Cannot select:' "$err"; then
printf 'target cannot select IR node: %s\n' \
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
elif grep -Eq 'LLVM ERROR: (TMS34010|M2)([: ]|$)' "$err"; then
printf 'target rejection: %s\n' \
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
elif grep -Fq 'LLVM ERROR: unsupported library call operation' "$err"; then
printf 'missing libcall lowering (floats/vectors are deferred to M6)\n'
elif grep -Fq 'LLVM ERROR: Could not match memory address' "$err"; then
printf 'inline asm memory constraint is not supported\n'
elif grep -Fq "error: could not allocate output register for constraint" "$err"; then
printf 'inline asm register constraint cannot be allocated\n'
elif grep -Fq 'error: unexpected token' "$err"; then
printf 'inline asm syntax is not supported by the TMS34010 parser\n'
elif grep -Fq 'error: invalid instruction mnemonic' "$err"; then
printf 'inline asm text is not TMS34010 assembly\n'
elif grep -Fq 'fast-math-flags specified for call' "$err"; then
printf 'IR verifier rejects the input (fast-math flags on an integer call)\n'
fi
}
# classify_one OUT ERR RC: print "pass|unsupported|crash<TAB>detail".
classify_one() {
out=$1
err=$2
rc=$3
if [ "$rc" -eq 0 ]; then
if [ -s "$out" ]; then
printf 'pass\tasm %s bytes\n' "$(wc -c < "$out" | tr -d ' ')"
else
printf 'crash\tllc exited 0 but produced an empty asm file\n'
fi
return
fi
if grep -Eq 'Assertion .* failed' "$err"; then
printf 'crash\tassertion: %s\n' "$(detail "$err" | cut -c1-160)"
return
fi
# Timeout(1) uses 124 for SIGTERM and 137 for SIGKILL. Keep both as
# crashes, but do not pretend SIGKILL is necessarily a timeout: it can be
# the OOM killer. Only 134 (SIGABRT from report_fatal_error) is the
# clear-diagnostic carve-out; any other signal is a crash even if a
# diagnostic was printed before it.
if [ "$rc" -eq 124 ]; then
printf 'crash\ttimeout after %ss\n' "$GENERIC_TIMEOUT"
return
fi
if [ "$rc" -eq 137 ]; then
printf 'crash\tkilled by signal 9 (SIGKILL; possibly OOM)\n'
return
fi
if [ "$rc" -ge 128 ] && [ "$rc" -ne 134 ]; then
sig=$((rc - 128))
if [ "$sig" -eq 0 ]; then
printf 'crash\texit 128 (signal range, no signal number)\n'
else
printf 'crash\tkilled by signal %s\n' "$sig"
fi
return
fi
reason=$(failure_reason "$err")
if [ -n "$reason" ]; then
printf 'unsupported\t%s\n' "$reason"
elif [ "$rc" -eq 134 ]; then
printf 'crash\tabort (SIGABRT) with no recognized diagnostic: %s\n' \
"$(detail "$err")"
else
printf 'crash\texit %s: %s\n' "$rc" "$(detail "$err")"
fi
}
# --- Phase 1: allowlist gate -------------------------------------------------
[ -f "$ALLOWLIST" ] || fail "no allowlist: $ALLOWLIST"
allow_total=0
while IFS= read -r name; do
case $name in
''|\#*) continue ;;
esac
allow_total=$((allow_total + 1))
src=$GENERIC_SRC/$name.ll
[ -f "$src" ] || fail "allowlist entry has no source: $src"
flat=$(printf '%s' "$name" | tr '/' '_')
out=$M5_WORK/allowlist/$flat.s
err=$M5_WORK/allowlist/$flat.err
set +e
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
"$src" -o "$out" 2> "$err"
rc=$?
set -e
[ "$rc" -eq 0 ] || fail "allowlist $name: llc exited $rc: $(detail "$err")"
[ -s "$out" ] || fail "allowlist $name: empty asm"
done < "$ALLOWLIST"
[ "$allow_total" -gt 0 ] || fail "generic-allowlist.txt is empty"
echo "M5 generic allowlist: PASS files=$allow_total"
# --- Phase 2: broad no-crash sweep ------------------------------------------
total=0
pass=0
unsupported=0
crash=0
: > "$M5_WORK/unsupported.txt"
{
echo "# M5 CodeGen/Generic compile-only sweep"
echo "# llc: $TMS_LLC"
echo "# flags: -march=tms34010 -filetype=asm -O0"
echo "# timeout: ${GENERIC_TIMEOUT}s"
echo "# rows: status<TAB>test<TAB>detail"
} > "$REPORT"
find "$GENERIC_SRC" -type f -name '*.ll' | sort > "$M5_WORK/tests.txt"
[ -s "$M5_WORK/tests.txt" ] || fail "no Generic .ll files under $GENERIC_SRC"
while IFS= read -r src; do
rel=${src#"$GENERIC_SRC"/}
name=${rel%.ll}
total=$((total + 1))
# Keep the report name relative to the Generic tree (subdirectories
# included) but use a flat, unique work file per test.
stem=$(basename "$src" .ll)
out=$M5_WORK/sweep/$total-$stem.s
err=$M5_WORK/sweep/$total-$stem.err
set +e
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
"$src" -o "$out" 2> "$err"
rc=$?
set -e
result=$(classify_one "$out" "$err" "$rc")
status=${result%% *}
why=${result#* }
case $status in
pass)
pass=$((pass + 1))
;;
unsupported)
unsupported=$((unsupported + 1))
printf '%s\n' "$name" >> "$M5_WORK/unsupported.txt"
;;
crash)
crash=$((crash + 1))
echo "M5 generic: CRASH $name: $why" >&2
;;
*)
fail "internal classification error for $name: $result"
;;
esac
printf '%s\t%s\t%s\n' "$status" "$name" "$why" >> "$REPORT"
done < "$M5_WORK/tests.txt"
{
echo "# total $total pass $pass unsupported $unsupported crash $crash"
} >> "$REPORT"
# --- Manifest check ----------------------------------------------------------
# Every unsupported row needs a reason, and a manifest row may not name a
# passing test (stale) or a crash (a crash is never a known failure).
[ -f "$MANIFEST" ] || fail "no expected-fail manifest: $MANIFEST"
: > "$M5_WORK/manifest.txt"
while IFS=$(printf '\t') read -r name reason; do
case $name in
''|\#*) continue ;;
esac
[ -n "${reason:-}" ] || fail "manifest entry '$name' has no reason"
[ -f "$GENERIC_SRC/$name.ll" ] || fail "manifest entry has no source: $name.ll"
if grep -Fxq "$name" "$M5_WORK/unsupported.txt"; then
printf '%s\n' "$name" >> "$M5_WORK/manifest.txt"
else
row=$(awk -F '\t' -v n="$name" '$2 == n { print $1 }' "$REPORT")
case $row in
pass)
fail "manifest entry '$name' now passes; remove it from the manifest"
;;
crash)
fail "manifest entry '$name' crashes; a crash is not a known failure"
;;
*)
fail "manifest entry '$name' is not in the sweep"
;;
esac
fi
done < "$MANIFEST"
sort -o "$M5_WORK/unsupported.txt" "$M5_WORK/unsupported.txt"
sort -o "$M5_WORK/manifest.txt" "$M5_WORK/manifest.txt"
listed=$(comm -23 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
[ -z "$listed" ] || fail "manifest names a non-unsupported test: $listed"
missing=$(comm -13 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
if [ -n "$missing" ]; then
echo "M5 generic: unsupported tests with no manifest reason:" >&2
echo "$missing" | sed 's/^/ /' >&2
fail "record every unsupported test in generic-expected-fail.txt"
fi
[ "$total" -gt 0 ] || fail "no Generic tests found"
[ "$crash" -eq 0 ] || fail "$crash Generic test(s) crashed"
[ "$pass" -gt 0 ] || fail "no Generic test passed"
echo "M5 generic sweep: PASS total=$total pass=$pass unsupported=$unsupported crash=$crash"
echo "M5 generic: report $REPORT"