[llvm] [MachineFrameInfo] Refactoring with computeMaxcallFrameSize() (NFC) (PR #78001)

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 12:46:11 PST 2024


================
@@ -184,26 +184,24 @@ uint64_t MachineFrameInfo::estimateStackSize(const MachineFunction &MF) const {
   return alignTo(Offset, StackAlign);
 }
 
-void MachineFrameInfo::computeMaxCallFrameSize(const MachineFunction &MF) {
+void MachineFrameInfo::computeMaxCallFrameSize(
+    MachineFunction &MF, std::vector<MachineBasicBlock::iterator> *FrameSDOps) {
   const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
   unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
   unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
   assert(FrameSetupOpcode != ~0u && FrameDestroyOpcode != ~0u &&
          "Can only compute MaxCallFrameSize if Setup/Destroy opcode are known");
 
   MaxCallFrameSize = 0;
-  for (const MachineBasicBlock &MBB : MF) {
-    for (const MachineInstr &MI : MBB) {
+  for (MachineBasicBlock &MBB : MF) {
+    for (MachineInstr &MI : MBB) {
       unsigned Opcode = MI.getOpcode();
       if (Opcode == FrameSetupOpcode || Opcode == FrameDestroyOpcode) {
         unsigned Size = TII.getFrameSize(MI);
         MaxCallFrameSize = std::max(MaxCallFrameSize, Size);
         AdjustsStack = true;
----------------
JonPsson1 wrote:

I think it would be best in that case to do the calls also during isel, given that not all targets actually need the frame pseudos. On SystemZ we would like to eliminate them early (see https://github.com/llvm/llvm-project/pull/77812) as they serve no use around calls (call frame allocated once for all calls in prolog), and we just realized that we are even suppose keep the StackFrameSize accuarate when splitting blocks in FinalizeISel, which we currently do not do.

I am a little uncertain on exactly what AdjustsStack means. Does it mean that the function redefines SP, or could it also mean that it makes any call (which do not necessarily change SP on all targets, I think)?

It seems that given the current MachineFrameInfo scan for frame instructions, AdjustsStack could be set always in SelectionDAG::getCALLSEQ_START() (and similar for GlobalISel)?  (and the current definition of AdjustsStack is then "any call", so maybe the comment could be clarified).



https://github.com/llvm/llvm-project/pull/78001


More information about the llvm-commits mailing list