Adding function calls in Machine IR after Register Allocation

I’m working on a problem where I need to add a function call to a machine function in case the machine function has a spilled register. The function requires me to pass 1 argument which is the stack frame address of the spiled register. I’m facing issues in trying to pass the argument to the function call.

According to the ARM abi, the argument needs to be present in r0 before the function call. If the r0 register is live, it needs to be spilled to the stack. Since I’m trying to insert the function call after register allocation, how do I get a new stack frame to spill the register?

I have a naive approach in my mind where I reserve an additional stack slot for all functions to accommodate for this potential spill. I assume this information needs to be included in the ARMFrameLoweringInfo file but I’m not entirely sure where to add this. I would also need to mark this stack frame to be unusable to the register allocation pass.

EDIT: I realized that a much simpler way to handle it would be to create push and pop instructions to save and restore r0. I would like to know if there could be any complications that might arise by choosing this approach.

I would appreciate any help in this. Thanks!

You can just do this at any point before / during PrologEpilogInserter.

1 Like