Make librustc_codegen_llvm aware of LLVM address spaces.#51576
Make librustc_codegen_llvm aware of LLVM address spaces.#51576DiamondLovesYou wants to merge 3 commits intorust-lang:masterfrom
librustc_codegen_llvm aware of LLVM address spaces.#51576Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
Mark-Simulacrum
left a comment
There was a problem hiding this comment.
The rustbuild changes look acceptable to me.
src/bootstrap/native.rs
Outdated
There was a problem hiding this comment.
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
src/librustc_target/Cargo.toml
Outdated
There was a problem hiding this comment.
I don't see this dependency actually being used -- but maybe I'm missing something?
There was a problem hiding this comment.
rustc_target shouldn't have any dependencies on the compiler, so hopefully this is unused.
There was a problem hiding this comment.
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
|
|
src/librustc_codegen_llvm/Cargo.toml
Outdated
There was a problem hiding this comment.
Missing newline at the end of file.
src/librustc_codegen_llvm/abi.rs
Outdated
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Same here, regarding the usecase of only needed to cast the pointee type.
src/librustc_codegen_llvm/builder.rs
Outdated
src/librustc_codegen_llvm/common.rs
Outdated
There was a problem hiding this comment.
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.
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.
We probably shouldn't have cached types like these.
src/librustc_codegen_llvm/context.rs
Outdated
There was a problem hiding this comment.
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.
memcpy has a dot at the end, but the others don't?
There was a problem hiding this comment.
Again, could have a pointercast variant that only casts the pointee.
There was a problem hiding this comment.
What is this all doing? Why would the function being called here ever return by indirection?
There was a problem hiding this comment.
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.
We should avoid touching the HIR here, but it's not clear what requirements there actually are.
There was a problem hiding this comment.
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.
Why all of these? We should avoid introspecting LLVM types at all costs IMO.
eddyb
left a comment
There was a problem hiding this comment.
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.
Good catch, thanks
src/librustc_target/spec/mod.rs
Outdated
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-amdgizis 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.