How to control stack/register allocation at a fine-grain level?

13 views
Skip to first unread message

Sylvain G

unread,
Sep 28, 2015, 1:59:20 AM9/28/15
to v8-dev
Hi,

I'm trying to modify V8's Crankshaft for a research project.

So far I'm duplicating some parts of code at the Hydrogen level (mostly loops), and modifying them with different optimizations than the usual Crankshaft is doing. I still need the original version of the code as a fallback in case something goes wrong (don't want to deoptimize everytime my modifications fail).

My basic idea was to save/overwrite the right stackframe to restore the state after taking the modified branch. It doesn't work because because the newly created variables in the duplicated code do not correspond with the original ones.

So here is my question: My modifications are sparse so I can handle them manually, but how to automatically match all the other variables?
how can I ensure that both branches in the CFG (my version and the original) use the same stack slots and same registers for the corresponding variables?

Or is there a better way to do this kind of thing at all?

Any explanation/suggestion would be very welcome.
Thanks,
Sylvain

Ben Noordhuis

unread,
Sep 28, 2015, 4:16:54 AM9/28/15
to v8-...@googlegroups.com
I think that's going to be hard. If I understand your question right,
you are essentially asking "how can I make two different programs do
the same thing?"

Sylvain G

unread,
Sep 28, 2015, 4:38:53 AM9/28/15
to v8-dev
Thanks for your answer!

I'm sorry if I wasn't clear. My question is more about "how can I make two program work on the same data?" rather than doing the exact same thing.

If I may take an example, say we have a loop working on 2 variables A and B. I'm creating another version of this loop, adding a variable C in it.
I then have the original loop with A and B, the modified loop with A', B' and C. My problem is that the A' and B' variables from the modified loop never correspond to the original loop's A and B variables. Would it be possible to merge A with A' and B with B', have them share the same register/stack slot so that, no matter which loop is actually executed, the whole program may execute normally?

Hope it helps to clarify

Jakob Kummerow

unread,
Sep 28, 2015, 7:37:14 AM9/28/15
to v8-...@googlegroups.com
Hydrogen (obviously) supports building branches. Look at IfBuilder and its existing uses. The key is that you push corresponding values into the same slots in the environment, then the register allocator will handle the rest. You could use this to model something like "if (condition) { special loop code } else { default loop code }". You probably need to do all of this at graph building time; later changes to the graph structure are unsupported (and very hairy if you try to hack them up).

Hydrogen does not support going back to a previous point in execution and taking another branch from there (which is what I understood your first mail to ask). You'd have to find a way to formulate such behavior in terms of IfBuilders.

In summary I agree with Ben: I think that's going to be hard.

--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sylvain G

unread,
Sep 28, 2015, 8:34:23 AM9/28/15
to v8-...@googlegroups.com
Right, thanks a lot for taking time to read and answer my questions.

I am already using the IfBuilder, which is indeed very convenient.
However, I have a bit of trouble understanding the environment class related to hydrogen, so I'm not sure as to exactly how pushing corresponding values in the same slots in the environment. From what you say, though, it seems that's exactly what I'm looking for :)

I actually have a transactional memory at my disposal to rollback any execution to a previous point in time, so this eases things down a bit. Right now I mostly need help understanding how the environment works and how to deal with it.
Thanks anyway for pointing me in the right direction!

You received this message because you are subscribed to a topic in the Google Groups "v8-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-dev/HRVD0x9ui_0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-dev+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages