Slide 1

Slide 1 text

A PoC-ish Trick: LLVM IR Generation with Ruby A Lightning Talk at RubyConf 2016 Kei Sawada (@remore)

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

a modern, fast, and open source language for data science and technical computing

Slide 4

Slide 4 text

Julia is 4 years old young Good performance, as fast as C Dynamic typing Julia has Capability to call C functions directly without wrappers or special APIs a compiler that used LLVM to translate Julia programs into ef cient executable code

Slide 5

Slide 5 text

In short,

Slide 6

Slide 6 text

Write some Julia code then you will get LLVM IR without hassle

Slide 7

Slide 7 text

debussy:~ guest$ julia _ _ _ _(_)_ | A fresh approach to technical computin (_) | (_) (_) | Documentation: http://docs.julialang.o _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.4.6 (2016-06-19 17:16 UTC) _/ |\__'_|_|_|\__'_| | |__/ | x86_64-apple-darwin15.5.0 julia>

Slide 8

Slide 8 text

debussy:~ guest$ julia _ _ _ _(_)_ | A fresh approach to technical computin (_) | (_) (_) | Documentation: http://docs.julialang.o _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.4.6 (2016-06-19 17:16 UTC) _/ |\__'_|_|_|\__'_| | |__/ | x86_64-apple-darwin15.5.0 julia> function hello() "rubyconf" end hello (generic function with 1 method) julia>

Slide 9

Slide 9 text

debussy:~ guest$ julia _ _ _ _(_)_ | A fresh approach to technical computin (_) | (_) (_) | Documentation: http://docs.julialang.o _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.4.6 (2016-06-19 17:16 UTC) _/ |\__'_|_|_|\__'_| | |__/ | x86_64-apple-darwin15.5.0 julia> function hello() "rubyconf" end hello (generic function with 1 method) julia> hello() "rubyconf" julia>

Slide 10

Slide 10 text

julia> code_llvm(hello, ()) define %jl_value_t* @julia_hello_21549() { top: ret %jl_value_t* inttoptr (i64 4447575696 to %jl_value_t*) } julia>

Slide 11

Slide 11 text

julia> code_llvm(hello, ()) define %jl_value_t* @julia_hello_21549() { top: ret %jl_value_t* inttoptr (i64 4447575696 to %jl_value_t*) } julia> code_native(hello, ()) .section __TEXT,__text,regular,pure_instructions Filename: none Source line: 2 pushq %rbp movq %rsp, %rbp movabsq $4447575696, %rax ## imm = 0x109189E90 Source line: 2 popq %rbp ret julia>

Slide 12

Slide 12 text

OK Julia is a thing But we are in

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

What if

Slide 15

Slide 15 text

You can write some Ruby code which can be translated into Julia where you can get LLVM IR easily?

Slide 16

Slide 16 text

Ruby -> Julia -> LLVM IR

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Julializer Allow you to convert your arbitrary Ruby code into Julia code

Slide 19

Slide 19 text

Time to DEMO!

Slide 20

Slide 20 text

For more examples and attempts, check out: github.com/remore/julializer github.com/remore/virtual_module Thanks!