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

split local #94

Open
nomaddo opened this issue May 8, 2018 · 4 comments
Open

split local #94

nomaddo opened this issue May 8, 2018 · 4 comments
Labels
backend related to the code generator enhancement optimization related to an optimization step

Comments

@nomaddo
Copy link
Collaborator

nomaddo commented May 8, 2018

I am planning to split local into two variables

  • local (really local in a basic block)
  • global (shared by basic blocks)

The name global conflict the name of global variables shared by some functions, so it is considerable to change it.

The reason I want to change it is for ease of writing optimizations.
Currently, it is difficult to write optimizations because every variable may be referred by other basic blocks.
By split them into local and global, we may implement optimizations with ease.
Yes, BasicBlock::isLocallyLimited can checi it. But I am wondering it is always right.

@doe300 What do you think about this?

@nomaddo nomaddo added question backend related to the code generator labels May 8, 2018
@doe300
Copy link
Owner

doe300 commented May 8, 2018

Great idea!
I thought of this too a few times, but never came up with a concept to do this correctly.
This would also simplify and speed-up register-association greatly.

For the naming, if we can't come up with a better name, I think BlockLocal and MethodLocal, e.g. as two sub-classes of Local should do.

One issue we need to consider is converting between method-wide or block-wide locals:

  • E.g. for hoisting instructions out of loops
  • Also the reverse direction (though not strictly necessary, but very useful), we need to convert them either automatically (if all uses within a single block) or via some kind of optimization/normalization step

Another problem is the generation of locals:

  • How does a front-end know whether a local is only used within a single block?

@doe300 doe300 added enhancement optimization related to an optimization step labels May 8, 2018
@nomaddo
Copy link
Collaborator Author

nomaddo commented May 8, 2018

@long-long-float, do you have a idea about this?

@nomaddo
Copy link
Collaborator Author

nomaddo commented May 8, 2018

How does a front-end know whether a local is only used within a single block?

It's okey to emit instructions, which are all global variables first.
By applying analysis of global-to-local, these should be converted to local.

This method is straightforward: Visit every basic block to know what variables must be global.

label1:
iadd c, a, b   // `a` and `b` is read before defining it in this basic block, should be global
iadd d, c, a

In this case, a and b must be global, but we need more analysis about c and d.
If no requirement of c and d exist, we can change c and d to local.

@doe300
Copy link
Owner

doe300 commented May 12, 2018

This method is straightforward: Visit every basic block to know what variables must be global.

We could use the new analysis/LivenessAnalysis for this, it gives the Locals used by a basic block but not written in the same block before usage as side-effect. Or we could use the LocalUsageAnalysis (in the same files) which determines for every basic block the "input" and "output" locals.

@doe300 doe300 removed the question label Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend related to the code generator enhancement optimization related to an optimization step
Projects
None yet
Development

No branches or pull requests

2 participants