compilers
play

Compilers Register Allocation Alex Aiken Register Allocation - PowerPoint PPT Presentation

Compilers Register Allocation Alex Aiken Register Allocation Intermediate code uses unlimited temporaries Simplifies code generation and optimization Complicates final translation to assembly Typical intermediate code uses too


  1. Compilers Register Allocation Alex Aiken

  2. Register Allocation • Intermediate code uses unlimited temporaries – Simplifies code generation and optimization – Complicates final translation to assembly • Typical intermediate code uses too many temporaries Alex Aiken

  3. Register Allocation • The problem: Rewrite the intermediate code to use no more temporaries than there are machine registers • Method: – Assign multiple temporaries to each register – But without changing the program behavior Alex Aiken

  4. Register Allocation • • Can allocate a, e, and f all to Consider the program one register (r 1 ): a := c + d e := a + b r 1 := r 2 + r 3 f := e - 1 r 1 := r 1 + r 4 r 1 := r 1 - 1 • Assume a & e dead after use – A dead temporary can be “reused” Alex Aiken

  5. Register Allocation • Register allocation is as old as compilers – Register allocation was used in the original FORTRAN compiler in the ‘50s – Very crude algorithms • A breakthrough came in 1980 – Register allocation scheme based on graph coloring – Relatively simple, global and works well in practice Alex Aiken

  6. Register Allocation Temporaries t 1 and t 2 can share the same register if at any point in the program at most one of t 1 or t 2 is live. Or If t 1 and t 2 are live at the same time, they cannot share a register Alex Aiken

  7. Register Allocation • Compute live variables for each point: {b,c,f} a := b + c {a,c,f} d := -a {c,d,f} e := d + f {c,d,e,f} {c,e} b := d + e f := 2 * e {b,c,e,f} e := e - 1 {c,f} {c,f} {b,c,f} {b} b := f + c {b} Alex Aiken

  8. Register Allocation • Construct an undirected graph – A node for each temporary – An edge between t 1 and t 2 if they are live simultaneously at some point in the program • This is the register interference graph (RIG) – Two temporaries can be allocated to the same register if there is no edge connecting them Alex Aiken

  9. Register Allocation a • For our example: b f c e d • E.g., b and c cannot be in the same register • E.g., b and d could be in the same register Alex Aiken

  10. Register Allocation Which of the following pairs of temporaries interfere in the code fragment given at right? A := 1 1 B := A * 2 2 A and B C := C - B 3 A and C A := B + 1 4 A < 16 5 B and C D := C + 1 6 C and D

  11. Register Allocation • Extracts exactly the information needed to characterize legal register assignments • Gives a global (i.e., over the entire flow graph) picture of the register requirements • After RIG construction the register allocation algorithm is architecture independent Alex Aiken

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend