diff --git a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h --- a/llvm/include/llvm/CodeGen/TargetRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/TargetRegisterInfo.h @@ -914,9 +914,12 @@ /// True if storage within the function requires the stack pointer to be /// aligned more than the normal calling convention calls for. - /// This cannot be overriden by the target, but canRealignStack can be - /// overridden. - bool needsStackRealignment(const MachineFunction &MF) const; + virtual bool shouldRealignStack(const MachineFunction &MF) const; + + /// True if stack realignment is required and still possible. + bool hasStackRealignment(const MachineFunction &MF) const { + return shouldRealignStack(MF) && canRealignStack(MF); + } /// Get the offset from the referenced frame index in the instruction, /// if there is one. diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1377,7 +1377,7 @@ CurFn->CSRSize = MFI.getCVBytesOfCalleeSavedRegisters(); CurFn->FrameSize = MFI.getStackSize(); CurFn->OffsetAdjustment = MFI.getOffsetAdjustment(); - CurFn->HasStackRealignment = TRI->needsStackRealignment(*MF); + CurFn->HasStackRealignment = TRI->hasStackRealignment(*MF); // For this function S_FRAMEPROC record, figure out which codeview register // will be the frame pointer. diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp --- a/llvm/lib/CodeGen/GCRootLowering.cpp +++ b/llvm/lib/CodeGen/GCRootLowering.cpp @@ -317,8 +317,8 @@ // size, we use UINT64_MAX to represent this. const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); - const bool DynamicFrameSize = MFI.hasVarSizedObjects() || - RegInfo->needsStackRealignment(MF); + const bool DynamicFrameSize = + MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF); FI->setFrameSize(DynamicFrameSize ? UINT64_MAX : MFI.getStackSize()); // Find all safe points. diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -1370,7 +1370,7 @@ // Don't promote to an alignment that would require dynamic stack // realignment. const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); - if (!TRI->needsStackRealignment(MF)) + if (!TRI->hasStackRealignment(MF)) while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign)) NewAlign = NewAlign / 2; @@ -1475,7 +1475,7 @@ // Don't promote to an alignment that would require dynamic stack // realignment. const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); - if (!TRI->needsStackRealignment(MF)) + if (!TRI->hasStackRealignment(MF)) while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign)) NewAlign = NewAlign / 2; diff --git a/llvm/lib/CodeGen/MachineFrameInfo.cpp b/llvm/lib/CodeGen/MachineFrameInfo.cpp --- a/llvm/lib/CodeGen/MachineFrameInfo.cpp +++ b/llvm/lib/CodeGen/MachineFrameInfo.cpp @@ -173,7 +173,7 @@ // value. Align StackAlign; if (adjustsStack() || hasVarSizedObjects() || - (RegInfo->needsStackRealignment(MF) && getObjectIndexEnd() != 0)) + (RegInfo->hasStackRealignment(MF) && getObjectIndexEnd() != 0)) StackAlign = TFI->getStackAlign(); else StackAlign = TFI->getTransientStackAlign(); diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -877,10 +877,9 @@ // incoming stack pointer if a frame pointer is required and is closer // to the incoming rather than the final stack pointer. const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); - bool EarlyScavengingSlots = (TFI.hasFP(MF) && - TFI.isFPCloseToIncomingSP() && + bool EarlyScavengingSlots = (TFI.hasFP(MF) && TFI.isFPCloseToIncomingSP() && RegInfo->useFPForScavengingIndex(MF) && - !RegInfo->needsStackRealignment(MF)); + !RegInfo->hasStackRealignment(MF)); if (RS && EarlyScavengingSlots) { SmallVector SFIs; RS->getScavengingFrameIndices(SFIs); @@ -1063,7 +1062,7 @@ // value. Align StackAlign; if (MFI.adjustsStack() || MFI.hasVarSizedObjects() || - (RegInfo->needsStackRealignment(MF) && MFI.getObjectIndexEnd() != 0)) + (RegInfo->hasStackRealignment(MF) && MFI.getObjectIndexEnd() != 0)) StackAlign = TFI.getStackAlign(); else StackAlign = TFI.getTransientStackAlign(); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6173,7 +6173,7 @@ // Don't promote to an alignment that would require dynamic stack // realignment. const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); - if (!TRI->needsStackRealignment(MF)) + if (!TRI->hasStackRealignment(MF)) while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign)) NewAlign = NewAlign / 2; diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp --- a/llvm/lib/CodeGen/StackMaps.cpp +++ b/llvm/lib/CodeGen/StackMaps.cpp @@ -511,7 +511,7 @@ const MachineFrameInfo &MFI = AP.MF->getFrameInfo(); const TargetRegisterInfo *RegInfo = AP.MF->getSubtarget().getRegisterInfo(); bool HasDynamicFrameSize = - MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(*(AP.MF)); + MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(*(AP.MF)); uint64_t FrameSize = HasDynamicFrameSize ? UINT64_MAX : MFI.getStackSize(); auto CurrentIt = FnInfos.find(AP.CurrentFnSym); diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -461,21 +461,13 @@ return !MF.getFunction().hasFnAttribute("no-realign-stack"); } -bool TargetRegisterInfo::needsStackRealignment( - const MachineFunction &MF) const { +bool TargetRegisterInfo::shouldRealignStack(const MachineFunction &MF) const { const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); const Function &F = MF.getFunction(); - Align StackAlign = TFI->getStackAlign(); - bool requiresRealignment = ((MFI.getMaxAlign() > StackAlign) || - F.hasFnAttribute(Attribute::StackAlignment)); - if (F.hasFnAttribute("stackrealign") || requiresRealignment) { - if (canRealignStack(MF)) - return true; - LLVM_DEBUG(dbgs() << "Can't realign function's stack: " << F.getName() - << "\n"); - } - return false; + return F.hasFnAttribute("stackrealign") || + (MFI.getMaxAlign() > TFI->getStackAlign()) || + F.hasFnAttribute(Attribute::StackAlignment); } bool TargetRegisterInfo::regmaskSubsetEqual(const uint32_t *mask0, diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp @@ -252,7 +252,7 @@ // Bail on stack adjustment needed on return for simplicity. const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); - if (MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(MF)) + if (MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF)) return false; if (Exit && getArgumentPopSize(MF, *Exit)) return false; @@ -363,7 +363,7 @@ return true; if (MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || MFI.hasStackMap() || MFI.hasPatchPoint() || - RegInfo->needsStackRealignment(MF)) + RegInfo->hasStackRealignment(MF)) return true; // With large callframes around we may need to use FP to access the scavenging // emergency spillslot. @@ -616,7 +616,7 @@ const AArch64RegisterInfo *RegInfo = Subtarget.getRegisterInfo(); // Don't need a scratch register if we're not going to re-align the stack. - if (!RegInfo->needsStackRealignment(*MF)) + if (!RegInfo->hasStackRealignment(*MF)) return true; // Otherwise, we can use any block as long as it has a scratch register // available. @@ -678,7 +678,7 @@ if (MFI.hasVarSizedObjects()) return false; - if (RegInfo->needsStackRealignment(MF)) + if (RegInfo->hasStackRealignment(MF)) return false; // This isn't strictly necessary, but it simplifies things a bit since the @@ -1375,7 +1375,7 @@ if (NumBytes) { // Alignment is required for the parent frame, not the funclet const bool NeedsRealignment = - !IsFunclet && RegInfo->needsStackRealignment(MF); + !IsFunclet && RegInfo->hasStackRealignment(MF); unsigned scratchSPReg = AArch64::SP; if (NeedsRealignment) { @@ -1981,13 +1981,13 @@ // Argument access should always use the FP. if (isFixed) { UseFP = hasFP(MF); - } else if (isCSR && RegInfo->needsStackRealignment(MF)) { + } else if (isCSR && RegInfo->hasStackRealignment(MF)) { // References to the CSR area must use FP if we're re-aligning the stack // since the dynamically-sized alignment padding is between the SP/BP and // the CSR area. assert(hasFP(MF) && "Re-aligned stack must have frame pointer"); UseFP = true; - } else if (hasFP(MF) && !RegInfo->needsStackRealignment(MF)) { + } else if (hasFP(MF) && !RegInfo->hasStackRealignment(MF)) { // If the FPOffset is negative and we're producing a signed immediate, we // have to keep in mind that the available offset range for negative // offsets is smaller than for positive ones. If an offset is available @@ -2029,9 +2029,10 @@ } } - assert(((isFixed || isCSR) || !RegInfo->needsStackRealignment(MF) || !UseFP) && - "In the presence of dynamic stack pointer realignment, " - "non-argument/CSR objects cannot be accessed through the frame pointer"); + assert( + ((isFixed || isCSR) || !RegInfo->hasStackRealignment(MF) || !UseFP) && + "In the presence of dynamic stack pointer realignment, " + "non-argument/CSR objects cannot be accessed through the frame pointer"); if (isSVE) { StackOffset FPOffset = @@ -2041,10 +2042,9 @@ StackOffset::get(MFI.getStackSize() - AFI->getCalleeSavedStackSize(), ObjectOffset); // Always use the FP for SVE spills if available and beneficial. - if (hasFP(MF) && - (SPOffset.getFixed() || - FPOffset.getScalable() < SPOffset.getScalable() || - RegInfo->needsStackRealignment(MF))) { + if (hasFP(MF) && (SPOffset.getFixed() || + FPOffset.getScalable() < SPOffset.getScalable() || + RegInfo->hasStackRealignment(MF))) { FrameReg = RegInfo->getFrameRegister(MF); return FPOffset; } diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp @@ -382,7 +382,7 @@ // stack needs to be dynamically re-aligned, the base pointer is the only // reliable way to reference the locals. if (MFI.hasVarSizedObjects() || MF.hasEHFunclets()) { - if (needsStackRealignment(MF)) + if (hasStackRealignment(MF)) return true; if (MF.getSubtarget().hasSVE()) { @@ -437,7 +437,7 @@ assert((!MF.getSubtarget().hasSVE() || AFI->hasCalculatedStackSizeSVE()) && "Expected SVE area to be calculated by this point"); - return TFI.hasFP(MF) && !needsStackRealignment(MF) && !AFI->getStackSizeSVE(); + return TFI.hasFP(MF) && !hasStackRealignment(MF) && !AFI->getStackSizeSVE(); } bool AArch64RegisterInfo::requiresFrameIndexScavenging( @@ -761,7 +761,7 @@ const auto &MFI = MF.getFrameInfo(); if (!MF.hasEHFunclets() && !MFI.hasVarSizedObjects()) return AArch64::SP; - else if (needsStackRealignment(MF)) + else if (hasStackRealignment(MF)) return getBaseRegister(); return getFrameRegister(MF); } diff --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp --- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp @@ -1014,7 +1014,7 @@ } } - if (TRI.needsStackRealignment(MF)) { + if (TRI.hasStackRealignment(MF)) { HasFP = true; const unsigned Alignment = MFI.getMaxAlign().value(); @@ -1447,8 +1447,9 @@ } return frameTriviallyRequiresSP(MFI) || MFI.isFrameAddressTaken() || - MF.getSubtarget().getRegisterInfo()->needsStackRealignment(MF) || - MF.getTarget().Options.DisableFramePointerElim(MF); + MF.getSubtarget().getRegisterInfo()->hasStackRealignment( + MF) || + MF.getTarget().Options.DisableFramePointerElim(MF); } // This is essentially a reduced version of hasFP for entry functions. Since the diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h @@ -79,7 +79,7 @@ bool hasBasePointer(const MachineFunction &MF) const; Register getBaseRegister() const; - bool canRealignStack(const MachineFunction &MF) const override; + bool shouldRealignStack(const MachineFunction &MF) const override; bool requiresRegisterScavenging(const MachineFunction &Fn) const override; bool requiresFrameIndexScavenging(const MachineFunction &MF) const override; diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp @@ -176,7 +176,7 @@ // When we need stack realignment, we can't reference off of the // stack pointer, so we reserve a base pointer. const MachineFrameInfo &MFI = MF.getFrameInfo(); - return MFI.getNumFixedObjects() && needsStackRealignment(MF); + return MFI.getNumFixedObjects() && shouldRealignStack(MF); } Register SIRegisterInfo::getBaseRegister() const { return AMDGPU::SGPR34; } @@ -358,7 +358,7 @@ return Reserved; } -bool SIRegisterInfo::canRealignStack(const MachineFunction &MF) const { +bool SIRegisterInfo::shouldRealignStack(const MachineFunction &MF) const { const SIMachineFunctionInfo *Info = MF.getInfo(); // On entry, the base address is 0, so it can't possibly need any more // alignment. @@ -368,7 +368,7 @@ if (Info->isEntryFunction()) return false; - return TargetRegisterInfo::canRealignStack(MF); + return TargetRegisterInfo::shouldRealignStack(MF); } bool SIRegisterInfo::requiresRegisterScavenging(const MachineFunction &Fn) const { diff --git a/llvm/lib/Target/ARC/ARCFrameLowering.cpp b/llvm/lib/Target/ARC/ARCFrameLowering.cpp --- a/llvm/lib/Target/ARC/ARCFrameLowering.cpp +++ b/llvm/lib/Target/ARC/ARCFrameLowering.cpp @@ -493,6 +493,6 @@ bool HasFP = MF.getTarget().Options.DisableFramePointerElim(MF) || MF.getFrameInfo().hasVarSizedObjects() || MF.getFrameInfo().isFrameAddressTaken() || - RegInfo->needsStackRealignment(MF); + RegInfo->hasStackRealignment(MF); return HasFP; } diff --git a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp --- a/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseRegisterInfo.cpp @@ -403,7 +403,7 @@ // If we have stack realignment and VLAs, we have no pointer to use to // access the stack. If we have stack realignment, and a large call frame, // we have no place to allocate the emergency spill slot. - if (needsStackRealignment(MF) && !TFI->hasReservedCallFrame(MF)) + if (hasStackRealignment(MF) && !TFI->hasReservedCallFrame(MF)) return true; // Thumb has trouble with negative offsets from the FP. Thumb2 has a limited @@ -458,8 +458,8 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); if (MF.getTarget().Options.DisableFramePointerElim(MF) && MFI.adjustsStack()) return true; - return MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() - || needsStackRealignment(MF); + return MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || + hasStackRealignment(MF); } Register diff --git a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp --- a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -2234,7 +2234,7 @@ *TII); } // If there's dynamic realignment, adjust for it. - if (RI.needsStackRealignment(MF)) { + if (RI.hasStackRealignment(MF)) { MachineFrameInfo &MFI = MF.getFrameInfo(); Align MaxAlign = MFI.getMaxAlign(); assert (!AFI->isThumb1OnlyFunction()); @@ -2251,7 +2251,6 @@ .add(predOps(ARMCC::AL)) .add(condCodeOp()); } - } MI.eraseFromParent(); return true; diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp --- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp +++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp @@ -206,8 +206,7 @@ return true; // Frame pointer required for use within this function. - return (RegInfo->needsStackRealignment(MF) || - MFI.hasVarSizedObjects() || + return (RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken()); } @@ -807,7 +806,7 @@ // sure if we also have VLAs, we have a base pointer for frame access. // If aligned NEON registers were spilled, the stack has already been // realigned. - if (!AFI->getNumAlignedDPRCS2Regs() && RegInfo->needsStackRealignment(MF)) { + if (!AFI->getNumAlignedDPRCS2Regs() && RegInfo->hasStackRealignment(MF)) { Align MaxAlign = MFI.getMaxAlign(); assert(!AFI->isThumb1OnlyFunction()); if (!AFI->isThumbFunction()) { @@ -1005,7 +1004,7 @@ // When dynamically realigning the stack, use the frame pointer for // parameters, and the stack/base pointer for locals. - if (RegInfo->needsStackRealignment(MF)) { + if (RegInfo->hasStackRealignment(MF)) { assert(hasFP(MF) && "dynamic stack realignment without a FP!"); if (isFixed) { FrameReg = RegInfo->getFrameRegister(MF); @@ -1783,7 +1782,7 @@ // instruction. // FIXME: It will be better just to find spare register here. if (AFI->isThumb2Function() && - (MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(MF))) + (MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF))) SavedRegs.set(ARM::R4); // If a stack probe will be emitted, spill R4 and LR, since they are @@ -1808,7 +1807,7 @@ // changes it, it'll be a spill, which implies we've used all the registers // and so R4 is already used, so not marking it here will be OK. // FIXME: It will be better just to find spare register here. - if (MFI.hasVarSizedObjects() || RegInfo->needsStackRealignment(MF) || + if (MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF) || MFI.estimateStackSize(MF) > 508) SavedRegs.set(ARM::R4); } diff --git a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp --- a/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp +++ b/llvm/lib/Target/ARM/Thumb1FrameLowering.cpp @@ -403,7 +403,7 @@ AFI->setGPRCalleeSavedArea2Size(GPRCS2Size); AFI->setDPRCalleeSavedAreaSize(DPRCSSize); - if (RegInfo->needsStackRealignment(MF)) { + if (RegInfo->hasStackRealignment(MF)) { const unsigned NrBitsToZero = Log2(MFI.getMaxAlign()); // Emit the following sequence, using R4 as a temporary, since we cannot use // SP as a source or destination register for the shifts: diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp --- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp @@ -576,7 +576,7 @@ const auto &MFI = MF.getFrameInfo(); const auto &HST = MF.getSubtarget(); assert(!MFI.hasVarSizedObjects() && - !HST.getRegisterInfo()->needsStackRealignment(MF)); + !HST.getRegisterInfo()->hasStackRealignment(MF)); return F.hasFnAttribute(Attribute::NoReturn) && F.hasFnAttribute(Attribute::NoUnwind) && !F.hasFnAttribute(Attribute::UWTable) && HST.noreturnStackElim() && @@ -1145,7 +1145,7 @@ auto &MFI = MF.getFrameInfo(); auto &HRI = *MF.getSubtarget().getRegisterInfo(); - bool HasExtraAlign = HRI.needsStackRealignment(MF); + bool HasExtraAlign = HRI.hasStackRealignment(MF); bool HasAlloca = MFI.hasVarSizedObjects(); // Insert ALLOCFRAME if we need to or at -O0 for the debugger. Think @@ -1265,7 +1265,7 @@ int Offset = MFI.getObjectOffset(FI); bool HasAlloca = MFI.hasVarSizedObjects(); - bool HasExtraAlign = HRI.needsStackRealignment(MF); + bool HasExtraAlign = HRI.hasStackRealignment(MF); bool NoOpt = MF.getTarget().getOptLevel() == CodeGenOpt::None; auto &HMFI = *MF.getInfo(); diff --git a/llvm/lib/Target/Lanai/LanaiFrameLowering.cpp b/llvm/lib/Target/Lanai/LanaiFrameLowering.cpp --- a/llvm/lib/Target/Lanai/LanaiFrameLowering.cpp +++ b/llvm/lib/Target/Lanai/LanaiFrameLowering.cpp @@ -33,7 +33,7 @@ // Get the alignment. Align StackAlign = - LRI->needsStackRealignment(MF) ? MFI.getMaxAlign() : getStackAlign(); + LRI->hasStackRealignment(MF) ? MFI.getMaxAlign() : getStackAlign(); // Get the maximum call frame size of all the calls. unsigned MaxCallFrameSize = MFI.getMaxCallFrameSize(); diff --git a/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp b/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp --- a/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp +++ b/llvm/lib/Target/Lanai/LanaiRegisterInfo.cpp @@ -147,14 +147,14 @@ // Addressable stack objects are addressed using neg. offsets from fp // or pos. offsets from sp/basepointer - if (!HasFP || (needsStackRealignment(MF) && FrameIndex >= 0)) + if (!HasFP || (hasStackRealignment(MF) && FrameIndex >= 0)) Offset += MF.getFrameInfo().getStackSize(); Register FrameReg = getFrameRegister(MF); if (FrameIndex >= 0) { if (hasBasePointer(MF)) FrameReg = getBaseRegister(); - else if (needsStackRealignment(MF)) + else if (hasStackRealignment(MF)) FrameReg = Lanai::SP; } @@ -245,7 +245,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); // When we need stack realignment and there are dynamic allocas, we can't // reference off of the stack pointer, so we reserve a base pointer. - if (needsStackRealignment(MF) && MFI.hasVarSizedObjects()) + if (hasStackRealignment(MF) && MFI.hasVarSizedObjects()) return true; return false; diff --git a/llvm/lib/Target/M68k/M68kFrameLowering.cpp b/llvm/lib/Target/M68k/M68kFrameLowering.cpp --- a/llvm/lib/Target/M68k/M68kFrameLowering.cpp +++ b/llvm/lib/Target/M68k/M68kFrameLowering.cpp @@ -46,7 +46,7 @@ return MF.getTarget().Options.DisableFramePointerElim(MF) || MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || - TRI->needsStackRealignment(MF); + TRI->hasStackRealignment(MF); } // FIXME Make sure no other factors prevent us from reserving call frame @@ -58,7 +58,7 @@ bool M68kFrameLowering::canSimplifyCallFramePseudos( const MachineFunction &MF) const { return hasReservedCallFrame(MF) || - (hasFP(MF) && !TRI->needsStackRealignment(MF)) || + (hasFP(MF) && !TRI->hasStackRealignment(MF)) || TRI->hasBasePointer(MF); } @@ -82,7 +82,7 @@ // have dynamic allocas in addition to dynamic realignment. if (TRI->hasBasePointer(MF)) FrameReg = TRI->getBaseRegister(); - else if (TRI->needsStackRealignment(MF)) + else if (TRI->hasStackRealignment(MF)) FrameReg = TRI->getStackRegister(); else FrameReg = TRI->getFrameRegister(MF); @@ -107,7 +107,7 @@ assert((-(Offset + StackSize)) % MFI.getObjectAlign(FI).value() == 0); return StackOffset::getFixed(Offset + StackSize); } - if (TRI->needsStackRealignment(MF)) { + if (TRI->hasStackRealignment(MF)) { if (FI < 0) { // Skip the saved FP. return StackOffset::getFixed(Offset + SlotSize); @@ -538,7 +538,7 @@ NumBytes = FrameSize - MMFI->getCalleeSavedFrameSize(); // Callee-saved registers are pushed on stack before the stack is realigned. - if (TRI->needsStackRealignment(MF)) + if (TRI->hasStackRealignment(MF)) NumBytes = alignTo(NumBytes, MaxAlign); // Get the offset of the stack slot for the FP register, which is @@ -608,7 +608,7 @@ // Realign stack after we pushed callee-saved registers (so that we'll be // able to calculate their offsets from the frame pointer). - if (TRI->needsStackRealignment(MF)) { + if (TRI->hasStackRealignment(MF)) { assert(HasFP && "There should be a frame pointer if stack is realigned."); BuildStackAlignAND(MBB, MBBI, DL, StackPtr, MaxAlign); } @@ -699,7 +699,7 @@ // Callee-saved registers were pushed on stack before the stack was // realigned. - if (TRI->needsStackRealignment(MF)) + if (TRI->hasStackRealignment(MF)) NumBytes = alignTo(FrameSize, MaxAlign); // Pop FP. @@ -734,8 +734,8 @@ // slot before popping them off! Same applies for the case, when stack was // realigned. Don't do this if this was a funclet epilogue, since the funclets // will not do realignment or dynamic stack allocation. - if ((TRI->needsStackRealignment(MF) || MFI.hasVarSizedObjects())) { - if (TRI->needsStackRealignment(MF)) + if ((TRI->hasStackRealignment(MF) || MFI.hasVarSizedObjects())) { + if (TRI->hasStackRealignment(MF)) MBBI = FirstCSPop; uint64_t LEAAmount = -CSSize; diff --git a/llvm/lib/Target/M68k/M68kISelLowering.cpp b/llvm/lib/Target/M68k/M68kISelLowering.cpp --- a/llvm/lib/Target/M68k/M68kISelLowering.cpp +++ b/llvm/lib/Target/M68k/M68kISelLowering.cpp @@ -1186,7 +1186,7 @@ // Can't do sibcall if stack needs to be dynamically re-aligned. PEI needs to // emit a special epilogue. const M68kRegisterInfo *RegInfo = Subtarget.getRegisterInfo(); - if (RegInfo->needsStackRealignment(MF)) + if (RegInfo->hasStackRealignment(MF)) return false; // Also avoid sibcall optimization if either caller or callee uses struct diff --git a/llvm/lib/Target/M68k/M68kRegisterInfo.cpp b/llvm/lib/Target/M68k/M68kRegisterInfo.cpp --- a/llvm/lib/Target/M68k/M68kRegisterInfo.cpp +++ b/llvm/lib/Target/M68k/M68kRegisterInfo.cpp @@ -176,7 +176,7 @@ unsigned BasePtr; if (hasBasePointer(MF)) BasePtr = (FIndex < 0 ? FramePtr : getBaseRegister()); - else if (needsStackRealignment(MF)) + else if (hasStackRealignment(MF)) BasePtr = (FIndex < 0 ? FramePtr : StackPtr); else if (AfterFPPop) BasePtr = StackPtr; @@ -228,7 +228,7 @@ // can't address variables from the stack pointer. MS inline asm can // reference locals while also adjusting the stack pointer. When we can't // use both the SP and the FP, we need a separate base pointer register. - bool CantUseFP = needsStackRealignment(MF); + bool CantUseFP = hasStackRealignment(MF); return CantUseFP && CantUseSP(MFI); } diff --git a/llvm/lib/Target/Mips/MipsFrameLowering.cpp b/llvm/lib/Target/Mips/MipsFrameLowering.cpp --- a/llvm/lib/Target/Mips/MipsFrameLowering.cpp +++ b/llvm/lib/Target/Mips/MipsFrameLowering.cpp @@ -95,15 +95,15 @@ const TargetRegisterInfo *TRI = STI.getRegisterInfo(); return MF.getTarget().Options.DisableFramePointerElim(MF) || - MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || - TRI->needsStackRealignment(MF); + MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || + TRI->hasStackRealignment(MF); } bool MipsFrameLowering::hasBP(const MachineFunction &MF) const { const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetRegisterInfo *TRI = STI.getRegisterInfo(); - return MFI.hasVarSizedObjects() && TRI->needsStackRealignment(MF); + return MFI.hasVarSizedObjects() && TRI->hasStackRealignment(MF); } // Estimate the size of the stack, including the incoming arguments. We need to diff --git a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp --- a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp +++ b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp @@ -198,8 +198,7 @@ // Reserve the base register if we need to both realign the stack and // allocate variable-sized objects at runtime. This should test the // same conditions as MipsFrameLowering::hasBP(). - if (needsStackRealignment(MF) && - MF.getFrameInfo().hasVarSizedObjects()) { + if (hasStackRealignment(MF) && MF.getFrameInfo().hasVarSizedObjects()) { Reserved.set(Mips::S7); Reserved.set(Mips::S7_64); } diff --git a/llvm/lib/Target/Mips/MipsSEFrameLowering.cpp b/llvm/lib/Target/Mips/MipsSEFrameLowering.cpp --- a/llvm/lib/Target/Mips/MipsSEFrameLowering.cpp +++ b/llvm/lib/Target/Mips/MipsSEFrameLowering.cpp @@ -535,7 +535,7 @@ BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) .addCFIIndex(CFIIndex); - if (RegInfo.needsStackRealignment(MF)) { + if (RegInfo.hasStackRealignment(MF)) { // addiu $Reg, $zero, -MaxAlignment // andi $sp, $sp, $Reg Register VR = MF.getRegInfo().createVirtualRegister(RC); diff --git a/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp b/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp --- a/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp +++ b/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp @@ -180,7 +180,7 @@ if ((FrameIndex >= MinCSFI && FrameIndex <= MaxCSFI) || EhDataRegFI || IsISRRegFI) FrameReg = ABI.GetStackPtr(); - else if (RegInfo->needsStackRealignment(MF)) { + else if (RegInfo->hasStackRealignment(MF)) { if (MFI.hasVarSizedObjects() && !MFI.isFixedObjectIndex(FrameIndex)) FrameReg = ABI.GetBasePtr(); else if (MFI.isFixedObjectIndex(FrameIndex)) diff --git a/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp b/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp --- a/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp @@ -238,7 +238,7 @@ // value. Align StackAlign; if (MFI.adjustsStack() || MFI.hasVarSizedObjects() || - (RegInfo->needsStackRealignment(Fn) && MFI.getObjectIndexEnd() != 0)) + (RegInfo->hasStackRealignment(Fn) && MFI.getObjectIndexEnd() != 0)) StackAlign = TFI.getStackAlign(); else StackAlign = TFI.getTransientStackAlign(); diff --git a/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp b/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp --- a/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp @@ -1349,7 +1349,7 @@ // If we need to realign the stack, then the stack pointer can no longer // serve as an offset into the caller's stack space. As a result, we need a // base pointer. - return needsStackRealignment(MF); + return hasStackRealignment(MF); } /// Returns true if the instruction's frame index diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -221,7 +221,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); return MF.getTarget().Options.DisableFramePointerElim(MF) || - RegInfo->needsStackRealignment(MF) || MFI.hasVarSizedObjects() || + RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken(); } @@ -229,7 +229,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetRegisterInfo *TRI = STI.getRegisterInfo(); - return MFI.hasVarSizedObjects() && TRI->needsStackRealignment(MF); + return MFI.hasVarSizedObjects() && TRI->hasStackRealignment(MF); } // Determines the size of the frame and maximum call frame size. @@ -486,7 +486,7 @@ if (hasFP(MF)) { // Realign Stack const RISCVRegisterInfo *RI = STI.getRegisterInfo(); - if (RI->needsStackRealignment(MF)) { + if (RI->hasStackRealignment(MF)) { Align MaxAlignment = MFI.getMaxAlign(); const RISCVInstrInfo *TII = STI.getInstrInfo(); @@ -568,7 +568,7 @@ // Restore the stack pointer using the value of the frame pointer. Only // necessary if the stack pointer was modified, meaning the stack size is // unknown. - if (RI->needsStackRealignment(MF) || MFI.hasVarSizedObjects()) { + if (RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects()) { assert(hasFP(MF) && "frame pointer should not have been eliminated"); adjustReg(MBB, LastFrameDestroy, DL, SPReg, FPReg, -FPOffset, MachineInstr::FrameDestroy); @@ -638,7 +638,7 @@ Offset += StackOffset::getFixed(FirstSPAdjustAmount); else Offset += StackOffset::getFixed(MFI.getStackSize()); - } else if (RI->needsStackRealignment(MF) && !MFI.isFixedObjectIndex(FI)) { + } else if (RI->hasStackRealignment(MF) && !MFI.isFixedObjectIndex(FI)) { // If the stack was realigned, the frame pointer is set in order to allow // SP to be restored, so we need another base register to record the stack // after realignment. diff --git a/llvm/lib/Target/Sparc/SparcFrameLowering.cpp b/llvm/lib/Target/Sparc/SparcFrameLowering.cpp --- a/llvm/lib/Target/Sparc/SparcFrameLowering.cpp +++ b/llvm/lib/Target/Sparc/SparcFrameLowering.cpp @@ -97,14 +97,9 @@ // Debug location must be unknown since the first debug location is used // to determine the end of the prologue. DebugLoc dl; - bool NeedsStackRealignment = RegInfo.needsStackRealignment(MF); - - // FIXME: unfortunately, returning false from canRealignStack - // actually just causes needsStackRealignment to return false, - // rather than reporting an error, as would be sensible. This is - // poor, but fixing that bogosity is going to be a large project. - // For now, just see if it's lied, and report an error here. - if (!NeedsStackRealignment && MFI.getMaxAlign() > getStackAlign()) + bool NeedsStackRealignment = RegInfo.shouldRealignStack(MF); + + if (NeedsStackRealignment && !RegInfo.canRealignStack(MF)) report_fatal_error("Function \"" + Twine(MF.getName()) + "\" required " "stack re-alignment, but LLVM couldn't handle it " "(probably because it has a dynamic alloca)."); @@ -252,9 +247,8 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); return MF.getTarget().Options.DisableFramePointerElim(MF) || - RegInfo->needsStackRealignment(MF) || - MFI.hasVarSizedObjects() || - MFI.isFrameAddressTaken(); + RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || + MFI.isFrameAddressTaken(); } StackOffset @@ -280,7 +274,7 @@ } else if (isFixed) { // Otherwise, argument access should always use %fp. UseFP = true; - } else if (RegInfo->needsStackRealignment(MF)) { + } else if (RegInfo->hasStackRealignment(MF)) { // If there is dynamic stack realignment, all local object // references need to be via %sp, to take account of the // re-alignment. 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 @@ -313,18 +313,13 @@ const VEInstrInfo &TII = *STI.getInstrInfo(); const VERegisterInfo &RegInfo = *STI.getRegisterInfo(); MachineBasicBlock::iterator MBBI = MBB.begin(); - bool NeedsStackRealignment = RegInfo.needsStackRealignment(MF); + bool NeedsStackRealignment = RegInfo.shouldRealignStack(MF); // Debug location must be unknown since the first debug location is used // to determine the end of the prologue. DebugLoc DL; - // FIXME: unfortunately, returning false from canRealignStack - // actually just causes needsStackRealignment to return false, - // rather than reporting an error, as would be sensible. This is - // poor, but fixing that bogosity is going to be a large project. - // For now, just see if it's lied, and report an error here. - if (!NeedsStackRealignment && MFI.getMaxAlign() > getStackAlign()) + if (NeedsStackRealignment && !RegInfo.canRealignStack(MF)) report_fatal_error("Function \"" + Twine(MF.getName()) + "\" required " "stack re-alignment, but LLVM couldn't handle it " @@ -428,7 +423,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); return MF.getTarget().Options.DisableFramePointerElim(MF) || - RegInfo->needsStackRealignment(MF) || MFI.hasVarSizedObjects() || + RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken(); } @@ -436,7 +431,7 @@ const MachineFrameInfo &MFI = MF.getFrameInfo(); const TargetRegisterInfo *TRI = STI.getRegisterInfo(); - return MFI.hasVarSizedObjects() && TRI->needsStackRealignment(MF); + return MFI.hasVarSizedObjects() && TRI->hasStackRealignment(MF); } bool VEFrameLowering::hasGOT(const MachineFunction &MF) const { @@ -461,7 +456,7 @@ return StackOffset::getFixed(FrameOffset + MF.getFrameInfo().getStackSize()); } - if (RegInfo->needsStackRealignment(MF) && !isFixed) { + if (RegInfo->hasStackRealignment(MF) && !isFixed) { // If data on stack require realignemnt, frame indexies are based on a %sp // or %s17 (bp) register. If there is a variable sized object, bp is used. if (hasBP(MF)) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -46,7 +46,7 @@ bool WebAssemblyFrameLowering::hasBP(const MachineFunction &MF) const { const auto *RegInfo = MF.getSubtarget().getRegisterInfo(); - return RegInfo->needsStackRealignment(MF); + return RegInfo->hasStackRealignment(MF); } /// Return true if the specified function should have a dedicated frame pointer diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -70,7 +70,7 @@ X86FrameLowering::canSimplifyCallFramePseudos(const MachineFunction &MF) const { return hasReservedCallFrame(MF) || MF.getInfo()->hasPreallocatedCall() || - (hasFP(MF) && !TRI->needsStackRealignment(MF)) || + (hasFP(MF) && !TRI->hasStackRealignment(MF)) || TRI->hasBasePointer(MF); } @@ -93,7 +93,7 @@ bool X86FrameLowering::hasFP(const MachineFunction &MF) const { const MachineFrameInfo &MFI = MF.getFrameInfo(); return (MF.getTarget().Options.DisableFramePointerElim(MF) || - TRI->needsStackRealignment(MF) || MFI.hasVarSizedObjects() || + TRI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() || MFI.isFrameAddressTaken() || MFI.hasOpaqueSPAdjustment() || MF.getInfo()->getForceFramePointer() || MF.getInfo()->hasPreallocatedCall() || @@ -534,7 +534,7 @@ uint64_t ProbeChunk = StackProbeSize * 8; uint64_t MaxAlign = - TRI->needsStackRealignment(MF) ? calculateMaxStackAlign(MF) : 0; + TRI->hasStackRealignment(MF) ? calculateMaxStackAlign(MF) : 0; // Synthesize a loop or unroll it, depending on the number of iterations. // BuildStackAlignAND ensures that only MaxAlign % StackProbeSize bits left @@ -1351,7 +1351,7 @@ // pointer, calls, or dynamic alloca then we do not need to adjust the // stack pointer (we fit in the Red Zone). We also check that we don't // push and pop from the stack. - if (has128ByteRedZone(MF) && !TRI->needsStackRealignment(MF) && + if (has128ByteRedZone(MF) && !TRI->hasStackRealignment(MF) && !MFI.hasVarSizedObjects() && // No dynamic alloca. !MFI.adjustsStack() && // No calls. !EmitStackProbeCall && // No stack probes. @@ -1420,7 +1420,7 @@ NumBytes = FrameSize - X86FI->getCalleeSavedFrameSize(); // Callee-saved registers are pushed on stack before the stack is realigned. - if (TRI->needsStackRealignment(MF) && !IsWin64Prologue) + if (TRI->hasStackRealignment(MF) && !IsWin64Prologue) NumBytes = alignTo(NumBytes, MaxAlign); // Save EBP/RBP into the appropriate stack slot. @@ -1481,7 +1481,7 @@ // Update the offset adjustment, which is mainly used by codeview to translate // from ESP to VFRAME relative local variable offsets. if (!IsFunclet) { - if (HasFP && TRI->needsStackRealignment(MF)) + if (HasFP && TRI->hasStackRealignment(MF)) MFI.setOffsetAdjustment(-NumBytes); else MFI.setOffsetAdjustment(-StackSize); @@ -1525,7 +1525,7 @@ // Realign stack after we pushed callee-saved registers (so that we'll be // able to calculate their offsets from the frame pointer). // Don't do this for Win64, it needs to realign the stack after the prologue. - if (!IsWin64Prologue && !IsFunclet && TRI->needsStackRealignment(MF)) { + if (!IsWin64Prologue && !IsFunclet && TRI->hasStackRealignment(MF)) { assert(HasFP && "There should be a frame pointer if stack is realigned."); BuildStackAlignAND(MBB, MBBI, DL, StackPtr, MaxAlign); @@ -1553,7 +1553,7 @@ // increments is necessary to ensure that the guard pages used by the OS // virtual memory manager are allocated in correct sequence. uint64_t AlignedNumBytes = NumBytes; - if (IsWin64Prologue && !IsFunclet && TRI->needsStackRealignment(MF)) + if (IsWin64Prologue && !IsFunclet && TRI->hasStackRealignment(MF)) AlignedNumBytes = alignTo(AlignedNumBytes, MaxAlign); if (AlignedNumBytes >= StackProbeSize && EmitStackProbeCall) { assert(!X86FI->getUsesRedZone() && @@ -1748,7 +1748,7 @@ // Realign stack after we spilled callee-saved registers (so that we'll be // able to calculate their offsets from the frame pointer). // Win64 requires aligning the stack after the prologue. - if (IsWin64Prologue && TRI->needsStackRealignment(MF)) { + if (IsWin64Prologue && TRI->hasStackRealignment(MF)) { assert(HasFP && "There should be a frame pointer if stack is realigned."); BuildStackAlignAND(MBB, MBBI, DL, SPOrEstablisher, MaxAlign); } @@ -1949,7 +1949,7 @@ // Callee-saved registers were pushed on stack before the stack was // realigned. - if (TRI->needsStackRealignment(MF) && !IsWin64Prologue) + if (TRI->hasStackRealignment(MF) && !IsWin64Prologue) NumBytes = alignTo(FrameSize, MaxAlign); } else { NumBytes = StackSize - CSSize; @@ -2011,9 +2011,9 @@ // slot before popping them off! Same applies for the case, when stack was // realigned. Don't do this if this was a funclet epilogue, since the funclets // will not do realignment or dynamic stack allocation. - if ((TRI->needsStackRealignment(MF) || MFI.hasVarSizedObjects()) && + if (((TRI->hasStackRealignment(MF)) || MFI.hasVarSizedObjects()) && !IsFunclet) { - if (TRI->needsStackRealignment(MF)) + if (TRI->hasStackRealignment(MF)) MBBI = FirstCSPop; unsigned SEHFrameOffset = calculateSetFPREG(SEHStackAllocAmt); uint64_t LEAAmount = @@ -2113,7 +2113,7 @@ // have dynamic allocas in addition to dynamic realignment. if (TRI->hasBasePointer(MF)) FrameReg = IsFixed ? TRI->getFramePtr() : TRI->getBaseRegister(); - else if (TRI->needsStackRealignment(MF)) + else if (TRI->hasStackRealignment(MF)) FrameReg = IsFixed ? TRI->getFramePtr() : TRI->getStackRegister(); else FrameReg = TRI->getFrameRegister(MF); @@ -2172,7 +2172,7 @@ assert(isAligned(MFI.getObjectAlign(FI), -(Offset + StackSize))); return StackOffset::getFixed(Offset + StackSize); } - } else if (TRI->needsStackRealignment(MF)) { + } else if (TRI->hasStackRealignment(MF)) { if (FI < 0) { // Skip the saved EBP. return StackOffset::getFixed(Offset + SlotSize + FPDelta); @@ -2263,7 +2263,7 @@ // answer we give is relative to the SP after the prologue, and not the // SP in the middle of the function. - if (MFI.isFixedObjectIndex(FI) && TRI->needsStackRealignment(MF) && + if (MFI.isFixedObjectIndex(FI) && TRI->hasStackRealignment(MF) && !STI.isTargetWin64()) return getFrameIndexReference(MF, FI, FrameReg); @@ -3247,7 +3247,7 @@ bool X86FrameLowering::canUseAsPrologue(const MachineBasicBlock &MBB) const { assert(MBB.getParent() && "Block is not attached to a function!"); const MachineFunction &MF = *MBB.getParent(); - return !TRI->needsStackRealignment(MF) || !MBB.isLiveIn(X86::EFLAGS); + return !TRI->hasStackRealignment(MF) || !MBB.isLiveIn(X86::EFLAGS); } bool X86FrameLowering::canUseAsEpilogue(const MachineBasicBlock &MBB) const { @@ -3497,7 +3497,7 @@ } // Flip it if we're accessing off of the FP. - if (!TRI->needsStackRealignment(MF) && hasFP(MF)) + if (!TRI->hasStackRealignment(MF) && hasFP(MF)) std::reverse(ObjectsToAllocate.begin(), ObjectsToAllocate.end()); } diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -4623,7 +4623,7 @@ // Can't do sibcall if stack needs to be dynamically re-aligned. PEI needs to // emit a special epilogue. const X86RegisterInfo *RegInfo = Subtarget.getRegisterInfo(); - if (RegInfo->needsStackRealignment(MF)) + if (RegInfo->hasStackRealignment(MF)) return false; // Also avoid sibcall optimization if either caller or callee uses struct @@ -25841,7 +25841,7 @@ if (RegInfo->hasBasePointer(MF)) Reg = RegInfo->getBaseRegister(); else { // Handles the SP or FP case. - bool CantUseFP = RegInfo->needsStackRealignment(MF); + bool CantUseFP = RegInfo->hasStackRealignment(MF); if (CantUseFP) Reg = RegInfo->getPtrSizedStackRegister(MF); else diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -5701,7 +5701,7 @@ Align Alignment = MFI.getObjectAlign(FrameIndex); // If the function stack isn't realigned we don't want to fold instructions // that need increased alignment. - if (!RI.needsStackRealignment(MF)) + if (!RI.hasStackRealignment(MF)) Alignment = std::min(Alignment, Subtarget.getFrameLowering()->getStackAlign()); if (Ops.size() == 2 && Ops[0] == 0 && Ops[1] == 1) { diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -648,7 +648,7 @@ // can't address variables from the stack pointer. MS inline asm can // reference locals while also adjusting the stack pointer. When we can't // use both the SP and the FP, we need a separate base pointer register. - bool CantUseFP = needsStackRealignment(MF); + bool CantUseFP = hasStackRealignment(MF); return CantUseFP && CantUseSP(MFI); } @@ -728,8 +728,8 @@ int FIOffset; Register BasePtr; if (MI.isReturn()) { - assert((!needsStackRealignment(MF) || - MF.getFrameInfo().isFixedObjectIndex(FrameIndex)) && + assert((!hasStackRealignment(MF) || + MF.getFrameInfo().isFixedObjectIndex(FrameIndex)) && "Return instruction can only reference SP relative frame objects"); FIOffset = TFI->getFrameIndexReferenceSP(MF, FrameIndex, BasePtr, 0).getFixed();