Closed PhilippRados closed 1 year ago
That's a good question. The compiler definitely assumes that these cases are rare! One of the reasons that I chose to rewrite the back-end to use QBE in Part 63 was to have someone else solve the spilling problem for me.
The big omissions in this compiler are: poor register management and next to no optimisation. I got the code to the self-compiling stage and then stopped as I was happy to end things there.
How does the spilling mechanism ensure that when a register is spilled that that same register isn't needed in the expression with the newly acquired register? Hypothetical example (I know this would be optimized away): Say we have an expression that requires two free registers and there is only one
how does the compiler ensure that this doesn't happen? I couldn't find any code that reloads the value if it's used in an operand. But it could happen that the spilled value is needed in an operation before it is reloaded. Does the compiler just assume that these cases are rare or are they avoided somehow?