[Truffle] Eliminating Calls to Side-Effect Free Methods?

Chris Seaton chris at chrisseaton.com
Wed Mar 12 15:29:16 UTC 2014


Hmm... I'll try actually running your code later and get back to you.

Here's one example of where I use executeVoid for a real benefit. The Ruby
fannkuch code swaps values using multiple assignment:

a, b = b, a

This is syntactic sugar for:

[a, b] = [b, a]

That is, an array assignment. Assignments in Ruby return the assigned
value, so the swap expression allocates and swaps an array. I desugar to:

t1 = b
t2 = a
a = t1
b = t2
return Array.new(t1, t2)

If we execute that last line, we allocate an Array object on the inner loop
of the benchmark. If we executeVoid, we don't.

I've wrapped this pattern up into ElidableResultNode.

https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/truffle/nodes/control/ElidableResultNode.java
https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/truffle/translator/Translator.java#L1322

This has a side-effect producing part (the assignment in this case) and a
result producing part (the array allocation in this case). If you
executeVoid it doesn't execute the latter.

So this is the difference between allocating memory in a benchmark, and not
having to allocate memory - obviously a big deal. When you start thinking
about it there's a few magic places you can use executeVoid, depending on
how your language works.

Chris




On 12 March 2014 15:18, Stefan Marr <java at stefan-marr.de> wrote:

> Hi Chris:
>
> On 12 Mar 2014, at 16:12, Chris Seaton <chris at chrisseaton.com> wrote:
>
> > This is how Ruby does it, and it does go to nothing.
>
> I should have mentioned: I tried that in the morning ;)
>
> Well, I did not introduce any executeVoid, because generally everything is
> an expression with a return value.
> But I tried to rewrite the SequenceNode based on what I saw in your Ruby
> implementation. Also, because my pervious not so good experience with
> @ExplodeLoop. But, the effect was zero.
> Normally, the PE should see that `last` is never read but at the end.
>
> Is the executeVoid an essential thing? Did you notice any difference with
> having it/not having it?
>
> Thanks
> Stefan
>
> --
> Stefan Marr
> INRIA Lille - Nord Europe
> http://stefan-marr.de/research/
>
>
>
>


More information about the graal-dev mailing list