-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Make librustc_codegen_llvm
aware of LLVM address spaces.
#51576
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
Make librustc_codegen_llvm
aware of LLVM address spaces.
#51576
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
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 rustbuild changes look acceptable to me.
src/bootstrap/native.rs
Outdated
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.
There should be no need for this here as AFAICT it's always globally set, we never do anything but pass it in from config.llvm_dump_enabled.
src/librustc_codegen_llvm/builder.rs
Outdated
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 looks wrong.
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.
Indeed!
src/librustc_target/Cargo.toml
Outdated
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 this dependency actually being used -- but maybe I'm missing something?
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.
rustc_target
shouldn't have any dependencies on the compiler, so hopefully this is unused.
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.
It is used for custom address space names.
Oh, it was. I forgot I had removed it.
r? @eddyb probably |
src/librustc_errors/lib.rs
Outdated
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.
|
src/librustc_codegen_llvm/Cargo.toml
Outdated
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.
Missing newline at the end of file.
src/librustc_codegen_llvm/abi.rs
Outdated
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 this is common, wouldn't a replacement for pointercast
that only casts the pointee, but preserves the AS, be better?
src/librustc_codegen_llvm/abi.rs
Outdated
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.
Instead of having a method to retrieve a specific AS and then another to create a pointer type, why not have e.g. .alloca_ptr_to(cx)
or .ptr_to(cx, AddrSpaceKind::Alloca)
(okay, the latter is a bit long).
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 actually already have those functions, I just probably added them after I wrote some of this 😄
src/librustc_codegen_llvm/abi.rs
Outdated
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.
By "dst" you mean "slice (length)"? Also, I should note this doesn't necessarily work.
The pair could just as well be (&T, &U)
where T: Sized, U: Sized
.
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.
A better approach might be to pass something extra to scalar_pair_element_llvm_type
. Same for everything else, really.
src/librustc_codegen_llvm/base.rs
Outdated
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.
Same here, regarding the usecase of only needed to cast the pointee type.
src/librustc_codegen_llvm/builder.rs
Outdated
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.
src/librustc_codegen_llvm/common.rs
Outdated
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.
Maybe pass the AddrSpaceKind
enum value around instead of the LLVM AS number?
src/librustc_codegen_llvm/consts.rs
Outdated
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.
There shouldn't be that many calls, making this non-optional (and using AddrSpaceKind
) would be better IMO.
src/librustc_codegen_llvm/context.rs
Outdated
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.
We probably shouldn't have cached types like these.
src/librustc_codegen_llvm/context.rs
Outdated
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 think this is worse, because it incurs extra branching. Might as well switch it to String
.
src/librustc_codegen_llvm/context.rs
Outdated
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.
memcpy has a dot at the end, but the others don't?
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.
Why would these two be needed?
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.
Again, could have a pointercast
variant that only casts the pointee.
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.
Same here.
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.
Superfluous ,
.
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.
What is this all doing? Why would the function being called here ever return by indirection?
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.
Accidentally included. Was created when I was trying to figure out how to work with the AMDGPU target machine. I tried having every function be the amdgpu kernel abi, which doesn't allow non-void
return types.
Removed in the next version, to be pushed Soon(TM).
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.
We should avoid touching the HIR here, but it's not clear what requirements there actually are.
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.
We need the address space of the global for the global's LLVM type, meaning it needs to compute the same address space as consts::codegen_static
.
At the time, I wasn't aware of a better way, but the next version now does what MonoItemExt::define
does.
src/librustc_codegen_llvm/type_.rs
Outdated
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.
Why all of these? We should avoid introspecting LLVM types at all costs IMO.
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 how any of the code around read-only and read-write global address spaces, actually works. Why are vtable pointers different from any other pointer?
If there is a flat address space, why isn't it used more often? Some documentation would help.
I hope there is a simpler way to support the target platform you want.
3ad92f6
to
2ee942f
Compare
This PR was labelled as Blocked 2 months ago:
@BatmanAoD is it still the case? |
Review ping @eddyb |
☔ The latest upstream changes (presumably #55982) made this pull request unmergeable. Please resolve the merge conflicts. |
2ee942f
to
e517b7c
Compare
src/librustc_codegen_llvm/context.rs
Outdated
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.
Should be Instruction
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.
Good catch, thanks
src/librustc_target/spec/mod.rs
Outdated
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.
Missing Instruction
?
b719335
to
7a13695
Compare
☔ The latest upstream changes (presumably #57108) made this pull request unmergeable. Please resolve the merge conflicts. |
286b70a
to
f0abb1b
Compare
☔ The latest upstream changes (presumably #57145) made this pull request unmergeable. Please resolve the merge conflicts. |
f0abb1b
to
724ab44
Compare
☔ The latest upstream changes (presumably #57416) made this pull request unmergeable. Please resolve the merge conflicts. |
In order to not require overloading functions based on their argument's address space (among other things), we require the presence of a "flat" (ie an address space which is shared with every other address space) address space. This isn't exposed in any way to Rust code. This just makes Rust compatible with LLVM target machines which, for example, place allocas in a different address space. `amdgcn-amd-amdhsa-amdgiz` is a specific example, which places allocas in address space 5 or the private (at the work item level) address space.
…l address space where possible.
724ab44
to
1019e20
Compare
☔ The latest upstream changes (presumably #58316) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @DiamondLovesYou you have conflicts you need to resolve |
ping from triage @DiamondLovesYou |
In order to not require overloading functions based on their argument's address
space (among other things), we require the presence of a "flat" (ie an address
space which is shared with every other address space) address space.
This isn't exposed in any way to Rust code. This just makes Rust compatible with
LLVM target machines which, for example, place allocas in a different address
space.
amdgcn-amd-amdhsa-amdgiz
is a specific example, which places allocas inaddress space 5 or the private (at the work item level) address space. This
includes working with nonuniform sized pointers.