-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[MIPS][ISel] Fix musttail #161860
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
base: main
Are you sure you want to change the base?
[MIPS][ISel] Fix musttail #161860
Changes from 3 commits
ac9497e
9a77adf
1e26120
20d634f
eaa5678
54412fe
b9e145d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3407,18 +3407,22 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, | |
| // Check if it's really possible to do a tail call. Restrict it to functions | ||
| // that are part of this compilation unit. | ||
| bool InternalLinkage = false; | ||
| bool IsMustTail = CLI.CB && CLI.CB->isMustTailCall(); | ||
| if (IsTailCall) { | ||
| IsTailCall = isEligibleForTailCallOptimization( | ||
| CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>()); | ||
| if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { | ||
| InternalLinkage = G->getGlobal()->hasInternalLinkage(); | ||
| IsTailCall &= (InternalLinkage || G->getGlobal()->hasLocalLinkage() || | ||
| G->getGlobal()->hasPrivateLinkage() || | ||
| G->getGlobal()->hasHiddenVisibility() || | ||
| G->getGlobal()->hasProtectedVisibility()); | ||
| } | ||
| CCInfo, StackSize, *MF.getInfo<MipsFunctionInfo>(), IsMustTail); | ||
| if (IsTailCall) { | ||
| if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { | ||
| InternalLinkage = G->getGlobal()->hasInternalLinkage(); | ||
| IsTailCall &= (InternalLinkage || G->getGlobal()->hasLocalLinkage() || | ||
|
||
| G->getGlobal()->isDSOLocal() || | ||
| G->getGlobal()->hasPrivateLinkage() || | ||
| G->getGlobal()->hasHiddenVisibility() || | ||
| G->getGlobal()->hasProtectedVisibility()); | ||
| } | ||
| } | ||
| } | ||
| if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall()) | ||
| if (!IsTailCall && IsMustTail) | ||
| report_fatal_error("failed to perform tail call elimination on a call " | ||
| "site marked musttail"); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -595,10 +595,9 @@ class TargetRegisterClass; | |
|
|
||
| /// isEligibleForTailCallOptimization - Check whether the call is eligible | ||
| /// for tail call optimization. | ||
| virtual bool | ||
| isEligibleForTailCallOptimization(const CCState &CCInfo, | ||
| unsigned NextStackOffset, | ||
| const MipsFunctionInfo &FI) const = 0; | ||
| virtual bool isEligibleForTailCallOptimization( | ||
| const CCState &CCInfo, unsigned NextStackOffset, | ||
| const MipsFunctionInfo &FI, bool IsMustTail = false) const = 0; | ||
|
||
|
|
||
| /// copyByValArg - Copy argument registers which were used to pass a byval | ||
| /// argument to the stack. Create a stack frame object for the byval | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -mtriple=mips-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS32 | ||
| ; RUN: llc -mtriple=mips64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=MIPS64 | ||
|
|
||
| ; Test musttail support for MIPS | ||
|
|
||
| define dso_local i32 @callee_args(i32 %a, i32 %b, i32 %c) { | ||
| ret i32 %a; | ||
| } | ||
|
|
||
| define i32 @test_musttail_args(i32 %x, i32 %y, i32 %z) { | ||
| ; MIPS32-LABEL: test_musttail_args: | ||
| ; MIPS32: # %bb.0: | ||
| ; MIPS32-NEXT: j callee_args | ||
| ; MIPS32-NEXT: nop | ||
| ; | ||
| ; MIPS64-LABEL: test_musttail_args: | ||
| ; MIPS64: # %bb.0: | ||
| ; MIPS64-NEXT: j callee_args | ||
| ; MIPS64-NEXT: nop | ||
| %ret = musttail call i32 @callee_args(i32 %x, i32 %y, i32 %z) | ||
| ret i32 %ret | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clean up this InternalLinkage variable? The remaining usage doesn't seem like it's connected to this code.
Is musttail of a function pointer okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, it makes sense
yes, I will add a test case for it