Register allocation by puzzle solving
Download
1 / 43

Register Allocation by Puzzle Solving - PowerPoint PPT Presentation


  • 488 Views
  • Updated On :

Register Allocation by Puzzle Solving Jens Palsberg UCLA Computer Science Department University of California, Los Angeles palsberg@ucla.edu This talk Register allocation Aliased registers and pre-coloring Optimal live-range splitting produces elementary programs

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Register Allocation by Puzzle Solving' - adamdaniel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Register allocation by puzzle solving l.jpg

Register Allocation by Puzzle Solving

Jens Palsberg

UCLA Computer Science Department

University of California, Los Angeles

palsberg@ucla.edu


This talk l.jpg
This talk

  • Register allocation

  • Aliased registers and pre-coloring

  • Optimal live-range splitting produces elementary programs

  • Elementary programs have elementary interference graphs

  • Coloring elementary graphs is the same as solving puzzles

  • A linear-time puzzle solving algorithm

  • Spilling

  • Experimental results

Copyright @ 2007 UCLA


Register allocation a collection of puzzles l.jpg
Register allocation  a collection of puzzles

Copyright @ 2007 UCLA


A compiler l.jpg
A Compiler

source language

parser

intermediate representation

code generator

machine code

Copyright @ 2007 UCLA


A better compiler l.jpg
A Better Compiler

source language

parser

intermediate representation

code generator with a

register allocator

machine code

Copyright @ 2007 UCLA


What is register allocation l.jpg
What is Register Allocation?

A = 10

B = 20

C = A + 30

Print C + 40 + B

Assume we have

two registers

Copyright @ 2007 UCLA


Register allocation liveness analysis graph coloring l.jpg
Register allocation = liveness analysis + graph coloring

A = 10

B = 20

C = A + 30

Print C + 40 + B

A

Interference graph:

B,A

A

B

C

With colors:

B,C

A

B

C

Copyright @ 2007 UCLA


After register allocation l.jpg
After Register Allocation

A = 10

B = 20

C = A + 30

Print C + 40 + B

A

B

C

R1 = 10

R2 = 20

R1 = R1 + 30

Print R1 + 40 + R2

Copyright @ 2007 UCLA


Core spill free register allocation problem l.jpg
Core (Spill-free) Register Allocation Problem

Instance: a program P and

a number K of available registers.

Problem: can each variable of P be mapped to one of the K registers such that:

variables with interfering live ranges

are assigned to different registers?

Theorem (Chaitin et al., 1981): NP-complete

Copyright @ 2007 UCLA


A program in ssa form has a chordal interference graph l.jpg
A program in SSA form has a chordal interference graph

  • Proved by three groups independently in 2005:

    • Bouchez (ENS Lyon)

    • Brisk et al. (UCLA)

    • Hack (U. Karlsruhe)

  • A chordal graph can be colored in linear time

Copyright @ 2007 UCLA


Aliased registers on the pentium l.jpg
Aliased registers on the Pentium

32 bits

EAX

EBX

ECX

EDX

16 bits

AX

BX

CX

DX

8 bits

CH

CL

BH

BL

DH

DL

AH

AL

Pre-coloring

Copyright @ 2007 UCLA


Weighted graphs and aligned 1 2 coloring l.jpg
Weighted Graphs and Aligned 1-2-coloring

  • Nodes have weight one or two

  • Two numbers 2i and 2i+1 are aligned

  • Aligned 1-2-coloring:

    • assigns a color to every vertex of weight one

    • assigns two aligned colors to every vertex of weight two

  • Partial aligned 1-2-coloring: partial function

    • models pre-coloring

Copyright @ 2007 UCLA


Aligned 1 2 coloring extension l.jpg
Aligned 1-2-coloring Extension

Instance: a number 2K of colors,

a weighted graph G, and

a partial aligned 1-2-coloring C of G

Problem: Extend C to an aligned 1-2-coloring

of G.

Aligned 1-2-coloring:no vertex is pre-colored

Coloring Extension: all vertices have weight one

Coloring: no vertex is pre-colored; all weight one

Copyright @ 2007 UCLA


Related work l.jpg
Related work

Copyright @ 2007 UCLA


This talk15 l.jpg
This talk

  • Register allocation

  • Aliased registers and pre-coloring

  • Optimal live-range splitting produces elementary programs

  • Elementary programs have elementary interference graphs

  • Coloring elementary graphs is the same as solving puzzles

  • A linear-time puzzle solving algorithm

  • Spilling

  • Experimental results

