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
71
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
Operating Systems: Three Easy Pieces, Chapter 49 / Sun's Network File System (NFS)
arata_nvm
0
4
デコンパイラ研究調査
arata_nvm
1
16
LLVMのDSL”TableGen”向け言語サーバーの開発
arata_nvm
0
25
5分でわかるPage-Fault Weird Machine
arata_nvm
2
360
eBPFを用いたAndroid向けデバッガ「eDBG」のx86_64 Linuxへの移植
arata_nvm
0
23
Pythonのcopy-and-patch JITの実装を読む
arata_nvm
0
150
eBPFを使った動的解析手法
arata_nvm
1
790
カーネルハック実験の振り返り
arata_nvm
1
62
Improving LLVM Backend Development with a New TableGen Language Server
arata_nvm
0
55
Featured
See All Featured
30 Presentation Tips
portentint
PRO
1
350
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
220
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
A better future with KSS
kneath
240
18k
Navigating Team Friction
lara
192
16k
Product Roadmaps are Hard
iamctodd
55
12k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.9k
Statistics for Hackers
jakevdp
799
230k
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