[llvm] [ARM][Thumb1] Improve EstimateFunctionSizeInBytes accuracy (PR #203318)
Simon Tatham via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 05:46:43 PDT 2026
================
@@ -2346,16 +2346,146 @@ bool ARMFrameLowering::restoreCalleeSavedRegisters(
// FIXME: Make generic?
static unsigned EstimateFunctionSizeInBytes(const MachineFunction &MF,
- const ARMBaseInstrInfo &TII) {
+ const ARMBaseInstrInfo &TII,
+ const ARMSubtarget &STI,
+ bool BigFrameOffsets) {
unsigned FnSize = 0;
+
+ if (MF.shouldSplitStack()) {
+ // Split stack prologue saves r4,r5; makes a copy of sp and loads
+ // a literal; compares the two, and if sp < literal, pushes
+ // further registers and calls __morestack.
+ FnSize += 0x24;
----------------
statham-arm wrote:
I don't really see how you could do that easily. The code that generates the instructions is long and full of conditionals. If we counted up the size of each instruction as it was generated, that would be easy to get wrong – the next person adding an instruction might very easily not notice the localised requirement to increment that count.
The check in #203319 seems to me like the least intrusive way to detect getting out of sync. It's true that it only checks the estimate for the function as a whole, rather than checking each of these individual upper bounds against specifically the instructions it has in mind, but in return, it checks at the point where the estimate _matters_, after any phases in between have had a chance to modify things.
https://github.com/llvm/llvm-project/pull/203318
More information about the llvm-commits
mailing list