-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MachineOutliner] Preserve regmasks in calls to outlined functions #120940
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
Closed
+124
−1
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # RUN: llc -mtriple=aarch64-apple-ios -run-pass=prologepilog -run-pass=machine-outliner %s -o - | FileCheck %s | ||
| --- | | ||
| declare swiftcc void @bar() | ||
| declare void @baz(i32, i32, i32) #0 | ||
nocchijiang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| define void @test_same_regmask() #0 { | ||
| ret void | ||
| } | ||
| define void @test_different_regmasks() #0 { | ||
| ret void | ||
| } | ||
| define void @foo(i32, i32, i32, i32, i32, i32, i32, i32) #0 { | ||
| ret void | ||
| } | ||
|
|
||
| attributes #0 = { minsize } | ||
| ... | ||
| --- | ||
| name: foo | ||
| tracksRegLiveness: true | ||
| body: | | ||
| bb.0: | ||
| RET undef $lr | ||
|
|
||
|
|
||
| ... | ||
| --- | ||
| name: test_same_regmask | ||
| tracksRegLiveness: true | ||
| body: | | ||
| ; CHECK-LABEL: name: test_same_regmask | ||
| ; CHECK: bb.1: | ||
| ; CHECK-NEXT: BL @OUTLINED_FUNCTION_1, csr_aarch64_aapcs | ||
|
|
||
| bb.0: | ||
| $sp = frame-setup SUBXri $sp, 16, 0 | ||
|
|
||
| bb.1: | ||
| $w0 = MOVZWi 1, 0 | ||
| $w1 = MOVZWi 2, 0 | ||
| $w2 = MOVZWi 3, 0 | ||
| BL @baz, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $w1, implicit killed $w2, implicit-def $sp | ||
| $w0 = MOVZWi 1, 0 | ||
| $w1 = MOVZWi 2, 0 | ||
| $w2 = MOVZWi 3, 0 | ||
| BL @baz, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $w1, implicit killed $w2, implicit-def $sp | ||
| $sp = ADDXri $sp, 16, 0 | ||
| RET undef $lr | ||
|
|
||
|
|
||
| ... | ||
| --- | ||
| name: test_different_regmasks | ||
| tracksRegLiveness: true | ||
| body: | | ||
| ; CHECK-LABEL: name: test_different_regmasks | ||
| ; CHECK: bb.1: | ||
| ; CHECK-NEXT: BL @OUTLINED_FUNCTION_0, CustomRegMask($fp,$lr,$wzr,$wzr_hi,$xzr,$b8,$b9,$b10,$b11,$b12,$b13,$b14,$b15,$d8,$d9,$d10,$d11,$d12,$d13,$d14,$d15,$h8,$h9,$h10,$h11,$h12,$h13,$h14,$h15,$s8,$s9,$s10,$s11,$s12,$s13,$s14,$s15,$w19,$w20,$w22,$w23,$w24,$w25,$w26,$w27,$w28,$w29,$w30,$x19,$x20,$x22,$x23,$x24,$x25,$x26,$x27,$x28,$b8_hi,$b9_hi,$b10_hi,$b11_hi,$b12_hi,$b13_hi,$b14_hi,$b15_hi,$h8_hi,$h9_hi,$h10_hi,$h11_hi,$h12_hi,$h13_hi,$h14_hi,$h15_hi,$s8_hi,$s9_hi,$s10_hi,$s11_hi,$s12_hi,$s13_hi,$s14_hi,$s15_hi,$w19_hi,$w20_hi,$w22_hi,$w23_hi,$w24_hi,$w25_hi,$w26_hi,$w27_hi,$w28_hi,$w29_hi,$w30_hi,$d8_d9,$d9_d10,$d10_d11,$d11_d12,$d12_d13,$d13_d14,$d14_d15,$d8_d9_d10_d11,$d9_d10_d11_d12,$d10_d11_d12_d13,$d11_d12_d13_d14,$d12_d13_d14_d15,$d8_d9_d10,$d9_d10_d11,$d10_d11_d12,$d11_d12_d13,$d12_d13_d14,$d13_d14_d15,$x22_x23_x24_x25_x26_x27_x28_fp,$w22_w23,$w24_w25,$w26_w27,$w28_w29,$x28_fp,$x22_x23,$x24_x25,$x26_x27) | ||
|
|
||
| bb.0: | ||
| $sp = frame-setup SUBXri $sp, 16, 0 | ||
|
|
||
| bb.1: | ||
| $w0 = MOVZWi 1, 0 | ||
| $w1 = MOVZWi 2, 0 | ||
| $w2 = MOVZWi 3, 0 | ||
| $w3 = MOVZWi 4, 0 | ||
| $w4 = MOVZWi 5, 0 | ||
| $w5 = MOVZWi 6, 0 | ||
| $w6 = MOVZWi 7, 0 | ||
| $w7 = MOVZWi 8, 0 | ||
| BL @foo, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $w1, implicit killed $w2, implicit killed $w3, implicit killed $w4, implicit killed $w5, implicit killed $w6, implicit killed $w7, implicit-def $sp | ||
| BL @bar, csr_aarch64_aapcs_swifterror, implicit-def dead $lr, implicit $sp, implicit-def $sp | ||
| $w0 = MOVZWi 1, 0 | ||
| $w1 = MOVZWi 2, 0 | ||
| $w2 = MOVZWi 3, 0 | ||
| $w3 = MOVZWi 4, 0 | ||
| $w4 = MOVZWi 5, 0 | ||
| $w5 = MOVZWi 6, 0 | ||
| $w6 = MOVZWi 7, 0 | ||
| $w7 = MOVZWi 8, 0 | ||
| BL @foo, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $w1, implicit killed $w2, implicit killed $w3, implicit killed $w4, implicit killed $w5, implicit killed $w6, implicit killed $w7, implicit-def $sp | ||
| BL @bar, csr_aarch64_aapcs_swifterror, implicit-def dead $lr, implicit $sp, implicit-def $sp | ||
| $w0 = MOVZWi 1, 0 | ||
| $w1 = MOVZWi 2, 0 | ||
| $w2 = MOVZWi 3, 0 | ||
| $w3 = MOVZWi 4, 0 | ||
| $w4 = MOVZWi 5, 0 | ||
| $w5 = MOVZWi 6, 0 | ||
| $w6 = MOVZWi 7, 0 | ||
| $w7 = MOVZWi 8, 0 | ||
| BL @foo, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $w0, implicit killed $w1, implicit killed $w2, implicit killed $w3, implicit killed $w4, implicit killed $w5, implicit killed $w6, implicit killed $w7, implicit-def $sp | ||
| BL @bar, csr_aarch64_aapcs_swifterror, implicit-def dead $lr, implicit $sp, implicit-def $sp | ||
| $sp = ADDXri $sp, 16, 0 | ||
| RET undef $lr | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I see you attempt to optimize the case with 1 just for copying the pointer. But I'd simply merging reg mask in place here, without using the extra set.
Basically, you could declare
RegMaskSizeoutside the loop, as it's a constant for the function.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.
I believe 1-regmask is the most common case and the memory allocation in
MF->allocateRegMask()should be avoided if possible.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.
The size of
RegMasksdepends on the number of call instructions in the outlined candidate, and I believe this usually one. However, I think you might be forgetting that non-call instruction can clobber a register. My understanding ofRegMaskis that it tells you which registers could be changed after executing that instruction.llvm-project/llvm/include/llvm/CodeGen/MachineOperand.h
Lines 921 to 927 in 76dba2e
But an outlined function might have other instructions as well as call instructions. I think you need to mark
MOP.isDef()registers as clobbered in the mask too (I believe this is what @MatzeB was alluding to).In that case, we will likely need to copy the mask using
allocateRegMask()anyway, so I think @kyulee-com suggestion might be worth considering.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.
If we need to mark registers from def operands in the mask, I have a follow-up question: should we drop all the def operands in favor of using regmask, or should we add the masked registers to the def list as well? My understanding is that regmask and def operands serve different purposes - regmask is primarily used to describe calling conventions, while def operands provide additional information specific to the callee. Including all defs in the regmask seems redundant to me. Could anyone clarify the intended distinction between these two, or share best practices for handling this case?
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.
That's a good question. It seems like RegMask and Def/Use registers hold similar information. I think the RegMask is responsible only to tell you which registers are clobbered after an instruction (usually a call). Def/Use registers are required to know which registers to pass as inputs to a function, and which to use a return values.
There is similar code in
FastISel.cppwhere it uses both Def/Use (In/Out) registers and a RegMask.llvm-project/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Lines 858 to 880 in 9a0e1c7