Copyright @ 2007 UCLA


From strict programs to elementary programs l.jpg
From strict programs to elementary programs

  • Optimal live range splitting : strict program  elementary program

  • Used by Appel and George (PLDI 2001)

Basic block

Statement1

Parallel copy

Statement2

Copyright @ 2007 UCLA


A program p is an elementary program if l.jpg
A program P is an elementary program if:

  • P is strict

  • P is in static single assignment form

  • For any variable v of P, LR(v) contains at most one program point outside the basic block that contains def(v)

  • If two variables u,v of P interfere, then either def(u) = def(v), or kill(u) = kill(v)

  • If two variables u,v of P interfere, then either LR(u)  LR(v), or LR(v)  LR(u)

Copyright @ 2007 UCLA



A clique substitution of p 3 l.jpg
A clique substitution of P3

  • P3 is a path with three vertices   

Copyright @ 2007 UCLA


Elementary graphs l.jpg
Elementary graphs

  • Definition: G is an elementary graph if and only if every connected component of G is a clique substitution of P3

  • Theorem: An elementary program has an elementary interference graph.

Copyright @ 2007 UCLA


Six classes of graphs l.jpg
Six classes of graphs

Copyright @ 2007 UCLA


This talk23 l.jpg
This talk

  • Register allocation

  • Aliased registers and pre-coloring

  • Optimal live-range splitting produces elementary programs

  • Elementary programs have elementary interference graphs

  • Coloring elementary graphs is the same as solving puzzles

  • A linear-time puzzle solving algorithm

  • Spilling

  • Experimental results

Copyright @ 2007 UCLA


A puzzle board l.jpg
A puzzle board

Copyright @ 2007 UCLA


The six kinds of pieces l.jpg
The six kinds of pieces

Copyright @ 2007 UCLA


A puzzle and a solution l.jpg
A puzzle and a solution

Copyright @ 2007 UCLA


From graphs to puzzles l.jpg
From graphs to puzzles

  • Given PX,Y,Z we build a puzzle:

  • Vertex  piece

  • Color  column

  • X-clique  upper row

  • Y-clique  both rows

  • Z-clique  lower row

  • Precoloring  some pieces are on the board already

  • Theorem: Aligned 1-2-coloring extension for clique substitutions of P3 and puzzle solving are equivalent under linear-time reductions

Copyright @ 2007 UCLA


A rule a pattern and a mismatch l.jpg
A rule, a pattern, and a mismatch

Copyright @ 2007 UCLA


Example program l.jpg
Example program

Copyright @ 2007 UCLA


Counterexample 1 l.jpg
Counterexample 1

Lesson: use a size-2 piece before two size-1 pieces

Copyright @ 2007 UCLA


Counterexample 2 l.jpg
Counterexample 2

Lesson: statements 7-10 must come before statements 11-14

Copyright @ 2007 UCLA


Counterexample 3 l.jpg
Counterexample 3

Lesson: statement 15 must come before statements 11-14

Copyright @ 2007 UCLA


Counterexample 4 l.jpg
Counterexample 4

Lesson: the order in statement 11-14 is crucial

Copyright @ 2007 UCLA


From graph coloring to puzzle solving l.jpg
From graph coloring to puzzle solving

  • Theorem: A puzzle is solvable if and only if our program succeeds on the puzzle

  • Our puzzle solving program runs in linear time

Copyright @ 2007 UCLA


This talk37 l.jpg
This talk

  • Register allocation

  • Aliased registers and pre-coloring

  • Optimal live-range splitting produces elementary programs

  • Elementary programs have elementary interference graphs

  • Coloring elementary graphs is the same as solving puzzles

  • A linear-time puzzle solving algorithm

  • Spilling

  • Experimental results

Copyright @ 2007 UCLA


Spilling l.jpg
Spilling

  • Visit each puzzle once

  • If the puzzle is not solvable, then remove some pieces and try to solve again

  • Each time we remove a piece, we also remove all other pieces that stem from the same variable in the original program

Copyright @ 2007 UCLA


Benchmark characteristics l.jpg
Benchmark characteristics

Copyright @ 2007 UCLA




Conclusion l.jpg
Conclusion

  • If you want to do register allocation for the Pentium, your problem is to solve a collection of puzzles

  • Fast compilation time, competitive code quality

  • Future work: compare with run times of code generated by Smith-Ramsey-Holloway (PLDI 2004)

  • Future work: compare with Appel-George (PLDI 2001)

Copyright @ 2007 UCLA