diff --git a/llvm/lib/Target/VE/VEFrameLowering.cpp b/llvm/lib/Target/VE/VEFrameLowering.cpp --- a/llvm/lib/Target/VE/VEFrameLowering.cpp +++ b/llvm/lib/Target/VE/VEFrameLowering.cpp @@ -323,8 +323,8 @@ // Get the number of bytes to allocate from the FrameInfo uint64_t NumBytes = MFI.getStackSize(); - // The VE ABI requires a reserved 176 bytes area at the top - // of stack as described in VESubtarget.cpp. So, we adjust it here. + // The VE ABI requires a reserved area at the top of stack as described + // in VESubtarget.cpp. So, we adjust it here. NumBytes = STI.getAdjustedFrameSize(NumBytes); // Finally, ensure that the size is sufficiently aligned for the diff --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp --- a/llvm/lib/Target/VE/VEISelLowering.cpp +++ b/llvm/lib/Target/VE/VEISelLowering.cpp @@ -341,7 +341,7 @@ MachineFunction &MF = DAG.getMachineFunction(); // Get the base offset of the incoming arguments stack space. - unsigned ArgsBaseOffset = 176; + unsigned ArgsBaseOffset = Subtarget->getRsaSize(); // Get the size of the preserved arguments area unsigned ArgsPreserved = 64; @@ -411,7 +411,7 @@ // The registers are exhausted. This argument was passed on the stack. assert(VA.isMemLoc()); // The CC_VE_Full/Half functions compute stack offsets relative to the - // beginning of the arguments area at %fp+176. + // beginning of the arguments area at %fp + the size of reserved area. unsigned Offset = VA.getLocMemOffset() + ArgsBaseOffset; unsigned ValSize = VA.getValVT().getSizeInBits() / 8; @@ -446,7 +446,7 @@ // TODO: need to calculate offset correctly once we support f128. unsigned ArgOffset = ArgLocs.size() * 8; VEMachineFunctionInfo *FuncInfo = MF.getInfo(); - // Skip the 176 bytes of register save area. + // Skip the reserved area at the top of stack. FuncInfo->setVarArgsFrameOffset(ArgOffset + ArgsBaseOffset); return Chain; @@ -489,7 +489,7 @@ CLI.IsTailCall = false; // Get the base offset of the outgoing arguments stack space. - unsigned ArgsBaseOffset = 176; + unsigned ArgsBaseOffset = Subtarget->getRsaSize(); // Get the size of the preserved arguments area unsigned ArgsPreserved = 8 * 8u; @@ -631,8 +631,7 @@ // Create a store off the stack pointer for this argument. SDValue StackPtr = DAG.getRegister(VE::SX11, PtrVT); - // The argument area starts at %fp+176 in the callee frame, - // %sp+176 in ours. + // The argument area starts at %fp/%sp + the size of reserved area. SDValue PtrOff = DAG.getIntPtrConstant(VA.getLocMemOffset() + ArgsBaseOffset, DL); PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff); diff --git a/llvm/lib/Target/VE/VEInstrInfo.cpp b/llvm/lib/Target/VE/VEInstrInfo.cpp --- a/llvm/lib/Target/VE/VEInstrInfo.cpp +++ b/llvm/lib/Target/VE/VEInstrInfo.cpp @@ -915,8 +915,8 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); const VEFrameLowering &TFL = *STI.getFrameLowering(); - // The VE ABI requires a reserved 176 bytes area at the top - // of stack as described in VESubtarget.cpp. So, we adjust it here. + // The VE ABI requires a reserved area at the top of stack as described + // in VEFrameLowering.cpp. So, we adjust it here. unsigned NumBytes = STI.getAdjustedFrameSize(0); // Also adds the size of parameter area. diff --git a/llvm/lib/Target/VE/VESubtarget.h b/llvm/lib/Target/VE/VESubtarget.h --- a/llvm/lib/Target/VE/VESubtarget.h +++ b/llvm/lib/Target/VE/VESubtarget.h @@ -70,10 +70,14 @@ VESubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS); /// Given a actual stack size as determined by FrameInfo, this function - /// returns adjusted framesize which includes space for register window - /// spills and arguments. + /// returns adjusted framesize which includes space for RSA, return + /// address, and frame poitner. uint64_t getAdjustedFrameSize(uint64_t FrameSize) const; + /// Get the size of RSA, return address, and frame pointer as described + /// in VEFrameLowering.cpp. + unsigned getRsaSize(void) const { return 176; }; + bool isTargetLinux() const { return TargetTriple.isOSLinux(); } }; diff --git a/llvm/lib/Target/VE/VESubtarget.cpp b/llvm/lib/Target/VE/VESubtarget.cpp --- a/llvm/lib/Target/VE/VESubtarget.cpp +++ b/llvm/lib/Target/VE/VESubtarget.cpp @@ -50,9 +50,10 @@ uint64_t VESubtarget::getAdjustedFrameSize(uint64_t FrameSize) const { // Calculate adjusted frame size by adding the size of RSA frame, // return address, and frame poitner as described in VEFrameLowering.cpp. + const VEFrameLowering *TFL = getFrameLowering(); - FrameSize += 176; // For RSA, RA, and FP. - FrameSize = alignTo(FrameSize, 16); // Requires 16 bytes alignment. + FrameSize += getRsaSize(); + FrameSize = alignTo(FrameSize, TFL->getStackAlign()); return FrameSize; }