[NFC][CodeGen] Tidy up TargetRegisterInfo stack realignment functions

Authored by tmatheson on Mar 15 2021, 6:01 AM.


[NFC][CodeGen] Tidy up TargetRegisterInfo stack realignment functions

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 and introducing
new names:

  • shouldRealignStack - true if there is any reason the stack should be realigned
  • canRealignStack - true if we are still able to realign the stack (e.g. we can still reserve/have reserved a frame pointer)
  • hasStackRealignment = shouldRealignStack && canRealignStack (not target customisable)

Targets can now override shouldRealignStack to indicate that stack realignment
is required.

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

Differential Revision: https://reviews.llvm.org/D98716

Change-Id: Ib9a4d21728bf9d08a545b4365418d3ffe1af4d87