Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48091850e1 | ||
|
|
9694497548 | ||
|
|
e609a4b84e | ||
|
|
abbee9f42f | ||
|
|
d73dc9c020 | ||
|
|
5daf528128 | ||
|
|
48eb9bd248 | ||
|
|
f4442e8f6f | ||
|
|
848a570b4f | ||
|
|
16a7244bf6 | ||
|
|
2a95b71509 | ||
|
|
98eea9feb0 | ||
|
|
41ff4f68d2 |
No files matched your search
@@ -3,12 +3,18 @@
|
||||
A modern C toolchain for the DEC VT1200 / TI TMS34010, built as a small fork of
|
||||
upstream LLVM.
|
||||
|
||||
**Status: M9 complete (M9.4).** Branch `m9` is the current milestone branch and
|
||||
the repository default on both repositories; `m8` is the previous snapshot.
|
||||
The M9 code state is project `24eca1c` and compiler `bec449573fe3`; this
|
||||
documentation update rides on top of it. Repository policy: each milestone
|
||||
branch is promoted to the default immediately after its clean final review,
|
||||
and the previous default stays as a snapshot.
|
||||
**Status: M10 complete (Phase 2 — the native clang pipeline).** Branch `m10` is
|
||||
the repository default on both repositories (the promotion lands with this
|
||||
push; `m9` becomes the previous snapshot). Repository
|
||||
policy: each milestone branch is promoted to the default immediately after its
|
||||
clean final review, and the previous default stays as a snapshot. M10 makes
|
||||
native `clang --target=tms34010 -c` correct for pointer code at `-O0` and `-O2`
|
||||
with no extra flags and no wrapper — the
|
||||
TMS34010 target owns both the bit-address transform and its compile defaults —
|
||||
and `-O0` objects are byte-identical to the M9 path. See "What M10 provides".
|
||||
The M10 code state (project `9694497`, compiler `eb28be2faf8d`) is the tip
|
||||
before this documentation commit; the M9 code state (project `24eca1c`,
|
||||
compiler `bec449573fe3`) is the previous snapshot.
|
||||
M9.1 closes the two highest-value remaining conformance classes: vector `.data`
|
||||
initializers (exact element bytes in the raw GSPA and native TI-COFF paths) and
|
||||
inline-asm `r`/`=r`/`&r` constraints (the A-register classes). M9.2 replaces
|
||||
@@ -27,14 +33,16 @@ MAME divide measurement is fast **88**, slow **3,302**, wide **221** and div32
|
||||
**1.8×** for div32 versus the two-DIVU wide phase, status
|
||||
`600D600D`, checksums `000000011E6F9AB4`/`00000000007512AE`/
|
||||
`F56810CFEDA9D656`/`00002C61C63842EE`. The shipped tiers report lit
|
||||
**129/129** (125 CodeGen + 4 MC; M9 adds nine CodeGen tests), clang **5/5**,
|
||||
M5 c-torture **79/79** at `-O0` and `-O2`, M6 c-torture **79** at `-O0` plus
|
||||
**132/132** (128 CodeGen + 4 MC) plus clang **10** (8 CodeGen + 1 Driver + 1
|
||||
Sema) = **142**, M5 c-torture **79/79** at `-O0` and `-O2`, M6 c-torture **79**
|
||||
at `-O0` plus
|
||||
the **20**-test bounded `-O2` subset, shipped c-testsuite **48 pass / 172 skip
|
||||
/ 220**, and Generic **197 = 151 pass / 46 unsupported / 0 crash**. The real
|
||||
/ 220**, and Generic **197 = 151 pass / 46 unsupported / 0 crash**. The serial
|
||||
M0–M8 gate list is **56/56 PASS**; the real
|
||||
VT1200 run remains **DEFERRED** (`VT1200_HOST` is unset;
|
||||
`scripts/tests/m7/hardware.sh` prints `HARDWARE: DEFERRED` and passes on the
|
||||
MAME-equivalent acceptance). M9 is the milestone branch; `m8` is the previous
|
||||
snapshot and stays the default until the promotion lands.
|
||||
MAME-equivalent acceptance). M10 is the milestone branch and repository default;
|
||||
`m9` is the previous snapshot.
|
||||
|
||||
M7.3 widened the validated VT1200 Xlib surface, added real
|
||||
stderr capture to the conformance runtime, and shipped the real-hardware
|
||||
@@ -102,8 +110,8 @@ boundary; the hardware run is still deferred.
|
||||
> the M0 pointer shapes: `int_diff` returns 8 and `int_diff4` returns 32,
|
||||
> and `late` carries the 24-bit addend (never 192).
|
||||
|
||||
Branch `m9` is the current milestone snapshot (M9.4) and the repository
|
||||
default; `m8` is the previous snapshot, `m7` the one before that,
|
||||
Branch `m10` is the repository default (M10); `m9` is the previous
|
||||
snapshot (M9.4), `m8` the one before that, `m7` the one before that,
|
||||
`m6` before that, `m5` before that, `m4` before that, `m3` the M3 snapshot,
|
||||
`m2` the M2 tip and `m1` the reproducible M1 snapshot.
|
||||
|
||||
@@ -121,34 +129,131 @@ default; `m8` is the previous snapshot, `m7` the one before that,
|
||||
- M7.4 plan: [`docs/superpowers/plans/2026-11-15-tms34010-m7-4-conformance-performance-and-boundary.md`](docs/superpowers/plans/2026-11-15-tms34010-m7-4-conformance-performance-and-boundary.md)
|
||||
- M8 plan: [`docs/superpowers/plans/2026-11-16-tms34010-m8-archives-dwarf-conformance-and-hardware.md`](docs/superpowers/plans/2026-11-16-tms34010-m8-archives-dwarf-conformance-and-hardware.md)
|
||||
- M9 plan: [`docs/superpowers/plans/2026-11-17-tms34010-m9-conformance-classes-debug-and-performance.md`](docs/superpowers/plans/2026-11-17-tms34010-m9-conformance-classes-debug-and-performance.md)
|
||||
- M10 plan: [`docs/superpowers/plans/2026-11-17-tms34010-m10-native-clang-pipeline.md`](docs/superpowers/plans/2026-11-17-tms34010-m10-native-clang-pipeline.md)
|
||||
- Phase 2/3 design: [`docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md`](docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md)
|
||||
- Spike: [`spike/REPORT-23.md`](spike/REPORT-23.md) (current, LLVM 23.1.5);
|
||||
[`spike/REPORT.md`](spike/REPORT.md) (historical, 19.1.7)
|
||||
|
||||
## Repositories
|
||||
|
||||
- **Compiler fork:** <https://git.wut.ee/opencode.siil.arti.ee/llvm-tms34010>
|
||||
(branch `m9`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2–M9 backend.
|
||||
Branch `m9` is the current milestone snapshot and the repository default;
|
||||
`m8` is the previous snapshot.
|
||||
Branch `m7` is before that,
|
||||
(branch `m10`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes, the M2–M9 backend and the M10 native
|
||||
pipeline (`ToolChain` + bit-address passes).
|
||||
Branch `m10` is the repository default (M10); `m9` is the previous snapshot.
|
||||
Branch `m8` is before that, `m7` is before that,
|
||||
`m6` is before that, `m5` is before
|
||||
that, `m4` is before that, branch `m3` is before that, branch `m2` is the M2
|
||||
tip and branch `tms34010` is the M1 tip and keeps the original M1 backend
|
||||
and suite.
|
||||
- **This project:** <https://git.wut.ee/opencode.siil.arti.ee/tms-c-compiler>
|
||||
(branch `m9`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2–M9 harnesses and the conformance tier.
|
||||
Branch `m9` is the current milestone snapshot and the repository default;
|
||||
`m8` is the previous snapshot.
|
||||
Branch `m7` is before that, `m6` is before
|
||||
(branch `m10`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2–M10 harnesses and the conformance tier.
|
||||
Branch `m10` is the repository default (M10); `m9` is the previous snapshot.
|
||||
Branch `m8` is before that, `m7` is before that, `m6` is before
|
||||
that, `m5` is before that, `m4` is before that, `m3` is before that, `m2` is
|
||||
the M2 snapshot and `m1` is the reproducible M1 snapshot, including the
|
||||
retired M1 harness.
|
||||
|
||||
The compiler fork is the canonical source for all target code. `patches/llvm`
|
||||
here is a **frozen M0 mirror** used by the default upstream+patches build;
|
||||
M2–M9 do not change it.
|
||||
M2–M9 do not change it; M10 adds `patches/llvm/0005-tms34010-toolchain.patch`
|
||||
(the `ToolChain` and its registration).
|
||||
|
||||
## What M10 provides
|
||||
|
||||
M10 is Phase 2: the native clang pipeline. Native `clang --target=tms34010 -c`
|
||||
is now semantically correct with **no flags and no wrapper** — the TMS34010
|
||||
target owns both the bit-address transform and its compile defaults. Full
|
||||
target rules are in
|
||||
[`build/llvm-clean/TMS34010.md`](build/llvm-clean/TMS34010.md) ("M10 state");
|
||||
the binding design is
|
||||
[`docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md`](docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md).
|
||||
|
||||
- **The `ToolChain` and its defaults.** A dedicated
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` (a `BareMetal` subclass) is
|
||||
registered in `clang/lib/Driver/CMakeLists.txt` and `Driver.cpp`, so
|
||||
`tms34010-unknown-none` and plain `--target=tms34010` resolve to it. It
|
||||
supplies this target's compile defaults: `-ffreestanding`, `-fno-builtin`,
|
||||
`-mllvm -replexitval=never`, `-disable-O0-optnone`, and no system include
|
||||
directories (`-I` still works; builtin headers stay reachable via
|
||||
`-resource-dir`). It is exported as
|
||||
`patches/llvm/0005-tms34010-toolchain.patch` and has no link job yet —
|
||||
`-c`/`-S` are the M10 surface; M11 extends the same file with the link job.
|
||||
- **The pipeline.** `TMS34010TargetMachine::registerPassBuilderCallbacks`
|
||||
registers the bit-address passes: at pipeline start the opaque
|
||||
`@__tms_bitptr(i32, ptr)` barrier runs (and, at `-O0`, the lowering
|
||||
immediately after it); at optimizer-last the scale → lower → final InstCombine
|
||||
runs (gated to `Level != O0`). A `"tms.bitaddr"` module flag (absent → `1` →
|
||||
`2`) makes the barrier idempotent, and a legacy lowering pass in
|
||||
`TMS34010PassConfig::addISelPrepare` is the codegen safety net for IR that
|
||||
still carries barrier calls. `llc` keeps its M9 IR contract (it builds no
|
||||
new-PM pipeline) and `opt` builds no `TargetMachine`, so both are unaffected.
|
||||
- **`-O0` byte identity.** `scripts/tests/m10/equivalence.sh` proves native
|
||||
`clang --target=tms34010 -O0 [-g] -c` objects are byte-identical to the frozen
|
||||
M9 oracle (`legacy-tms-clang`) across the whole 23-file corpus
|
||||
(**46/46** at `-O0` and `-O0 -g`); an `-O2` asm-shape phase pins the
|
||||
aggregate-return and
|
||||
switch shapes. `scripts/tests/m10/bitaddr-idempotent.sh` proves the flag-2
|
||||
re-entry path.
|
||||
- **`tms-clang` becomes a flag mapper.** `scripts/tms-clang` keeps its argument
|
||||
parser and the `TMS_CLANG`/`TMS_CLANG_EXTRA_FLAGS` overrides, then execs
|
||||
`clang --target=tms34010` with `-O0`/`-O2`, `-g`, `-I` and
|
||||
`-S -emit-llvm -o OUT.ll`. No `tms-bitaddr`, no `opt`, no awk static-variadic
|
||||
guard. The four gates that traced its internals (`m4/mul.sh`, `m5/jr.sh`,
|
||||
`m5/policy.sh`, `m3/run.sh`) now assert the same invariants at the driver
|
||||
seam.
|
||||
- **Gate edits.** `m5/jr.sh` re-pins the linked `.text` size: native `-O2`
|
||||
initially tightened it to 850 bytes, but that size was measured while the
|
||||
`-O2` path still misread bit offsets as byte offsets (DAGCombiner re-chained
|
||||
a memcpy source load and the f64 MSW store past the stores producing them)
|
||||
and folded f32/f64 constants to IEEE bits; the debug-cycle correctness fixes
|
||||
(below) cost instructions and restore the M9 legacy value of **910** bytes,
|
||||
which `m5/jr.sh` now pins. The JR count (14) and the zero-displacement JA
|
||||
count are unchanged.
|
||||
- **Breadth proof.** Because `tms-clang` is the thin wrapper, the fresh
|
||||
full-suite run (`build/m10-bare`) now compiles every row through native
|
||||
clang — so it is the breadth proof for the new pipeline, not just a
|
||||
regression check. The total is unchanged at **1,912 = 1,618 pass / 294 skip /
|
||||
0 fail / 0 crash**.
|
||||
- **The `-O2` bit-address aliasing fix — three causes.** The sweep found two
|
||||
`-O2`-only miscompiles, and fixing them uncovered a third:
|
||||
1. **f32/f64 constant folding.** `-O2` folded `bitcast(float C to i32)` /
|
||||
IPSCCP results to IEEE bits before the late float-constant pass could emit
|
||||
the GSP encodings — fixed by protecting f32/f64 constants before the
|
||||
optimizer (`TMS34010LowerFloatConstantsPass` at pipeline start for `-O1`+
|
||||
loads them from GSP globals as volatile).
|
||||
2. **`BaseIndexOffset` byte misread.** DAGCombiner's `BaseIndexOffset` read
|
||||
bit addresses as byte offsets and reordered memory operations (the
|
||||
aggregate marker-1 byte load and the f64 MSW float markers) — fixed by a
|
||||
`TMS34010ISD::BITADDR` node (selected straight to `ADDI`) at the
|
||||
target-computed offset sites, so `BaseIndexOffset` falls back to the
|
||||
byte-accurate `MachinePointerInfo`.
|
||||
3. **The underlying class.** Closing those exposed it: any address built as
|
||||
`inttoptr(add(ptrtoint, bits))` folds to a plain `ISD::ADD` on this
|
||||
32-bit-pointer target, so ordinary source pointer arithmetic was still
|
||||
miscompiled at `-O2` (reproducer: `p[0]=v; p[1]=w; ((char*)p)[5]=0x7f;`
|
||||
stored the byte before the word store). Fixed by a target intrinsic
|
||||
`llvm.tms34010.bitaddr` that lowers to `BITADDR`, now used by **every**
|
||||
runtime pointer-offset emitter: the barrier lowering, the
|
||||
aggregate/i64/narrow-mem leaves, and both GEP-scaling passes. Regression
|
||||
tests: `m10-bitaddr-chain-i64.ll`, `bitaddr-chain-o2.c`.
|
||||
A zero offset stays the base itself, so `-O0` objects are unchanged.
|
||||
`scripts/m3/run.sh` compiles `branch` with `-fno-inline` at `-O2` (not `-O0`,
|
||||
which would change the pinned condition codes) so `m3/dis-roundtrip.sh` keeps
|
||||
its `_sumto`/`_max2`/`_lt` calls. `m6/float.sh`, `m6/aggregate.sh`,
|
||||
`m6/i64.sh`, `m6/bitfield.sh`, `m6/varargs.sh` and `m6/runtime.sh` now pass at
|
||||
both `-O0` and `-O2`.
|
||||
- **Residual (documented, not reachable at `-O2`).** `scaleConstantGep` emits a
|
||||
compile-time `ConstantExpr` address, which cannot hold a call; it folds to a
|
||||
`GlobalAddress+offset`, so no runtime `ADD` exists to mis-decompose.
|
||||
- **Boundary.** M10 is complete: native `-O0` is byte-identical to M9 and
|
||||
`-O2` is correct across the shipped gates after the debug-cycle fixes above.
|
||||
M11 (Phase 3) makes the flow fully
|
||||
conventional: a committed CRT (`crt0.o` via `llvm-mc`), headers
|
||||
(`sdk/include`), a library (`libtms.a`), a sysroot, and a `tms-link` link
|
||||
job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper and
|
||||
no project variables.
|
||||
|
||||
## What M9 provides
|
||||
|
||||
@@ -1212,41 +1317,55 @@ scripts/tms-cc -L lib -l flib hello.c -o hello.coff
|
||||
conformance result block. For X11/ROM-call programs, use the M4 harness and
|
||||
`scripts/m4/x11m4.h`.
|
||||
|
||||
The existing IR-only `scripts/tms-clang` remains the gate pipeline and is
|
||||
unchanged; `tms-cc` is the user-facing driver on top of it. Native
|
||||
`clang --target=tms34010 -c` is still not semantically correct for pointer
|
||||
code because LLVM GEPs are byte-based (Phase 2).
|
||||
`scripts/tms-clang` is now a thin flag mapper over native clang: it keeps its
|
||||
argument parser and `TMS_CLANG`/`TMS_CLANG_EXTRA_FLAGS` overrides, then execs
|
||||
`clang --target=tms34010` with the requested `-O0`/`-O2`, `-g`, `-I` and
|
||||
`-S -emit-llvm -o OUT.ll`. The bit-address barrier, the compile defaults and
|
||||
the static-variadic guard all live in the target now, so the wrapper carries
|
||||
none of them. Native `clang --target=tms34010 -c` is correct for pointer code
|
||||
at `-O0` and `-O2` (M10).
|
||||
|
||||
## Run the M9 gates
|
||||
## Run the M10 gates
|
||||
|
||||
These are the documented commands on branch `m9`; all must pass. The MAME and
|
||||
These are the documented commands on branch `m10`; all must pass. The MAME and
|
||||
conformance gates are slow, share the M4 SDK image, and must run **serially**
|
||||
(no two gates at once). The M9 gate list is the
|
||||
(no two gates at once). The M10 gate list is the
|
||||
M7.1/M7.2/M7.3/M7.4/M8.1/M8.2/M5/M6 list plus the M9.1/M9.2 lit additions and
|
||||
DWARF form/rnglists gate (step 3g),
|
||||
the fresh end-to-end two-tier suite and the four-phase i64 performance gate
|
||||
(step 3f). The count
|
||||
change is lit **120 → 129** (nine new `m9-*` CodeGen tests; MC stays 4); the
|
||||
fresh full-suite total is **1,618 pass / 294 skip / 0 fail / 0 crash**.
|
||||
(step 3f), plus the M10 gates (step 3h). The serial M0–M8 gate list is
|
||||
**56/56 PASS** and the hardware gate prints `HARDWARE: DEFERRED`. The count
|
||||
change from M9 is: TMS34010 lit **129 → 132** (128 CodeGen — three new tests,
|
||||
`m10-state1-lower`, `m6-memcpy-chain` and `m10-bitaddr-chain-i64` — plus 4 MC)
|
||||
and clang **5 → 10** (8 CodeGen + 1 Driver + 1 Sema), for **142** lit in
|
||||
total. The fresh
|
||||
full-suite total is unchanged at
|
||||
**1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**.
|
||||
|
||||
```sh
|
||||
# 1. Build llc, the assembler/disassembler driver and dwarfdump
|
||||
ninja -C build/llvm-clean-build llc clang opt llvm-mc llvm-dwarfdump
|
||||
|
||||
# 2. LLVM codegen tests: 125 passed
|
||||
# (34 m2-* + 8 m3-* + 18 m4-* + 15 m5-* + 28 m6-* + 11 m7-* + 2 m8-*
|
||||
# + 9 m9-*)
|
||||
# 2. LLVM codegen tests: 128 passed
|
||||
# (34 m2-* + 8 m3-* + 18 m4-* + 15 m5-* + 29 m6-* + 11 m7-* + 2 m8-*
|
||||
# + 9 m9-* + 2 m10-*)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/llvm/test/CodeGen/TMS34010
|
||||
|
||||
# 3. MC tests: 4 passed (encodings, disassembler, round-trip, JR range)
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010
|
||||
|
||||
# 3b. Clang tests: 5 passed (the sub-byte stride Sema warning and the
|
||||
# TMS34010 CodeGen layout/ptrdiff/triple/aggregate cases)
|
||||
# 3b. Clang tests: 10 passed (8 CodeGen + the Sema subbyte-stride warning +
|
||||
# the driver tms34010-defaults.c)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/clang/test/Sema/tms34010-subbyte-stride.c \
|
||||
build/llvm-clean/clang/test/CodeGen/TMS34010
|
||||
build/llvm-clean/clang/test/CodeGen/TMS34010 \
|
||||
build/llvm-clean/clang/test/Driver/tms34010-defaults.c
|
||||
|
||||
# 3h. M10 gates (hermetic; the equivalence gate compiles the whole corpus
|
||||
# through native clang and the frozen M9 oracle)
|
||||
scripts/tests/m10/equivalence.sh # -O0 / -O0 -g byte identity + -O2 shapes
|
||||
scripts/tests/m10/bitaddr-idempotent.sh # "tms.bitaddr" flag re-entry
|
||||
|
||||
# 3a. M7.1 correctness/ABI gates (MAME; run serially)
|
||||
scripts/tests/m7/pointer-o2.sh # default -O2 p += n + natural memmove
|
||||
@@ -1278,19 +1397,19 @@ M6_LINKER=tms-link scripts/tests/m6/runtime.sh
|
||||
M6_LINKER=tms-link scripts/tests/m6/i64.sh
|
||||
# -> the M5/M6 library links accept tms-link; GSPLNK stays the default/oracle
|
||||
|
||||
# 3f. M9.4 full external suites (two-tier: bare default ~35 min; serial) and
|
||||
# 3f. full external suites (two-tier: bare default ~35 min; serial) and
|
||||
# the four-phase i64 performance gate (MAME; serial)
|
||||
scripts/m8/setup-os2.sh # once: direct 2ine + qemu-i386 fallback
|
||||
LLVM_BIN=$PWD/build/llvm-clean-build/bin \
|
||||
scripts/tests/m7/full-suite.sh --corpus all --redo --work build/m9-bare-full
|
||||
scripts/tests/m7/full-suite.sh --corpus all --work build/m10-bare
|
||||
# -> c-torture 1692 = 1408 pass / 284 skip / 0 fail / 0 crash
|
||||
# c-testsuite 220 = 210 pass / 10 skip / 0 fail / 0 crash
|
||||
# all 1912 = 1618 pass / 294 skip / 0 fail / 0 crash
|
||||
# The bare tier is the driver default (M5_CONFORMANCE_BARE=1). The explicit
|
||||
# 10-test full-loader exception list is scripts/tests/m7/full-suite.full-loader;
|
||||
# the curated M5/M6 gates below are the full-loader tier by default
|
||||
# (M5_CONFORMANCE_BARE=0). The fresh TSV/report are in build/m9-bare-full and
|
||||
# scripts/tests/m7/full-suite-report.txt.
|
||||
# (M5_CONFORMANCE_BARE=0). The fresh TSV/report are in build/m10-bare
|
||||
# (full-suite-results.tsv / full-suite-report.txt).
|
||||
scripts/tests/m7/i64div.sh # fast/slow/wide/div32 DIVU paths in MAME
|
||||
# -> M7 I64DIV PERF: PASS; fast_frames=88 slow_frames=3302 wide_frames=221
|
||||
# div32_frames=120 ratio=37.5 wide_ratio=14.9 div32_ratio=1.8
|
||||
@@ -1371,7 +1490,7 @@ The gate log prints each tier's counts; skipped tests carry a feature reason
|
||||
and are never counted as passes. The conformance tiers run serially because
|
||||
`M4_SDK` is shared; the MAME boot dominates the runtime.
|
||||
|
||||
## Run the M4 gates (branch `m4`; also green on `m5`–`m9`)
|
||||
## Run the M4 gates (branch `m4`; also green on `m5`–`m10`)
|
||||
|
||||
These are the documented commands on branch `m4`; all must pass. On branches
|
||||
`m5`–`m9`, use the M9 list above (it includes `llvm-mc`,
|
||||
@@ -2036,9 +2155,24 @@ linking in `tms-link`, multi-TU DWARF merging, the rotate/count/byte-swap
|
||||
lowering and 64/32 i64 divide path, 20 conformance flips and the final
|
||||
M8/M9 boundary. M9 is complete: vector `.data` and inline-asm `r` (22 flips),
|
||||
the DWARF v5 form gate and `.debug_rnglists`, the single-DIVU 64/32 path and
|
||||
the final M9/M10 boundary. M10 owns the remaining conformance classes, the
|
||||
pre-existing `pr63843` hang, further performance work and the real VT1200 run
|
||||
when the unit is available (the run remains **deferred**).
|
||||
the final M9/M10 boundary. M10 (Phase 2) is complete: native
|
||||
`clang --target=tms34010 -c` is correct for pointer code at `-O0` and `-O2`
|
||||
with no extra flags (the target owns the
|
||||
bit-address transform and its compile defaults), `-O0` objects are
|
||||
byte-identical to the M9 path (**46/46**), and the full suite and every gate —
|
||||
including the `-O2` float/aggregate/round-trip gates — stay green after a debug
|
||||
cycle that closed the `-O2` bit-address aliasing gap (a `BITADDR` node plus the
|
||||
`llvm.tms34010.bitaddr` intrinsic) and protected f32/f64 constants before the
|
||||
optimizer (see
|
||||
"What M10 provides"). M11 (Phase 3)
|
||||
makes the flow fully conventional — a committed CRT (`crt0.o` via `llvm-mc`),
|
||||
headers (`sdk/include`), a library (`libtms.a`), a sysroot and a `tms-link`
|
||||
link job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper
|
||||
and no project variables. The remaining genuine conformance classes
|
||||
(`blockaddress`, vector runtime, inline-asm memory constraints, nested
|
||||
functions, VLAs, sret/aggregate/variadic/float returns, libm, runtime aborts),
|
||||
the pre-existing `pr63843` hang, further performance work and the real VT1200
|
||||
run (still **deferred** until the unit is available) remain open.
|
||||
2ine r5.01 is a later speed-up for the GSPA/GSPLNK step. The compiler fork is
|
||||
canonical for target code; this project holds the plan, harness, pins and
|
||||
integration tests.
|
||||
@@ -0,0 +1,515 @@
|
||||
# TMS34010 M10 (Phase 2) — Native clang Pipeline Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make `clang --target=tms34010 -c` semantically correct for pointer code at `-O0` and `-O2` with no extra flags, by moving the bit-address barrier, the post-optimizer scaling and the barrier lowering into the TMS34010 target's own pass pipeline.
|
||||
|
||||
**Architecture:** A minimal clang `ToolChain` supplies this target's compile defaults (freestanding, no builtins, no system includes, `-replexitval=never`). The transform logic from `tools/tms-bitaddr/bitscale.cpp` is ported to new-PM module passes in `llvm/lib/Target/TMS34010/` and registered from `TMS34010TargetMachine::registerPassBuilderCallbacks`: the barrier on the pipeline-start extension point (which also lowers immediately at `-O0`), scale/lower/final-InstCombine on optimizer-last. A `"tms.bitaddr"` module flag makes repeated application impossible, and a legacy pass in `addISelPrepare` lowers any barrier calls that still reach codegen. `llc`'s IR contract is untouched because `llc` builds no new-PM pipeline.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), `llvm/lib/Target/TMS34010`, clang driver `ToolChains`, new pass manager (`PassBuilder` EP callbacks), module flags, lit/FileCheck, shell gates, MAME for runtime gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md` (§7 and §7.8 are this milestone; §8 is M11, which gets its own plan after M10 is promoted because it extends the same `ToolChain` file).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m9`/`55a0991`, compiler `m9`/`4e7d48d2717e`. Cut `m10` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. Export the driver change as `patches/llvm/0005-*.patch`.
|
||||
- No new user-visible flag may be required for correctness: `clang --target=tms34010 -O2 -c` works with no extra arguments.
|
||||
- `llc`'s IR contract is unchanged: for `i8` GEPs the byte offset is the bit offset (`m2-late-gep.ll` → `ADDI 24`).
|
||||
- `opt` behaviour is unchanged: it builds no `TargetMachine`, so no target hook fires there.
|
||||
- `clang -O0 -c` objects must be **byte-identical** to the M9 path (`scripts/tms-clang` + `llc -O0`) across the corpus. `-O2` is gated on behaviour, not bytes.
|
||||
- Existing gates stay green: lit **129/129**, clang **5/5**, the M2–M9 gate list, the two-tier full suite **1,618 pass / 294 skip / 0 fail / 0 crash**, i64div **88/3302/221/120** with checksums `000000011E6F9AB4` / `00000000007512AE` / `F56810CFEDA9D656` / `00002C61C63842EE`.
|
||||
- TI ABI, the all-stack convention, GSPLNK as the byte/symbol oracle and the two-tier harness are unchanged.
|
||||
- `-O0` and `-O2` are both first-class. A change that only holds at one level is incomplete.
|
||||
- Debug locations survive every new pass: the M9.2 gates (`scripts/tests/m9/dwarf-ranges.sh`, `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`) must pass unchanged.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **`clang -emit-llvm` output fed to `llc`** — a user's normal two-step flow must not double-transform; llc must accept the emitted IR and produce the same code as `-c` (Task 3).
|
||||
2. **Hand-written IR through `llc`** — `getelementptr i8, ptr %p, i32 24` must still be `ADDI 24`; a barrier inside llc would silently redefine every existing fixture (Task 2).
|
||||
3. **`-O0` parity with the legacy path** — byte drift here means a hidden semantic change (optnone, always-inline, an extra InstCombine) rather than a benign optimization difference (Task 4).
|
||||
4. **Ordinary loop code at `-O2`** — `IndVarSimplify`'s i33 exit-value rewrite must not resurface as a compile failure once the shell wrapper stops passing `-replexitval=never` (Task 1, Task 5).
|
||||
5. **Debug info through the port** — barrier/lower must copy `!dbg`, or `-g -c` objects lose their line table and the DWARF gates go red (Task 2, Task 6).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: TMS34010 `ToolChain` with the target's compile defaults
|
||||
|
||||
**Files:**
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.h`
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.cpp`
|
||||
- Modify: `clang/lib/Driver/ToolChains/CMakeLists.txt`
|
||||
- Modify: `clang/lib/Driver/Driver.cpp` (arch switch in `Driver::getToolChain`, after the `msp430` case at ~line 7286)
|
||||
- Test: `clang/test/Driver/tms34010-defaults.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `toolchains::BareMetal` (`clang/lib/Driver/ToolChains/BareMetal.h`), whose ctor is `BareMetal(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)`.
|
||||
- Produces: `class TMS34010ToolChain : public BareMetal` with the same ctor, overriding `void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const`, which appends `-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never` and then calls `BareMetal::addClangTargetOptions`.
|
||||
|
||||
- [ ] **Step 1: Write the failing driver test**
|
||||
|
||||
```c
|
||||
// clang/test/Driver/tms34010-defaults.c
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
// FLAGS-SAME: -fno-builtin
|
||||
// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
// NOSYS-NOT: "-internal-isystem"
|
||||
int f(int n) { return n + 1; }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: FAIL — the `-###` line has no `-ffreestanding` / `-mllvm -replexitval=never`.
|
||||
|
||||
- [ ] **Step 3: Implement the ToolChain**
|
||||
|
||||
`TMS34010.h` subclasses `BareMetal` with the forwarding ctor and the `addClangTargetOptions` override. `TMS34010.cpp` pushes the four default arguments in this order (`-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never`) before delegating to the base. In `Driver.cpp`, insert after the `msp430` case:
|
||||
|
||||
```cpp
|
||||
case llvm::Triple::tms34010:
|
||||
TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
```
|
||||
|
||||
Add the header to `Driver.cpp`'s include block and `TMS34010.cpp` to `ToolChains/CMakeLists.txt` (`add_clang_library(clangDriver ...)`).
|
||||
|
||||
- [ ] **Step 4: Run it green, plus the loop case**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: PASS.
|
||||
|
||||
Then compile the shape that fails today, with no extra flags:
|
||||
|
||||
```sh
|
||||
printf 'int sumto(int n){int s=0;for(int i=0;i<=n;i++)s+=i;return s;}\n' > /tmp/opencode/m10-loop.c
|
||||
build/llvm-clean-build/bin/clang --target=tms34010 -O2 -c /tmp/opencode/m10-loop.c -o /tmp/opencode/m10-loop.o
|
||||
```
|
||||
Expected: exit 0, object written (before this task: `fatal error: TMS34010: i33 multiply (umul_lohi shape) reached code generation`).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add clang/lib/Driver/ToolChains/TMS34010.h \
|
||||
clang/lib/Driver/ToolChains/TMS34010.cpp \
|
||||
clang/lib/Driver/ToolChains/CMakeLists.txt \
|
||||
clang/lib/Driver/Driver.cpp clang/test/Driver/tms34010-defaults.c
|
||||
git -C build/llvm-clean commit -m "tms34010: add the driver ToolChain with the target compile defaults"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: Bit-address passes and pipeline hooks (`-O0` and `-O2` correct)
|
||||
|
||||
**Files:**
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.h`
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp`
|
||||
- Modify: `llvm/lib/Target/TMS34010/CMakeLists.txt`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.h`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-o0.c`, `clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `tools/tms-bitaddr/bitscale.cpp` as the behavioural reference (modes `--bitptr`, `--scale`, `--lower-bitptr`); `OptimizationLevel` from the pipeline-start callback.
|
||||
- Produces: free functions `bool tms34010BitPtr(Module &M, OptimizationLevel Level)`, `bool tms34010ScaleGEP(Module &M)`, `bool tms34010LowerBitPtr(Module &M)`; new-PM passes `TMS34010BitPtrPass(OptimizationLevel)`, `TMS34010ScaleGEPPass`, `TMS34010LowerBitPtrPass`, each `PassInfoMixin` with `PreservedAnalyses run(Module &M, ModuleAnalysisManager &)`; `void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) override`.
|
||||
|
||||
- [ ] **Step 1: Write the failing asm tests**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
struct S { char c; int i; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int load_s(struct S *p) { return p[1].i; }
|
||||
int load_b(char *p) { return p[4]; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _load_s:
|
||||
// CHECK: ADDI 40, A{{[0-9]+}}
|
||||
// CHECK-LABEL: _load_b:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
```
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -S -o - %s | FileCheck %s
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _sumto:
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: FAIL — `ADDI 4` instead of `ADDI 32` (`_load_s` likewise off by the scale factor).
|
||||
|
||||
- [ ] **Step 3: Port the barrier pass**
|
||||
|
||||
In `TMS34010BitAddr.cpp`, implement `tms34010BitPtr` and `TMS34010BitPtrPass` by porting the `--bitptr` mode of `tools/tms-bitaddr/bitscale.cpp` **verbatim in behaviour**: the same `@__tms_bitptr(i32 bitoff, ptr base)` declaration with `nounwind readnone`, the same constant-expression-GEP rewrite to `inttoptr(add(ptrtoint, 8*off))`, the same declaration/body validation error, and every replaced instruction copies its `!dbg` location. Keep the `--normalize` mode out (nothing calls it).
|
||||
|
||||
- [ ] **Step 4: Port the lowering pass**
|
||||
|
||||
Implement `tms34010LowerBitPtr` and `TMS34010LowerBitPtrPass` from the `--lower-bitptr` mode: replace each call with `inttoptr(add(ptrtoint base, bitoff))` and drop the declaration; copy `!dbg` from the call. Then confirm the port compiles and is reachable (registration comes in Step 6):
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck`
|
||||
Expected: clean build, no new warnings in the target.
|
||||
|
||||
- [ ] **Step 5: Port the scaling pass**
|
||||
|
||||
Implement `tms34010ScaleGEP`: multiply only the indices of GEPs that reach it (optimizer-created byte GEPs), keep the `switch.table.` special case (`isSwitchTableBase` → shift 3 even when `GepShift == 0`), and keep the `0 + x` / `x * 1` folding.
|
||||
|
||||
- [ ] **Step 6: Register the pipeline hooks**
|
||||
|
||||
In `TMS34010TargetMachine.cpp`:
|
||||
|
||||
```cpp
|
||||
void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
|
||||
PB.registerPipelineStartEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||
MPM.addPass(TMS34010BitPtrPass(Level));
|
||||
if (Level == OptimizationLevel::O0) {
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
}
|
||||
});
|
||||
PB.registerOptimizerLastEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel,
|
||||
ThinOrFullLTOPhase) {
|
||||
MPM.addPass(TMS34010ScaleGEPPass());
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
MPM.addPass(InstCombinePass(InstCombineOptions()
|
||||
.setVerifyFixpoint(false)));
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
`-O0` deliberately adds no `scale` (no optimizer runs, so no optimizer-created GEPs) and no `InstCombine` — that is what keeps `-O0` byte-identical to the legacy path (Task 4). Declare the override in `TMS34010TargetMachine.h` and add `TMS34010BitAddr.cpp` to the target's `CMakeLists.txt`.
|
||||
|
||||
- [ ] **Step 7: Run both asm tests green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: PASS at both levels.
|
||||
|
||||
- [ ] **Step 8: Prove `llc`'s contract is unchanged**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m2-late-gep.ll`
|
||||
Expected: PASS — still `ADDI 24`, not `ADDI 192`.
|
||||
|
||||
- [ ] **Step 9: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/CMakeLists.txt \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o0.c \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
git -C build/llvm-clean commit -m "tms34010: move the bit-address barrier into the clang pipeline"
|
||||
```
|
||||
|
||||
End-to-end native proof (compile → link → MAME) lands in Task 5, when
|
||||
`tms-clang` routes every harness through native clang; at this point only the
|
||||
asm-level tests can observe the pipeline directly.
|
||||
|
||||
---
|
||||
|
||||
### Task 3: State machine, idempotency and the codegen safety net
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (module-flag transitions)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`addISelPrepare` legacy pass)
|
||||
- Create: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the passes from Task 2.
|
||||
- Produces: module flag `"tms.bitaddr"` with values `1` (barriered, not lowered) and `2` (lowered/final); `class TMS34010LowerBitPtrLegacyPass : public ModulePass` in `TMS34010BitAddr.h` for the legacy codegen pipeline; `TMS34010PassConfig::addISelPrepare()` override that adds it before `TargetPassConfig::addISelPrepare()`.
|
||||
|
||||
- [ ] **Step 1: Write the failing state-1 test**
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
@__tms_bitptr = external nounwind readnone
|
||||
!llvm.module.flags = !{!0}
|
||||
!0 = !{i32 4, !"tms.bitaddr", i32 1}
|
||||
define ptr @advance(ptr %p) {
|
||||
%q = call ptr @__tms_bitptr(i32 32, ptr %p)
|
||||
ret ptr %q
|
||||
}
|
||||
; CHECK-LABEL: _advance:
|
||||
; CHECK: ADDI 32, A{{[0-9]+}}
|
||||
; CHECK-NOT: CALLA
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: FAIL — the call is not lowered, so the asm contains `CALLA __tms_bitptr`.
|
||||
|
||||
- [ ] **Step 3: Implement the flag transitions**
|
||||
|
||||
`TMS34010BitPtrPass` sets `"tms.bitaddr"` to `1` when absent and does nothing when the value is `1` or `2` (module-level check first, before touching any instruction). `TMS34010LowerBitPtrPass` lowers only when the value is `1`, then sets it to `2`; with no flag it is a no-op. Write the value with `M.addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", ConstantInt::get(Type::getInt32Ty(M.getContext()), 1))` — `Override` so a second write replaces the value instead of erroring.
|
||||
|
||||
- [ ] **Step 4: Implement the codegen safety net**
|
||||
|
||||
Add `class TMS34010LowerBitPtrLegacyPass : public ModulePass` (in `TMS34010BitAddr.h`, defined in the `.cpp`) whose `runOnModule` calls `tms34010LowerBitPtr`. In `TMS34010PassConfig`, override:
|
||||
|
||||
```cpp
|
||||
void addISelPrepare() override {
|
||||
addPass(new TMS34010LowerBitPtrLegacyPass());
|
||||
TargetPassConfig::addISelPrepare();
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Run the state-1 test green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build llc clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 6: Write the end-to-end idempotency gate**
|
||||
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh` (shell, `set -eu`, `ROOT=$(cd "$(dirname "$0")/../../.." && pwd)`):
|
||||
|
||||
1. Compile a pointer file at `-O0` to IR: `clang --target=tms34010 -O0 -S -emit-llvm -o run1.ll src.c`.
|
||||
2. Assert `run1.ll` contains `"tms.bitaddr", i32 2` and no `__tms_bitptr`.
|
||||
3. Re-run the same command to `run2.ll` and `cmp` — identical.
|
||||
4. `llc -march=tms34010 -O0 -filetype=asm run1.ll` and assert `ADDI 32` for `p[1]`.
|
||||
5. Compile the same source with `clang --target=tms34010 -O0 -c` and validate the object: `python3 scripts/m4/coff-check.py native.o` must exit 0 (magic and section table valid).
|
||||
|
||||
- [ ] **Step 7: Run the idempotency gate**
|
||||
|
||||
Run: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
Expected: `m10 bitaddr idempotent: PASS`.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: make the bit-address pipeline idempotent"
|
||||
git add scripts/tests/m10/bitaddr-idempotent.sh
|
||||
git commit -m "m10: gate bit-address pipeline idempotency"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: Static-variadic guard and the `-O0` equivalence gate
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (guard inside the barrier pass)
|
||||
- Create: `scripts/tests/m10/legacy-tms-clang` (exact copy of the M9 script, `git show m9:scripts/tms-clang`)
|
||||
- Create: `scripts/tests/m10/equivalence.sh`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `TMS34010BitPtrPass(OptimizationLevel Level)` from Task 2.
|
||||
- Produces: the diagnostic `error: static variadic definition '<name>' loses its '...' arguments at -O2 (dead argument elimination); remove 'static' or compile with -O0` emitted at `-O2` only; `scripts/tests/m10/equivalence.sh` returning non-zero with a per-file diff list.
|
||||
|
||||
- [ ] **Step 1: Write the failing guard test**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
// CHECK: static variadic definition 'sum' loses its '...' arguments
|
||||
static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
int call(void) { return sum(1, 2); }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: FAIL — compiles silently (the guard still lives in the shell script).
|
||||
|
||||
- [ ] **Step 3: Move the guard into the barrier pass**
|
||||
|
||||
Port the `awk` guard's condition exactly: at `Level != O0`, scan each function definition; if it has `internal`/`private` linkage AND a variadic signature AND no `llvm.va_start`/`va_arg` use, report that diagnostic with the function's name and fail compilation (`report_fatal_error` or a diagnostic the driver prints as `error:`). Keep the `-O0` exemption.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: PASS (both RUN lines).
|
||||
|
||||
- [ ] **Step 5: Create the legacy reference copy**
|
||||
|
||||
Run: `git show m9:scripts/tms-clang > scripts/tests/m10/legacy-tms-clang && chmod +x scripts/tests/m10/legacy-tms-clang`
|
||||
Expected: byte-identical to the M9 script; it is the oracle for the rest of the milestone.
|
||||
|
||||
- [ ] **Step 6: Write the equivalence gate**
|
||||
|
||||
`scripts/tests/m10/equivalence.sh` compiles each corpus file twice and compares objects:
|
||||
|
||||
- native: `clang --target=tms34010 -O0 -c "$f" -o native.o`
|
||||
- legacy: `scripts/tests/m10/legacy-tms-clang -O0 -o legacy.ll "$f"` then `llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o`
|
||||
- require `cmp native.o legacy.o`.
|
||||
|
||||
Corpus: every `*.c` in `scripts/m4`, `scripts/m5`, `scripts/m6` plus `scripts/tests/m5/conformance/shim.c` and `heap.c`. Run the whole set at `-O0`, then at `-O0 -g`, and report per-file pass/fail with a summary line `m10 equivalence: pass=<n> fail=<n>`.
|
||||
|
||||
Then a second phase in the same script covers `-O2`, where byte identity is not
|
||||
expected: compile a heredoc fixture at `-O2` and FileCheck its asm shapes —
|
||||
`p[1]` for `int*` (`ADDI 32`), a struct-array stride, a `switch` table load and
|
||||
an aggregate return — so the scaling pass is pinned on optimizer-created GEPs.
|
||||
|
||||
- [ ] **Step 7: Run the gate, then prove it discriminates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0`.
|
||||
|
||||
Then temporarily run the native side at `-O2` (edit a copy, not the gate) and confirm the comparison reports failures — proving the gate is not vacuous. Revert the copy.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
git -C build/llvm-clean commit -m "tms34010: reject static variadics in the pre-optimizer barrier"
|
||||
git add scripts/tests/m10/legacy-tms-clang scripts/tests/m10/equivalence.sh
|
||||
git commit -m "m10: gate native/legacy object equivalence at -O0"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: `tms-clang` becomes a wrapper; gates move to the new seam
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tms-clang` (replace the body with the flag mapper)
|
||||
- Modify: `scripts/tests/m4/mul.sh:29`
|
||||
- Modify: `scripts/tests/m5/jr.sh:114-120`
|
||||
- Modify: `scripts/tests/m5/policy.sh:51-70`
|
||||
- Modify: `scripts/tests/m3/run.sh` (the `TMS_OPT` wrapper it installs)
|
||||
- Test: those four gates plus `scripts/tests/m10/equivalence.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the `ToolChain` defaults (Task 1) and the pipeline hooks (Task 2, Task 3).
|
||||
- Produces: `scripts/tms-clang` with the unchanged CLI (`-O0|-O2|-g|-I dir -o OUT.ll IN.c`) that maps to `clang --target=tms34010 [-O0|-O2] [-g] [-I dir] -S -emit-llvm -o OUT.ll IN.c` and no longer invokes `$TMS_OPT` or `$TMS_BITADDR`.
|
||||
|
||||
- [ ] **Step 1: Record the current gate behaviour as the baseline**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS on the pre-rewrite script (this is the behaviour that must survive).
|
||||
|
||||
- [ ] **Step 2: Rewrite `scripts/tms-clang`**
|
||||
|
||||
Keep the argument parser, `set -eu`, and the `TMS_CLANG`/`TMS_CLANG_EXTRA_FLAGS` overrides; delete the temp-dir pipeline, the awk guard (now in the pass), the `run_bitaddr` calls and both `opt` invocations. The whole script becomes the argument parse plus one `exec` of clang with `-S -emit-llvm`.
|
||||
|
||||
- [ ] **Step 3: Repoint the four gates**
|
||||
|
||||
- `m4/mul.sh`: replace the `grep -q -- '-replexitval=never' scripts/tms-clang` check with an assertion on the driver seam, e.g. `"$TMS_CLANG" -### --target=tms34010 -O2 -c ... 2>&1 | grep -q -- '-replexitval=never'`.
|
||||
- `m5/jr.sh`: drop the `OPT_NOREPLEXIT` wrapper and call `tms-clang -O2` directly; keep the same final assertion on the emitted IR/asm.
|
||||
- `m5/policy.sh`: replace the `opt-trace` harness with the `-###` check plus the existing final-IR/asm assertions for the switch-table and loop shapes.
|
||||
- `m3/run.sh`: same treatment for whatever `TMS_OPT` wrapper it installs.
|
||||
|
||||
Each edit must assert the same invariant, just observed at the driver seam instead of inside the script.
|
||||
|
||||
- [ ] **Step 4: Run the four gates green**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS, with the `-replexitval=never` policy still asserted.
|
||||
|
||||
- [ ] **Step 5: Prove native end-to-end**
|
||||
|
||||
With `tms-clang` now mapping to clang, the conformance harness compiles with
|
||||
native clang. Write a small pointer program and run it through the harness:
|
||||
|
||||
```sh
|
||||
cat > /tmp/opencode/m10-ptr.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
int a[3] = {10, 20, 30};
|
||||
int *p = a;
|
||||
printf("%d %d\n", p[2], (int)(p + 2 - p));
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
scripts/tests/m5/conformance/run.sh --id m10-ptr --mode native \
|
||||
--expect 'status=0;stdout=30 2\n' /tmp/opencode/m10-ptr.c
|
||||
```
|
||||
|
||||
Expected: `PASS m10-ptr` (status 0, stdout `30 2`). The full breadth proof is the
|
||||
suite in Task 6, which now also compiles through native clang.
|
||||
|
||||
- [ ] **Step 6: Re-run the equivalence gate against the new wrapper**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0` — the oracle copy is unchanged, so this proves the wrapper
|
||||
produces the same IR the old script did.
|
||||
|
||||
- [ ] **Step 7: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tms-clang scripts/tests/m4/mul.sh scripts/tests/m5/jr.sh \
|
||||
scripts/tests/m5/policy.sh scripts/tests/m3/run.sh
|
||||
git commit -m "m10: tms-clang maps to clang; gates assert the driver seam"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Full gate sweep, docs, patch export, promote `m10`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md` (M10 status, `tms-clang` description, gate list)
|
||||
- Modify: `build/llvm-clean/TMS34010.md` (M10 section, pipeline description)
|
||||
- Modify: `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (M10 acceptance met)
|
||||
- Create: `patches/llvm/0005-tms34010-toolchain.patch`
|
||||
- Test: the full M0–M10 gate list
|
||||
|
||||
- [ ] **Step 1: Export the driver patch**
|
||||
|
||||
Run: `git -C build/llvm-clean diff m9..m10 -- clang/ > patches/llvm/0005-tms34010-toolchain.patch`
|
||||
Expected: the patch contains only `ToolChains/TMS34010.{h,cpp}`, `ToolChains/CMakeLists.txt`, `Driver.cpp` and the driver test.
|
||||
|
||||
- [ ] **Step 2: Run the compiler tests**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010 build/llvm-clean/llvm/test/MC/TMS34010 build/llvm-clean/clang/test/CodeGen/TMS34010 build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: 129 TMS34010 lit tests plus the new ones, and 5 clang tests plus the new ones, all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M9/M10 behaviour gates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh && scripts/tests/m10/bitaddr-idempotent.sh && tools/tms-bitaddr/tests/run.sh && scripts/tests/m9/dwarf-ranges.sh && scripts/tests/m8/dwarf-multi.sh && scripts/tests/m7/debug.sh`
|
||||
Expected: all PASS; DWARF output unchanged.
|
||||
|
||||
- [ ] **Step 4: Run the full suite and the divide measurement**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m10-bare`
|
||||
Expected: `all total=1912 pass=1618 skip=294 fail=0 crash=0`.
|
||||
Every row now compiles through native clang, because `tms-clang` is the thin
|
||||
wrapper — so this run is the breadth proof for the new pipeline, not just a
|
||||
regression check.
|
||||
Run: `scripts/tests/m7/i64div.sh`
|
||||
Expected: `fast=88 slow=3302 wide=221 div32=120`, ratios 37.5/14.9/1.8, all four checksums exact.
|
||||
|
||||
- [ ] **Step 5: Run the remaining M0–M8 gates**
|
||||
|
||||
Run the serial list from `README.md`'s gate section (M0, M2–M8 native/object/JR/MMTM/policy/robust/spike/i64/float/varargs/bitfield/aggregate/runtime, the curated c-torture and c-testsuite tiers, `hardware.sh` → `HARDWARE: DEFERRED`).
|
||||
Expected: every gate PASS; hardware DEFERRED.
|
||||
|
||||
- [ ] **Step 6: Update the docs**
|
||||
|
||||
Record in `README.md`, `TMS34010.md` and the spec: M10 complete, `clang --target=tms34010 -c` now correct with no flags, the ToolChain defaults, the pipeline hooks and state flag, the `-O0` byte-identity result, the new gates, and the M10/M11 boundary (M11 = CRT/headers/`libtms.a`/sysroot/link job).
|
||||
|
||||
- [ ] **Step 7: Commit, review, push, promote**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M10 native pipeline"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m10: document the native clang pipeline"
|
||||
```
|
||||
|
||||
Then run the M10 whole-branch review. Only after it is clean: push `m10` in both repositories, set it as the default branch on both remotes, and update the README's default-branch language. `m9` stays as the previous snapshot.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M10 ends with `clang --target=tms34010 -O2 -c` correct for pointer code and for ordinary loops, `-O0` objects byte-identical to the M9 path, and every existing gate green. M11 (Phase 3: CRT, headers, `libtms.a`, sysroot, `tms-link` link job) is planned separately once M10 is promoted, because it extends the `ToolChain` file created in Task 1.
|
||||
@@ -710,6 +710,86 @@ gate stays green and the new M9 lit/DWARF gates pass, while the real VT1200
|
||||
run remains **DEFERRED**. M9 is complete; the remaining classes are the M9/M10
|
||||
boundary.
|
||||
|
||||
### M10 — the native clang pipeline (Phase 2)
|
||||
|
||||
M10 moves the bit-address transform and this target's compile defaults into
|
||||
the target, so native `clang --target=tms34010 -c` is correct for pointer code
|
||||
at `-O0` and `-O2` with **no extra flags
|
||||
and no wrapper**. `m10` is the repository default (the promotion lands with this
|
||||
push; `m9` is the previous snapshot). The binding design is
|
||||
`2026-11-17-tms34010-phase-2-3-design.md` §7.
|
||||
|
||||
- **The `ToolChain`.** A minimal `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`
|
||||
(`BareMetal` subclass, registered in `CMakeLists.txt`/`Driver.cpp`) supplies
|
||||
`-ffreestanding`, `-fno-builtin`, `-mllvm -replexitval=never`,
|
||||
`-disable-O0-optnone` and no system includes; `-c`/`-S` are the surface (no
|
||||
link job yet).
|
||||
- **The pipeline.** `registerPassBuilderCallbacks` runs the
|
||||
`@__tms_bitptr` barrier at pipeline start (plus lowering at `-O0`) and
|
||||
scale → lower → final InstCombine at optimizer-last (gated to `Level != O0`);
|
||||
a `"tms.bitaddr"` module flag (absent → `1` → `2`) makes it idempotent, and a
|
||||
legacy lowering pass in `addISelPrepare` is the codegen safety net.
|
||||
- **`tms-clang`** becomes a thin flag mapper; the four gates that traced its
|
||||
internals assert the same invariants at the driver seam.
|
||||
|
||||
M10 acceptance (met, M10 complete): native
|
||||
`clang/test/CodeGen/TMS34010/bitaddr-o0.c`/`bitaddr-o2.c` pin `p[1]` → `ADDI
|
||||
32` (i32), `ADDI 16` (`short`), `ADDI 32` (`char p[4]`) at `-O0` and `-O2`, and
|
||||
an ordinary `sumto` loop compiles at `-O2` with no extra flags;
|
||||
`bitaddr-static-vararg.c` pins the guard at `-O0`/`-O1`/`-O2`,
|
||||
`float-const-o2.c` pins the pre-optimizer f32/f64 constant protection, and
|
||||
`tms34010-defaults.c` pins the `ToolChain` defaults. Native `-O0` (and `-O0
|
||||
-g`) objects are **byte-identical** to the M9 path across the 23-file corpus
|
||||
(`scripts/tests/m10/equivalence.sh`, **46/46** at `-O0` and `-O0 -g`);
|
||||
idempotency is
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh`. TMS34010 lit is **132/132** (128
|
||||
CodeGen + 4 MC) and clang is **10** (8 CodeGen + the driver
|
||||
`tms34010-defaults.c` + the Sema subbyte-stride test), for **142** lit in
|
||||
total; the serial M0–M8 gate list is **56/56 PASS** with `HARDWARE: DEFERRED`.
|
||||
The fresh two-tier full
|
||||
suite is unchanged at **1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**, the
|
||||
four-phase i64 gate is unchanged at fast **88** / slow **3,302** / wide **221** /
|
||||
div32 **120** frames (37.5× / 14.9× / 1.8×, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`/`F56810CFEDA9D656`/`00002C61C63842EE`),
|
||||
and the hardware run remains **DEFERRED**. `m5/jr.sh` re-pins the linked
|
||||
`.text` to **910** bytes (the first M10 pin of 850 was measured through the
|
||||
pre-fix `-O2` bit-offset-aliasing and float-constant-folding hazards; the
|
||||
correctness fixes below cost instructions and restore the M9 legacy value;
|
||||
the JR count is unchanged).
|
||||
|
||||
The `-O2` bit-address aliasing gap is fixed with three changes. (1)
|
||||
DAGCombiner's `BaseIndexOffset` aliasing reads address offsets in **bytes**, so
|
||||
every target-computed bit offset now routes through a `TMS34010ISD::BITADDR`
|
||||
node (selected straight to `ADDI`) for the f64/i64/aggregate return-slot and
|
||||
hidden-return reads; `BaseIndexOffset` does not match the custom node, so
|
||||
aliasing falls back to the byte-accurate `MachinePointerInfo` and the
|
||||
program-order chain is kept, and a zero offset stays the base itself so `-O0`
|
||||
objects remain byte-identical. (2) `f32`/`f64` literals are protected
|
||||
**before** the optimizer: `TMS34010LowerFloatConstantsPass` runs at clang
|
||||
pipeline start for `-O1`+ and replaces each literal store/return/argument with
|
||||
a volatile load from a GSP-initialised global, so the middle-end cannot fold
|
||||
`bitcast(float C to i32)` to IEEE bits (the late llc pass keeps plain loads and
|
||||
still covers `-O0`). (3) Closing those two exposed the underlying class: any
|
||||
address built as `inttoptr(add(ptrtoint, bits))` folds to a plain `ISD::ADD` on
|
||||
this 32-bit-pointer target, so ordinary source pointer arithmetic was still
|
||||
miscompiled at `-O2` (reproducer `p[0]=v; p[1]=w; ((char*)p)[5]=0x7f;` stored
|
||||
the byte before the word store). This is the bit-address aliasing mechanism,
|
||||
fixed by a target intrinsic `llvm.tms34010.bitaddr` that lowers to `BITADDR` and
|
||||
is now used by **every** runtime pointer-offset emitter — the barrier lowering,
|
||||
the aggregate/i64/narrow-mem leaves and both GEP-scaling passes (regression
|
||||
tests `m10-bitaddr-chain-i64.ll`, `bitaddr-chain-o2.c`). The residual is
|
||||
documented: `scaleConstantGep` emits a compile-time `ConstantExpr` address,
|
||||
which cannot hold a call, so it folds to a `GlobalAddress+offset` and no
|
||||
runtime `ADD` exists to mis-decompose (not reachable at `-O2`). With
|
||||
these, `m6/float.sh` (8 float markers), `m6/aggregate.sh` (2 markers),
|
||||
`m6/i64.sh`, `m6/bitfield.sh`, `m6/varargs.sh` and `m6/runtime.sh` all pass at
|
||||
`-O0` and `-O2`. `scripts/m3/run.sh` compiles `branch` with `-fno-inline` at
|
||||
`-O2` (chosen over `-O0` to keep the pinned condition codes), so
|
||||
`m3/dis-roundtrip.sh` keeps its `_sumto`/`_max2`/`_lt` calls to check. The
|
||||
**M10/M11 boundary** is Phase 3: a committed CRT
|
||||
(`crt0.o` via `llvm-mc`), headers, `libtms.a`, a sysroot and a `tms-link` link
|
||||
job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| risk | mitigation |
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
# TMS34010 Phase 2 and Phase 3 — native clang pipeline and conventional toolchain
|
||||
|
||||
Status: proposed, revised after the builder check. Phase 1 (`tms-cc` usability
|
||||
driver) is complete and pushed on `m9` (project `55a0991`, compiler
|
||||
`4e7d48d2717e`).
|
||||
|
||||
Decisions already taken by the human partner:
|
||||
|
||||
| Decision | Choice |
|
||||
|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (shim + SDK runtimes behind CRT/headers/ToolChain) |
|
||||
| clang-level defaults (`-replexitval=never`, `-ffreestanding`, …) | A minimal `ToolChain` lands in Phase 2 |
|
||||
| M10 success criterion | Runtime and suite equivalence, not byte-identical objects |
|
||||
| Vendor `flib`/`rts` archives | Committed to the repository |
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
Phase 1 gave a working one-command build (`scripts/tms-cc hello.c -o hello.coff`)
|
||||
but it hides a pipeline only the wrapper script knows about. Native
|
||||
`clang --target=tms34010 -c` still **miscompiles pointer code**. Verified on
|
||||
`m9`:
|
||||
|
||||
```c
|
||||
int load(int *p) { return p[1]; }
|
||||
```
|
||||
|
||||
- `clang --target=tms34010 -O0 -S` → `ADDI 4, A0` (byte offset — wrong; a 32-bit
|
||||
element is 32 bit-addresses away)
|
||||
- `scripts/tms-clang` + `llc` → `ADDI 32, A0` (bit offset — correct)
|
||||
|
||||
The cause is structural: LLVM GEP indices are byte units, TMS34010 pointers are
|
||||
bit addresses, and the optimizer re-forms byte GEPs from
|
||||
`inttoptr(add(ptrtoint, …))` unless an opaque barrier blocks it. Correctness
|
||||
needs three ordered steps — **pre-optimizer barrier → middle-end →
|
||||
post-optimizer scale, lower, final InstCombine**.
|
||||
|
||||
The builder check also showed the wrapper hides more than the barrier. Native
|
||||
`clang -O2 -c` fails on an ordinary loop because `IndVarSimplify` rewrites the
|
||||
loop's exit value into an i33 multiply that the target rejects;
|
||||
`scripts/tms-clang` avoids it with `-replexitval=never`, a pass option no
|
||||
`TargetMachine` can set. The wrapper additionally supplies `-ffreestanding`,
|
||||
`-fno-builtin`, `-nostdinc`, `-Xclang -disable-O0-optnone`, a pre-optimizer
|
||||
static-variadic guard, and `instcombine<no-verify-fixpoint>`. So Phase 2 is "the
|
||||
target owns the transform **and** the target's compile defaults", not the
|
||||
transform alone.
|
||||
|
||||
Phase 3 then makes the whole flow conventional: a CRT, headers, a library and a
|
||||
link job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper
|
||||
and no project variables.
|
||||
|
||||
These are projects, not small changes. They map onto the repository's milestone
|
||||
pattern as **M10 (Phase 2)** and **M11 (Phase 3)**.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
### Phase 2 (M10)
|
||||
|
||||
1. `clang --target=tms34010 -c` is semantically correct for pointer code at
|
||||
`-O0` and `-O2`, with **no extra flags** and no wrapper script.
|
||||
2. `clang --target=tms34010 -O2 -c` compiles ordinary loop code (the i33 /
|
||||
`-replexitval` class) without the user passing anything.
|
||||
3. The transform lives in the target: `llvm/lib/Target/TMS34010/`, registered
|
||||
through `TMS34010TargetMachine::registerPassBuilderCallbacks`.
|
||||
4. A **minimal `ToolChain`** supplies this target's compile defaults
|
||||
(freestanding, no builtins, no system includes, `-replexitval=never`).
|
||||
5. `scripts/tms-clang` keeps its command-line contract but becomes a thin
|
||||
`clang` wrapper.
|
||||
6. Gates that observe the wrapper's internals are re-pointed at the new seam.
|
||||
7. Every M2–M9 gate, lit test and the 1,618-pass full suite stays green.
|
||||
|
||||
### Phase 3 (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` produces a loadable TI-COFF image
|
||||
that runs under `tms-run`, with no project wrapper and no `M4_*` variables.
|
||||
2. A committed, reproducible **CRT** (`crt0`), **headers** and **library**
|
||||
(`libtms.a`), plus the committed vendor `flib.lib`/`rts.lib`, resolved
|
||||
through a sysroot.
|
||||
3. The driver owns the link step: `tms-link` is the linker job, with `-l`, `-L`,
|
||||
`-nostdlib`, `-Wl,` and layout options passed through.
|
||||
4. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multiple TUs and `-nostdlib` behave the
|
||||
way they do for any freestanding clang target.
|
||||
5. Phase 1's user-visible behaviour (`printf` output via `tms-run`) is preserved.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Hosted C library.** No file I/O, no console/terminal driver, no `libm`, no
|
||||
locale. `printf` continues to write the conformance result block.
|
||||
- **lld.** TI-COFF is not an lld flavour; `tms-link` remains the linker.
|
||||
- **LTO.** Bitcode leaving a completed pipeline is final; re-optimizing it is
|
||||
unsupported.
|
||||
- **Changing the TI ABI, the all-stack convention, the GSPA/GSPLNK oracle, or
|
||||
the pointer model.**
|
||||
- **Replacing `llc`'s IR contract.** Hand-written IR passed straight to `llc`
|
||||
keeps the M9 meaning (§7.4).
|
||||
- **Byte-identical objects.** Explicitly dropped: native `-O2` IRGen differs
|
||||
from M9's `clang -O0` IRGen + `opt`, and `-O2` codegen differs from `llc -O0`
|
||||
(measured 424 vs 416 bytes on an integer-only file, different block layout).
|
||||
- Real VT1200 hardware validation (still deferred; no unit).
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- A user-visible flag that must be remembered for correctness. Correctness and
|
||||
this target's compile defaults are properties of the target.
|
||||
- Divergence in generic clang/LLVM beyond (a) the new
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` and (b) its two registration
|
||||
edits. Exported as patch `0005`, extended by Phase 3.
|
||||
- Two implementations of the transform that can drift. `tools/tms-bitaddr`
|
||||
becomes a **test oracle**, not a second production path.
|
||||
- Silently changing what a gate measures. Any gate edit must preserve the
|
||||
invariant it was asserting.
|
||||
|
||||
## 5. Current state (verified on `m9`)
|
||||
|
||||
| Fact | Evidence |
|
||||
|---|---|
|
||||
| The transform is a standalone IR rewriter, not a pass | `tools/tms-bitaddr/bitscale.cpp` parses IR, mutates it, writes it; modes `--bitptr --scale --normalize --lower-bitptr` |
|
||||
| `clang -O2` fails on ordinary loops | `IndVarSimplify` exit-value rewrite → i33 multiply → `TMS34010RejectUnsupportedIR` fatal |
|
||||
| M9 avoids it with a pass option | `scripts/tms-clang`: `opt -passes='default<O2>' -replexitval=never` |
|
||||
| The wrapper carries freestanding defaults | `clang --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone -ffreestanding -fno-builtin -nostdinc` (always `-O0` IRGen) |
|
||||
| A pre-optimizer guard lives in the wrapper | awk scan rejecting `internal` variadic definitions with no `llvm.va_start` (DAE would drop `...`) |
|
||||
| A final InstCombine needs an option | `instcombine<no-verify-fixpoint>` for the shim's `emit_uint64` `zext … nneg` fixpoint |
|
||||
| Gates observe the wrapper's internals | `m3/run.sh` and `m5/jr.sh` inject `opt` wrappers; `m5/policy.sh` traces `opt` arguments; `m4/mul.sh` greps `scripts/tms-clang` for the flag |
|
||||
| The target already assumes bit offsets in codegen | `TMS34010PassConfig::addIRPasses()` hosts `ScaleMemExpansionGEPs`, `ExpandAggMem`, `LowerI64`, `ExpandNarrowMem` |
|
||||
| clang builds a `PassBuilder` **with** the `TargetMachine` | `clang/lib/CodeGen/BackendUtil.cpp:937` |
|
||||
| so target pass callbacks are reachable from clang | `PassBuilder::PassBuilder` calls `TM->registerPassBuilderCallbacks(*this)` (`llvm/lib/Passes/PassBuilder.cpp:581`) |
|
||||
| Pipeline-start callbacks run at `-O0` | `PassBuilderPipelines.cpp:2438`, inside `buildO0DefaultPipeline` |
|
||||
| Optimizer-last callbacks do **not** run at `-O0` | `invokeOptimizerLastEPCallbacks` only at `:1692`, `:1933`, `:2524` |
|
||||
| `llc` runs no new-PM pipeline | `llc.cpp:839` only calls `Target->addPassesToEmitFile` |
|
||||
| `opt` builds no `TargetMachine` | `tools/opt/NewPMDriver.cpp` registers plugin callbacks only |
|
||||
| The driver has no TMS34010 `ToolChain` | no `tms34010` under `clang/lib/Driver/` |
|
||||
| The native link needs a repair step today | `scripts/m4/run.sh` runs `coff-check.py --repair --entry 018A0000` on every linked image |
|
||||
| SDK `flib`/`rts` are generated, not committed | `build/m6-sdk/{flib,rts}.lib`, extracted from the 1987 vendor image |
|
||||
| A TMS34010 MC assembler exists | `llvm/test/MC/TMS34010` (4 tests) — usable for a committed CRT |
|
||||
| `tms-link` reads System V `ar` archives | M8.1 (`scripts/tests/m8/native-lib.sh`) |
|
||||
|
||||
## 6. Approaches considered
|
||||
|
||||
### Phase 2
|
||||
|
||||
**A. Target-level pass hooks (chosen).** Barrier on the pipeline-start extension
|
||||
point; scale/lower/final-InstCombine on optimizer-last (`-O0` handles both in
|
||||
the start callback, §7.3); registered from
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks`. No user flag, and the
|
||||
transform stays inside the target directory.
|
||||
|
||||
**B. In-tree clang frontend patch.** Insert the passes in
|
||||
`clang/lib/CodeGen/BackendUtil.cpp`. Explicit ordering, but the fork's first
|
||||
divergence in generic clang code, re-carried on every LLVM bump. Rejected: A
|
||||
covers every clang path because clang passes its `TargetMachine` to the
|
||||
`PassBuilder`.
|
||||
|
||||
**C. Out-of-tree pass plugin plus an opt-in flag.** Smallest divergence, but
|
||||
correctness becomes flag-dependent and forgettable. Rejected: it does not
|
||||
satisfy "plain clang is correct".
|
||||
|
||||
**Rejected outright: bit units in `DataLayout`.** LLVM's addressing unit is the
|
||||
byte and `getTypeAllocSize` is byte-quantised; a bit-unit GEP cannot be
|
||||
expressed. That is why the barrier exists.
|
||||
|
||||
**Amendment after the builder check.** A alone is not sufficient: the
|
||||
`-replexitval`, freestanding and include defaults cannot come from a
|
||||
`TargetMachine`. They come from a minimal `ToolChain`, which is also the natural
|
||||
home for Phase 3's sysroot and link job. This keeps one driver file rather than
|
||||
two phases of driver surgery, and it means Phase 3 extends a file instead of
|
||||
introducing one.
|
||||
|
||||
### Phase 3
|
||||
|
||||
**A. Dedicated `ToolChain` + sysroot + CRT + `libtms.a` (chosen).** Follows how
|
||||
freestanding clang targets work, gives conventional `-I`/`-l`/`-L`/`-nostdlib`
|
||||
behaviour, and keeps `tms-link` behind a normal link job.
|
||||
|
||||
**B. Keep `tms-cc` and only rename it.** Cheapest, but it keeps a project script
|
||||
as the interface and cannot satisfy `clang hello.c -o hello`.
|
||||
|
||||
**C. Target the vendor 2ine/VT1200 OS environment.** Real OS applications, but a
|
||||
different runtime contract and acceptance path. Rejected: the chosen scope is
|
||||
freestanding with conventional UX.
|
||||
|
||||
## 7. Phase 2 (M10) design
|
||||
|
||||
### 7.1 Pass inventory
|
||||
|
||||
Port `tools/tms-bitaddr/bitscale.cpp` into new-PM passes under
|
||||
`llvm/lib/Target/TMS34010/`:
|
||||
|
||||
| New pass | Source mode | Responsibility |
|
||||
|---|---|---|
|
||||
| `TMS34010BitPtrPass` | `--bitptr` | Replace every GEP (and `inttoptr` of a bit addend over `ptrtoint`) with `@__tms_bitptr(i32 bitoff, ptr base)`; rewrite constant-expression GEPs as `inttoptr(add(ptrtoint, 8*off))`; copy `!dbg`; run the static-variadic guard (§7.6) |
|
||||
| `TMS34010ScaleGEPPass` | `--scale` | Multiply optimizer-created byte-GEP indices by 8; keep the `switch.table.*` special case |
|
||||
| `TMS34010LowerBitPtrPass` | `--lower-bitptr` | Replace each call with `inttoptr(add(ptrtoint base, bitoff))`, then drop the declaration |
|
||||
|
||||
`--normalize` is not ported: nothing in the shipped pipeline calls it, and its
|
||||
input contract is what `llc` does natively. The tool keeps the mode for its own
|
||||
tests and stays the equivalence oracle.
|
||||
|
||||
The port is a rewrite into `PassInfoMixin` form, not a move: the current code is
|
||||
a `main()`-driven module mutator.
|
||||
|
||||
### 7.2 Pipeline registration
|
||||
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB)`:
|
||||
|
||||
```
|
||||
PB.registerPipelineStartEPCallback(<level L: append barrier; if L == O0 also
|
||||
append lower>);
|
||||
PB.registerOptimizerLastEPCallback(<append scale → lower → instcombine>);
|
||||
```
|
||||
|
||||
At `-O0` no optimizer runs, so there are no optimizer-created GEPs to scale and
|
||||
no InstCombine is needed; adding one would move `-O0` output away from the M9
|
||||
path. `-O0` therefore runs barrier + lower only, which is what makes the
|
||||
byte-identity check possible.
|
||||
|
||||
`TMS34010PassConfig::addISelPrepare()` prepends `<lower → instcombine>` for IR
|
||||
that reaches codegen still holding barrier calls (hand-written or intermediate
|
||||
IR). It is placed before `TargetPassConfig::addISelPrepare()` so it runs before
|
||||
`PreISelIntrinsicLowering`/`CodeGenPrepare`, matching M9's "lower before the
|
||||
backend sees it". `TMS34010PassConfig::addIRPasses()` is unchanged.
|
||||
|
||||
The final InstCombine is constructed with
|
||||
`InstCombineOptions().setVerifyFixpoint(false)` — the in-tree equivalent of the
|
||||
wrapper's `instcombine<no-verify-fixpoint>`.
|
||||
|
||||
Consequences that make this safe:
|
||||
|
||||
- `clang` reaches the hooks because it builds `PassBuilder PB(TM.get(), …)`.
|
||||
- `llc` never builds a new-PM pipeline, so **direct `llc` on IR keeps the M9
|
||||
contract** and the 129 lit tests are unaffected.
|
||||
- `opt` builds no `TargetMachine`, so `opt` never fires the hooks.
|
||||
|
||||
### 7.3 State machine (idempotency)
|
||||
|
||||
A module flag carries the state so the barrier cannot run twice:
|
||||
|
||||
| Flag `"tms.bitaddr"` | Meaning | Pipeline start | Optimizer last | Codegen (`addISelPrepare`) |
|
||||
|---|---|---|---|---|
|
||||
| absent | not ours / hand-written IR | apply barrier → `1`; at `-O0` immediately lower → `2` | skip | skip |
|
||||
| `1` | barriered, not lowered | skip | scale, lower, instcombine → `2` | lower, instcombine → `2` |
|
||||
| `2` | lowered / final | skip | skip | skip |
|
||||
|
||||
Flag: `Module::addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", i32)`, set
|
||||
only by the pass performing the transition.
|
||||
|
||||
Because `-O0` lowers inside the start callback, **clang never emits state-1
|
||||
IR**, which closes the previous hole where `clang -O0 -emit-llvm` → `opt -O2` →
|
||||
`llc` would have lowered unscaled optimizer GEPs.
|
||||
|
||||
Scenario check:
|
||||
|
||||
| Command | Result |
|
||||
|---|---|
|
||||
| `clang -O2 -c` | barrier → optimize → scale/lower/instcombine → codegen skips |
|
||||
| `clang -O0 -c` | barrier + lower + instcombine in the start callback |
|
||||
| `clang -O0 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2` on state-1 IR | barrier skipped, optimization + lowering run once |
|
||||
| `llc` on hand-written IR | no flag → untouched (M9 meaning) |
|
||||
| `opt` on state-2 IR | hooks never fire; optimizing final IR is unsupported (§7.5) |
|
||||
|
||||
### 7.4 Why `llc`'s contract must not change
|
||||
|
||||
`m2-late-gep.ll` pins `getelementptr i8, ptr %p, i32 24` → `ADDI 24`: for `i8`
|
||||
GEPs the byte offset *is* the bit offset. A barrier inside `llc` would turn every
|
||||
such test into `ADDI 192` and redefine the IR contract the gate suite is built
|
||||
on. The hooks therefore live only in the new-PM pipeline, which `llc` does not
|
||||
build. This is a design invariant.
|
||||
|
||||
### 7.5 Limitations to document
|
||||
|
||||
- IR emitted by a completed `clang` pipeline (`-emit-llvm`) is **final**;
|
||||
re-optimizing it with `clang`/`opt -O2` is unsupported.
|
||||
- LTO is unsupported for this target (bitcode is already lowered).
|
||||
- The barrier must preserve `!dbg`; this keeps `-g -c` DWARF correct (M9.2
|
||||
depends on it).
|
||||
|
||||
### 7.6 Minimal `ToolChain` (new in M10)
|
||||
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`, registered in
|
||||
`clang/lib/Driver/ToolChains/CMakeLists.txt` and the driver's target selection so
|
||||
`tms34010-unknown-none` (and plain `--target=tms34010`) resolve to it.
|
||||
|
||||
M10 responsibilities (the whole file is ~150 lines):
|
||||
|
||||
- `addClangTargetOptions`: append `-ffreestanding`, `-fno-builtin`,
|
||||
`-mllvm -replexitval=never`, and `-disable-O0-optnone` (the last because the
|
||||
legacy M9 path ran `-O0` without the `optnone` attribute, so the flag keeps
|
||||
native `-O0 -c` objects byte-identical to the M9 path).
|
||||
- Include behaviour: no system include directories (`-nostdinc` semantics
|
||||
without the flag); `-I` still works.
|
||||
- Keep object emission as today (integrated TI-COFF writer, no external
|
||||
assembler).
|
||||
- No link job yet: `-c`/`-S` are the M10 surface; linking stays with `tms-cc`
|
||||
until M11.
|
||||
|
||||
The static-variadic guard moves into `TMS34010BitPtrPass` as a pre-optimizer
|
||||
rejection: an `internal`/`private` variadic definition with no
|
||||
`llvm.va_start`/`va_arg` in the body is diagnosed with the same message the
|
||||
wrapper prints today.
|
||||
|
||||
### 7.7 What `tms-clang` becomes, and the gates that must change
|
||||
|
||||
`scripts/tms-clang` becomes a flag mapper:
|
||||
|
||||
| `tms-clang` flag | becomes |
|
||||
|---|---|
|
||||
| `-O0` / `-O2` | `clang --target=tms34010 -O0` / `-O2` |
|
||||
| `-g` | `-g` |
|
||||
| `-I dir` | `-I dir` |
|
||||
| `-o OUT.ll` | `-S -emit-llvm -o OUT.ll` |
|
||||
| `$TMS_CLANG_EXTRA_FLAGS` | passed through unchanged |
|
||||
| `$TMS_OPT` / `$TMS_BITADDR` | no longer used |
|
||||
|
||||
Gate edits required (same invariant, new seam):
|
||||
|
||||
| Gate | Today | M10 |
|
||||
|---|---|---|
|
||||
| `scripts/tests/m3/run.sh`, `scripts/tests/m5/jr.sh` | inject an `opt` wrapper to add `-replexitval=never` | pass nothing; assert the compile succeeds and the loop shape survives in the emitted IR |
|
||||
| `scripts/tests/m5/policy.sh` | traces `opt` arguments, asserts the flag and no `-switch-to-lookup` | asserts `-replexitval=never` appears in `clang -###` output (the ToolChain seam) and inspects the final IR/asm for the same shapes |
|
||||
| `scripts/tests/m4/mul.sh` | greps `scripts/tms-clang` for the flag | greps the ToolChain source/defaults, or asserts via `clang -###` |
|
||||
|
||||
### 7.8 Acceptance (M10)
|
||||
|
||||
1. **Native correctness:** `clang/test/CodeGen/TMS34010/` tests for `p[1]`
|
||||
(i32 → `ADDI 32`), byte/struct pointers, array indexing and pointer
|
||||
difference at `-O0` and `-O2`; an ordinary `for` loop compiles at `-O2`
|
||||
without extra flags.
|
||||
2. **Native end-to-end:** the pointer programs run correctly end to end
|
||||
(compile with native clang, link with the existing `tms-cc`/`tms-link` path,
|
||||
run under MAME) at `-O0` and `-O2`.
|
||||
3. **Equivalence (chosen criterion):** the full suite stays **1,618 pass / 294
|
||||
skip / 0 fail / 0 crash**; suite markers and checksums are unchanged; i64div
|
||||
stays 88/3302/221/120 with the same four checksums; a curated asm-shape set
|
||||
(pointer arithmetic, struct offsets, switch tables, aggregate returns)
|
||||
matches M9's shapes.
|
||||
4. **Pass equivalence:** proven end-to-end, because individual new-PM passes are
|
||||
not addressable from `opt` (it builds no `TargetMachine`): `clang -O0 -c`
|
||||
objects must be byte-identical to the M9 path, which exercises the barrier
|
||||
and lowering port directly, while the scaling pass is pinned by the M5 policy
|
||||
gate (switch table) and an `-O2` asm-shape set.
|
||||
5. **Unchanged gates:** lit 129/129 plus the new tests, clang 5/5 plus driver
|
||||
tests, every M2–M9 gate green after the §7.7 edits, which are reviewed as
|
||||
part of the milestone.
|
||||
6. **No user flags:** `clang --target=tms34010 -O2 -c` with nothing else.
|
||||
|
||||
## 8. Phase 3 (M11) design
|
||||
|
||||
### 8.1 Driver link job
|
||||
|
||||
Extend the M10 `ToolChain` with a link job invoking `tms-link`: `-o`,
|
||||
`--entry _start`, `--text`, `--bss`, `--prog-len`, `--ram-len`, libraries,
|
||||
optional `--map`. `-Wl,…` passes through; `-nostdlib` removes CRT and default
|
||||
libraries; `-g` maps to `--keep-debug` (and the default stays stripped).
|
||||
|
||||
**Linker prerequisite:** the production path must not depend on
|
||||
`coff-check.py --repair`. `tms-link` must emit a loader-valid image unaided
|
||||
(valid file/optional header, even `.bss`), and `coff-check.py` stays a *checker*
|
||||
in the gates. This is small linker work added to M11.1.
|
||||
|
||||
### 8.2 CRT, headers, library, sysroot
|
||||
|
||||
| Artifact | Source | Build |
|
||||
|---|---|---|
|
||||
| `crt0.o` | `sdk/crt0.asm`, generalised from `conformance/entry.asm`: `setf`, stack setup, call `main`, write status/magic | `llvm-mc -triple=tms34010 -filetype=obj`, reproducible |
|
||||
| headers | `sdk/include/` (moved from `scripts/tests/m5/conformance/include`) | installed into the sysroot |
|
||||
| `libtms.a` | `sdk/shim.c`, `sdk/heap.c` (printf family, `malloc`/`free`, `mem*`/`str*`) | System V `ar`, which `tms-link` reads |
|
||||
| `flib.lib`, `rts.lib` | committed copies of the extracted 1987 vendor archives | linked by default for the shim's `%f` path |
|
||||
|
||||
The sysroot layout is `lib/clang/<ver>/tms34010-unknown-none/{include,lib}` plus
|
||||
a `--tms-sysroot=` override. Because the vendor archives are committed and the
|
||||
CRT is reproducible, `clang --target=tms34010 hello.c -o hello` needs no
|
||||
project variables and no SDK extraction step.
|
||||
|
||||
The conformance harness and `tms-cc` point at the relocated headers rather than
|
||||
keeping a second copy.
|
||||
|
||||
### 8.3 Command surface after Phase 3
|
||||
|
||||
```
|
||||
clang --target=tms34010 hello.c -o hello # CRT + libtms + flib/rts + tms-link
|
||||
clang --target=tms34010 -c hello.c -o hello.o # TI-COFF object
|
||||
clang --target=tms34010 -S hello.c -o hello.s # GSPA assembly
|
||||
clang --target=tms34010 -O2 -g a.c b.c -o app # multi-TU, debug kept
|
||||
clang --target=tms34010 -nostdlib -Wl,--entry=_start ...
|
||||
tms-run hello # unchanged
|
||||
```
|
||||
|
||||
`scripts/tms-cc` stays as a compatibility alias adding `--run` and the project's
|
||||
default layout; it is no longer the recommended interface.
|
||||
|
||||
### 8.4 Acceptance (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` then `tms-run hello` prints
|
||||
`hello` with status 0, from a shell with no project variables set.
|
||||
2. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multi-TU and `-nostdlib` behave
|
||||
conventionally; `clang/test/Driver/TMS34010*.c` pins the link and include
|
||||
command lines.
|
||||
3. The CRT rebuilds byte-identically from source with no DOSBox/2ine dependency,
|
||||
and the committed vendor archives match the extracted originals.
|
||||
4. The single-command flow builds one M4/M5/M6 harness program unchanged.
|
||||
5. M2–M10 gates, lit, the conformance full suite and the i64div numbers are
|
||||
unchanged.
|
||||
|
||||
## 9. Constraints
|
||||
|
||||
- Branch `m10` from `m9`; `m11` from `m10` after Phase 2 is promoted. Default
|
||||
promotion only after a clean whole-branch review, per standing policy.
|
||||
- LLVM/Clang stay pinned at 23.1.5. `patches/llvm/0001..0004` stay as they are;
|
||||
Phase 2 adds `0005` (the `ToolChain` and its registration), extended in
|
||||
Phase 3.
|
||||
- Every existing gate, the TI ABI, the all-stack convention, GSPLNK as the
|
||||
byte/symbol oracle and the two-tier conformance harness stay intact.
|
||||
- No force-push, no default-branch change, no history rewrite.
|
||||
- `-O0` and `-O2` are both first-class.
|
||||
|
||||
## 10. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Barrier applied twice | Module-flag state machine (§7.3) with the scenario table as tests |
|
||||
| `llc`'s IR contract silently changes | Hooks only in the new-PM pipeline; `m2-late-gep.ll` and the 129 lit tests guard it |
|
||||
| Codegen-created late GEPs after lowering | Lowering in `addISelPrepare` before `CodeGenPrepare`, matching M9 order; `addrSinkUsingGEPs` stays disabled |
|
||||
| Debug info lost in the port | Barrier copies `!dbg`; M9.2 gates (`m9/dwarf-ranges.sh`, `m8/dwarf-multi.sh`, `m7/debug.sh`) must pass unchanged |
|
||||
| Pass port drifts from the oracle | `tools/tms-bitaddr` retained as the oracle (§7.8.4) |
|
||||
| Gate edits weaken coverage | Each §7.7 edit must assert the same invariant at the new seam and be reviewed |
|
||||
| `-replexitval` regresses on other loop shapes | Full suite plus the M3/M5 loop gates; the flag is a compile-time policy, not codegen |
|
||||
| Native `-O2` differs from M9 in size | Accepted by decision; behaviour gates (§7.8.3) replace byte identity |
|
||||
| Driver file grows into two phases of surgery | One file from M10, extended rather than rewritten in M11 |
|
||||
| `coff-check --repair` hides a tms-link defect | M11.1 fixes `tms-link`; the checker stays in the gate with `--repair` removed from production |
|
||||
| Committed vendor archives drift | Gate compares the committed copies against freshly extracted ones |
|
||||
| Two copies of headers/CRT | Phase 3 relocates the single source and regenerates harness paths |
|
||||
|
||||
## 11. Sequencing and what is left to the builder
|
||||
|
||||
**M10.0** minimal `ToolChain` (defaults + include behaviour) → **M10.1** pass
|
||||
port + oracle equivalence → **M10.2** pipeline hooks + state machine →
|
||||
**M10.3** `tms-clang` rewrite, gate edits, equivalence sweep → **M10.4**
|
||||
docs/gates/promote.
|
||||
|
||||
**M11.1** link job + `tms-link` header fix → **M11.2** `crt0` via `llvm-mc` →
|
||||
**M11.3** headers, `libtms.a`, committed vendor archives, sysroot → **M11.4**
|
||||
single-command end-to-end, docs, gates, promote.
|
||||
|
||||
Left to the builder (verify during implementation, do not re-litigate):
|
||||
|
||||
1. Exact pass signatures; whether InstCombine is added via
|
||||
`createInstructionCombiningPass`/`InstCombinePass(InstCombineOptions...)`.
|
||||
2. Whether `addISelPrepare` prepending is sufficient or `addIRPasses` also needs
|
||||
the safety-net lowering (measure both `-O0` outputs).
|
||||
3. Module-flag name/behaviour enum (`"tms.bitaddr"` / `Override` proposed).
|
||||
4. Whether the static-variadic guard belongs in the barrier pass or a separate
|
||||
pre-opt pass in the same callback.
|
||||
5. Sysroot resolution order (`-resource-dir` relative versus `--tms-sysroot`).
|
||||
6. Whether `libtms.a` is always linked or gated on `-l tms`, and how `flib`/`rts`
|
||||
are selected (`%f` needs them; `-nostdlib` must not).
|
||||
7. Whether `tms-cc`'s `--run` stays in the script.
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) | user |
|
||||
| clang-level defaults (`replexitval`, freestanding, includes) | Minimal `ToolChain` in Phase 2, extended in Phase 3 | user |
|
||||
| M10 success criterion | Runtime + suite equivalence | user |
|
||||
| Vendor `flib`/`rts` | Committed to the repo | user |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (no hosted libc/file I/O/libm) | user |
|
||||
| Milestone mapping | Phase 2 = M10, Phase 3 = M11 | this doc |
|
||||
| `-O0` pipeline | Barrier + lower in the start callback; no state-1 IR from clang | this doc |
|
||||
| `tms-bitaddr` fate | Test oracle, not a production path | this doc |
|
||||
| `llc` IR contract | Unchanged (bit offsets by definition) | this doc |
|
||||
| `-g` at link | Maps to `--keep-debug`; default stays stripped | this doc |
|
||||
| `coff-check.py --repair` | Leaves the production path; `tms-link` emits valid images | this doc |
|
||||
| Gate edits for the new seam | Required and reviewed (§7.7) | this doc |
|
||||
@@ -0,0 +1,200 @@
|
||||
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
|
||||
index 506536cdc04f..71ce08e3e5b6 100644
|
||||
--- a/clang/lib/Driver/CMakeLists.txt
|
||||
+++ b/clang/lib/Driver/CMakeLists.txt
|
||||
@@ -91,6 +91,7 @@ add_clang_library(clangDriver
|
||||
ToolChains/SPIRVOpenMP.cpp
|
||||
ToolChains/SYCL.cpp
|
||||
ToolChains/TCE.cpp
|
||||
+ ToolChains/TMS34010.cpp
|
||||
ToolChains/UEFI.cpp
|
||||
ToolChains/VEToolchain.cpp
|
||||
ToolChains/WebAssembly.cpp
|
||||
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
|
||||
index e606cdc4c1cf..8a36e6a29fae 100644
|
||||
--- a/clang/lib/Driver/Driver.cpp
|
||||
+++ b/clang/lib/Driver/Driver.cpp
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "ToolChains/Serenity.h"
|
||||
#include "ToolChains/Solaris.h"
|
||||
#include "ToolChains/TCE.h"
|
||||
+#include "ToolChains/TMS34010.h"
|
||||
#include "ToolChains/UEFI.h"
|
||||
#include "ToolChains/VEToolchain.h"
|
||||
#include "ToolChains/WebAssembly.h"
|
||||
@@ -7287,6 +7288,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
|
||||
case llvm::Triple::msp430:
|
||||
TC = std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
+ case llvm::Triple::tms34010:
|
||||
+ TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
+ break;
|
||||
case llvm::Triple::riscv32:
|
||||
case llvm::Triple::riscv64:
|
||||
case llvm::Triple::riscv32be:
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.cpp b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
new file mode 100644
|
||||
index 000000000000..a2fc8eb68917
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
@@ -0,0 +1,44 @@
|
||||
+//===--- TMS34010.cpp - TMS34010 ToolChain ----------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#include "TMS34010.h"
|
||||
+
|
||||
+using namespace clang;
|
||||
+using namespace clang::driver;
|
||||
+using namespace clang::driver::toolchains;
|
||||
+using namespace llvm::opt;
|
||||
+
|
||||
+TMS34010ToolChain::TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const ArgList &Args)
|
||||
+ : BareMetal(D, Triple, Args) {}
|
||||
+
|
||||
+void TMS34010ToolChain::addClangTargetOptions(
|
||||
+ const ArgList &DriverArgs, ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const {
|
||||
+ // The TMS34010 backend has no native 33-bit multiply, so IndVarSimplify's
|
||||
+ // i33 exit-value rewrite would otherwise reach code generation and abort on
|
||||
+ // an ordinary loop. Disable that rewrite, and compile freestanding with no
|
||||
+ // builtins (there is no libc for this target yet).
|
||||
+ CC1Args.push_back("-ffreestanding");
|
||||
+ CC1Args.push_back("-fno-builtin");
|
||||
+ CC1Args.push_back("-mllvm");
|
||||
+ CC1Args.push_back("-replexitval=never");
|
||||
+ // The legacy tms-clang path ran the -O0 pipeline without the `optnone`
|
||||
+ // attribute (it passed -disable-O0-optnone), so its -O0 objects carry the
|
||||
+ // mem2reg'd shape and no per-parameter spill slot. Match that so native
|
||||
+ // `clang --target=tms34010 -O0 -c` stays byte-identical to the M9 path.
|
||||
+ CC1Args.push_back("-disable-O0-optnone");
|
||||
+
|
||||
+ BareMetal::addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadKind);
|
||||
+}
|
||||
+
|
||||
+void TMS34010ToolChain::AddClangSystemIncludeArgs(const ArgList &,
|
||||
+ ArgStringList &) const {
|
||||
+ // No system include paths for this target. The builtin headers are located
|
||||
+ // through -resource-dir, matching the previous generic bare-metal behaviour.
|
||||
+}
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.h b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
new file mode 100644
|
||||
index 000000000000..598f85ba4b8f
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
@@ -0,0 +1,37 @@
|
||||
+//===--- TMS34010.h - TMS34010 ToolChain ------------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+
|
||||
+#include "BareMetal.h"
|
||||
+
|
||||
+namespace clang {
|
||||
+namespace driver {
|
||||
+namespace toolchains {
|
||||
+
|
||||
+class LLVM_LIBRARY_VISIBILITY TMS34010ToolChain : public BareMetal {
|
||||
+public:
|
||||
+ TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const llvm::opt::ArgList &Args);
|
||||
+
|
||||
+ void
|
||||
+ addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const override;
|
||||
+
|
||||
+ void
|
||||
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args) const override;
|
||||
+};
|
||||
+
|
||||
+} // namespace toolchains
|
||||
+} // namespace driver
|
||||
+} // namespace clang
|
||||
+
|
||||
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o0.c b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
new file mode 100644
|
||||
index 000000000000..e62cab807aa3
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
@@ -0,0 +1,18 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// The bit-address barrier hides each source GEP behind an opaque
|
||||
+// @__tms_bitptr(i32 bitoff, ptr base) call before the optimizer, and -O0
|
||||
+// lowers it straight back to the bit-addressed inttoptr(add) form, so a
|
||||
+// byte-indexed GEP must reach codegen as an 8x bit offset.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+short load_h(short *p) { return p[1]; }
|
||||
+int load_b(char *p) { return p[4]; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _load_h:
|
||||
+// CHECK: ADDI 16, A{{[0-9]+}}
|
||||
+// CHECK-LABEL: _load_b:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o2.c b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..39b0f38ce948
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
@@ -0,0 +1,17 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// At -O2 the barrier hides source GEPs before the optimizer, the post-opt
|
||||
+// scale rescales the byte GEPs the optimizer creates, lowering undoes the
|
||||
+// barrier, and a final instcombine canonicalizes the result, so a byte-indexed
|
||||
+// GEP must still reach codegen as an 8x bit offset. `-replexitval=never` is
|
||||
+// the ToolChain default (Task 1); %clang_cc1 bypasses the driver, so it is
|
||||
+// passed explicitly to keep the `sumto` loop below the i33 closed-form
|
||||
+// rewrite.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _sumto:
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
new file mode 100644
|
||||
index 000000000000..78aecf0a8424
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
@@ -0,0 +1,6 @@
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O1 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
+// CHECK: static variadic definition 'sum' loses its '...' arguments
|
||||
+static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
+int call(void) { return sum(1, 2); }
|
||||
diff --git a/clang/test/Driver/tms34010-defaults.c b/clang/test/Driver/tms34010-defaults.c
|
||||
new file mode 100644
|
||||
index 000000000000..670b094fd7bb
|
||||
--- /dev/null
|
||||
+++ b/clang/test/Driver/tms34010-defaults.c
|
||||
@@ -0,0 +1,8 @@
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
+// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
+// FLAGS-SAME: -fno-builtin
|
||||
+// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
+// FLAGS-SAME: "-disable-O0-optnone"
|
||||
+// NOSYS-NOT: "-internal-isystem"
|
||||
+int f(int n) { return n + 1; }
|
||||
+16
-15
@@ -25,7 +25,7 @@
|
||||
# (250,200) inside the mapped window. A markers-only or root-window bit is a
|
||||
# failure.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# Overridable: TMS_CLANG TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# SDK_IMG M3_WORK M3_COFF M3_SDK LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
@@ -34,8 +34,6 @@ DIR=$ROOT/scripts/m3
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
@@ -59,7 +57,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
@@ -68,19 +66,22 @@ mkdir -p "$(dirname "$COFF")"
|
||||
|
||||
# IndVarSimplify's exit-value replacement turns sumto's loop into an i33
|
||||
# multiply (n*(n+1)/2), and this target has no multiply or i64 support: llc
|
||||
# then dies selecting umul_lohi. Keep the loop (which is the point of the M3
|
||||
# branch test) by disabling only that rewrite, and only for branch.c; xhello
|
||||
# and layout use the normal optimizer pipeline. branch.c itself is unchanged.
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
# then dies selecting umul_lohi. The TMS34010 ToolChain passes
|
||||
# -mllvm -replexitval=never, so the ordinary tms-clang -O2 pipeline keeps the
|
||||
# loop (the point of the M3 branch test) with no local opt wrapper.
|
||||
echo "== compile and select"
|
||||
export TMS_CLANG TMS_BITADDR
|
||||
export TMS_CLANG
|
||||
for name in xhello branch layout; do
|
||||
opt=$TMS_OPT
|
||||
[ "$name" = branch ] && opt=$OPT_NOREPLEXIT
|
||||
TMS_OPT=$opt "$ROOT/scripts/tms-clang" -O2 -I "$DIR" -o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
# branch.c needs -fno-inline: at -O2 clang inlines sumto/max2/lt into
|
||||
# branch_test and constant-folds sumto(10), so the disassembler round-trip
|
||||
# would have no _sumto/_max2/_lt calls to check. -O0 would stop the inlining
|
||||
# too, but it also changes the branch condition codes the round-trip pins
|
||||
# (sumto LT/EQ, max2 GT); -fno-inline keeps the -O2 shapes and just leaves
|
||||
# the calls in place.
|
||||
extra=
|
||||
[ "$name" = branch ] && extra=-fno-inline
|
||||
TMS_CLANG_EXTRA_FLAGS=$extra "$ROOT/scripts/tms-clang" -O2 -I "$DIR" \
|
||||
-o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$ASM/$name.ll" -o "$ASM/$name.s" \
|
||||
|| fail "llc failed for $name.c"
|
||||
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 3 gate: bit-address pipeline idempotency and the codegen safety net.
|
||||
#
|
||||
# scripts/tests/m10/bitaddr-idempotent.sh
|
||||
#
|
||||
# Task 3 records the bit-address barrier/lowering lifecycle in the module flag
|
||||
# "tms.bitaddr" (1 = barriered, not lowered; 2 = lowered/final) and adds a
|
||||
# legacy codegen pass so a module that still holds an @__tms_bitptr call when it
|
||||
# reaches llc is lowered instead of emitted as a CALLA. This gate checks:
|
||||
#
|
||||
# 1. clang --target=tms34010 -O0 -S -emit-llvm on a pointer file leaves the
|
||||
# module flagged "tms.bitaddr" = 2 (lowered) with no @__tms_bitptr call;
|
||||
# 2. re-running the identical command produces byte-identical IR (idempotent);
|
||||
# 3. llc emits ADDI 32 for p[1] (a bit offset, not the byte offset 4);
|
||||
# 4. clang -c produces a TI-COFF object starting with the 0x0090 magic.
|
||||
#
|
||||
# Step 4 asserts the TI-COFF magic directly rather than running
|
||||
# scripts/m4/coff-check.py: that validator is linked-image specific (it requires
|
||||
# GSPLNK's optional header) and rejects a plain object ("invalid header
|
||||
# nscns=... opthdr=0").
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC M10_BITADDR_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
WORK=${M10_BITADDR_WORK:-$ROOT/build/m10-bitaddr-idempotent}
|
||||
|
||||
fail() {
|
||||
echo "m10 bitaddr idempotent: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
cat > "$WORK/src.c" <<'EOF'
|
||||
int load_i(int *p) { return p[1]; }
|
||||
EOF
|
||||
|
||||
echo "== clang -O0 -S -emit-llvm (run1) -> flag 2, no barrier"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run1.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm failed"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/run1.ll" \
|
||||
|| { grep -n 'tms.bitaddr\|__tms_bitptr' "$WORK/run1.ll" >&2 || true; \
|
||||
fail "run1.ll does not carry tms.bitaddr = 2"; }
|
||||
if grep -q '__tms_bitptr' "$WORK/run1.ll"; then
|
||||
fail "run1.ll still contains @__tms_bitptr (the barrier was not lowered)"
|
||||
fi
|
||||
|
||||
echo "== re-run the identical command -> byte-identical IR"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run2.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm (run2) failed"
|
||||
cmp "$WORK/run1.ll" "$WORK/run2.ll" \
|
||||
|| fail "the second compile is not byte-identical (not idempotent)"
|
||||
|
||||
# Re-entry: feed the already-lowered IR back through clang as IR input. The
|
||||
# barrier must see "tms.bitaddr" = 2 and skip, and the lowering must see a value
|
||||
# other than 1 and skip, so the re-entered module keeps flag 2, has no
|
||||
# @__tms_bitptr call, and is unchanged except for the ModuleID (which is the
|
||||
# input file's path, not the original source's).
|
||||
echo "== re-enter the lowered IR through clang -x ir -> still flag 2, unchanged"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -x ir \
|
||||
-o "$WORK/reentered.ll" "$WORK/run1.ll" \
|
||||
|| fail "clang -O0 -S -emit-llvm -x ir failed on run1.ll"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/reentered.ll" \
|
||||
|| fail "reentered.ll does not carry tms.bitaddr = 2"
|
||||
if grep -q '__tms_bitptr' "$WORK/reentered.ll"; then
|
||||
fail "reentered.ll still contains @__tms_bitptr (the barrier was re-applied)"
|
||||
fi
|
||||
grep -v '^; ModuleID' "$WORK/run1.ll" > "$WORK/run1.noid"
|
||||
grep -v '^; ModuleID' "$WORK/reentered.ll" > "$WORK/reentered.noid"
|
||||
cmp "$WORK/run1.noid" "$WORK/reentered.noid" \
|
||||
|| fail "the re-entered IR differs beyond the ModuleID line"
|
||||
|
||||
echo "== llc emits ADDI 32 for p[1] from the flagged IR"
|
||||
"$LLC" -march=tms34010 -O0 -filetype=asm -o "$WORK/run1.s" "$WORK/run1.ll" \
|
||||
|| fail "llc -filetype=asm failed on run1.ll"
|
||||
grep -Eq '^[[:space:]]*ADDI[[:space:]]+32([^0-9]|$)' "$WORK/run1.s" \
|
||||
|| { cat "$WORK/run1.s" >&2; fail "run1.s lacks ADDI 32 for p[1]"; }
|
||||
if grep -Eq '^[[:space:]]*ADDI[[:space:]]+4([^0-9]|$)' "$WORK/run1.s"; then
|
||||
cat "$WORK/run1.s" >&2
|
||||
fail "run1.s emits ADDI 4 (a byte offset, not the bit offset 32)"
|
||||
fi
|
||||
|
||||
echo "== clang -c produces a TI-COFF object with the 0x0090 magic"
|
||||
"$CLANG" --target=tms34010 -O0 -c -o "$WORK/native.o" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -c failed"
|
||||
python3 - "$WORK/native.o" <<'PY' || fail "native.o magic is wrong"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if not data:
|
||||
sys.exit("native.o is empty")
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
print(" native.o: %d bytes, TI-COFF magic 90 00" % len(data))
|
||||
PY
|
||||
|
||||
echo "m10 bitaddr idempotent: PASS"
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 4 gate: native/legacy object equivalence at -O0, and -O2 shape pinning.
|
||||
#
|
||||
# scripts/tests/m10/equivalence.sh
|
||||
#
|
||||
# Phase 1 (byte identity): every corpus translation unit is compiled twice and
|
||||
# the objects must be byte-identical:
|
||||
#
|
||||
# native: clang --target=tms34010 -O0 [-g] -c "$f" -o native.o
|
||||
# legacy: scripts/tests/m10/legacy-tms-clang -O0 [-g] -o legacy.ll "$f"
|
||||
# then llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o
|
||||
#
|
||||
# The frozen legacy-tms-clang (byte-identical to the m9 tms-clang) is the oracle;
|
||||
# native clang must reproduce it exactly. The corpus is every *.c in scripts/m4,
|
||||
# scripts/m5 and scripts/m6 plus the M5 conformance shim and heap. layout-ti.c is
|
||||
# excluded: it is the 1987 TI compiler's reference source (a union/struct tag
|
||||
# reuse modern clang rejects) whose output layout-ti.s is the golden for
|
||||
# scripts/tests/m4/layout.sh; it is not a clang-compilable input.
|
||||
#
|
||||
# Phase 2 (behaviour): a heredoc fixture is compiled at -O2 and its asm shapes are
|
||||
# FileChecked to pin the post-optimizer scaling pass on optimizer-created GEPs
|
||||
# (SROA aggregate strides, switch tables, aggregate-return .fca.N.gep loads).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC FILECHECK M10_EQUIV_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
FILECHECK=${FILECHECK:-$LLVM_BIN/FileCheck}
|
||||
LEGACY=$ROOT/scripts/tests/m10/legacy-tms-clang
|
||||
WORK=${M10_EQUIV_WORK:-$ROOT/build/m10-equivalence}
|
||||
INC=$ROOT/scripts/tests/m5/conformance/include
|
||||
|
||||
# The frozen legacy script derives its ROOT from its own path
|
||||
# (scripts/tests/m10), so its default tool paths are wrong. Point it at the real
|
||||
# build tools explicitly. TMS_OPT is only consulted for the -O2 branch the
|
||||
# gate never uses, but the script's tool check requires it to exist.
|
||||
export TMS_CLANG=$CLANG
|
||||
export TMS_OPT=$LLVM_BIN/opt
|
||||
export TMS_BITADDR=$ROOT/tools/tms-bitaddr/tms-bitaddr
|
||||
|
||||
fail() {
|
||||
echo "m10 equivalence: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
[ -x "$FILECHECK" ] || fail "missing FileCheck: $FILECHECK"
|
||||
[ -x "$LEGACY" ] || fail "missing legacy oracle: $LEGACY"
|
||||
[ -x "$TMS_BITADDR" ] || fail "missing tms-bitaddr: $TMS_BITADDR"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Emit one corpus path per line. layout-ti.c is the TI-compiler golden source.
|
||||
corpus() {
|
||||
for f in "$ROOT"/scripts/m4/*.c "$ROOT"/scripts/m5/*.c "$ROOT"/scripts/m6/*.c; do
|
||||
case "$f" in
|
||||
*layout-ti.c) ;;
|
||||
*) printf '%s\n' "$f" ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$ROOT/scripts/tests/m5/conformance/shim.c"
|
||||
printf '%s\n' "$ROOT/scripts/tests/m5/conformance/heap.c"
|
||||
}
|
||||
|
||||
# compare_mode MODE -- compile every corpus file native vs legacy and cmp.
|
||||
# Prints a per-mode summary and sets TOTPASS/TOTFAIL (global).
|
||||
compare_mode() {
|
||||
mode=$1
|
||||
pass=0
|
||||
failn=0
|
||||
echo "== equivalence at $mode"
|
||||
for f in $(corpus); do
|
||||
base=$(basename "$f")
|
||||
native=$WORK/$base.native.o
|
||||
legacy=$WORK/$base.legacy.ll
|
||||
legacyobj=$WORK/$base.legacy.o
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$CLANG" --target=tms34010 $mode -I "$INC" -c "$f" -o "$native" \
|
||||
2> "$WORK/$base.native.err"; then
|
||||
echo "FAIL (native compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.native.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$LEGACY" $mode -I "$INC" -o "$legacy" "$f" \
|
||||
2> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (legacy compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if ! "$LLC" -march=tms34010 -O0 -filetype=obj "$legacy" -o "$legacyobj" \
|
||||
2>> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (llc) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if cmp -s "$native" "$legacyobj"; then
|
||||
pass=$((pass + 1))
|
||||
echo "OK $base"
|
||||
else
|
||||
echo "DIFF $base"
|
||||
failn=$((failn + 1))
|
||||
fi
|
||||
done
|
||||
echo "m10 equivalence [$mode]: pass=$pass fail=$failn"
|
||||
TOTPASS=$((TOTPASS + pass))
|
||||
TOTFAIL=$((TOTFAIL + failn))
|
||||
}
|
||||
|
||||
TOTPASS=0
|
||||
TOTFAIL=0
|
||||
|
||||
compare_mode "-O0"
|
||||
compare_mode "-O0 -g"
|
||||
|
||||
echo "m10 equivalence: pass=$TOTPASS fail=$TOTFAIL"
|
||||
|
||||
if [ "$TOTFAIL" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Phase 2: pin the post-optimizer scaling pass on optimizer-created GEPs at -O2.
|
||||
echo "== -O2 shape pinning"
|
||||
cat > "$WORK/o2.c" <<'EOF'
|
||||
struct S { int a; int b; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int stride(struct S *p) { return p[3].b; }
|
||||
int sw_tab(int c) {
|
||||
switch (c) {
|
||||
case 10: return 7;
|
||||
case 11: return 3;
|
||||
case 12: return 9;
|
||||
case 13: return 1;
|
||||
case 14: return 5;
|
||||
case 15: return 2;
|
||||
case 16: return 8;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
__attribute__((noinline)) struct S mk(int a, int b) { struct S s; s.a = a; s.b = b; return s; }
|
||||
int use_mk(int a, int b) { return mk(a, b).b; }
|
||||
EOF
|
||||
"$CLANG" --target=tms34010 -O2 -S -o "$WORK/o2.s" "$WORK/o2.c" \
|
||||
|| fail "clang -O2 -S failed on the shape fixture"
|
||||
cat > "$WORK/o2.checks" <<'EOF'
|
||||
CHECK-LABEL: _load_i:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 4, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _stride:
|
||||
; The p[3] and .b offsets are now llvm.tms34010.bitaddr (BITADDR) nodes, so
|
||||
; the field offset stays relative instead of folding to the absolute 224.
|
||||
CHECK: ADDI 192, A{{[0-9]+}}
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 28, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _sw_tab:
|
||||
CHECK: SLL 3, A{{[0-9]+}}
|
||||
CHECK: MOVB {{.*}}A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _mk:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _use_mk:
|
||||
CHECK: CALLA _mk
|
||||
CHECK: ADDI -32, A{{[0-9]+}}
|
||||
EOF
|
||||
"$FILECHECK" "$WORK/o2.checks" < "$WORK/o2.s" \
|
||||
|| fail "-O2 shape pinning failed"
|
||||
|
||||
echo "m10 equivalence: PASS"
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
#!/bin/sh
|
||||
# tms-clang -- C IR pipeline: clang IR, the --bitptr semantic barrier, optimize,
|
||||
# scale the late byte-indexed GEPs, lower the barrier, and restore the M0
|
||||
# pointer-difference folding.
|
||||
#
|
||||
# Usage: tms-clang [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c
|
||||
#
|
||||
# -O0: clang IR -> --bitptr -> --lower-bitptr -> OUT (bit-addressed).
|
||||
# -O2 (the default): clang IR -> --bitptr -> opt -> --scale -> --lower-bitptr
|
||||
# -> opt -passes=instcombine -> OUT.
|
||||
#
|
||||
# -g passes clang -g through to the IR; the barrier passes copy !dbg
|
||||
# locations, so llc -filetype=obj emits the DWARF `.debug_*` sections. The
|
||||
# asm path still has no GSPA-assemblable debug directives.
|
||||
#
|
||||
# The barrier is required by the M0/M2 pointer model: pointers are bit
|
||||
# addresses, so `(int)(p + n) - (int)p` must be 8n at run time (the optimizer's
|
||||
# DataLayout would otherwise fold it to n). `--bitptr` replaces every GEP (and
|
||||
# an inttoptr of a bit addend over a ptrtoint base) with an opaque
|
||||
# @__tms_bitptr(i32 bitoff, ptr base) call, so InstCombine cannot canonicalize
|
||||
# the already-scaled bit offset back into a byte-indexed GEP; the M6 post-opt
|
||||
# `--scale` then multiplied that index by 8 again (the `p += n` over-scale, and
|
||||
# the reason the shim's memmove used constant end-pointer steps).
|
||||
#
|
||||
# The optimizer still creates genuinely byte-indexed GEPs (SROA aggregate
|
||||
# splits, switch tables), so the post-opt `--scale` is needed for those. By
|
||||
# then every original GEP is a call, so the pass only sees optimizer-created
|
||||
# byte GEPs. `--normalize` is not used there: it would treat those byte
|
||||
# offsets as already-scaled bits, which an aggregate return's `.fca.N.gep`
|
||||
# load (+4 bytes, not +4 bits) turns into an 8x address bug.
|
||||
#
|
||||
# `--lower-bitptr` then replaces each call with inttoptr(add(ptrtoint base,
|
||||
# bitoff)) and the final instcombine restores the M0 pointer-difference folding
|
||||
# (`int_diff` 8/32, the pointer-difference divide) and canonicalizes the
|
||||
# lowered bit GEPs, which llc already treats as bit offsets.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# The fork build (TMS34010 target + clang bit-address changes). The older
|
||||
# `build/llvm-build` tree is a stock clang without the target and has no
|
||||
# matching opt, so it is not a usable default.
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/build/llvm-clean-build/bin/clang}
|
||||
TMS_OPT=${TMS_OPT:-$ROOT/build/llvm-clean-build/bin/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
# Extra language flags from the caller (M4_EXTRA_CFLAGS). The conformance
|
||||
# c-torture sweep uses this for -std=gnu89; shipped gates leave it empty.
|
||||
TMS_CLANG_EXTRA_FLAGS=${TMS_CLANG_EXTRA_FLAGS:-}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
if [ ! -x "$tool" ]; then
|
||||
echo "tms-clang: missing tool: $tool" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG/TMS_OPT/TMS_BITADDR" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
OPTIMIZE=1
|
||||
DEBUG_FLAGS=
|
||||
INCLUDES=
|
||||
OUT=
|
||||
IN=
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-O0) OPTIMIZE=0; shift ;;
|
||||
-O2) OPTIMIZE=1; shift ;;
|
||||
-g) DEBUG_FLAGS=-g; shift ;;
|
||||
-I) [ $# -ge 2 ] || usage; INCLUDES="$INCLUDES -I $2"; shift 2 ;;
|
||||
-I*) INCLUDES="$INCLUDES $1"; shift ;;
|
||||
-o) [ $# -ge 2 ] || usage; OUT=$2; shift 2 ;;
|
||||
-*) usage ;;
|
||||
*) [ -z "$IN" ] || usage; IN=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$IN" ] || usage
|
||||
[ -n "$OUT" ] || usage
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tms-clang.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
$DEBUG_FLAGS -S -emit-llvm -ffreestanding -fno-builtin -nostdinc $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS \
|
||||
-o "$TMP/step1.ll" "$IN"
|
||||
|
||||
# A `static` variadic definition is local, so DeadArgumentElimination removes
|
||||
# its `...` when nothing keeps the varargs alive and rewrites every call site
|
||||
# to drop the extra arguments. The M4 contiguous-stack walk in the body still
|
||||
# reads those slots, so -O2 silently miscompiles it. Reject that shape before
|
||||
# opt, but leave a definition that genuinely uses a va_list alone (M6):
|
||||
# llvm.va_start/va_arg keep `...` through DAE, and the target lowers the walk
|
||||
# from the named argument area rather than the last fixed parameter. -O0
|
||||
# (which M4's varargs gate uses) and external definitions such as sprintf are
|
||||
# unaffected.
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
STATIC_VARARG=$(awk '
|
||||
/^define / {
|
||||
in_def = 1
|
||||
sig = $0
|
||||
va_start = 0
|
||||
next
|
||||
}
|
||||
in_def && /llvm\.va_start|va_arg ptr/ { va_start = 1 }
|
||||
in_def && /^}/ {
|
||||
if (!va_start &&
|
||||
sig ~ /[^A-Za-z0-9_](internal|private)[^A-Za-z0-9_]/ &&
|
||||
sig ~ /\.\.\./) {
|
||||
print sig
|
||||
exit
|
||||
}
|
||||
in_def = 0
|
||||
}
|
||||
' "$TMP/step1.ll")
|
||||
if [ -n "$STATIC_VARARG" ]; then
|
||||
NAME=$(printf '%s\n' "$STATIC_VARARG" |
|
||||
sed -n 's/.*@\([A-Za-z0-9_.$-]*\)(.*/\1/p')
|
||||
echo "tms-clang: error: static variadic definition '${NAME:-?}' loses its" \
|
||||
"'...' arguments at -O2 (dead argument elimination); remove 'static'" \
|
||||
"or compile with -O0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hide every source GEP (and source pointer-int arithmetic) behind the opaque
|
||||
# bit-pointer barrier before the optimizer, so the bit-addressed model survives
|
||||
# without being re-canonicalized into byte GEPs.
|
||||
run_bitaddr() { # run_bitaddr MODE IN OUT
|
||||
if ! "$TMS_BITADDR" "$1" "$2" "$3" 2> "$TMP/bitaddr.err"; then
|
||||
cat "$TMP/bitaddr.err" >&2
|
||||
echo "tms-clang: error: tms-bitaddr $1 failed on $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$TMP/bitaddr.err" "$TMP/bitaddr-$1.log"
|
||||
}
|
||||
|
||||
run_bitaddr --bitptr "$TMP/step1.ll" "$TMP/bitptr.ll"
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
# i64 exists since M6, but IndVarSimplify's exit-value replacement still
|
||||
# rewrites a loop's final value into a closed-form i33 multiply (e.g.
|
||||
# n*(n+1)/2 for sumto), which is an unsupported shape for this 32-bit
|
||||
# target. -replexitval is an option of IndVarSimplify; disabling only that
|
||||
# rewrite keeps the loop, which is what ordinary -O2 code needs. This is a
|
||||
# driver policy, not a target TTI policy: opt runs without a target machine
|
||||
# here. llc diagnoses the raw i33 shape reached by an opt run that omits
|
||||
# this flag (m5-policy.ll).
|
||||
"$TMS_OPT" -passes='default<O2>' -replexitval=never \
|
||||
-S "$TMP/bitptr.ll" -o "$TMP/opt.ll"
|
||||
# The optimizer may create new byte-indexed GEPs (SROA aggregate splits,
|
||||
# switch tables), so scale those. Every source GEP is still an opaque call,
|
||||
# so this pass cannot see (and re-scale) an already-bit offset.
|
||||
run_bitaddr --scale "$TMP/opt.ll" "$TMP/scaled.ll"
|
||||
# Lower the barrier and restore the M0 pointer-difference folding. The
|
||||
# lowered inttoptr(add) shapes canonicalize to GEPs whose index is already
|
||||
# a bit count; llc treats a GEP index as a bit offset, and no scale follows.
|
||||
# `no-verify-fixpoint` suppresses only InstCombine's idempotence check: the
|
||||
# M6 shim's emit_uint64 has a `zext i32 %base to i64` that a second run
|
||||
# would re-mark `nneg`, which the verifier reports as "did not reach a
|
||||
# fixpoint". The first run's output is the intended IR and all gates pass
|
||||
# with it; the flag is the documented escape for this known shape.
|
||||
run_bitaddr --lower-bitptr "$TMP/scaled.ll" "$TMP/lowered.ll"
|
||||
"$TMS_OPT" -passes='instcombine<no-verify-fixpoint>' \
|
||||
-S "$TMP/lowered.ll" -o "$OUT"
|
||||
else
|
||||
# No optimizer, so no byte GEPs can be created; lower the barrier directly
|
||||
# back to the historical bit-addressed inttoptr(add) form.
|
||||
run_bitaddr --lower-bitptr "$TMP/bitptr.ll" "$OUT"
|
||||
fi
|
||||
@@ -27,12 +27,14 @@
|
||||
# elsewhere in the body (an unrelated local at *FP(64), the constant 0x400,
|
||||
# an 0x4800 that merely shares a prefix) is not evidence.
|
||||
#
|
||||
# Our branch.c is built exactly like the M3 gate: tms-clang -O2 with the
|
||||
# -replexitval=never optimizer (that rewrite would turn sumto's loop into an
|
||||
# i33 multiply, which the target cannot select), then llc -O0. Dropping
|
||||
# -replexitval=never makes this check fail to compile the loop, not pass.
|
||||
# Our branch.c is built exactly like the M3 gate: tms-clang -O2 then llc -O0.
|
||||
# The TMS34010 ToolChain passes -mllvm -replexitval=never (IndVarSimplify's
|
||||
# exit-value replacement would otherwise turn sumto's loop into an i33
|
||||
# multiply, which the target cannot select), so the ordinary -O2 pipeline
|
||||
# keeps the loop with no local opt wrapper. Removing that default makes this
|
||||
# check fail to compile the loop, not pass.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TI_BRANCH TI_XHELLO
|
||||
# Overridable: TMS_CLANG TMS_LLC TI_BRANCH TI_XHELLO
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
@@ -41,19 +43,17 @@ SRC=$ROOT/scripts/m3
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TI_BRANCH=${TI_BRANCH:-$DIR/ti-branch.s}
|
||||
TI_XHELLO=${TI_XHELLO:-$DIR/ti-xhello.s}
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
export TMS_CLANG
|
||||
|
||||
fail() {
|
||||
echo "M3 diff: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$TI_BRANCH" ] || fail "stored TI golden missing: $TI_BRANCH"
|
||||
@@ -62,13 +62,8 @@ done
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m3-diff.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# branch.c is generated through a wrapper so only this file keeps its loop.
|
||||
OPT_NOREPLEXIT=$TMP/opt-noreplexit
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
echo "== compile our branch.s and xhello.s"
|
||||
TMS_OPT=$OPT_NOREPLEXIT "$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$TMP/branch.ll" "$SRC/branch.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$TMP/branch.ll" -o "$TMP/branch.s"
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
|
||||
@@ -9,6 +9,9 @@ ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_MUL_WORK:-$ROOT/build/m4-mul}
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
|
||||
fail() {
|
||||
echo "m4 mul: FAIL: $*" >&2
|
||||
exit 1
|
||||
@@ -24,10 +27,12 @@ M4_WORK="$WORK" \
|
||||
ASM=$WORK/m4.asm
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
|
||||
# The loop source must compile with the ordinary driver -O2 pipeline: no local
|
||||
# -replexitval flag and no i33/i64 multiply in the emitted IR.
|
||||
grep -q -- '-replexitval=never' "$ROOT/scripts/tms-clang" \
|
||||
|| fail "scripts/tms-clang does not disable IndVarSimplify exit-value replacement"
|
||||
# The loop source must compile with the ordinary driver -O2 pipeline: the
|
||||
# TMS34010 ToolChain passes -mllvm -replexitval=never (asserted at the driver
|
||||
# seam), and no i33/i64 multiply may appear in the emitted IR.
|
||||
"$TMS_CLANG" -### --target=tms34010 -O2 -c "$DIR/loop.c" 2>&1 \
|
||||
| grep -q -- '-replexitval=never' \
|
||||
|| fail "the TMS34010 driver does not disable IndVarSimplify exit-value replacement"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/asm/loop.ll"; then
|
||||
sed 's/^/ /' "$WORK/asm/loop.ll" >&2
|
||||
fail "loop.ll still contains an i33/i64 multiply"
|
||||
|
||||
+15
-11
@@ -21,7 +21,7 @@
|
||||
#
|
||||
# scripts/tests/m5/jr.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LLVM_MC
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_LLC TMS_LLVM_MC
|
||||
# DIS34 M5_JR_WORK DOSBOX MAME MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
@@ -29,8 +29,6 @@ ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
@@ -44,7 +42,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
@@ -109,14 +107,12 @@ PY
|
||||
}
|
||||
|
||||
# The M3 gate keeps the loop in branch.c (IndVarSimplify would otherwise turn
|
||||
# sumto into an i33 multiply that this target cannot select).
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
# sumto into an i33 multiply that this target cannot select). The TMS34010
|
||||
# ToolChain passes -mllvm -replexitval=never, so tms-clang -O2 keeps the loop
|
||||
# without the local opt wrapper this gate used to install.
|
||||
|
||||
echo "== compile the M3 branch.c loop"
|
||||
TMS_OPT=$OPT_NOREPLEXIT TMS_CLANG="$TMS_CLANG" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$WORK/branch.ll" "$SRC/branch.c" || fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.s" || fail "llc -filetype=asm failed"
|
||||
@@ -229,7 +225,15 @@ echo "== linked .text size"
|
||||
# bytes, so re-measure after changing the ABI. M7.3 grew the v2.2 table from
|
||||
# 30 to 36 entries; scripts/m3/run.sh generates a 6-byte JAUC stub for every
|
||||
# entry, so the linked image gained 6*6 = 36 bytes (874 -> 910). The stub set
|
||||
# is part of this fixture, not target code.
|
||||
# is part of this fixture, not target code. M10's native clang -O2 pipeline
|
||||
# (the driver seam now supplies -replexitval=never) tightens the -O2 codegen
|
||||
# across all three M3 TUs (branch.c, layout.c and xhello.c). The earlier M10
|
||||
# pin of 850 was measured while the -O2 path still misread bit offsets as byte
|
||||
# offsets (DAGCombiner re-chained a memcpy source load and the f64 MSW store
|
||||
# past the stores producing them) and folded f32/f64 constants to IEEE bits;
|
||||
# closing those hazards in the debug cycle costs instructions, and the correct
|
||||
# size returns to 910 — the same value the M9 legacy path produced. The JR
|
||||
# count is unchanged.
|
||||
EXPECTED_TEXT_BYTES=910
|
||||
EXPECTED_JR=14
|
||||
TEXT_BITS=$(awk '$1 == ".text" && $2 == "0" { print $4; exit }' "$M3_WORK/m3.map")
|
||||
|
||||
+24
-35
@@ -18,8 +18,7 @@
|
||||
#
|
||||
# scripts/tests/m5/policy.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR TMS_DRIVER
|
||||
# M5_POLICY_WORK
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_LLC TMS_DRIVER M5_POLICY_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
@@ -28,7 +27,6 @@ LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_DRIVER=${TMS_DRIVER:-$ROOT/scripts/tms-clang}
|
||||
WORK=${M5_POLICY_WORK:-$ROOT/build/m5-policy}
|
||||
|
||||
@@ -37,38 +35,30 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_DRIVER"; do
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_DRIVER"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
export TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR
|
||||
export TMS_CLANG TMS_OPT TMS_LLC
|
||||
|
||||
# 1. The switch-to-lookup workaround is gone and the ordinary -O2 path still
|
||||
# produces a table that is indexed in bits. Trace the real opt invocation
|
||||
# rather than grepping the driver source.
|
||||
OPT_REAL=$TMS_OPT
|
||||
TRACE=$WORK/opt-switch.args
|
||||
cat > "$WORK/opt-trace" <<EOF
|
||||
#!/bin/sh
|
||||
printf '%s\n' "\$*" >> "$TRACE"
|
||||
exec "$OPT_REAL" "\$@"
|
||||
EOF
|
||||
chmod +x "$WORK/opt-trace"
|
||||
export TRACE
|
||||
: > "$TRACE"
|
||||
|
||||
TMS_OPT=$WORK/opt-trace "$TMS_DRIVER" -O2 -o "$WORK/switch.ll" \
|
||||
"$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "default -O2 could not compile the M4 switch"
|
||||
grep -q -- '-replexitval=never' "$TRACE" \
|
||||
|| { sed 's/^/ /' "$TRACE" >&2; \
|
||||
fail "the opt invocation does not pass -replexitval=never"; }
|
||||
if grep -q -- '-switch-to-lookup' "$TRACE"; then
|
||||
sed 's/^/ /' "$TRACE" >&2
|
||||
fail "the opt invocation still passes -switch-to-lookup"
|
||||
# produces a table that is indexed in bits. tms-clang is now a flag mapper
|
||||
# over clang, so assert the driver policy at the driver seam (-###) instead
|
||||
# of tracing an opt invocation that no longer happens.
|
||||
"$TMS_CLANG" -### --target=tms34010 -O2 -c "$ROOT/scripts/m4/switch.c" \
|
||||
> "$WORK/driver.args" 2>&1 \
|
||||
|| fail "the driver seam could not be queried"
|
||||
grep -q -- '-replexitval=never' "$WORK/driver.args" \
|
||||
|| { sed 's/^/ /' "$WORK/driver.args" >&2; \
|
||||
fail "the driver does not pass -replexitval=never"; }
|
||||
if grep -q -- '-switch-to-lookup' "$WORK/driver.args"; then
|
||||
sed 's/^/ /' "$WORK/driver.args" >&2
|
||||
fail "the driver still passes -switch-to-lookup"
|
||||
fi
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/switch.ll" "$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "default -O2 could not compile the M4 switch"
|
||||
grep -q 'switch.table' "$WORK/switch.ll" \
|
||||
|| fail "the M4 switch produced no lookup table (the test is not exercising the fix)"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/switch.ll" \
|
||||
@@ -86,8 +76,8 @@ if ! grep -Eq '^[[:space:]]*MOVB[[:space:]]+\*A[0-9]+' "$WORK/sw_tile.s"; then
|
||||
fi
|
||||
echo " ok default -O2 switch table is indexed in bits"
|
||||
|
||||
# 2. The driver keeps its documented -replexitval policy (traced above) and the
|
||||
# loop is not rewritten into an unsupported closed form.
|
||||
# 2. The driver keeps its documented -replexitval policy (asserted at the -###
|
||||
# seam above) and the loop is not rewritten into an unsupported closed form.
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/loop.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "default -O2 could not compile the M4 loop"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/loop.ll"; then
|
||||
@@ -100,14 +90,13 @@ echo " ok driver -O2 keeps the loop and passes -replexitval=never"
|
||||
|
||||
# 3. The raw opt+llc path (no -replexitval) reaches the closed-form i33
|
||||
# multiply. It must fail with the target's clear diagnostic, not a
|
||||
# SelectionDAG "Cannot select" or an assertion.
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
-S -emit-llvm -ffreestanding -fno-builtin -nostdinc \
|
||||
# SelectionDAG "Cannot select" or an assertion. The native clang -O0 emit
|
||||
# is fed straight to opt without -replexitval; the barrier/lowering has
|
||||
# already run inside clang, so no tms-bitaddr step is needed.
|
||||
"$TMS_CLANG" --target=tms34010 -O0 -S -emit-llvm \
|
||||
-o "$WORK/loop.step1.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "clang could not emit the raw loop IR"
|
||||
"$TMS_BITADDR" --scale "$WORK/loop.step1.ll" "$WORK/loop.scaled.ll" 2>/dev/null \
|
||||
|| fail "tms-bitaddr --scale failed"
|
||||
"$TMS_OPT" -passes='default<O2>' -S "$WORK/loop.scaled.ll" \
|
||||
"$TMS_OPT" -passes='default<O2>' -S "$WORK/loop.step1.ll" \
|
||||
-o "$WORK/loop.opt.ll" || fail "opt failed on the raw loop"
|
||||
grep -Eq '\bmul i(33|64)\b' "$WORK/loop.opt.ll" \
|
||||
|| fail "the raw opt pipeline did not produce the i33 multiply"
|
||||
|
||||
@@ -108,8 +108,10 @@ grep -A8 'define.*@narrow8(' "$IR" | grep -Eq 'and i32 .*, 255' \
|
||||
|| { grep -A8 'define.*@narrow8(' "$IR" >&2 || true; \
|
||||
fail "narrow8 lost its (p & 0xff) mask"; }
|
||||
for fn in late64 late64s; do
|
||||
# The 24-bit addend now spells llvm.tms34010.bitaddr(base, 24) instead of
|
||||
# the foldable add; still reject the byte-scaled 192 below.
|
||||
grep -A8 "define.*@$fn(" "$IR" \
|
||||
| grep -Eq 'getelementptr i8, ptr %p, i32 24|add i32 %bit[.a-z0-9]*, 24' \
|
||||
| grep -Eq 'getelementptr i8, ptr %p, i32 24|add i32 %bit[.a-z0-9]*, 24|llvm\.tms34010\.bitaddr\(i32 %bit[.a-z0-9]*, i32 24\)' \
|
||||
|| { grep -A8 "define.*@$fn(" "$IR" >&2 || true; \
|
||||
fail "$fn does not carry the 24-bit addend"; }
|
||||
if grep -A8 "define.*@$fn(" "$IR" | grep -Eq 'i32 192'; then
|
||||
|
||||
+29
-135
@@ -1,61 +1,44 @@
|
||||
#!/bin/sh
|
||||
# tms-clang -- C IR pipeline: clang IR, the --bitptr semantic barrier, optimize,
|
||||
# scale the late byte-indexed GEPs, lower the barrier, and restore the M0
|
||||
# pointer-difference folding.
|
||||
# tms-clang -- thin flag mapper onto the fork's clang driver.
|
||||
#
|
||||
# Usage: tms-clang [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c
|
||||
#
|
||||
# -O0: clang IR -> --bitptr -> --lower-bitptr -> OUT (bit-addressed).
|
||||
# -O2 (the default): clang IR -> --bitptr -> opt -> --scale -> --lower-bitptr
|
||||
# -> opt -passes=instcombine -> OUT.
|
||||
# The TMS34010 ToolChain now supplies this target's compile defaults
|
||||
# (`-ffreestanding`, `-fno-builtin`, no system includes,
|
||||
# `-mllvm -replexitval=never`, `-disable-O0-optnone`), and the bit-pointer
|
||||
# barrier / lowering pipeline runs inside clang's own pipeline (guarded by the
|
||||
# `"tms.bitaddr"` module flag), so this script no longer drives `tms-bitaddr`
|
||||
# or `opt`. It maps its historical CLI onto a single clang invocation:
|
||||
#
|
||||
# -g passes clang -g through to the IR; the barrier passes copy !dbg
|
||||
# locations, so llc -filetype=obj emits the DWARF `.debug_*` sections. The
|
||||
# asm path still has no GSPA-assemblable debug directives.
|
||||
# clang --target=tms34010 [-O0|-O2] [-g] [-I dir] -S -emit-llvm -o OUT.ll IN.c
|
||||
#
|
||||
# The barrier is required by the M0/M2 pointer model: pointers are bit
|
||||
# addresses, so `(int)(p + n) - (int)p` must be 8n at run time (the optimizer's
|
||||
# DataLayout would otherwise fold it to n). `--bitptr` replaces every GEP (and
|
||||
# an inttoptr of a bit addend over a ptrtoint base) with an opaque
|
||||
# @__tms_bitptr(i32 bitoff, ptr base) call, so InstCombine cannot canonicalize
|
||||
# the already-scaled bit offset back into a byte-indexed GEP; the M6 post-opt
|
||||
# `--scale` then multiplied that index by 8 again (the `p += n` over-scale, and
|
||||
# the reason the shim's memmove used constant end-pointer steps).
|
||||
# `-disable-O0-optnone` keeps the -O0 pipeline running the barrier/lowering
|
||||
# passes, so `-O0` objects stay byte-identical to the M9 tms-clang + opt path
|
||||
# (proven by scripts/tests/m10/equivalence.sh against the frozen
|
||||
# legacy-tms-clang oracle). `-g` passes through to the IR; the barrier passes
|
||||
# copy !dbg locations, so llc -filetype=obj emits the DWARF `.debug_*` sections.
|
||||
#
|
||||
# The optimizer still creates genuinely byte-indexed GEPs (SROA aggregate
|
||||
# splits, switch tables), so the post-opt `--scale` is needed for those. By
|
||||
# then every original GEP is a call, so the pass only sees optimizer-created
|
||||
# byte GEPs. `--normalize` is not used there: it would treat those byte
|
||||
# offsets as already-scaled bits, which an aggregate return's `.fca.N.gep`
|
||||
# load (+4 bytes, not +4 bits) turns into an 8x address bug.
|
||||
#
|
||||
# `--lower-bitptr` then replaces each call with inttoptr(add(ptrtoint base,
|
||||
# bitoff)) and the final instcombine restores the M0 pointer-difference folding
|
||||
# (`int_diff` 8/32, the pointer-difference divide) and canonicalizes the
|
||||
# lowered bit GEPs, which llc already treats as bit offsets.
|
||||
# The `static` variadic rejection that used to live here (the awk guard) is now
|
||||
# owned by the barrier pass, which rejects the shape at every non-`-O0` level.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# The fork build (TMS34010 target + clang bit-address changes). The older
|
||||
# `build/llvm-build` tree is a stock clang without the target and has no
|
||||
# matching opt, so it is not a usable default.
|
||||
# `build/llvm-build` tree is a stock clang without the target and is not a
|
||||
# usable default.
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/build/llvm-clean-build/bin/clang}
|
||||
TMS_OPT=${TMS_OPT:-$ROOT/build/llvm-clean-build/bin/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
# Extra language flags from the caller (M4_EXTRA_CFLAGS). The conformance
|
||||
# c-torture sweep uses this for -std=gnu89; shipped gates leave it empty.
|
||||
TMS_CLANG_EXTRA_FLAGS=${TMS_CLANG_EXTRA_FLAGS:-}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
if [ ! -x "$tool" ]; then
|
||||
echo "tms-clang: missing tool: $tool" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG/TMS_OPT/TMS_BITADDR" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [ ! -x "$TMS_CLANG" ]; then
|
||||
echo "tms-clang: missing tool: $TMS_CLANG" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPTIMIZE=1
|
||||
OPT_FLAGS=-O2
|
||||
DEBUG_FLAGS=
|
||||
INCLUDES=
|
||||
OUT=
|
||||
@@ -68,8 +51,8 @@ usage() {
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-O0) OPTIMIZE=0; shift ;;
|
||||
-O2) OPTIMIZE=1; shift ;;
|
||||
-O0) OPT_FLAGS=-O0; shift ;;
|
||||
-O2) OPT_FLAGS=-O2; shift ;;
|
||||
-g) DEBUG_FLAGS=-g; shift ;;
|
||||
-I) [ $# -ge 2 ] || usage; INCLUDES="$INCLUDES -I $2"; shift 2 ;;
|
||||
-I*) INCLUDES="$INCLUDES $1"; shift ;;
|
||||
@@ -82,97 +65,8 @@ done
|
||||
[ -n "$IN" ] || usage
|
||||
[ -n "$OUT" ] || usage
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tms-clang.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
$DEBUG_FLAGS -S -emit-llvm -ffreestanding -fno-builtin -nostdinc $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS \
|
||||
-o "$TMP/step1.ll" "$IN"
|
||||
|
||||
# A `static` variadic definition is local, so DeadArgumentElimination removes
|
||||
# its `...` when nothing keeps the varargs alive and rewrites every call site
|
||||
# to drop the extra arguments. The M4 contiguous-stack walk in the body still
|
||||
# reads those slots, so -O2 silently miscompiles it. Reject that shape before
|
||||
# opt, but leave a definition that genuinely uses a va_list alone (M6):
|
||||
# llvm.va_start/va_arg keep `...` through DAE, and the target lowers the walk
|
||||
# from the named argument area rather than the last fixed parameter. -O0
|
||||
# (which M4's varargs gate uses) and external definitions such as sprintf are
|
||||
# unaffected.
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
STATIC_VARARG=$(awk '
|
||||
/^define / {
|
||||
in_def = 1
|
||||
sig = $0
|
||||
va_start = 0
|
||||
next
|
||||
}
|
||||
in_def && /llvm\.va_start|va_arg ptr/ { va_start = 1 }
|
||||
in_def && /^}/ {
|
||||
if (!va_start &&
|
||||
sig ~ /[^A-Za-z0-9_](internal|private)[^A-Za-z0-9_]/ &&
|
||||
sig ~ /\.\.\./) {
|
||||
print sig
|
||||
exit
|
||||
}
|
||||
in_def = 0
|
||||
}
|
||||
' "$TMP/step1.ll")
|
||||
if [ -n "$STATIC_VARARG" ]; then
|
||||
NAME=$(printf '%s\n' "$STATIC_VARARG" |
|
||||
sed -n 's/.*@\([A-Za-z0-9_.$-]*\)(.*/\1/p')
|
||||
echo "tms-clang: error: static variadic definition '${NAME:-?}' loses its" \
|
||||
"'...' arguments at -O2 (dead argument elimination); remove 'static'" \
|
||||
"or compile with -O0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hide every source GEP (and source pointer-int arithmetic) behind the opaque
|
||||
# bit-pointer barrier before the optimizer, so the bit-addressed model survives
|
||||
# without being re-canonicalized into byte GEPs.
|
||||
run_bitaddr() { # run_bitaddr MODE IN OUT
|
||||
if ! "$TMS_BITADDR" "$1" "$2" "$3" 2> "$TMP/bitaddr.err"; then
|
||||
cat "$TMP/bitaddr.err" >&2
|
||||
echo "tms-clang: error: tms-bitaddr $1 failed on $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$TMP/bitaddr.err" "$TMP/bitaddr-$1.log"
|
||||
}
|
||||
|
||||
run_bitaddr --bitptr "$TMP/step1.ll" "$TMP/bitptr.ll"
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
# i64 exists since M6, but IndVarSimplify's exit-value replacement still
|
||||
# rewrites a loop's final value into a closed-form i33 multiply (e.g.
|
||||
# n*(n+1)/2 for sumto), which is an unsupported shape for this 32-bit
|
||||
# target. -replexitval is an option of IndVarSimplify; disabling only that
|
||||
# rewrite keeps the loop, which is what ordinary -O2 code needs. This is a
|
||||
# driver policy, not a target TTI policy: opt runs without a target machine
|
||||
# here. llc diagnoses the raw i33 shape reached by an opt run that omits
|
||||
# this flag (m5-policy.ll).
|
||||
"$TMS_OPT" -passes='default<O2>' -replexitval=never \
|
||||
-S "$TMP/bitptr.ll" -o "$TMP/opt.ll"
|
||||
# The optimizer may create new byte-indexed GEPs (SROA aggregate splits,
|
||||
# switch tables), so scale those. Every source GEP is still an opaque call,
|
||||
# so this pass cannot see (and re-scale) an already-bit offset.
|
||||
run_bitaddr --scale "$TMP/opt.ll" "$TMP/scaled.ll"
|
||||
# Lower the barrier and restore the M0 pointer-difference folding. The
|
||||
# lowered inttoptr(add) shapes canonicalize to GEPs whose index is already
|
||||
# a bit count; llc treats a GEP index as a bit offset, and no scale follows.
|
||||
# `no-verify-fixpoint` suppresses only InstCombine's idempotence check: the
|
||||
# M6 shim's emit_uint64 has a `zext i32 %base to i64` that a second run
|
||||
# would re-mark `nneg`, which the verifier reports as "did not reach a
|
||||
# fixpoint". The first run's output is the intended IR and all gates pass
|
||||
# with it; the flag is the documented escape for this known shape.
|
||||
run_bitaddr --lower-bitptr "$TMP/scaled.ll" "$TMP/lowered.ll"
|
||||
"$TMS_OPT" -passes='instcombine<no-verify-fixpoint>' \
|
||||
-S "$TMP/lowered.ll" -o "$OUT"
|
||||
else
|
||||
# No optimizer, so no byte GEPs can be created; lower the barrier directly
|
||||
# back to the historical bit-addressed inttoptr(add) form.
|
||||
run_bitaddr --lower-bitptr "$TMP/bitptr.ll" "$OUT"
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
exec "$TMS_CLANG" --target=tms34010 $OPT_FLAGS $DEBUG_FLAGS $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS -S -emit-llvm -o "$OUT" "$IN"
|
||||
Reference in new issue
Block a user