Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
コンパイラ基盤を支える言語たち
Search
Arata
April 17, 2026
110
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
コンパイラ基盤を支える言語たち
Arata
April 17, 2026
More Decks by Arata
See All by Arata
Black Hat USA 2026の面白かった発表を紹介
arata_nvm
1
14
Operating Systems: Three Easy Pieces, Chapter 49 / Sun's Network File System (NFS)
arata_nvm
0
15
デコンパイラ研究調査
arata_nvm
1
34
LLVMのDSL”TableGen”向け言語サーバーの開発
arata_nvm
0
37
5分でわかるPage-Fault Weird Machine
arata_nvm
2
430
eBPFを用いたAndroid向けデバッガ「eDBG」のx86_64 Linuxへの移植
arata_nvm
0
26
Pythonのcopy-and-patch JITの実装を読む
arata_nvm
0
160
eBPFを使った動的解析手法
arata_nvm
1
820
カーネルハック実験の振り返り
arata_nvm
1
69
Featured
See All Featured
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
500
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
310
4 Signs Your Business is Dying
shpigford
187
23k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.5k
The Limits of Empathy - UXLibs8
cassininazir
1
620
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
250
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Rails Girls Zürich Keynote
gr2m
96
14k
Transcript
コンパイラ基盤を支える言語たち 2026/04/17 コンパイラのコンパの部分 #02 Arata 1
導入:コンパイラの中で使われているDSL(ドメイン特化言語) コンパイラには DSLで宣言的に記述できると嬉しい 処理がある 命令セット(ISA)の定義 e.g. このCPUは RAX という64bitのレジスタを持つ 命令選択
e.g. 加算は ADD r32, r32 (CPU命令)で実装できる 最適化ルール e.g. x + 0 は x に最適化できる 2
導入:どのように嬉しいか 宣言的に記述できる 再利用できる 静的に検査できる 3
好きなDSL3選 4
1. Go SSA rewrite rules 2015年ごろ開発開始 命令選択や最適化ルールの記述に使われる このルールに基づいてGoのコードが生成される Goのシンプルさとうまくマッチしている コードの例(
LEA a, [c]; ADD a, d => LEA a, [c+d] ) (ADD(Q|L)const [c] (LEA(Q|L) [d] {s} x)) && is32Bit(int64(c)+int64(d)) => (LEA(Q|L) [c+d] {s} x) 5
2. Cranelift ISLE 2021年ごろ開発開始 命令選択や最適化ルールの記述に使われる このルールに基づいてRustのコードが生成される ルールの検証に気持ちがある 型検査が実装されている ルール同士の重複があるとエラーになる 書き換え前後で意味が変わらないかSMTソルバーで検査できる
コードの例( ADD x, y => LEA a, [x+y] ) (rule iadd_base_case_32_or_64_lea -5 (lower (has_type (ty_32_or_64 ty) (iadd _ x y))) (x64_lea ty (to_amode_add (mem_flags_trusted) x y (zero_offset)))) 6
3. LLVM TableGen 2002年ごろ開発開始 命令セットの定義や命令選択の記述など、幅広く使われる (基本的に)C++のコードが生成される 制御構文があり一番言語っぽい バックエンド次第でなんでもできる SQLクエリ生成、JSON生成など コードの例(
ADD x, -1 => DEC x ) def : Pat<(add GR32:$src, -1), (!cast<Instruction>(DEC32r#suffix) GR32:$src)>; 7
紹介しきれなかったDSL 命令セットの定義 / 命令選択 GCC Machine Description OpenJDK HotSpot ADL
最適化ルール / 書き換えルール Cranelift Peepmatic MLIR PDLL 命令セットの定義 Ghidra SLEIGH QEMU DecodeTree 8
紹介しきれなかったDSL(続き) VM V8 Torque GraalVM Truffle DSL GraalVM Bytecode DSL
Erlang/OTP BEAM LuaJIT DynASM 9
好きなDSLがあればぜひ教えてください! 10
参考文献 LLVM TableGen https://llvm.org/docs/TableGen/ProgRef.html https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/X86/X86.td https://github.com/llvm/llvm- project/commit/a6240f6b1a34f9238cbe8bc8c9b6376257236b0a https://github.com/mshockwave/SQLGen Cranelift ISLE
https://github.com/bytecodealliance/wasmtime/blob/main/cranelift/isle/docs/lang uage-reference.md https://cfallin.org/blog/2023/01/20/cranelift-isle/ 11
参考文献 Cranelift Peepmatic https://github.com/bytecodealliance/wasmtime/tree/dba74024aa412f28487137 5db292c1bf9079d769/cranelift/peepmatic MLIR PDLL https://mlir.llvm.org/docs/PDLL/ https://www.jeremykun.com/2024/08/04/mlir-pdll/ GCC
Machine Description https://github.com/gcc-mirror/gcc/blob/master/gcc/config/ia64/ia64.md https://gcc.gnu.org/onlinedocs/gccint/Machine-Desc.html https://www.cse.iitb.ac.in/grc/intdocs/gcc-writing-md.html 12
参考文献 Ghidra SLEIGH - https://ghidra.re/ghidra_docs/languages/html/sleigh.html https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Processor s/x86/data/languages/ia.sinc Golans SSA
rewrite rules https://github.com/golang/go/blob/e870de9936a7efa42ac1915ff4ffb16017dbc 819/src/cmd/compile/internal/ssa/_gen/AMD64.rules https://www.quasilyte.dev/blog/post/go_ssa_rules/ OpenJDK HotSpot ADL https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/x86.ad https://hsmemo.github.io/articles/noVxQtU9lk.html https://www.dcs.gla.ac.uk/~jsinger/pdfs/sicsa_openjdk/OpenJDKArchitecture.pd 13