This is an archive of the discontinued LLVM Phabricator instance.

MachineModuleInfo: Move HasSplitStack handling to AsmPrinter
ClosedPublic

Authored by arsenm on Apr 18 2022, 6:59 AM.

Details

Summary

This is used to emit one field in doFinalization for the module. We
can accumulate this when emitting all individual functions directly in
the AsmPrinter, rather than accumulating additional state in
MachineModuleInfo.

Move the special case behavior predicate into MachineFrameInfo to
share it. This now promotes it to generic behavior. I'm assuming this
is fine because no other target implements adjustForSegmentedStacks,
or has tests using the split-stack attribute.

Diff Detail

Event Timeline

arsenm created this revision.Apr 18 2022, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2022, 6:59 AM
arsenm requested review of this revision.Apr 18 2022, 6:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 18 2022, 6:59 AM
Herald added a subscriber: wdng. · View Herald Transcript
rnk added a comment.Apr 18 2022, 12:42 PM

I read through the situation described in PR37807 the two relevant commits (rG9cc1ffadc5ad06ab846a7da95a1afb874b9f3d98 and D48444), and I think I understand the two issues.

I think it would be simpler if we tracked a boolean (HasSplitStackPrologue) on each MachineFrameInfo object indicating whether a split stack prologue was emitted or not for some particular function. This avoids the need to duplicate this stack size and tail call checking logic in the AsmPrinter.

The root of the issue here is that we are checking IR attributes in MF.shouldSplitStack(), but we allow ourselves to revise that decision during prologue emission if we have a leaf function that doesn't use any stack. The AsmPrinter should look at the MIR, not the IR, and that will simplify things.

llvm/lib/Target/ARM/ARMAsmPrinter.cpp
27

Seems unnecessary?

I read through the situation described in PR37807 the two relevant commits (rG9cc1ffadc5ad06ab846a7da95a1afb874b9f3d98 and D48444), and I think I understand the two issues.

I think it would be simpler if we tracked a boolean (HasSplitStackPrologue) on each MachineFrameInfo object indicating whether a split stack prologue was emitted or not for some particular function. This avoids the need to duplicate this stack size and tail call checking logic in the AsmPrinter.

The root of the issue here is that we are checking IR attributes in MF.shouldSplitStack(), but we allow ourselves to revise that decision during prologue emission if we have a leaf function that doesn't use any stack. The AsmPrinter should look at the MIR, not the IR, and that will simplify things.

I tried this and it doesn't quite work. Maintaining the current behavior requires 2 fields; that split-stacks requested and whether or not it was actually emitted. Do you think it would be better to just move the StackSize == 0 && !MFI.hasTailCall() check into a helper in MFI, track a second field in MFI, or just keep having the AsmPrinter look at the attribute?

rnk added a comment.Apr 18 2022, 2:58 PM

I tried this and it doesn't quite work. Maintaining the current behavior requires 2 fields; that split-stacks requested and whether or not it was actually emitted. Do you think it would be better to just move the StackSize == 0 && !MFI.hasTailCall() check into a helper in MFI, track a second field in MFI, or just keep having the AsmPrinter look at the attribute?

I think you're right, that's the way to go. This logic is shared between targets anyway, and it gives us a place to park the long comments about the desired behavior, which is that all non-leaf functions need split stack prologues, even if they use no stack space.

arsenm updated this revision to Diff 423770.Apr 19 2022, 4:37 PM
arsenm edited the summary of this revision. (Show Details)

Move special case predicate to MFI

rnk accepted this revision.Apr 19 2022, 4:56 PM

lgtm

llvm/include/llvm/CodeGen/AsmPrinter.h
219

I think this is missing a negative, maybe it can be "when it also contains functions without a split stack prologue".

This revision is now accepted and ready to land.Apr 19 2022, 4:56 PM