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
LLVM Assembler for OpenRISC 1000
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Simon Cook
October 13, 2012
Technology
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LLVM Assembler for OpenRISC 1000
Simon Cook
October 13, 2012
More Decks by Simon Cook
See All by Simon Cook
Using the GCC regression test suite for LLVM (and other compilers)
simonpcook
0
240
AAPSIM: Implementing a LLVM based simulator
simonpcook
0
150
Chip Hack
simonpcook
0
270
OpenRISC Toolchains
simonpcook
0
230
An Introduction to Writing Applications for the Parallella Board
simonpcook
0
320
MAchine Guided Energy Efficient Compilation
simonpcook
0
76
Introduction to LLVM
simonpcook
1
230
MAGEEC
simonpcook
0
61
Other Decks in Technology
See All in Technology
データ組織の転換期 一足飛びしない段階的戦略
leveragestech
PRO
0
100
数値で見る Microsoft MVP 〜Spec Kit と GitHub Copilot Agent で作るデータ可視化ダッシュボード〜
yutakaosada
0
170
クラウドを使う側から、作る側へ / 大吉祥寺.pm 2026前夜祭
fujiwara3
7
1.8k
最高のシステムプロンプトを作るためにフィードバック機能を導入した話
alchemy1115
1
230
脱Jenkins、インターン生が挑んだCIツールGitHubActions移行
mixi_engineers
PRO
1
260
AIがAPIを書く時代に、私たちは何を設計すべきか
nagix
0
160
人依存からAIネイティブの体制へ:バックエンド開発の裏側【SORACOM Discovery 2026】
soracom
PRO
0
130
全社でのソフトウェアサプライチェーン攻撃対策をやってみた with Takumi Guard
z63d
0
330
VPCセキュリティ対応の最新事情
nagisa53
1
350
カメラ×AIで挑む「ホワイト物流」― 車両管理、自動化の壁と突破口【SORACOM Discovery 2026】
soracom
PRO
0
180
書籍セキュアAPIについて
riiimparm
0
390
MCPをつなげて作る組織横断のAIエージェント基盤
tsubakimoto_s
0
380
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.6k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
190
Product Roadmaps are Hard
iamctodd
55
12k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
Building the Perfect Custom Keyboard
takai
2
820
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
Fireside Chat
paigeccino
42
4k
The Curse of the Amulet
leimatthew05
2
13k
Transcript
LLVM Integrated Assembler for OpenRISC 1000 Simon Cook, Embecosm October
13, 2012 Copyright © 2012 Embecosm. Freely available under a Creative Commons license 0
Compiling with clang Without Integrated Assembler clang -target or1k -ccc-host-triple
or1k-elf -v helloworld.c - clang <...> -o /tmp/helloworld-Q1WvbT.s -x c helloworld.c - or1k-elf-gcc -v -c -o /tmp/helloworld-BZmisI.o -x assembler /tmp/helloworld.Q1WvbT.s <...>lib/gcc/<...>/as -o /tmp/helloworld-BZmisI.o /tmp/helloworld.Q1WvbT.s - or1k-elf-gcc -v -o a.out /tmp/helloworld-BZmisI.o <...>libexec/gcc/<...>collect2 <...> /tmp/helloworld-BZmisI.o Copyright © 2012 Embecosm. Freely available under a Creative Commons license 2
Compiling with clang Without Integrated Assembler clang -target or1k -ccc-host-triple
or1k-elf -v helloworld.c - clang <...> -o /tmp/helloworld-Q1WvbT.s -x c helloworld.c - or1k-elf-gcc -v -c -o /tmp/helloworld-BZmisI.o -x assembler /tmp/helloworld.Q1WvbT.s <...>lib/gcc/<...>/as -o /tmp/helloworld-BZmisI.o /tmp/helloworld.Q1WvbT.s - or1k-elf-gcc -v -o a.out /tmp/helloworld-BZmisI.o <...>libexec/gcc/<...>collect2 <...> /tmp/helloworld-BZmisI.o Copyright © 2012 Embecosm. Freely available under a Creative Commons license 2
Compiling with clang Without Integrated Assembler clang -target or1k -ccc-host-triple
or1k-elf -v helloworld.c - clang <...> -o /tmp/helloworld-Q1WvbT.s -x c helloworld.c - or1k-elf-gcc -v -c -o /tmp/helloworld-BZmisI.o -x assembler /tmp/helloworld.Q1WvbT.s <...>lib/gcc/<...>/as -o /tmp/helloworld-BZmisI.o /tmp/helloworld.Q1WvbT.s - or1k-elf-gcc -v -o a.out /tmp/helloworld-BZmisI.o <...>libexec/gcc/<...>collect2 <...> /tmp/helloworld-BZmisI.o Copyright © 2012 Embecosm. Freely available under a Creative Commons license 2
Compiling with clang Without Integrated Assembler clang -target or1k -ccc-host-triple
or1k-elf -v helloworld.c - clang <...> -o /tmp/helloworld-Q1WvbT.s -x c helloworld.c - or1k-elf-gcc -v -c -o /tmp/helloworld-BZmisI.o -x assembler /tmp/helloworld.Q1WvbT.s <...>lib/gcc/<...>/as -o /tmp/helloworld-BZmisI.o /tmp/helloworld.Q1WvbT.s - or1k-elf-gcc -v -o a.out /tmp/helloworld-BZmisI.o <...>libexec/gcc/<...>collect2 <...> /tmp/helloworld-BZmisI.o Copyright © 2012 Embecosm. Freely available under a Creative Commons license 2
LLVM Machine Code LLVM project to solve problems surrounding assembly,
disassembly, etc. Wasteful to format a .s file and then call an assembler to parse this new file. Estimated 20% of compile time is assembly, gain some of this back. Avoids issues of incompatible/out of date assemblers. Uses definitions of instructions already defined in TableGen for the compiler. Copyright © 2012 Embecosm. Freely available under a Creative Commons license 3
TableGen Language for defining records (instructions, registers) in a flexible
manner. Class based structure which allows many similar records to be created quickly. - class ALU_RR<bits<4> subOp, string asmstr, list<dag> pattern> : <...> { let Inst{25-21} = rD; <...> - def ADD : ALU1_RR<0x0, "l.add", add>; These records are then parsed to give build many different compiler components from the same definition - e.g. Assembler Tables, Disassembler Tables, Calling Convention Information, etc. Copyright © 2012 Embecosm. Freely available under a Creative Commons license 4
OR1K Implementation The same steps can be applied to most
targets Four main components have been implemented - Assembly Parser - Instruction Encoder - Instruction Decoder - ELF Object Writer Copyright © 2012 Embecosm. Freely available under a Creative Commons license 5
OR1K Implementation Parsing Assembly Files Done primarily for debugging and
testing - Currently aiming for working assembler, will make standalone later Using a MCAsmTargetParser and given instruction, parse operands to determine type and value. - e.g. r1 −→ <MCOperand Reg:2> Operands (nmenonic is also an operand) are then passed to TableGen'erated function which carries out type checking (l.add 1, 2, 3 makes no sense) and stores in instruction stream. - $ echo "l.add r1, r2, r3" | llvm-mc -arch or1k -show-inst - l.add r1, r2, r3 # <MCInst #17 ADD # <MCOperand Reg:2> # <MCOperand Reg:3> # <MCOperand Reg:4>> Copyright © 2012 Embecosm. Freely available under a Creative Commons license 6
OR1K Implementation Instruction Encoding Majority of this is already handled
by TableGen - Uses the Insn field to store bit patterns and definitions on where operands go within the instruction Define register encodings - r1 −→ 0x1, etc. Define custom operand encodings - e.g. memory operands - Encode register as before, bitshift and or with immediate operand. It does not matter where an operand is in the instruction, TableGen manages this. Copyright © 2012 Embecosm. Freely available under a Creative Commons license 7
OR1K Implementation Instruction Decoding As before, most of work done
by TableGen built functions. Requires instruction definitions to all be unambiguous. Added (primarily) for completeness, but allows more debugging to take place. Anything that required custom encoding requires custom decoding. Copyright © 2012 Embecosm. Freely available under a Creative Commons license 8
OR1K Implementation ELF Object Writing Defining all the important constants
- Architecture identifier, etc. Defining relocations, LLVM fixups - So that the linker can do its job correctly Driven by TableGen Copyright © 2012 Embecosm. Freely available under a Creative Commons license 9
Testing Encoding and Decoding Instructions painstakingly encoded and tests added.
# RUN: llvm-mc -arch=or1k -mattr=mul,div,ror -show-encoding %s | FileCheck %s l.add r1, r2, r3 # CHECK: # encoding: [0xe0,0x22,0x18,0x00] l.addi r3, r4, 2 # CHECK: # encoding: [0x9c,0x64,0x00,0x02] l.and r1, r2, r3 # CHECK: # encoding: [0xe0,0x22,0x18,0x03] l.andi r3, r4, 2 # CHECK: # encoding: [0xa4,0x64,0x00,0x02] Copyright © 2012 Embecosm. Freely available under a Creative Commons license 10
Testing Assembling Tests for each instruction have been written for
assembly and disassembly. Copyright © 2012 Embecosm. Freely available under a Creative Commons license 11
The Future Near term - Fix bugs (primarily calculating relocations)
- Add or1k specific object testcases - More testing in general (making -integrated-as the default) Not-so-near term - More standalone assembly features (i.e. gas alternative) Long Term - Mainline Adoption - Further LLVM Integration - e.g. lld (LLVM linker) Copyright © 2012 Embecosm. Freely available under a Creative Commons license 12
The Future Near term - Fix bugs (primarily calculating relocations)
- Add or1k specific object testcases - More testing in general (making -integrated-as the default) Not-so-near term - More standalone assembly features (i.e. gas alternative) Long Term - Mainline Adoption - Further LLVM Integration - e.g. lld (LLVM linker) Copyright © 2012 Embecosm. Freely available under a Creative Commons license 12
The Future Near term - Fix bugs (primarily calculating relocations)
- Add or1k specific object testcases - More testing in general (making -integrated-as the default) Not-so-near term - More standalone assembly features (i.e. gas alternative) Long Term - Mainline Adoption - Further LLVM Integration - e.g. lld (LLVM linker) Copyright © 2012 Embecosm. Freely available under a Creative Commons license 12
Thank You Thank You www.embecosm.com Copyright © 2012 Embecosm. Freely
available under a Creative Commons license 13