-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[RISCV] Support PreserveMost calling convention #148214
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
Open
wangpc-pp
wants to merge
2
commits into
llvm:main
Choose a base branch
from
wangpc-pp:main-riscv-preserve-most
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+205
−1
Open
Changes from all commits
Commits
Show all changes
2 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
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,187 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 < %s | FileCheck %s -check-prefix=RV32I | ||
; RUN: llc -mtriple=riscv64 < %s | FileCheck %s -check-prefix=RV64I | ||
; RUN: llc -mtriple=riscv32 -mattr=+e -target-abi ilp32e < %s | FileCheck %s -check-prefix=RV32E | ||
; RUN: llc -mtriple=riscv64 -mattr=+e -target-abi lp64e < %s | FileCheck %s -check-prefix=RV64E | ||
|
||
; Check the PreserveMost calling convention works. | ||
|
||
declare void @standard_cc_func() | ||
declare preserve_mostcc void @preserve_mostcc_func() | ||
|
||
define preserve_mostcc void @preserve_mostcc1() nounwind { | ||
; RV32I-LABEL: preserve_mostcc1: | ||
; RV32I: # %bb.0: # %entry | ||
; RV32I-NEXT: addi sp, sp, -64 | ||
; RV32I-NEXT: sw ra, 60(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t0, 56(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t1, 52(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t2, 48(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a0, 44(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a1, 40(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a2, 36(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a3, 32(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a4, 28(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a5, 24(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a6, 20(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw a7, 16(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t3, 12(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t4, 8(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t5, 4(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: sw t6, 0(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: call standard_cc_func | ||
; RV32I-NEXT: lw ra, 60(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t0, 56(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t1, 52(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t2, 48(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a0, 44(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a1, 40(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a2, 36(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a3, 32(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a4, 28(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a5, 24(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a6, 20(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw a7, 16(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t3, 12(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t4, 8(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t5, 4(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: lw t6, 0(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: addi sp, sp, 64 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: preserve_mostcc1: | ||
; RV64I: # %bb.0: # %entry | ||
; RV64I-NEXT: addi sp, sp, -128 | ||
; RV64I-NEXT: sd ra, 120(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t0, 112(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t1, 104(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t2, 96(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a0, 88(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a1, 80(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a2, 72(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a3, 64(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a4, 56(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a5, 48(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a6, 40(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd a7, 32(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t3, 24(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t4, 16(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t5, 8(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: sd t6, 0(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: call standard_cc_func | ||
; RV64I-NEXT: ld ra, 120(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t0, 112(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t1, 104(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t2, 96(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a0, 88(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a1, 80(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a2, 72(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a3, 64(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a4, 56(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a5, 48(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a6, 40(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld a7, 32(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t3, 24(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t4, 16(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t5, 8(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: ld t6, 0(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: addi sp, sp, 128 | ||
; RV64I-NEXT: ret | ||
; | ||
; RV32E-LABEL: preserve_mostcc1: | ||
; RV32E: # %bb.0: # %entry | ||
; RV32E-NEXT: addi sp, sp, -40 | ||
; RV32E-NEXT: sw ra, 36(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw t0, 32(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw t1, 28(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw t2, 24(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a0, 20(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a1, 16(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a2, 12(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a3, 8(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a4, 4(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: sw a5, 0(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: call standard_cc_func | ||
; RV32E-NEXT: lw ra, 36(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw t0, 32(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw t1, 28(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw t2, 24(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a0, 20(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a1, 16(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a2, 12(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a3, 8(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a4, 4(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: lw a5, 0(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: addi sp, sp, 40 | ||
; RV32E-NEXT: ret | ||
; | ||
; RV64E-LABEL: preserve_mostcc1: | ||
; RV64E: # %bb.0: # %entry | ||
; RV64E-NEXT: addi sp, sp, -80 | ||
; RV64E-NEXT: sd ra, 72(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd t0, 64(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd t1, 56(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd t2, 48(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a0, 40(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a1, 32(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a2, 24(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a3, 16(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a4, 8(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: sd a5, 0(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: call standard_cc_func | ||
; RV64E-NEXT: ld ra, 72(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld t0, 64(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld t1, 56(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld t2, 48(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a0, 40(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a1, 32(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a2, 24(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a3, 16(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a4, 8(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: ld a5, 0(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: addi sp, sp, 80 | ||
; RV64E-NEXT: ret | ||
entry: | ||
call void @standard_cc_func() | ||
ret void | ||
} | ||
|
||
define preserve_mostcc void @preserve_mostcc2() nounwind { | ||
wangpc-pp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; RV32I-LABEL: preserve_mostcc2: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi sp, sp, -16 | ||
; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill | ||
; RV32I-NEXT: call preserve_mostcc_func | ||
; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload | ||
; RV32I-NEXT: addi sp, sp, 16 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: preserve_mostcc2: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi sp, sp, -16 | ||
; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill | ||
; RV64I-NEXT: call preserve_mostcc_func | ||
; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload | ||
; RV64I-NEXT: addi sp, sp, 16 | ||
; RV64I-NEXT: ret | ||
; | ||
; RV32E-LABEL: preserve_mostcc2: | ||
; RV32E: # %bb.0: | ||
; RV32E-NEXT: addi sp, sp, -4 | ||
; RV32E-NEXT: sw ra, 0(sp) # 4-byte Folded Spill | ||
; RV32E-NEXT: call preserve_mostcc_func | ||
; RV32E-NEXT: lw ra, 0(sp) # 4-byte Folded Reload | ||
; RV32E-NEXT: addi sp, sp, 4 | ||
; RV32E-NEXT: ret | ||
; | ||
; RV64E-LABEL: preserve_mostcc2: | ||
; RV64E: # %bb.0: | ||
; RV64E-NEXT: addi sp, sp, -8 | ||
; RV64E-NEXT: sd ra, 0(sp) # 8-byte Folded Spill | ||
; RV64E-NEXT: call preserve_mostcc_func | ||
; RV64E-NEXT: ld ra, 0(sp) # 8-byte Folded Reload | ||
; RV64E-NEXT: addi sp, sp, 8 | ||
; RV64E-NEXT: ret | ||
call preserve_mostcc void @preserve_mostcc_func() | ||
ret void | ||
} |
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.
This isn't going to work as the PLT stub can/does clobber some temporary registers (and exactly which depend on a lot of things). This is why AArch64 does not preserve x16-x18.
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.
Looking at lld,
t1
,t2
, andt3
are clobbered by the PLT resolver, so we need to account for that.I think this means: