drcjt / CSharp-80

C# AOT compiler for Z80 based computers including the TRS-80 and ZX Spectrum
https://drcjt.github.io/CSharp-80/
GNU General Public License v3.0
51 stars 3 forks source link

Add Register Allocator #477

Open drcjt opened 7 months ago

drcjt commented 7 months ago

No register allocation is done during compilation. The intermediate representation is stack based and this is converted into stack based operations of the Z80.

There are a couple of complications with adding register allocation support:

Using a typical solution for register allocation may result in a lot of spilling due to the above resulting in potentially worse performance. Some experimentation will be required to determine if register allocation is worth it.

Note that the compiler will pass parameters in registers in certain limited cases such as when calling intrinsic methods.

drcjt commented 3 months ago

Dotnet runtime uses Linear Scan Register Allocator - https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/jit/lsra-detail.md

SDCC uses Optimal Register allocator (in polynomial time) - https://link.springer.com/content/pdf/10.1007/978-3-642-37051-9_1.pdf

Some notes from the latter paper on Z80 architecture: