-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV] Put Large Code Model Constant Pools in .text #151393
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
lenary
wants to merge
6
commits into
llvm:main
Choose a base branch
from
lenary:pr/riscv-constant-pool-large-model
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.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a58a45
[RISCV] Put Large Code Model Constant Pools in .text
lenary f74d1cb
Braces
lenary 82debbb
Improve test
lenary 71c1056
Ensure we use the function's section if possible
lenary d4391a3
Merge remote-tracking branch 'origin/main' into pr/riscv-constant-poo…
lenary 73c32ba
clang-format
lenary 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
; RUN: llc -mtriple=riscv64 -mattr=+f,+zfh -target-abi=lp64f -code-model=large -verify-machineinstrs < %s \ | ||
; RUN: -filetype=obj -o - | llvm-readobj -r - \ | ||
; RUN: | FileCheck %s -check-prefix=RV64I | ||
; RUN: llc -mtriple=riscv64 -mattr=+zfinx,+zhinx -target-abi=lp64 -code-model=large -verify-machineinstrs < %s \ | ||
; RUN: -filetype=obj -o - | llvm-readobj -r - \ | ||
; RUN: | FileCheck %s -check-prefix=RV64I | ||
|
||
|
||
;; This tests that we are lowering large code model constants into `.text` | ||
;; constant pools, so that accessing them is close to `.text`, rather than | ||
;; far away in `.data`. The other choices are `.rodata` and `.data.rel.ro`, | ||
;; both of which may not be close enough to `.text` to be referenced. | ||
;; | ||
;; The test uses `readobj` to check that there are relocations against the | ||
;; `.text` section for these addresses. This is not compatible with PIC, | ||
;; just like the rest of the large code model. | ||
|
||
; RV64I: Section (3) .rela.text { | ||
; RV64I-NEXT: R_RISCV_64 G 0x0 | ||
; RV64I-NEXT: R_RISCV_64 addr 0x0 | ||
; RV64I-NEXT: R_RISCV_64 W 0x0 | ||
; RV64I-NEXT: R_RISCV_64 X 0x0 | ||
|
||
; Check lowering of globals | ||
@G = global i32 0 | ||
define i32 @lower_global(i32 %a) nounwind { | ||
%1 = load volatile i32, ptr @G | ||
ret i32 %1 | ||
} | ||
|
||
; Check lowering of blockaddresses | ||
@addr = global ptr null | ||
define void @lower_blockaddress() nounwind { | ||
store volatile ptr blockaddress(@lower_blockaddress, %block), ptr @addr | ||
ret void | ||
|
||
block: | ||
unreachable | ||
} | ||
|
||
; Check lowering of blockaddress that forces a displacement to be added | ||
define signext i32 @lower_blockaddress_displ(i32 signext %w) nounwind { | ||
entry: | ||
%x = alloca ptr, align 8 | ||
store ptr blockaddress(@lower_blockaddress_displ, %test_block), ptr %x, align 8 | ||
%cmp = icmp sgt i32 %w, 100 | ||
br i1 %cmp, label %if.then, label %if.end | ||
|
||
if.then: | ||
%addr = load ptr, ptr %x, align 8 | ||
br label %indirectgoto | ||
|
||
if.end: | ||
br label %return | ||
|
||
test_block: | ||
br label %return | ||
|
||
return: | ||
%retval = phi i32 [ 3, %if.end ], [ 4, %test_block ] | ||
ret i32 %retval | ||
|
||
indirectgoto: | ||
indirectbr ptr %addr, [ label %test_block ] | ||
} | ||
|
||
; Check lowering of constantpools | ||
define float @lower_constantpool(float %a) nounwind { | ||
%1 = fadd float %a, 1.000244140625 | ||
ret float %1 | ||
} | ||
|
||
; Check lowering of extern_weaks | ||
@W = extern_weak global i32 | ||
|
||
define i32 @lower_extern_weak(i32 %a) nounwind { | ||
%1 = load volatile i32, ptr @W | ||
ret i32 %1 | ||
} | ||
|
||
@X = global half 1.5 | ||
|
||
define half @lower_global_half(half %a) nounwind { | ||
%b = load half, ptr @X | ||
%1 = fadd half %a, %b | ||
ret half %1 | ||
} |
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 don't see any reason to expect that .text is with +-2GB of a function in an arbitrary section. The large code model has no limit on the amount of code you're allowed to include in a program. If you need to ensure distance, you need to emit the constant pool into the same section as 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 have addressed this, I'm not sure very well - I added a
const Function *
parameter because we don't have the function's section whenemitConstantPool
is called. This allows us to call into the section resolution logic for the function itself.