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

Implement Code Optimisation Stage, Part 1 - Local Optimisation #5

Open
aalhour opened this issue May 26, 2016 · 0 comments
Open

Implement Code Optimisation Stage, Part 1 - Local Optimisation #5

aalhour opened this issue May 26, 2016 · 0 comments

Comments

@aalhour
Copy link
Owner

aalhour commented May 26, 2016

Code Optimization

Three main types in Compiler Research:

  1. Local Optimization: Basic Blocks level.
  2. Regional Optimization - won't be implemented.
  3. Global Optimization.
  4. Inter-Procedural Optimization - won't be supported.

Local Optimisation:

  • Algebraic Expressions Simplification:

     x = x + 0    =>   x = x
     x = x * 1    =>   x = x
     x = x * 0    =>   x = 0
     x = x + 8    =>   x = x << 3
     x = x ** x   =>   x = x * x
    
  • Constant Folding:

      a = 2 * 3   =>   a = 6
      b = 1 + 2   =>   b = 3
    
  • Dead Code Elimination. Dead code is code that does't contribute to the program's result.

  • Peephole Optimisations.

  • SSA-based Optimisations:

    • Ensure registers (or variables in IR) are assigned once, in all computations.
    • Common Subexpression Elimination:
     a = x * x
     ...
     d = x * x    =>   d = a
    
    • Copy Propagation:

      b = x       =>    gets eliminated and all references changed to "x"
      c = b * 2   =>    c = x * 2
      
    • Constant Propagation:

      a = 2       =>   *eliminated*
      b = a + 2   =>   b = 2 + 2   =>    b = 4
      c = b * 3   =>   c = 4 * 3   =>    c = 12       
      
@aalhour aalhour added the todo label May 26, 2016
@aalhour aalhour added this to the Complete Compiler Backend milestone May 26, 2016
@aalhour aalhour changed the title Implement Code Optimisation Stage. Implement Code Optimisation Stage - Part 1 - Local Optimisation Jul 25, 2016
@aalhour aalhour changed the title Implement Code Optimisation Stage - Part 1 - Local Optimisation Implement Code Optimisation Stage, Part 1 - Local Optimisation Jul 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant