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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Akira Moroo
March 19, 2017
Programming
580
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
More Decks by Akira Moroo
See All by Akira Moroo
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
Exploring x86 MSR Space
retrage
0
1.6k
LLMでバイナリ解析支援
retrage
0
280
GitHub ActionsでDevSecOpsごっこ
retrage
0
130
Practical Rust (Hypervisor) Firmware
retrage
3
2k
Bypassing UEFI Secure Boot with Thin-Hypervisor
retrage
0
1.3k
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
730
Other Decks in Programming
See All in Programming
残高管理から台帳サービスへの進化
artoy
1
210
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
0
140
ChromeでローカルLLM
ryu1013
0
150
APNsからLive Activityを開始する話
yumnumm
0
170
phperだってパンチカードでコーディングしたい
o0h
PRO
0
370
Simple Storage Service(S3) is not simple
iwatsukayura
0
300
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
290
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.8k
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
180
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
360
golang-bob.pdf
iwatsukayura
0
130
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Accessibility Awareness
sabderemane
1
250
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
My Coaching Mixtape
mlcsv
0
360
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Designing for humans not robots
tammielis
254
26k
The Cult of Friendly URLs
andyhume
79
7k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
Being A Developer After 40
akosma
92
590k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Transcript
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を使ったいいデバッグ⽅法を知りたい