NVPTXPrologEpilogPass.cpp revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===-- NVPTXPrologEpilogPass.cpp - NVPTX prolog/epilog inserter ----------===//
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//                     The LLVM Compiler Infrastructure
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// This file is distributed under the University of Illinois Open Source
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// License. See LICENSE.TXT for details.
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===----------------------------------------------------------------------===//
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// This file is a copy of the generic LLVM PrologEpilogInserter pass, modified
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// to remove unneeded functionality and to handle virtual registers. Most code
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// here is a copy of PrologEpilogInserter.cpp.
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//===----------------------------------------------------------------------===//
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "NVPTX.h"
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/CodeGen/MachineFrameInfo.h"
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/CodeGen/MachineFunction.h"
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/CodeGen/MachineFunctionPass.h"
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Pass.h"
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Support/Debug.h"
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Support/raw_ostream.h"
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Target/TargetFrameLowering.h"
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "llvm/Target/TargetRegisterInfo.h"
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace llvm;
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace {
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass NVPTXPrologEpilogPass : public MachineFunctionPass {
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  static char ID;
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  NVPTXPrologEpilogPass() : MachineFunctionPass(ID) {}
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  virtual bool runOnMachineFunction(MachineFunction &MF);
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  void calculateFrameObjectOffsets(MachineFunction &Fn);
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
413c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMachineFunctionPass *llvm::createNVPTXPrologEpilogPass() {
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  return new NVPTXPrologEpilogPass();
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrychar NVPTXPrologEpilogPass::ID = 0;
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool NVPTXPrologEpilogPass::runOnMachineFunction(MachineFunction &MF) {
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const TargetMachine &TM = MF.getTarget();
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const TargetFrameLowering &TFI = *TM.getFrameLowering();
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool Modified = false;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  calculateFrameObjectOffsets(MF);
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) {
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      MachineInstr *MI = I;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        if (!MI->getOperand(i).isFI())
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry          continue;
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        TRI.eliminateFrameIndex(MI, 0, i, NULL);
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        Modified = true;
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      }
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Add function prolog/epilog
683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  TFI.emitPrologue(MF);
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // If last instruction is a return instruction, add an epilogue
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (!I->empty() && I->back().isReturn())
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      TFI.emitEpilogue(MF, *I);
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  return Modified;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystatic inline void
813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryAdjustStackOffset(MachineFrameInfo *MFI, int FrameIdx,
823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                  bool StackGrowsDown, int64_t &Offset,
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry                  unsigned &MaxAlign) {
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // If the stack grows down, add the object size to find the lowest address.
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (StackGrowsDown)
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Offset += MFI->getObjectSize(FrameIdx);
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned Align = MFI->getObjectAlignment(FrameIdx);
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // If the alignment of this object is greater than that of the stack, then
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // increase the stack alignment to match.
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MaxAlign = std::max(MaxAlign, Align);
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Adjust to alignment boundary.
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  Offset = (Offset + Align - 1) / Align * Align;
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (StackGrowsDown) {
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset << "]\n");
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MFI->setObjectOffset(FrameIdx, -Offset); // Set the computed offset
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  } else {
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset << "]\n");
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MFI->setObjectOffset(FrameIdx, Offset);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Offset += MFI->getObjectSize(FrameIdx);
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid
1083c827367444ee418f129b2c238299f49d3264554Jarkko PoyryNVPTXPrologEpilogPass::calculateFrameObjectOffsets(MachineFunction &Fn) {
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const TargetFrameLowering &TFI = *Fn.getTarget().getFrameLowering();
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  const TargetRegisterInfo *RegInfo = Fn.getTarget().getRegisterInfo();
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  bool StackGrowsDown =
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsDown;
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Loop over all of the stack objects, assigning sequential addresses...
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MachineFrameInfo *MFI = Fn.getFrameInfo();
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Start at the beginning of the local area.
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // The Offset is the distance from the stack top in the direction
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // of stack growth -- so it's always nonnegative.
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  int LocalAreaOffset = TFI.getOffsetOfLocalArea();
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (StackGrowsDown)
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    LocalAreaOffset = -LocalAreaOffset;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  assert(LocalAreaOffset >= 0
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry         && "Local area offset should be in direction of stack growth");
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  int64_t Offset = LocalAreaOffset;
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // If there are fixed sized objects that are preallocated in the local area,
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // non-fixed objects can't be allocated right at the start of local area.
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // We currently don't support filling in holes in between fixed sized
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // objects, so we adjust 'Offset' to point to the end of last fixed sized
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // preallocated object.
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  for (int i = MFI->getObjectIndexBegin(); i != 0; ++i) {
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    int64_t FixedOff;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (StackGrowsDown) {
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // The maximum distance from the stack pointer is at lower address of
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // the object -- which is given by offset. For down growing stack
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // the offset is negative, so we negate the offset to get the distance.
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      FixedOff = -MFI->getObjectOffset(i);
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    } else {
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // The maximum distance from the start pointer is at the upper
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      // address of the object.
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      FixedOff = MFI->getObjectOffset(i) + MFI->getObjectSize(i);
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (FixedOff > Offset) Offset = FixedOff;
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // NOTE: We do not have a call stack
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  unsigned MaxAlign = MFI->getMaxAlignment();
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // No scavenger
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // FIXME: Once this is working, then enable flag will change to a target
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // check for whether the frame is large enough to want to use virtual
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // frame index registers. Functions which don't want/need this optimization
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // will continue to use the existing code path.
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (MFI->getUseLocalStackAllocationBlock()) {
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    unsigned Align = MFI->getLocalFrameMaxAlign();
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Adjust to alignment boundary.
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Offset = (Offset + Align - 1) / Align * Align;
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n");
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Resolve offsets for objects in the local block.
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    for (unsigned i = 0, e = MFI->getLocalFrameObjectCount(); i != e; ++i) {
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      std::pair<int, int64_t> Entry = MFI->getLocalFrameObjectMap(i);
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      int64_t FIOffset = (StackGrowsDown ? -Offset : Offset) + Entry.second;
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      DEBUG(dbgs() << "alloc FI(" << Entry.first << ") at SP[" <<
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry            FIOffset << "]\n");
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      MFI->setObjectOffset(Entry.first, FIOffset);
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    }
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Allocate the local block
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Offset += MFI->getLocalFrameSize();
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MaxAlign = std::max(Align, MaxAlign);
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // No stack protector
1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Then assign frame offsets to stack objects that are not used to spill
1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // callee saved registers.
1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (MFI->isObjectPreAllocated(i) &&
1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        MFI->getUseLocalStackAllocationBlock())
1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      continue;
1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (MFI->isDeadObjectIndex(i))
1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      continue;
1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    AdjustStackOffset(MFI, i, StackGrowsDown, Offset, MaxAlign);
1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // No scavenger
1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (!TFI.targetHandlesStackFrameRounding()) {
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // If we have reserved argument space for call sites in the function
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // immediately on entry to the current function, count it as part of the
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // overall stack size.
2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (MFI->adjustsStack() && TFI.hasReservedCallFrame(Fn))
2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      Offset += MFI->getMaxCallFrameSize();
2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // Round up the size to a multiple of the alignment.  If the function has
2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // any calls or alloca's, align to the target's StackAlignment value to
2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // ensure that the callee's frame or the alloca data is suitably aligned;
2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // otherwise, for leaf functions, align to the TransientStackAlignment
2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // value.
2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    unsigned StackAlign;
2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    if (MFI->adjustsStack() || MFI->hasVarSizedObjects() ||
2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry        (RegInfo->needsStackRealignment(Fn) && MFI->getObjectIndexEnd() != 0))
2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      StackAlign = TFI.getStackAlignment();
2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    else
2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      StackAlign = TFI.getTransientStackAlignment();
2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // If the frame pointer is eliminated, all frame offsets will be relative to
2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // SP not FP. Align to MaxAlign so this works.
2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    StackAlign = std::max(StackAlign, MaxAlign);
2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    unsigned AlignMask = StackAlign - 1;
2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  // Update frame info to pretend that this is part of the stack...
2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  int64_t StackSize = Offset - LocalAreaOffset;
2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  MFI->setStackSize(StackSize);
2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry