Pro Yearly is on sale from $80 to $50! »

A PoC-ish Trick: LLVM IR Generation with Ruby

Fbe207d1bece86feb799fbc1841ce735?s=47 remore
November 11, 2016

A PoC-ish Trick: LLVM IR Generation with Ruby

A Lightning Talk at RubyConf 2016

Fbe207d1bece86feb799fbc1841ce735?s=128

remore

November 11, 2016
Tweet

Transcript

  1. A PoC-ish Trick: LLVM IR Generation with Ruby A Lightning

    Talk at RubyConf 2016 Kei Sawada (@remore)
  2. None
  3. a modern, fast, and open source language for data science

    and technical computing
  4. 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
  5. In short,

  6. Write some Julia code then you will get LLVM IR

    without hassle
  7. 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>
  8. 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>
  9. 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>
  10. julia> code_llvm(hello, ()) define %jl_value_t* @julia_hello_21549() { top: ret %jl_value_t*

    inttoptr (i64 4447575696 to %jl_value_t*) } julia>
  11. 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>
  12. OK Julia is a thing But we are in

  13. None
  14. What if

  15. You can write some Ruby code which can be translated

    into Julia where you can get LLVM IR easily?
  16. Ruby -> Julia -> LLVM IR

  17. None
  18. Julializer Allow you to convert your arbitrary Ruby code into

    Julia code
  19. Time to DEMO!

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