Skip to content

Commit 8052dae

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 63c738d + 870b831 commit 8052dae

File tree

3 files changed

+3
-3
lines changed
  • compiler

3 files changed

+3
-3
lines changed

compiler/rustc_codegen_gcc/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
1414
// TODO(antoyo)
1515
}
1616

17-
fn get_param(&self, index: usize) -> Self::Value {
17+
fn get_param(&mut self, index: usize) -> Self::Value {
1818
self.cx.current_func.borrow().expect("current func")
1919
.get_param(index as i32)
2020
.to_rvalue()

compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
615615
fn_abi.apply_attrs_callsite(self, callsite)
616616
}
617617

618-
fn get_param(&self, index: usize) -> Self::Value {
618+
fn get_param(&mut self, index: usize) -> Self::Value {
619619
llvm::get_param(self.llfn(), index as c_uint)
620620
}
621621
}

compiler/rustc_codegen_ssa/src/traits/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ use rustc_target::abi::call::FnAbi;
44

55
pub trait AbiBuilderMethods<'tcx>: BackendTypes {
66
fn apply_attrs_callsite(&mut self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, callsite: Self::Value);
7-
fn get_param(&self, index: usize) -> Self::Value;
7+
fn get_param(&mut self, index: usize) -> Self::Value;
88
}

0 commit comments

Comments
 (0)