For my compiler course I'm building a register allocator based on graph coloring for MIPS architecture. I'm following Muchnick's treatment on the same for my implementation.

Muchnick has been a little fuzzy about how to treat arguments of function in these allocators.

I've made a few assumptions and thought I'd clarify the same.

  1. There is this step to convert to lower level IR from middle level IR. Nested function calls have not been handled. My idea is to scan the function call from right to left and lay down IRs for the innermost calls outward. This way I can use the MIPS calling convention of assigning the first few arguments to argument registers and the remaining to stack with minimum amount of spills (just 1).
  2. Register coalescing treatment in the book is not intuitive to me since it does not address how the LIR code of moving function arguments to fixed argument registers are handled. After much deliberation I've come to the conclusion that I should not do register coalescing for argument passing moves.

Feedback/thoughts on these assumptions immensely appreciated.

有帮助吗?

解决方案

I think you don't want to do register coalescing for argument passing moves from virtual register to argument register regarding function call actual arguments (or, for function call formal arguments copied vice versa on function entry) before register allocation.

However, when you see such a move, you can tag a hint to the allocator that that move target argument register is the preferred choice. When the preferred choice doesn't interfere appropriately*, you can use it for the allocation, with the result that after allocation you'll have a move rx,rx, which you can easily eliminate later.

(Of course, you may find more than one such hint, so then you take the most applicable one, most (and often all) of them will be ruled out from other interference: same register passed to multiple calls; call in a loop, etc..)

(*appropriately means that the argument (real) register isn't otherwise used or trashed in during the lifetime of the virtual register, e.g. by a nested function call or some other. (Identifying this can be as easy as inspecting interferences of the virtual register.))

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top