[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform SSA -type of optimizations #313

Open
kangax opened this issue Dec 1, 2016 · 3 comments
Open

Perform SSA -type of optimizations #313

kangax opened this issue Dec 1, 2016 · 3 comments

Comments

@kangax
Copy link
Member
kangax commented Dec 1, 2016

(as @hzoo suggested in Slack)

c.f.: https://en.wikipedia.org/wiki/Static_single_assignment_form

var x = 1;
var x = 2;
y = x;

We can determine that 1st statement is useless. Combined with variable inlining, we could shorten this to the ideal y = 2.

@boopathi
Copy link
Member
boopathi commented Dec 2, 2016

So, I'm thinking to implement something like this -

  1. make the flow graph for a declaration (decl -> reference -> K violation -> ref -> K violation -> ref)
  2. traverse this flow graph -
    1. create declarations/bindings for every constantViolation
    2. update the following reference items in the flow graph to reference this new binding

thoughts or suggestions ?

@kangax
Copy link
Member Author
kangax commented Dec 5, 2016

The way I see it is we're dealing with 2 things here — duplicate declarations (aka K violations) and partial evaluation (where we can statically resolve x to its value and replace identifier with it in y = x case).

It might be simpler to break it in these 2 steps.

@boopathi can you explain your "decl -> reference -> K violation -> ref -> K violation -> ref" chain? why does reference would link back to K violation? How would it look in the above example? I'm trying to understand.

@boopathi
Copy link
Member
boopathi commented Dec 5, 2016

That's the flow graph ... Right now, we don't have the control flow for something that we calculate based on positions and other clues ...

So, for this example -

var a = 1;
foo(a);
a = 2;
bar(a);
var a = a + 3;
baz(a);

We need to rename the references correctly to the corresponding declarations (when replaced). So the flow for a in the example would be - decl -> ref -> k violation -> ref -> k violation -> ref ... so from this graph,

  1. we can replace all k violations to new declarations
  2. and the references that follow to reference this new declaration.
var a = 1;
foo(a);
var a2 = 2;
bar(a2); // a needs to be updated to a2 and a2's references should point here
var a3 = a2 + 3;
baz(a3);

And we deal with branching and looping accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants