Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ELVMでLLVM IR
Search
Akira Moroo
March 19, 2017
Programming
590
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ELVMでLLVM IR
ELVMのLLVM IRバックエンドを作って遊んだときのスライドです.
Akira Moroo
March 19, 2017
Transcript
12 slides
ELVMでLLVM IR 2017/03/19 @retrage
動機 • LLVMで遊んでみたい • フロントエンドを作ったりはしたくない • clang –emit-llvmで出⼒させたコードで遊ぶのも⾯⽩ くない •
LLVMを始めよう! 〜 LLVM IRの基礎はclangが 教えてくれた・Brainf**kコンパイラを作ってみ よう 〜 • http://itchyny.hatenablog.com/entry/2017/02/27/ 100000 • BrainF**kからLLVM IRを吐くようなものを作るとい う話
LLVM • コンパイラ基盤 • LLVM IRという中間表現を使う フロントエンド LLVM IR バックエンド
最適化 コード ターゲット clang opt llc • opt: LLVM IRに対し最適化 • lli:LLVM RIをVMで実⾏
ELVM • “LLVMのパロディ” フロントエンド ELVM IR バックエンド コード ターゲット 8cc
elc • ターゲット • BrainF**k, WhiteSpace, C++14(compile time)など • 環境依存でない中間表現ELVM IR
ELVMでLLVM IR • ELVMのLLVM IRバックエンドを作ろう • Q. 何かいいことor新しいことはある? • A.⼀切ない
• C ->ELVM IR -> C -> LLVM IRと同じ • LLVMの恩恵を感じてみたい • ELVMのバックエンドを作るのは⽐較的簡単
LLVM IRについて • 例: • unsigned int a = 5;
• a += 5; • %a = alloca i32 • store i32 5, i32* %a • %1 = load i32* %a • %2 = add i32 %1, 5 • store i32 %2, i32* @a
C->ELVM IR • ELVMでは8ccをフロントエンドにELVM IRを出⼒ $ cat hello.c #include <stdio.h>
int main() { const char* p = "Hello, world!\n"; for (; *p; p++) putchar(*p); return 0; } $ out/8cc -S -I. -Ilibc -Iout hello.c $ wc –l hello.s 12554 ../elvm/hello.s
ELVM IR -> LLVM IR $ ./elvm/out/elc –ll hello.c.eir >
hello.c.eir.ll $ wc –l hello.c.eir.ll 33882 hello.c.eir.ll $ clang –S –O0 –emit-llvm hello.c $wc –l hello.ll 45 hello.ll $ time lli hello.c.eir.ll Hello, world! real 0m0.339s user 0m0.300s sys 0m0.037s $ time lli hello.ll Hello, world! real 0m0.009s user 0m0.009s sys 0m0.000s
最適化させてみる $ wc –l hello.c.eir.ll 33882 hello.c.eir.ll $ time lli
hello.c.eir.ll Hello, world! real 0m0.339s user 0m0.300s sys 0m0.037s $ opt -O3 -S hello.c.eir.ll –o hello.c.eir.ll.opt 15865 hello.c.eir.ll.opt $ time lli hello.c.eir.ll.opt Hello, world! real 0m0.198s user 0m0.163s sys 0m0.032s
まとめ • LLVM IRのことが少しわかったような気がする • まだまだ使っていない仕様がたくさんある • ELVM IRへの変換によるオーバーヘッドはoptで ある程度削減できるっぽい
• LLVMのELVM IR向けバックエンドが実装されている ようなので,ELVM IR <-> LLVM IRできるかも • コンパイラでの最適化について良い本を知って いたら教えてください
参考⽂献 • http://shinh.skr.jp/slide/elvm/000.html • http://itchyny.hatenablog.com/entry/2017/02/27/ 100000 • http://llvm.org/docs/LangRef.html • http://llvm.org/docs/CommandGuide/opt.html
LLVM IRバックエンドつらい • 無名の識別⼦は%から始まる番号になっている • 少しでもずれたりすると怒られる • ELVM IRのsrcがREG/IMMで命令が結構変わる •
デバッグむずい • C->ELVM IRだとすぐにコード量が膨れあがる • lliを使ったいいデバッグ⽅法を知りたい
More Decks by Akira Moroo
See All by Akira Moroo
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
Exploring x86 MSR Space
retrage
0
1.6k
LLMでバイナリ解析支援
retrage
0
300
GitHub ActionsでDevSecOpsごっこ
retrage
0
140
Practical Rust (Hypervisor) Firmware
retrage
3
2k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.4k
Porting Linux to Nabla Containers
retrage
0
1.3k
Network Boot from Bell Labs
retrage
2
1.9k
Unikernelで始める自作OS/OS Development with Unikernel
retrage
1
740
Other Decks in Programming
See All in Programming
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
270
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
650
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
240
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
270
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
540
LLM 101
dalinaum
0
500
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
手の動かし方がわからなかった私が個人開発者になるまで
usagi0920_pochi
0
200
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
330
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
530
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
980
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Prompt Engineering for Job Search
mfonobong
0
590
A Tale of Four Properties
chriscoyier
163
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
490
WCS-LA-2024
lcolladotor
0
1k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
480
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
1
300
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.7k