Re: Simple register allocation for assembly

journeyman@compilerguru.com (journeyman)
12 Jan 2003 17:44:34 -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: journeyman@compilerguru.com (journeyman)
Newsgroups: comp.compilers
Date: 12 Jan 2003 17:44:34 -0500
Organization: Posted via Supernews, http://www.supernews.com
References: 03-01-031
Keywords: registers
Posted-Date: 12 Jan 2003 17:44:34 EST

On 7 Jan 2003 23:28:46 -0500, Falk Hueffner
<falk.hueffner@student.uni-tuebingen.de> wrote:
>There are only instructions with 0 to 3 inputs and 0 to 1 outputs,
>conditional branches, and unconditional branches. No spilling is to be
>done, if no register allocation can be done, the program should
>abort. Also, I expect very small input sizes, so resource usage is not
>very important. So at first glance this looks pretty easy, but I can't
>really come up with a simple algoritm, any hints?


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.


If you're really talking about small programs, it's probably not worth
the effort. Try using macro expansions (#define) to rename the
registers by hand.


As a random musing, you might try estimating the live ranges
textually, using a good string-oriented language (Perl) to match
patterns. It might work if you keep your program structured. You'll
have to take backward branches into account...


HTH,


Morris


Post a followup to this message

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