Open Source Compilers for RISC-V Jeremy Bennett Past, Present and Future

Copyright © 2019 Embecosm. Freely available under a Creative Commons Attribution-ShareAlike license. Newlib Tool Chain Components (GNU) Glibc RV32GC compiler libc/libm RV64GC libraries libgcc libstdc++v3 Source Object GCC GAS code code Ada /C++ Fortran binutils objdump OpenMP disassemble Complete In progress CGEN GDB target sim Not available Newlib Tool Chain Components (/LLVM) BSD libc Musl RV32GC compiler libc/libm RV64GC libraries CompilerRT libc++ Source Clang/ LLVM Object code LLVM int. asm code Ada C/C++ binutils Fortran llvm-objdump OpenMP

Complete disassemble In progress TableGen LLDBGDB Not available In tree History (official) RV64 support

In tree RV32 9.x ... 8.x (experimental) 7.x 6.x 5.x 4.x Out of tree 3.9.x since 2013 3.8.x LLVM 3.7.x 3.6.x 3.5.x 3.4.x 9.x ... In tree 8.x ... Out of tree 7.x 6.x since 2011 GCC 5.x 4.9.x

2014 2015 2016 2017 2018 2019 Future Developments

● LLVM – Ada, Flang (?), , Rust – machine inliner and shrinkwrap optimizations – bit manipulation and vector ISA extension support – decent CompilerRT implementation ● GCC – bit manipulation and vector ISA extension support ● Both compilers – -march consistency!!! – combined elimination: OpenTuner – fast emulation libraries Deep Dive Compiling for RV32 IoT Class Devices Today’s Size Optimization Techniques Embench data GCC size

-Os save-restore SmallSmall isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Today’s Size Optimization Techniques Embench data -Oz save-restore GCC size LLVM size -Oz -Os save-restore SmallSmall isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Today’s Size Optimization Techniques Embench data -Oz save-restore GCC size LLVM size -Oz -Os save-restore SmallSmall isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Today’s Speed Optimization Techniques Embench data GCC speed

-Os save-restore LargeLarge isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Today’s Speed Optimization Techniques Embench data -Oz save-restore GCC speed LLVM speed -Oz -Os save-restore LargeLarge isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Today’s Speed Optimization Techniques Embench data -Oz save-restore GCC speed LLVM speed -Oz -Os save-restore LargeLarge isis goodgood -Os

-O1

-O2

-O3

-O3 unroll/inline

0 0.5 1 1.5 2 2.5 3 Future Size Optimization Techniques Embench data GCC size -Os save-restore

RV32IMCB -Os save-restore

-Os combined elimination SmallSmall isis goodgood

-O2

RV32IMCB -O2

-O2 combined elimination for -Os

0 0.5 1 1.5 2 Future Size Optimization Techniques Embench data GCC size -Os save-restore LLVM size

RV32IMCB -Os save-restore Small is good -Os combined elimination Small is good

-O2

RV32IMCB -O2

-O2 combined elimination for -Os

0 0.5 1 1.5 2 Future Size Optimization Techniques Embench data GCC size -Os save-restore LLVM size

RV32IMCB -Os save-restore

-Os combined elimination SmallSmall isis goodgood

-O2

RV32IMCB -O2

-O2 combined elimination for -Os

0 0.5 1 1.5 2 The Detail Matters: Bit Manipulation Code size with gcc -Os -msave-restore 1.2 RV32IMC RV32IMBC 1

0.8

0.6

0.4

0.2

0 4 2 c n h t r y s 6 u g o d e t e d rt 6 3 i d c in e d e 5 e e n e lr s t u o t c b e n t- v o a 2 n p i n s a s n r u e l in b - a h j u i m i o c c b u n le h c o rd b e ik m ff m m tt s i ic q m t w - u t e - s p o ta a h a n le n c s h m tt - a e lib n g s The Detail Matters: Bit Manipulation Code size with gcc -Os -msave-restore 1.2 RV32IMC RV32IMBC 1

0.8

0.6

0.4

0.2

0 4 2 c n h t r y s 6 u g o d e t e d rt 6 3 i d c in e d e 5 e e n e lr s t u o t c b e n t- v o a 2 n p i n s a s n r u e l in b - a h j u i m i o c c b u n le h c o rd b e ik m ff m m tt s i ic q m t w - u t e - s p o ta a h a n le n c s h m tt - a e lib n g s How are we progressing?

Embench GCC code size 1.2 Arm Cortex M4 RI5CY RV32IMC 1.1

1

0.9

0.8

0.70.0 4.9.4 5.5 6.5 7.5 8.3 9.2 10.0.0 How are we progressing?

Embench GCC code size 1.2 Arm Cortex M4 RI5CY RV32IMC 1.1

1

0.9

0.8

0.70.0 4.9.4 5.5 6.5 7.5 8.3 9.2 10.0.0 Thank You Jeremy Bennett [email protected] www.embecosm.com

Copyright © 2019 Embecosm. Freely available under a Creative Commons Attribution-ShareAlike license.