+/// AdjustStackOffset - Helper function used to adjust the stack frame offset.
+static inline void
+AdjustStackOffset(MachineFrameInfo *FFI, int FrameIdx,
+ bool StackGrowsDown, int64_t &Offset,
+ unsigned &MaxAlign) {
+ // If stack grows down, we need to add size of find the lowest address of the
+ // object.
+ if (StackGrowsDown)
+ Offset += FFI->getObjectSize(FrameIdx);
+
+ unsigned Align = FFI->getObjectAlignment(FrameIdx);
+
+ // 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(FrameIdx, -Offset); // Set the computed offset
+ } else {
+ FFI->setObjectOffset(FrameIdx, Offset);
+ Offset += FFI->getObjectSize(FrameIdx);
+ }
+}