@@ -80,11 +80,6 @@ namespace {
8080class PEIImpl {
8181 RegScavenger *RS = nullptr ;
8282
83- // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
84- // stack frame indexes.
85- unsigned MinCSFrameIndex = std::numeric_limits<unsigned >::max();
86- unsigned MaxCSFrameIndex = 0 ;
87-
8883 // Save and Restore blocks of the current function. Typically there is a
8984 // single save block, unless Windows EH funclets are involved.
9085 MBBVector SaveBlocks;
@@ -456,9 +451,7 @@ void PEIImpl::calculateSaveRestoreBlocks(MachineFunction &MF) {
456451}
457452
458453static void assignCalleeSavedSpillSlots (MachineFunction &F,
459- const BitVector &SavedRegs,
460- unsigned &MinCSFrameIndex,
461- unsigned &MaxCSFrameIndex) {
454+ const BitVector &SavedRegs) {
462455 if (SavedRegs.empty ())
463456 return ;
464457
@@ -490,8 +483,7 @@ static void assignCalleeSavedSpillSlots(MachineFunction &F,
490483
491484 const TargetFrameLowering *TFI = F.getSubtarget ().getFrameLowering ();
492485 MachineFrameInfo &MFI = F.getFrameInfo ();
493- if (!TFI->assignCalleeSavedSpillSlots (F, RegInfo, CSI, MinCSFrameIndex,
494- MaxCSFrameIndex)) {
486+ if (!TFI->assignCalleeSavedSpillSlots (F, RegInfo, CSI)) {
495487 // If target doesn't implement this, use generic code.
496488
497489 if (CSI.empty ())
@@ -534,8 +526,7 @@ static void assignCalleeSavedSpillSlots(MachineFunction &F,
534526 // min.
535527 Alignment = std::min (Alignment, TFI->getStackAlign ());
536528 FrameIdx = MFI.CreateStackObject (Size, Alignment, true );
537- if ((unsigned )FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
538- if ((unsigned )FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
529+ MFI.setIsCalleeSavedObjectIndex (FrameIdx, true );
539530 } else {
540531 // Spill it to the stack where we must.
541532 FrameIdx = MFI.CreateFixedSpillStackObject (Size, FixedSlot->Offset );
@@ -676,15 +667,13 @@ void PEIImpl::spillCalleeSavedRegs(MachineFunction &MF) {
676667 const Function &F = MF.getFunction ();
677668 const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
678669 MachineFrameInfo &MFI = MF.getFrameInfo ();
679- MinCSFrameIndex = std::numeric_limits<unsigned >::max ();
680- MaxCSFrameIndex = 0 ;
681670
682671 // Determine which of the registers in the callee save list should be saved.
683672 BitVector SavedRegs;
684673 TFI->determineCalleeSaves (MF, SavedRegs, RS);
685674
686675 // Assign stack slots for any callee-saved registers that must be spilled.
687- assignCalleeSavedSpillSlots (MF, SavedRegs, MinCSFrameIndex, MaxCSFrameIndex );
676+ assignCalleeSavedSpillSlots (MF, SavedRegs);
688677
689678 // Add the code to save and restore the callee saved registers.
690679 if (!F.hasFnAttribute (Attribute::Naked)) {
@@ -752,10 +741,10 @@ static inline void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx,
752741
753742// / Compute which bytes of fixed and callee-save stack area are unused and keep
754743// / track of them in StackBytesFree.
755- static inline void
756- computeFreeStackSlots (MachineFrameInfo &MFI, bool StackGrowsDown,
757- unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex ,
758- int64_t FixedCSEnd, BitVector &StackBytesFree) {
744+ static inline void computeFreeStackSlots (MachineFrameInfo &MFI,
745+ bool StackGrowsDown,
746+ int64_t FixedCSEnd ,
747+ BitVector &StackBytesFree) {
759748 // Avoid undefined int64_t -> int conversion below in extreme case.
760749 if (FixedCSEnd > std::numeric_limits<int >::max ())
761750 return ;
@@ -769,11 +758,10 @@ computeFreeStackSlots(MachineFrameInfo &MFI, bool StackGrowsDown,
769758 if (MFI.getStackID (i) == TargetStackID::Default)
770759 AllocatedFrameSlots.push_back (i);
771760 // Add callee-save objects if there are any.
772- if (MinCSFrameIndex <= MaxCSFrameIndex) {
773- for (int i = MinCSFrameIndex; i <= (int )MaxCSFrameIndex; ++i)
774- if (MFI.getStackID (i) == TargetStackID::Default)
775- AllocatedFrameSlots.push_back (i);
776- }
761+ for (int i = MFI.getObjectIndexBegin (); i < MFI.getObjectIndexEnd (); i++)
762+ if (MFI.isCalleeSavedObjectIndex (i) &&
763+ MFI.getStackID (i) == TargetStackID::Default)
764+ AllocatedFrameSlots.push_back (i);
777765
778766 for (int i : AllocatedFrameSlots) {
779767 // These are converted from int64_t, but they should always fit in int
@@ -923,20 +911,28 @@ void PEIImpl::calculateFrameObjectOffsets(MachineFunction &MF) {
923911 Align MaxAlign = MFI.getMaxAlign ();
924912 // First assign frame offsets to stack objects that are used to spill
925913 // callee saved registers.
926- if (MaxCSFrameIndex >= MinCSFrameIndex) {
927- for (unsigned i = 0 ; i <= MaxCSFrameIndex - MinCSFrameIndex; ++i) {
928- unsigned FrameIndex =
929- StackGrowsDown ? MinCSFrameIndex + i : MaxCSFrameIndex - i;
930-
914+ if (StackGrowsDown) {
915+ for (int FI = MFI.getObjectIndexBegin (); FI < MFI.getObjectIndexEnd ();
916+ FI++) {
917+ // Only allocate objects on the default stack.
918+ if (!MFI.isCalleeSavedObjectIndex (FI) ||
919+ MFI.getStackID (FI) != TargetStackID::Default)
920+ continue ;
921+ // TODO: should we be using MFI.isDeadObjectIndex(FI) here?
922+ AdjustStackOffset (MFI, FI, StackGrowsDown, Offset, MaxAlign);
923+ }
924+ } else {
925+ for (int FI = MFI.getObjectIndexEnd () - 1 ; FI >= MFI.getObjectIndexBegin ();
926+ FI--) {
931927 // Only allocate objects on the default stack.
932- if (MFI.getStackID (FrameIndex) != TargetStackID::Default)
928+ if (!MFI.isCalleeSavedObjectIndex (FI) ||
929+ MFI.getStackID (FI) != TargetStackID::Default)
933930 continue ;
934931
935- // TODO: should this just be if (MFI.isDeadObjectIndex(FrameIndex))
936- if (!StackGrowsDown && MFI.isDeadObjectIndex (FrameIndex))
932+ if (MFI.isDeadObjectIndex (FI))
937933 continue ;
938934
939- AdjustStackOffset (MFI, FrameIndex , StackGrowsDown, Offset, MaxAlign);
935+ AdjustStackOffset (MFI, FI , StackGrowsDown, Offset, MaxAlign);
940936 }
941937 }
942938
@@ -1025,7 +1021,7 @@ void PEIImpl::calculateFrameObjectOffsets(MachineFunction &MF) {
10251021 for (unsigned i = 0 , e = MFI.getObjectIndexEnd (); i != e; ++i) {
10261022 if (MFI.isObjectPreAllocated (i) && MFI.getUseLocalStackAllocationBlock ())
10271023 continue ;
1028- if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex )
1024+ if (MFI. isCalleeSavedObjectIndex (i) )
10291025 continue ;
10301026 if (RS && RS->isScavengingFrameIndex ((int )i))
10311027 continue ;
@@ -1077,7 +1073,7 @@ void PEIImpl::calculateFrameObjectOffsets(MachineFunction &MF) {
10771073 for (unsigned i = 0 , e = MFI.getObjectIndexEnd (); i != e; ++i) {
10781074 if (MFI.isObjectPreAllocated (i) && MFI.getUseLocalStackAllocationBlock ())
10791075 continue ;
1080- if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex )
1076+ if (MFI. isCalleeSavedObjectIndex (i) )
10811077 continue ;
10821078 if (RS && RS->isScavengingFrameIndex ((int )i))
10831079 continue ;
@@ -1113,8 +1109,7 @@ void PEIImpl::calculateFrameObjectOffsets(MachineFunction &MF) {
11131109 if (!ObjectsToAllocate.empty () &&
11141110 MF.getTarget ().getOptLevel () != CodeGenOptLevel::None &&
11151111 MFI.getStackProtectorIndex () < 0 && TFI.enableStackSlotScavenging (MF))
1116- computeFreeStackSlots (MFI, StackGrowsDown, MinCSFrameIndex, MaxCSFrameIndex,
1117- FixedCSEnd, StackBytesFree);
1112+ computeFreeStackSlots (MFI, StackGrowsDown, FixedCSEnd, StackBytesFree);
11181113
11191114 // Now walk the objects and actually assign base offsets to them.
11201115 for (auto &Object : ObjectsToAllocate)
0 commit comments