Skip to content

Smaller tslang.exe: only the MLIR extensions and LLVM backends the compiler uses - #839

Merged
ASDAlexander77 merged 2 commits into
mainfrom
compiler-size
Nov 13, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
compiler-size

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

Makes the compiler executable smaller: a release tslang.exe goes from about 98 MB to 71.4 MB.

  1. Register only the MLIR extensions tslang uses. registerAllExtensions referenced the extension of every upstream dialect (GPU, NVVM, ROCDL, linalg, vector, sparse tensor, the transform dialect's...), so the linker kept ~14 MB of code nothing runs. createMLIRContext now registers the to-LLVM interfaces of the dialects it loads (arith, cf, func, index, math) and the func extensions only. tslang's lowering already calls those patterns directly.
  2. Link only the X86, ARM, AArch64 and WebAssembly backends. AllTargets* plus llvm::InitializeAllTargets() linked every backend LLVM was built with. The official LLVM package the release downloads also has RISCV, BPF and NVPTX. TSLANG_TARGETS (CMake cache variable) names the backends; each is linked only when LLVM has it, and tslang.cpp initializes the same list (TSLANG_TARGET_<NAME> definitions).

Measurements (Windows x64 Release)

tslang.exe official LLVM 22.1.8 package local custom LLVM
before ~98 MB (estimated) 87.8 MB
+ extensions 83.8 MB 73.3 MB
+ backends 71.4 MB 73.4 MB (already only these backends)

The ~98 MB baseline on the official package is estimated as the 83.8 MB build plus the ~14 MB the extensions change removes on the local build; it was not built on the official package.

Where the size was, from a link map of the local build: LLVM 52 MB, MLIR 27 MB (MLIRTypeScript 5.6 MB), clang 3.5 MB, rest 4 MB.

Testing

  • ctest -C Release against the official prebuilt LLVM + MLIR archive (as create-release does): 7064 passed.
  • ctest -C Release against the local custom LLVM: 6976 passed on the first commit. On the final branch, the whole suite was not re-run end to end: a first run had 35 failures from stale runtime/helper targets, and after a full rebuild those 35 were re-run and all passed.
  • One run hit a single segfault in test-own-err-own_err_iface_field_result, on the build without the backends commit; it passed 10/10 when repeated alone, so it looks flaky.
  • Not built on Linux yet: the Linux release uses the official Linux package (all targets), which has the four backends, so it should behave the same.

Notes for reviewers

  • A compile for a target outside the four (e.g. --mtriple=riscv64) is no longer possible with a release build; nothing in tests or docs uses one. Adding a backend is one entry in TSLANG_TARGETS plus one line in initializeTargets().
  • Link-time code generation was looked at and dropped: the release links prebuilt LLVM (which can't be rebuilt in CI), and /GL objects only link with the exact MSVC build that compiled them.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 13, 2026 12:29
registerAllExtensions referenced every upstream dialect's extension (GPU, NVVM,
ROCDL, linalg, vector, sparse tensor, the transform dialect's), keeping ~14 MB
of code nothing runs. Register the to-LLVM interfaces of the dialects tslang
loads (arith, cf, func, index, math) and the func extensions only.

Release tslang.exe: 87.8 MB -> 73.3 MB. ctest Release: 6976 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AllTargets* linked every backend LLVM was built with, and llvm::InitializeAllTargets()
referenced them all. The official prebuilt LLVM a release links also has RISCV, BPF
and NVPTX, which no tslang target uses. TSLANG_TARGETS (CMake) names the backends,
each linked only when LLVM has it, and tslang.cpp initializes the same list.

tslang.exe on the official LLVM 22.1.8 package: 83.8 MB -> 71.4 MB (and with the
previous commit, ~98 MB -> 71.4 MB). A local LLVM with exactly these four backends
is unchanged. ctest Release on the official package: 7064 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 79da51f into main Nov 13, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the compiler-size branch November 13, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant