- // Align the final stack pointer offset, but only if there are calls in the
- // function. This ensures that any calls to subroutines have their stack
- // frames suitable aligned.
- if (FFI->hasCalls())
- Offset = (Offset+StackAlignment-1)/StackAlignment*StackAlignment;
+ // Make sure the special register scavenging spill slot is closest to the
+ // stack pointer.
+ if (RS && !RegInfo->hasFP(Fn)) {
+ int SFI = RS->getScavengingFrameIndex();
+ if (SFI >= 0) {
+ // If stack grows down, we need to add size of find the lowest
+ // address of the object.
+ if (StackGrowsDown)
+ Offset += FFI->getObjectSize(SFI);
+
+ unsigned Align = FFI->getObjectAlignment(SFI);
+ // If the alignment of this object is greater than that of the
+ // stack, then increase the stack alignment to match.
+ MaxAlign = std::max(MaxAlign, Align);
+ // Adjust to alignment boundary
+ Offset = (Offset+Align-1)/Align*Align;
+
+ if (StackGrowsDown) {
+ FFI->setObjectOffset(SFI, -Offset); // Set the computed offset
+ } else {
+ FFI->setObjectOffset(SFI, Offset);
+ Offset += FFI->getObjectSize(SFI);
+ }
+ }
+ }
+
+ // Round up the size to a multiple of the alignment, but only if there are
+ // calls or alloca's in the function. This ensures that any calls to
+ // subroutines have their stack frames suitable aligned.
+ if (!RegInfo->targetHandlesStackFrameRounding() &&
+ (FFI->hasCalls() || FFI->hasVarSizedObjects())) {
+ // If we have reserved argument space for call sites in the function
+ // immediately on entry to the current function, count it as part of the
+ // overall stack size.
+ if (RegInfo->hasReservedCallFrame(Fn))
+ Offset += FFI->getMaxCallFrameSize();
+
+ unsigned AlignMask = TFI.getStackAlignment() - 1;
+ Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
+ }