Proposing LLVM Extensions for Generating Native Code Fragments Frej - - PowerPoint PPT Presentation

proposing llvm extensions for generating native code
SMART_READER_LITE
LIVE PREVIEW

Proposing LLVM Extensions for Generating Native Code Fragments Frej - - PowerPoint PPT Presentation

Proposing LLVM Extensions for Generating Native Code Fragments Frej Drejhammar and Lars Rasmusson Swedish Institute of Computer Science { frej,lars.rasmusson } @sics.se 150413 Who am I? Senior researcher at the Swedish Institute of Computer


slide-1
SLIDE 1

Proposing LLVM Extensions for Generating Native Code Fragments

Frej Drejhammar and Lars Rasmusson Swedish Institute of Computer Science {frej,lars.rasmusson}@sics.se 150413

slide-2
SLIDE 2

Who am I?

Senior researcher at the Swedish Institute of Computer Science (SICS) working on programming languages, tools and distributed systems. Currently working on an Ericsson funded JIT-compiler for Erlang.

slide-3
SLIDE 3

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-4
SLIDE 4

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-5
SLIDE 5

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-6
SLIDE 6

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-7
SLIDE 7

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-8
SLIDE 8

Patchpoints

call void (i64, i32, i8*, i32, ...)* @llvm.experimental.patchpoint.void( i64 <id>, i32 <shadow-size>,i8* <ptr>, i32 <N>, arg0, arg1, ....)

Generated code Ensure first <N> argu- ments match CC <shadow-size> Call <ptr>    Padding (nop) Stack map ID: <id> Arg<N> is in register X Arg<N+1> is 42 Register Z is live But how to create the function pointed to by <ptr>?

slide-9
SLIDE 9

The explicitcc Calling Convention

define explicitcc void @foo( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber (38, 40) { ; rcx , rdx call void (...)* @llvm. experimental .retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) }

Register allocator is told where the arguments are and which registers to preserve. llvm.experimental.retwr allows returning values in registers. Use the same internal register ids as the llvm.read_register and llvm.write_register intrinsics.

slide-10
SLIDE 10

The explicitcc Calling Convention

define explicitcc void @foo( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber (38, 40) { ; rcx , rdx call void (...)* @llvm. experimental .retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) }

Register allocator is told where the arguments are and which registers to preserve. llvm.experimental.retwr allows returning values in registers. Use the same internal register ids as the llvm.read_register and llvm.write_register intrinsics.

slide-11
SLIDE 11

The explicitcc Calling Convention

define explicitcc void @foo( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber (38, 40) { ; rcx , rdx call void (...)* @llvm. experimental .retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) }

Register allocator is told where the arguments are and which registers to preserve. llvm.experimental.retwr allows returning values in registers. Use the same internal register ids as the llvm.read_register and llvm.write_register intrinsics.

slide-12
SLIDE 12

The explicitcc Calling Convention

define explicitcc void @foo( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber (38, 40) { ; rcx , rdx call void (...)* @llvm. experimental .retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) }

Register allocator is told where the arguments are and which registers to preserve. llvm.experimental.retwr allows returning values in registers. Use the same internal register ids as the llvm.read_register and llvm.write_register intrinsics.

slide-13
SLIDE 13

The explicitcc Calling Convention

define explicitcc void @foo( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber (38, 40) { ; rcx , rdx call void (...)* @llvm. experimental .retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) }

Register allocator is told where the arguments are and which registers to preserve. llvm.experimental.retwr allows returning values in registers. Use the same internal register ids as the llvm.read_register and llvm.write_register intrinsics.

slide-14
SLIDE 14

Try it out

Complete patch series http://reviews.llvm.org/D8953 http://reviews.llvm.org/D8954 http://reviews.llvm.org/D8955 http://reviews.llvm.org/D8956 http://reviews.llvm.org/D8957 http://reviews.llvm.org/D8959 http://reviews.llvm.org/D8960 http://reviews.llvm.org/D8961

slide-15
SLIDE 15

Example

define explicitcc void @ex0( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber () { call void (...)* @retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) unreachable }

slide-16
SLIDE 16

Example

define explicitcc void @ex0( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber () { call void (...)* @retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) unreachable } ex0: movq %rbx , %rcx movq %rax , %rbx movq %rcx , %rax retq

slide-17
SLIDE 17

Example

define explicitcc void @ex0( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber () { call void (...)* @retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) unreachable } ex0: movq %rbx , %rcx movq %rax , %rbx movq %rcx , %rax retq define explicitcc void @ex1 () { noclobber (38) { ; rcx call void asm sideeffect "call foo", "~{ rcx}"() ret }

slide-18
SLIDE 18

Example

define explicitcc void @ex0( i64 hwreg (35) %p0 , ; rax i64 hwreg (37) %p1) ; rbx noclobber () { call void (...)* @retwr( i64 hwreg (37) %p0 , i64 hwreg (35) %p1) unreachable } ex0: movq %rbx , %rcx movq %rax , %rbx movq %rcx , %rax retq define explicitcc void @ex1 () { noclobber (38) { ; rcx call void asm sideeffect "call foo", "~{ rcx}"() ret } ex1: pushq %rcx callq foo popq %rcx retq