Code Generation
Backends and lowering: Cranelift, native, LLVM, GPU, and debug info.
Code Generation
code generation は、Sounio に複数の実在する compiler profile がある ことを最もはっきり示す領域です。正しい説明は「既定 artifact が一つ の path を公開している」ではなく、「repo は checked JIT artifact と checked GPU artifact を別々に公開しており、それぞれ別の backend contract を持つ」です。
現在のソースマップ
self-hosted/native/は native lowering、encoding、ABI、register allocation、object format を扱います。self-hosted/wasm/は WASM 向け lowering、encoding、module construction を扱います。self-hosted/gpu/は PTX、SPIR-V、Metal、tensor-oriented work、GPU lowering を扱います。self-hosted/llvm/は LLVM 向けの別サブツリーとして残っています。
checked artifact が証明すること
- JIT profile: Cranelift JIT が有効。LLVM と GPU codegen は無効。
- GPU profile: GPU codegen が有効。JIT は無効。PTX 出力は
build --backend gpuで利用可能。 - したがって docs では、default profile の挙動、GPU profile の挙動、 source tree 上の実装範囲を分けて書く必要があります。
native v2 preview レーン
リポジトリには、backend sovereignty program 用の public preview
native-v2 レーンも追加されています。互換エイリアス
native-v2-shadow は廃止されました。これは新しい安定した
エンドユーザ向けバックエンドではありません。
- 目的は、
RuntimeContext、ターゲット別レジスタ方針、Machine IR の期待値を 機械可読な artifact に固定することです。 - 現在の
x86-64preview レーンは、self-hosted shell で実際の Machine IR + legality path を通ってscalar_coreな native ELF を生成し、RuntimeContext経由でgc_stateと managed-object descriptor table を 公開し、native-v2 heap object を固定容量の handle table でalloc/field/index 解決します。さらに、precise slot scanning と pin-aware relocation を持つ executable な descriptor-driven mark-compact GC model も持ちます。その subset 外の opcode family は fail-closed です。 AArch64は contract 上では既に方針定義されていますが、公開 native emitter としてはまだ昇格していません。
有効な backend set を確認する
export SOUC_BIN="$(pwd)/artifacts/omega/souc-bin/souc-linux-x86_64-jit"
"$SOUC_BIN" info
export SOUC_GPU_BIN="$(pwd)/artifacts/omega/souc-bin/souc-linux-x86_64-gpu"
"$SOUC_GPU_BIN" info
"$SOUC_GPU_BIN" build examples/kernel_vec_add.sio --backend gpu -o /tmp/kernel_vec_add.ptx
export SOUNIO_NATIVE_V2_CONTRACT_PATH=/tmp/native_backend_v2_contract.v1.json
"$SOUC_BIN" run self-hosted/compiler/main.sio -- --self-test
正規の gate-backed artifact は artifacts/omega/native_backend_v2_contract.v1.json です。
古くならない codegen docs の書き方
- 実装アーキテクチャを説明するときは backend directory を書く。
- 既定の公開体験を説明するときは checked JIT artifact を書く。
- 公開 GPU codegen を説明するときは checked GPU artifact を書く。
- backend の実行 path は、実際に検証した artifact と command に結び付けて書く。