10.07.2015 Views

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

14 3 JUST-IN-TIME COMPILATIONOnce compiled the optimized version of the loop becomes available to the interpreter.When the interpreter is going to execute bytecode corresponding to the loop it can insteadpass control to the compiled version of the loop. Once the optimized loop finishesthe interpreter updates is state based on the results of the optimized loop and resumesinterpretation.As an example <strong>for</strong> a trace we will look at the RPython functions defined in Figure 5, thedetails of PyPy’s <strong>JIT</strong> will be introduced in Section 5. This example is taken from [BCFR09].The function strange_sum executes a loop that calls the function f which does somecalculations on its inputs. When the loop is considered hot, after executing it a certainnumber of times, the execution is traced. The tracing records all operations executed inone iteration of the loop, the recorded trace is also shown in Figure 5. The tracing onlyrecorded the hot else path, inserting a guard to check the condition. The tracing alsoinlined the call to f. The operations recorded correspond to the internal representationof the functions. The trace ends with a jump to its beginning and is only left when one ofthe guards generated <strong>for</strong> the conditional paths fails.def strange_sum(n):result = 0while n >= 0:result = f(result, n)n -= 1return resultdef f(a, b):if b % 46 == 41:return a - belse:return a + b# loop_start(result0, n0)# i0 = int_mod(n0, Const(46))# i1 = int_eq(i0, Const(41))# guard_false(i1)# result1 = int_add(result0, n0)# n1 = int_sub(n0, Const(1))# i2 = int_ge(n1, Const(0))# guard_true(i2)# jump(result1, n1)Figure 5: Two simple RPython functions, and a trace recorded when executing the functionstrange_sum

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!