diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-11-26 16:02:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-26 16:02:23 +0100 |
| commit | 324b4bcb3caaaa70476d65c86e8d399f09145bab (patch) | |
| tree | 9c4962cfd0cdb8997b2c402e734da1254e1e80e5 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 1e79d79dac11ce121b972fbaa0db9b0d1756b991 (diff) | |
| parent | 870b8311c17fb51139d5cc95fc592bcea85ee6ac (diff) | |
| download | rust-324b4bcb3caaaa70476d65c86e8d399f09145bab.tar.gz rust-324b4bcb3caaaa70476d65c86e8d399f09145bab.zip | |
Rollup merge of #91169 - RDambrosio016:master, r=bjorn3
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.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
