Re: Simple register allocation for assembly

Christian Bau <christian.bau@cbau.freeserve.co.uk>
17 Jan 2003 19:41:36 -0500

          From comp.compilers

Related articles
Simple register allocation for assembly falk.hueffner@student.uni-tuebingen.de (Falk Hueffner) (2003-01-07)
Re: Simple register allocation for assembly journeyman@compilerguru.com (2003-01-12)
Re: Simple register allocation for assembly christian.bau@cbau.freeserve.co.uk (Christian Bau) (2003-01-17)
Re: Simple register allocation for assembly robert.thorpe@antenova.com (Rob Thorpe) (2003-01-17)
Re: Simple register allocation for assembly tmk@netvision.net.il (2003-01-25)
Re: Simple register allocation for assembly housel@cox.net (2003-01-27)
| List of all articles for this month |

From: Christian Bau <christian.bau@cbau.freeserve.co.uk>
Newsgroups: comp.compilers
Date: 17 Jan 2003 19:41:36 -0500
Organization: Compilers Central
References: 03-01-031 03-01-055
Keywords: registers
Posted-Date: 17 Jan 2003 19:41:36 EST

  journeyman@compilerguru.com (journeyman) wrote:


> [ with respect to a simple register allocator ]


> Okay, you've striped out the hard part of of register allocation,
> which is what to do when you don't have enough registers. But, you're
> still left with a not-completely-trivial problem.
>
> A basic algorithm for register allocation is to compute the live range
> of the register candidates, and construct an interference graph that
> links together candidates that are live at the same time. Then you
> assign "colors" to each node. If you can color the graph using only n
> colors, you can allocate the candidates using only n registers.
>
> You compute the live range by propagating backwards information about
> values used, and propagating forward information about values defined.
> A candidate is live at any point in the program when it's been defined
> and will be used. This is a standard dataflow algorithm.
>
> Unfortunately, graph-coloring is NP-complete, so it gets expensive
> real fast as the size of your interference graph gets larger.
> Production allocators use heuristics to select the colors.


What is NP-complete is graph-coloring with the absolutely minimum
number of colors. If you don't insist on getting the best possible
solution, graph coloring is much easier. Take the next variable, try
if it can use any of the existing colors, and create a new color only
when necessary.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.