Julia Compilation versus Interpretation

306 views
Skip to first unread message

rpre...@gmail.com

unread,
May 2, 2016, 11:36:27 AM5/2/16
to julia-dev
Hi All,

I've been working on and exploring some aspects of Julia's internals over the past few days - mainly codegen.cpp, toplevel.cpp and interpreter.cpp. I was curious if anyone could shed some light on the heuristics that Julia uses to determine whether to compile an expression using codegen.cpp (LLVM) or interpret it directly using interpreter.cpp.

I have checked the developer docs but the only information is:

:c:func:jl_toplevel_eval_flex then uses some simple heuristics to decide whether to JIT compiler the AST or to interpret it directly.

 Does anyone have any insights into what these "simple heuristics" are?

---
Background: I am attempting to develop a new LLVM pass for Julia (in the style of @simd) that is enabled on a basic block basis by expressions added by a macro (all very much similar to the way @simd currently works). However, as I change the location of my pass-enabling expression within a broader quote, Julia will sometimes interpret the expression (so the LLVM pass doesn't get called), and sometimes it will compile the expression (and the LLVM pass runs successfully). Clearly there is logic behind this choice, however despite some digging through jl_toplevel_eval_flex, I have been unable to decipher the conditions that lead to interpretation (my knowledge of the Julia internal DSL is still somewhat limited).

Jameson Nash

unread,
May 3, 2016, 11:30:05 AM5/3/16
to juli...@googlegroups.com
Currently all functions are compiled, so the simplest heuristic is simply to put your test code in a function. That also gives you the benefit of being able to use code_llvm / code_native to review what the pass did.

At the toplevel, the heuristic is also quite simplistic: it compiles the expression if it uses intrinsics or has a backward branch.
Reply all
Reply to author
Forward
0 new messages