-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Change cg_ssa's get_param to borrow the builder mutably #91169
Merged
Merged
Conversation
This file contains 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
Some changes occured to rustc_codegen_gcc cc @antoyo |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. Please see the contribution instructions for more information. |
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Nov 24, 2021
@rustbot label: +A-codegen +T-compiler |
rustbot
added
A-codegen
Area: Code generation
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Nov 24, 2021
📌 Commit 870b831 has been approved by |
bors
added
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Nov 25, 2021
@bors rollup=always |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Nov 25, 2021
Change cg_ssa's get_param to borrow the builder mutably This is a small change to make `get_param` more flexible for codegens that may need to modify things when retrieving function parameters. This will currently only be used by [rustc_codegen_nvvm](https://github.com/Rust-GPU/Rust-CUDA) (my own project), but may be useful to more codegens in the future. This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as `i128` -> `<2 x i64>`. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex: ```rs fn get_param(&self, index: usize) -> Self::Value { let val = llvm::get_param(self.llfn(), index as c_uint); trace!("Get param `{:?}`", val); unsafe { let llfnty = LLVMRustGetFunctionType(self.llfn()); let map = self.remapped_integer_args.borrow(); if let Some((_, key)) = map.get(llfnty) { if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) { trace!("Casting irregular param {:?} to {:?}", val, new_ty); return transmute_llval( *self.llbuilder.lock().unwrap(), &self.cx, val, *new_ty, ); } } val } } ``` However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Nov 25, 2021
Change cg_ssa's get_param to borrow the builder mutably This is a small change to make `get_param` more flexible for codegens that may need to modify things when retrieving function parameters. This will currently only be used by [rustc_codegen_nvvm](https://github.com/Rust-GPU/Rust-CUDA) (my own project), but may be useful to more codegens in the future. This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as `i128` -> `<2 x i64>`. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex: ```rs fn get_param(&self, index: usize) -> Self::Value { let val = llvm::get_param(self.llfn(), index as c_uint); trace!("Get param `{:?}`", val); unsafe { let llfnty = LLVMRustGetFunctionType(self.llfn()); let map = self.remapped_integer_args.borrow(); if let Some((_, key)) = map.get(llfnty) { if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) { trace!("Casting irregular param {:?} to {:?}", val, new_ty); return transmute_llval( *self.llbuilder.lock().unwrap(), &self.cx, val, *new_ty, ); } } val } } ``` However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Nov 25, 2021
Change cg_ssa's get_param to borrow the builder mutably This is a small change to make `get_param` more flexible for codegens that may need to modify things when retrieving function parameters. This will currently only be used by [rustc_codegen_nvvm](https://github.com/Rust-GPU/Rust-CUDA) (my own project), but may be useful to more codegens in the future. This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as `i128` -> `<2 x i64>`. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex: ```rs fn get_param(&self, index: usize) -> Self::Value { let val = llvm::get_param(self.llfn(), index as c_uint); trace!("Get param `{:?}`", val); unsafe { let llfnty = LLVMRustGetFunctionType(self.llfn()); let map = self.remapped_integer_args.borrow(); if let Some((_, key)) = map.get(llfnty) { if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) { trace!("Casting irregular param {:?} to {:?}", val, new_ty); return transmute_llval( *self.llbuilder.lock().unwrap(), &self.cx, val, *new_ty, ); } } val } } ``` However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Nov 26, 2021
Change cg_ssa's get_param to borrow the builder mutably This is a small change to make `get_param` more flexible for codegens that may need to modify things when retrieving function parameters. This will currently only be used by [rustc_codegen_nvvm](https://github.com/Rust-GPU/Rust-CUDA) (my own project), but may be useful to more codegens in the future. This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as `i128` -> `<2 x i64>`. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex: ```rs fn get_param(&self, index: usize) -> Self::Value { let val = llvm::get_param(self.llfn(), index as c_uint); trace!("Get param `{:?}`", val); unsafe { let llfnty = LLVMRustGetFunctionType(self.llfn()); let map = self.remapped_integer_args.borrow(); if let Some((_, key)) = map.get(llfnty) { if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) { trace!("Casting irregular param {:?} to {:?}", val, new_ty); return transmute_llval( *self.llbuilder.lock().unwrap(), &self.cx, val, *new_ty, ); } } val } } ``` However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Nov 26, 2021
…askrgr Rollup of 4 pull requests Successful merges: - rust-lang#91169 (Change cg_ssa's get_param to borrow the builder mutably) - rust-lang#91176 (If the thread does not get the lock in the short term, yield the CPU) - rust-lang#91212 (Fix ICE due to out-of-bounds statement index when reporting borrowck error) - rust-lang#91225 (Fix invalid scrollbar display on source code page) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-codegen
Area: Code generation
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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.
This is a small change to make
get_param
more flexible for codegens that may need to modify things when retrieving function parameters.This will currently only be used by rustc_codegen_nvvm (my own project), but may be useful to more codegens in the future.
This is needed because cg_nvvm needs to remap certain types to libnvvm-friendly types, such as
i128
-><2 x i64>
. Because cg_ssa does not give mutable access to the builder, i resorted to using a mutex:However, i predict this is pretty bad for performance, considering how much builders are called during codegen, so i would greatly appreciate having a more flexible API for this.