[llvm] d636b76 - [CodeGen] Use AdjustStackOffset for Callee Saved Registers in PEI::calculateFrameObjectOffsets
Daniel McIntosh via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 2 08:41:17 PST 2022
Author: Daniel McIntosh
Date: 2022-03-02T11:41:12-05:00
New Revision: d636b76ecaa67394c09afb4f1c127527ebb798bf
URL: https://github.com/llvm/llvm-project/commit/d636b76ecaa67394c09afb4f1c127527ebb798bf
DIFF: https://github.com/llvm/llvm-project/commit/d636b76ecaa67394c09afb4f1c127527ebb798bf.diff
LOG: [CodeGen] Use AdjustStackOffset for Callee Saved Registers in PEI::calculateFrameObjectOffsets
Also, changes how the CSR loop is indexed, which should avoid bugs like the one fixed by rG4a57bb5a3b74bdad9b0518009a7d7ac7ca2ac650
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D120668
Added:
Modified:
llvm/lib/CodeGen/PrologEpilogInserter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
index 46ae48bd6a3cf..5af14aeecd1a8 100644
--- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
@@ -856,47 +856,34 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) {
if (FixedOff > Offset) Offset = FixedOff;
}
+ Align MaxAlign = MFI.getMaxAlign();
// First assign frame offsets to stack objects that are used to spill
// callee saved registers.
- if (StackGrowsDown && MaxCSFrameIndex >= MinCSFrameIndex) {
- for (unsigned i = MinCSFrameIndex; i <= MaxCSFrameIndex; ++i) {
- if (MFI.getStackID(i) !=
- TargetStackID::Default) // Only allocate objects on the default stack.
- continue;
+ if (MaxCSFrameIndex >= MinCSFrameIndex) {
+ for (unsigned i = 0; i <= MaxCSFrameIndex - MinCSFrameIndex; ++i) {
+ unsigned FrameIndex =
+ StackGrowsDown ? MinCSFrameIndex + i : MaxCSFrameIndex - i;
- // If the stack grows down, we need to add the size to find the lowest
- // address of the object.
- Offset += MFI.getObjectSize(i);
-
- // Adjust to alignment boundary
- Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
-
- LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n");
- MFI.setObjectOffset(i, -Offset); // Set the computed offset
- }
- } else if (MaxCSFrameIndex >= MinCSFrameIndex) {
- // Be careful about underflow in comparisons agains MinCSFrameIndex.
- for (unsigned i = MaxCSFrameIndex; i != MinCSFrameIndex - 1; --i) {
- if (MFI.getStackID(i) !=
- TargetStackID::Default) // Only allocate objects on the default stack.
+ // Only allocate objects on the default stack.
+ if (MFI.getStackID(FrameIndex) != TargetStackID::Default)
continue;
- if (MFI.isDeadObjectIndex(i))
+ // TODO: should this just be if (MFI.isDeadObjectIndex(FrameIndex))
+ if (!StackGrowsDown && MFI.isDeadObjectIndex(FrameIndex))
continue;
- // Adjust to alignment boundary
- Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew);
-
- LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n");
- MFI.setObjectOffset(i, Offset);
- Offset += MFI.getObjectSize(i);
+ AdjustStackOffset(MFI, FrameIndex, StackGrowsDown, Offset, MaxAlign,
+ Skew);
}
}
+ assert(MaxAlign == MFI.getMaxAlign() &&
+ "MFI.getMaxAlign should already account for all callee-saved "
+ "registers without a fixed stack slot");
+
// FixedCSEnd is the stack offset to the end of the fixed and callee-save
// stack area.
int64_t FixedCSEnd = Offset;
- Align MaxAlign = MFI.getMaxAlign();
// Make sure the special register scavenging spill slot is closest to the
// incoming stack pointer if a frame pointer is required and is closer
More information about the llvm-commits
mailing list