Currently needsStackRealignment returns false if canRealignStack returns false. This means that the behavior of needsStackRealignment does not correspond to it's name and description; a function might need stack realignment, but if it is not possible then this function returns false. Furthermore, needsStackRealignment is not virtual and therefore some backends have made use of canRealignStack to indicate whether a function needs stack realignment.
This patch attempts to clarify the situation by separating them:
- Make needsStackRealignment virtual so that backends can override it
- Override needsStackRealignment rather than canRealignStack in SIRegisterInfo
- Update some call sites of needsStackRealignment (where backend tests were failing). Some of these may not be necessary.
This change will make it easier in a future change to handle the case where we need to realign the stack but can't do so (for example when the register allocator creates an aligned spill after the frame pointer has been eliminated).
I've found this pair of functions confusing before. I think the naming and having to call both in most situations is still confusing. I'm also not sure why this is in TargetRegisterInfo, and not TargetFrameLowering.
needsStackRealignment feels too strong given that the target can say we're not realigning the stack anyway. How about something like hasImpliedStackRealignment? And a partner function to call both called something like hasStackRealignment?