Skip to content

[CodeGen] Don't check attrs for stack realign #92564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/CodeGen/MachineFrameInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ class MachineFrameInfo {

MachineFrameInfo(const MachineFrameInfo &) = delete;

bool isStackRealignable() const { return StackRealignable; }

/// Return true if there are any stack objects in this function.
bool hasStackObjects() const { return !Objects.empty(); }

Expand Down Expand Up @@ -603,6 +605,12 @@ class MachineFrameInfo {
/// Make sure the function is at least Align bytes aligned.
void ensureMaxAlignment(Align Alignment);

/// Return true if stack realignment is forced by function attributes or if
/// the stack alignment.
bool shouldRealignStack() const {
return ForcedRealign || MaxAlignment > StackAlignment;
}

/// Return true if this function adjusts the stack -- e.g.,
/// when calling another function. This is only valid during and after
/// prolog/epilog code insertion.
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ void MachineFunction::init() {
// explicitly asked us not to.
bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
!F.hasFnAttribute("no-realign-stack");
bool ForceRealignSP = F.hasFnAttribute(Attribute::StackAlignment) ||
F.hasFnAttribute("stackrealign");
FrameInfo = new (Allocator) MachineFrameInfo(
getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
/*ForcedRealign=*/CanRealignSP &&
F.hasFnAttribute(Attribute::StackAlignment));
/*ForcedRealign=*/ForceRealignSP && CanRealignSP);

setUnsafeStackSize(F, *FrameInfo);

Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/CodeGen/TargetRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,11 @@ bool TargetRegisterInfo::isCalleeSavedPhysReg(
}

bool TargetRegisterInfo::canRealignStack(const MachineFunction &MF) const {
return !MF.getFunction().hasFnAttribute("no-realign-stack");
return MF.getFrameInfo().isStackRealignable();
}

bool TargetRegisterInfo::shouldRealignStack(const MachineFunction &MF) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();
const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
const Function &F = MF.getFunction();
return F.hasFnAttribute("stackrealign") ||
(MFI.getMaxAlign() > TFI->getStackAlign()) ||
F.hasFnAttribute(Attribute::StackAlignment);
return MF.getFrameInfo().shouldRealignStack();
}

bool TargetRegisterInfo::regmaskSubsetEqual(const uint32_t *mask0,
Expand Down
Loading