diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index d29fb14e5bd40..49c07652c8261 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -27,12 +27,17 @@ use crate::llvm::{self, Attribute, AttributePlace, Type, Value}; use crate::type_of::LayoutLlvmExt; trait ArgAttributesExt { - fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value); - fn apply_attrs_to_callsite( + fn apply_attrs_to_llfn<'ll>( &self, idx: AttributePlace, - cx: &CodegenCx<'_, '_>, - callsite: &Value, + cx: &CodegenCx<'ll, '_>, + llfn: Value<'ll>, + ); + fn apply_attrs_to_callsite<'ll>( + &self, + idx: AttributePlace, + cx: &CodegenCx<'ll, '_>, + callsite: Value<'ll>, ); } @@ -116,16 +121,21 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&' } impl ArgAttributesExt for ArgAttributes { - fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value) { + fn apply_attrs_to_llfn<'ll>( + &self, + idx: AttributePlace, + cx: &CodegenCx<'ll, '_>, + llfn: Value<'ll>, + ) { let attrs = get_attrs(self, cx); attributes::apply_to_llfn(llfn, idx, &attrs); } - fn apply_attrs_to_callsite( + fn apply_attrs_to_callsite<'ll>( &self, idx: AttributePlace, - cx: &CodegenCx<'_, '_>, - callsite: &Value, + cx: &CodegenCx<'ll, '_>, + callsite: Value<'ll>, ) { let attrs = get_attrs(self, cx); attributes::apply_to_callsite(callsite, idx, &attrs); @@ -236,14 +246,14 @@ trait ArgAbiExt<'ll, 'tcx> { fn store( &self, bx: &mut Builder<'_, 'll, 'tcx>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ); fn store_fn_arg( &self, bx: &mut Builder<'_, 'll, 'tcx>, idx: &mut usize, - dst: PlaceRef<'tcx, &'ll Value>, + dst: PlaceRef<'tcx, Value<'ll>>, ); } @@ -255,8 +265,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn store( &self, bx: &mut Builder<'_, 'll, 'tcx>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { match &self.mode { PassMode::Ignore => {} @@ -310,7 +320,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { &self, bx: &mut Builder<'_, 'll, 'tcx>, idx: &mut usize, - dst: PlaceRef<'tcx, &'ll Value>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { let mut next = || { let val = llvm::get_param(bx.llfn(), *idx as c_uint); @@ -347,8 +357,8 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn store_arg( &mut self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { arg_abi.store(self, val, dst) } @@ -363,12 +373,12 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> { fn apply_attrs_llfn( &self, cx: &CodegenCx<'ll, 'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, instance: Option>, ); /// Apply attributes to a function call. - fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value); + fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>); } impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { @@ -470,7 +480,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { fn apply_attrs_llfn( &self, cx: &CodegenCx<'ll, 'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, instance: Option>, ) { let mut func_attrs = SmallVec::<[_; 3]>::new(); @@ -648,7 +658,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { } } - fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value) { + fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>) { let mut func_attrs = SmallVec::<[_; 2]>::new(); if self.ret.layout.is_uninhabited() { func_attrs.push(llvm::AttributeKind::NoReturn.create_attr(bx.cx.llcx)); @@ -659,7 +669,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { attributes::apply_to_callsite(callsite, llvm::AttributePlace::Function, &{ func_attrs }); let mut i = 0; - let mut apply = |cx: &CodegenCx<'_, '_>, attrs: &ArgAttributes| { + let mut apply = |cx: &CodegenCx<'ll, '_>, attrs: &ArgAttributes| { attrs.apply_attrs_to_callsite(llvm::AttributePlace::Argument(i), cx, callsite); i += 1; i - 1 diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 317dc3d55a62c..c6fb235059fd1 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -537,7 +537,7 @@ pub(crate) fn inline_asm_call<'ll>( bx: &mut Builder<'_, 'll, '_>, asm: &str, cons: &str, - inputs: &[&'ll Value], + inputs: &[Value<'ll>], output: llvm::Type<'ll>, labels: &[&'ll llvm::BasicBlock], volatile: bool, @@ -547,7 +547,7 @@ pub(crate) fn inline_asm_call<'ll>( unwind: bool, dest: Option<&'ll llvm::BasicBlock>, catch_funclet: Option<(&'ll llvm::BasicBlock, Option<&Funclet<'ll>>)>, -) -> Option<&'ll Value> { +) -> Option> { let argtys = inputs .iter() .map(|v| { @@ -1170,11 +1170,11 @@ fn any_target_feature_enabled( /// Fix up an input value to work around LLVM bugs. fn llvm_fixup_input<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - mut value: &'ll Value, + mut value: Value<'ll>, reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, instance: Instance<'_>, -) -> &'ll Value { +) -> Value<'ll> { use InlineAsmRegClass::*; let dl = &bx.tcx.data_layout; match (reg, layout.backend_repr) { @@ -1373,11 +1373,11 @@ fn llvm_fixup_input<'ll, 'tcx>( /// Fix up an output value to work around LLVM bugs. fn llvm_fixup_output<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - mut value: &'ll Value, + mut value: Value<'ll>, reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, instance: Instance<'_>, -) -> &'ll Value { +) -> Value<'ll> { use InlineAsmRegClass::*; match (reg, layout.backend_repr) { (AArch64(AArch64InlineAsmRegClass::vreg), BackendRepr::Scalar(s)) => { diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index d74c6dd68564b..6fdc2a1589f47 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -26,23 +26,27 @@ use crate::llvm::{ }; use crate::{attributes, llvm_util}; -pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) { +pub(crate) fn apply_to_llfn<'ll>(llfn: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute]) { if !attrs.is_empty() { llvm::AddFunctionAttributes(llfn, idx, attrs); } } -pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) { +pub(crate) fn apply_to_callsite<'ll>( + callsite: Value<'ll>, + idx: AttributePlace, + attrs: &[&'ll Attribute], +) { if !attrs.is_empty() { llvm::AddCallSiteAttributes(callsite, idx, attrs); } } -pub(crate) fn has_string_attr(llfn: &Value, name: &str) -> bool { +pub(crate) fn has_string_attr<'ll>(llfn: Value<'ll>, name: &str) -> bool { llvm::HasStringAttribute(llfn, name) } -pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) { +pub(crate) fn remove_string_attr_from_llfn<'ll>(llfn: Value<'ll>, name: &str) { llvm::RemoveStringAttrFromFn(llfn, name); } @@ -503,7 +507,7 @@ fn create_alloc_family_attr<'ll>(llcx: llvm::Context<'ll>) -> &'ll llvm::Attribu pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( cx: &SimpleCx<'ll>, tcx: TyCtxt<'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, codegen_fn_attrs: &CodegenFnAttrs, instance: Option>, sanitizer_ignorelist: Option<&SanitizerIgnoreList>, diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 4e1a3f998a265..83b5b7405d63d 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -659,8 +659,8 @@ pub(crate) unsafe fn llvm_optimize<'ll>( // Returns the new function, or `None` if nothing was wrapped fn handle_offload<'ll>( cx: &SimpleCx<'ll>, - old_fn: &'ll llvm::Value, - ) -> Option<&'ll llvm::Value> { + old_fn: llvm::Value<'ll>, + ) -> Option> { let old_fn_ty = cx.get_type_of_global(old_fn); let old_param_types = cx.func_params_types(old_fn_ty); let old_param_count = old_param_types.len(); diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 7909072db1d8d..0b230f1608da1 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -34,14 +34,14 @@ use crate::llvm::{self, Value}; use crate::{ModuleLlvm, attributes}; pub(crate) struct ValueIter<'ll> { - cur: Option<&'ll Value>, - step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>, + cur: Option>, + step: unsafe extern "C" fn(Value<'ll>) -> Option>, } impl<'ll> Iterator for ValueIter<'ll> { - type Item = &'ll Value; + type Item = Value<'ll>; - fn next(&mut self) -> Option<&'ll Value> { + fn next(&mut self) -> Option> { let old = self.cur; if let Some(old) = old { self.cur = unsafe { (self.step)(old) }; @@ -221,7 +221,7 @@ pub(crate) fn compile_codegen_unit( (module, cost) } -pub(crate) fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) { +pub(crate) fn set_link_section<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) { let Some(sect) = attrs.link_section else { return }; let buf = SmallCStr::new(sect.as_str()); llvm::set_section(llval, &buf); @@ -248,7 +248,7 @@ pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility { } } -pub(crate) fn set_variable_sanitizer_attrs(llval: &Value, attrs: &CodegenFnAttrs) { +pub(crate) fn set_variable_sanitizer_attrs<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) { if attrs.sanitizers.disabled.contains(SanitizerSet::ADDRESS) || attrs.sanitizers.disabled.contains(SanitizerSet::KERNELADDRESS) { diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index ed5da8e69246f..32e9578355976 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -61,10 +61,10 @@ impl<'a, 'll> SBuilder<'a, 'll> { pub(crate) fn call( &mut self, llty: Type<'ll>, - llfn: &'ll Value, - args: &[&'ll Value], + llfn: Value<'ll>, + args: &[Value<'ll>], funclet: Option<&Funclet<'ll>>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("call {:?} with args ({:?})", llfn, args); let args = self.check_call("call", llty, llfn, args); @@ -79,7 +79,7 @@ impl<'a, 'll> SBuilder<'a, 'll> { self.llbuilder(), llty, llfn, - args.as_ptr() as *const &llvm::Value, + args.as_ptr(), args.len() as c_uint, bundles.as_ptr(), bundles.len() as c_uint, @@ -99,7 +99,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { pub(crate) fn append_block( cx: &'a GenericCx<'ll, CX>, - llfn: &'ll Value, + llfn: Value<'ll>, name: &str, ) -> &'ll BasicBlock { unsafe { @@ -116,11 +116,11 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { unsafe { self.llbuilder_raw.as_ref() } } - pub(crate) fn trunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + pub(crate) fn trunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - pub(crate) fn bitcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + pub(crate) fn bitcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildBitCast(self.llbuilder(), val, dest_ty, UNNAMED) } } @@ -128,7 +128,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { llvm::LLVMBuildRetVoid(self.llbuilder()); } - pub(crate) fn ret(&mut self, v: &'ll Value) { + pub(crate) fn ret(&mut self, v: Value<'ll>) { unsafe { llvm::LLVMBuildRet(self.llbuilder(), v); } @@ -146,7 +146,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { // easily jump to the beginning of the function to place our allocas there. We trust the user // to manually do that. FIXME(offload): improve the genericCx and add more llvm wrappers to // handle this. - pub(crate) fn direct_alloca(&mut self, size: Size, align: Align, name: &str) -> &'ll Value { + pub(crate) fn direct_alloca(&mut self, size: Size, align: Align, name: &str) -> Value<'ll> { let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()); let val = unsafe { let alloca = llvm::LLVMBuildAlloca(self.llbuilder(), ty, UNNAMED); @@ -163,10 +163,10 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { fn build_gep( &mut self, stride: Size, - ptr: &'ll Value, - index: &'ll Value, + ptr: Value<'ll>, + index: Value<'ll>, flags: GEPNoWrapFlags, - ) -> &'ll Value { + ) -> Value<'ll> { let ty = if stride.bytes() == 1 { // LLVM prefers `i8` as the canonical form for a single-byte GEP. self.cx.type_i8() @@ -187,7 +187,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - pub(crate) fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value { + pub(crate) fn store(&mut self, val: Value<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { debug!("Store {:?} -> {:?}", val, ptr); assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer); unsafe { @@ -197,7 +197,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - pub(crate) fn load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + pub(crate) fn load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); llvm::LLVMSetAlignment(load, align.bytes() as c_uint); @@ -281,7 +281,7 @@ impl<'ll, 'tcx> Deref for Builder<'_, 'll, 'tcx> { macro_rules! math_builder_methods { ($($name:ident($($arg:ident),*) => $llvm_capi:ident),+ $(,)?) => { - $(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value { + $(fn $name(&mut self, $($arg: Value<'ll>),*) -> Value<'ll> { unsafe { llvm::$llvm_capi(self.llbuilder(), $($arg,)* UNNAMED) } @@ -291,7 +291,7 @@ macro_rules! math_builder_methods { macro_rules! set_math_builder_methods { ($($name:ident($($arg:ident),*) => ($llvm_capi:ident, $llvm_set_math:ident)),+ $(,)?) => { - $(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value { + $(fn $name(&mut self, $($arg: Value<'ll>),*) -> Value<'ll> { unsafe { let instr = llvm::$llvm_capi(self.llbuilder(), $($arg,)* UNNAMED); llvm::$llvm_set_math(instr); @@ -324,7 +324,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.span = span; } - fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: &'ll Value, name: &str) -> &'ll BasicBlock { + fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: Value<'ll>, name: &str) -> &'ll BasicBlock { unsafe { let name = SmallCStr::new(name); llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, name.as_ptr()) @@ -343,7 +343,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llvm::LLVMBuildRetVoid(self.llbuilder()); } - fn ret(&mut self, v: &'ll Value) { + fn ret(&mut self, v: Value<'ll>) { unsafe { llvm::LLVMBuildRet(self.llbuilder(), v); } @@ -399,7 +399,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn cond_br( &mut self, - cond: &'ll Value, + cond: Value<'ll>, then_llbb: &'ll BasicBlock, else_llbb: &'ll BasicBlock, ) { @@ -410,7 +410,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn switch( &mut self, - v: &'ll Value, + v: Value<'ll>, else_llbb: &'ll BasicBlock, cases: impl ExactSizeIterator, ) { @@ -465,14 +465,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llty: Type<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - return_slot: ReturnSlot<&'ll Value>, - args: &[&'ll Value], + llfn: Value<'ll>, + return_slot: ReturnSlot>, + args: &[Value<'ll>], then: &'ll BasicBlock, catch: &'ll BasicBlock, funclet: Option<&Funclet<'ll>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { // If this function returns indirectly (`PassMode::Indirect`), // the `return_slot` should be the first argument. let args = match return_slot { @@ -563,7 +563,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unchecked_umul(x, y) => LLVMBuildNUWMul, } - fn unchecked_suadd(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_suadd(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let add = llvm::LLVMBuildAdd(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(add).is_some() { @@ -573,7 +573,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { add } } - fn unchecked_susub(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_susub(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let sub = llvm::LLVMBuildSub(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(sub).is_some() { @@ -583,7 +583,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { sub } } - fn unchecked_sumul(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_sumul(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let mul = llvm::LLVMBuildMul(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(mul).is_some() { @@ -594,7 +594,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn or_disjoint(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn or_disjoint(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let or = llvm::LLVMBuildOr(self.llbuilder(), a, b, UNNAMED); @@ -679,7 +679,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { val } - fn alloca(&mut self, size: Size, align: Align) -> &'ll Value { + fn alloca(&mut self, size: Size, align: Align) -> Value<'ll> { let mut bx = Builder::with_cx(self.cx); bx.position_at_start(unsafe { llvm::LLVMGetFirstBasicBlock(self.llfn()) }); bx.direct_alloca(size, align, "") @@ -697,7 +697,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + fn load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment()); @@ -706,7 +706,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn volatile_load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + fn volatile_load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = self.load(ty, ptr, align); llvm::LLVMSetVolatile(load, llvm::TRUE); @@ -717,11 +717,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_load( &mut self, ty: Type<'ll>, - ptr: &'ll Value, + ptr: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, volatile: bool, size: Size, - ) -> &'ll Value { + ) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); // Set atomic ordering @@ -736,7 +736,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } #[instrument(level = "trace", skip(self))] - fn load_operand(&mut self, place: PlaceRef<'tcx, &'ll Value>) -> OperandRef<'tcx, &'ll Value> { + fn load_operand(&mut self, place: PlaceRef<'tcx, Value<'ll>>) -> OperandRef<'tcx, Value<'ll>> { if place.layout.is_unsized() { let tail = self.tcx.struct_tail_for_codegen(place.layout.ty, self.typing_env()); if matches!(tail.kind(), ty::Foreign(..)) { @@ -755,7 +755,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { #[instrument(level = "trace", skip(bx))] fn scalar_load_metadata<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, - load: &'ll Value, + load: Value<'ll>, scalar: abi::Scalar, layout: TyAndLayout<'tcx>, offset: Size, @@ -842,9 +842,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn write_operand_repeatedly( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { if self.cx.sess().opts.optimize == OptLevel::No { // To let debuggers single-step over lines like @@ -860,7 +860,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) { + fn range_metadata(&mut self, load: Value<'ll>, range: WrappingRange) { if self.cx.sess().opts.optimize == OptLevel::No { // Don't emit metadata we're not going to use return; @@ -874,14 +874,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.set_metadata_node(load, llvm::MD_range, &md); } - fn nonnull_metadata(&mut self, load: &'ll Value) { + fn nonnull_metadata(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_nonnull, &[]); } fn store_with_flags( &mut self, - val: &'ll Value, - ptr: &'ll Value, + val: Value<'ll>, + ptr: Value<'ll>, align: Align, flags: MemFlags, ) { @@ -940,8 +940,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_store( &mut self, - val: &'ll Value, - ptr: &'ll Value, + val: Value<'ll>, + ptr: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, volatile: bool, size: Size, @@ -960,24 +960,24 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::default()) } - fn inbounds_gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn inbounds_gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::InBounds) } - fn inbounds_nuw_gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn inbounds_nuw_gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::InBounds | GEPNoWrapFlags::NUW) } /* Casts */ - fn trunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn trunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn unchecked_utrunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn unchecked_utrunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { debug_assert_ne!(self.val_ty(val), dest_ty); let trunc = self.trunc(val, dest_ty); @@ -989,7 +989,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { trunc } - fn unchecked_strunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn unchecked_strunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { debug_assert_ne!(self.val_ty(val), dest_ty); let trunc = self.trunc(val, dest_ty); @@ -1001,19 +1001,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { trunc } - fn sext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn sext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildSExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptoui_sat(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptoui_sat(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.fptoui.sat", &[dest_ty, self.val_ty(val)], &[val]) } - fn fptosi_sat(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptosi_sat(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.fptosi.sat", &[dest_ty, self.val_ty(val)], &[val]) } - fn fptoui(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptoui(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { // On WebAssembly the `fptoui` and `fptosi` instructions currently have // poor codegen. The reason for this is that the corresponding wasm // instructions, `i32.trunc_f32_s` for example, will trap when the float @@ -1044,7 +1044,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unsafe { llvm::LLVMBuildFPToUI(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptosi(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptosi(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { // see `fptoui` above for why wasm is different here if self.sess().target.is_like_wasm { let src_ty = self.cx.val_ty(val); @@ -1062,35 +1062,35 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unsafe { llvm::LLVMBuildFPToSI(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn uitofp(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn uitofp(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildUIToFP(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn sitofp(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn sitofp(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildSIToFP(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptrunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptrunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildFPTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fpext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fpext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildFPExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn ptrtoint(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn ptrtoint(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildPtrToInt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn inttoptr(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn inttoptr(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildIntToPtr(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn bitcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn bitcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildBitCast(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn intcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>, is_signed: bool) -> &'ll Value { + fn intcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>, is_signed: bool) -> Value<'ll> { unsafe { llvm::LLVMBuildIntCast2( self.llbuilder(), @@ -1102,17 +1102,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn pointercast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn pointercast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildPointerCast(self.llbuilder(), val, dest_ty, UNNAMED) } } /* Comparisons */ - fn icmp(&mut self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + fn icmp(&mut self, op: IntPredicate, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let op = llvm::IntPredicate::from_generic(op); unsafe { llvm::LLVMBuildICmp(self.llbuilder(), op as c_uint, lhs, rhs, UNNAMED) } } - fn fcmp(&mut self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + fn fcmp(&mut self, op: RealPredicate, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let op = llvm::RealPredicate::from_generic(op); unsafe { llvm::LLVMBuildFCmp(self.llbuilder(), op as c_uint, lhs, rhs, UNNAMED) } } @@ -1132,11 +1132,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { /* Miscellaneous instructions */ fn memcpy( &mut self, - dst: &'ll Value, + dst: Value<'ll>, dst_align: Align, - src: &'ll Value, + src: Value<'ll>, src_align: Align, - size: &'ll Value, + size: Value<'ll>, flags: MemFlags, tt: Option, ) { @@ -1167,11 +1167,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn memmove( &mut self, - dst: &'ll Value, + dst: Value<'ll>, dst_align: Align, - src: &'ll Value, + src: Value<'ll>, src_align: Align, - size: &'ll Value, + size: Value<'ll>, flags: MemFlags, ) { assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memmove not supported"); @@ -1192,9 +1192,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn memset( &mut self, - ptr: &'ll Value, - fill_byte: &'ll Value, - size: &'ll Value, + ptr: Value<'ll>, + fill_byte: Value<'ll>, + size: Value<'ll>, align: Align, flags: MemFlags, ) { @@ -1212,28 +1212,28 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn vscale(&mut self, ty: Type<'ll>) -> &'ll Value { + fn vscale(&mut self, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMRustBuildVScale(self.llbuilder(), ty) } } fn select( &mut self, - cond: &'ll Value, - then_val: &'ll Value, - else_val: &'ll Value, - ) -> &'ll Value { + cond: Value<'ll>, + then_val: Value<'ll>, + else_val: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildSelect(self.llbuilder(), cond, then_val, else_val, UNNAMED) } } - fn va_arg(&mut self, list: &'ll Value, ty: Type<'ll>) -> &'ll Value { + fn va_arg(&mut self, list: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildVAArg(self.llbuilder(), list, ty, UNNAMED) } } - fn extract_element(&mut self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value { + fn extract_element(&mut self, vec: Value<'ll>, idx: Value<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildExtractElement(self.llbuilder(), vec, idx, UNNAMED) } } - fn vector_splat(&mut self, num_elts: u64, elt: &'ll Value) -> &'ll Value { + fn vector_splat(&mut self, num_elts: u64, elt: Value<'ll>) -> Value<'ll> { unsafe { let elt_ty = self.cx.val_ty(elt); let undef = llvm::LLVMGetUndef(self.type_vector(elt_ty, num_elts)); @@ -1243,25 +1243,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn extract_value(&mut self, agg_val: &'ll Value, idx: u64) -> &'ll Value { + fn extract_value(&mut self, agg_val: Value<'ll>, idx: u64) -> Value<'ll> { assert_eq!(idx as c_uint as u64, idx); unsafe { llvm::LLVMBuildExtractValue(self.llbuilder(), agg_val, idx as c_uint, UNNAMED) } } - fn insert_value(&mut self, agg_val: &'ll Value, elt: &'ll Value, idx: u64) -> &'ll Value { + fn insert_value(&mut self, agg_val: Value<'ll>, elt: Value<'ll>, idx: u64) -> Value<'ll> { assert_eq!(idx as c_uint as u64, idx); unsafe { llvm::LLVMBuildInsertValue(self.llbuilder(), agg_val, elt, idx as c_uint, UNNAMED) } } - fn set_personality_fn(&mut self, personality: &'ll Value) { + fn set_personality_fn(&mut self, personality: Value<'ll>) { unsafe { llvm::LLVMSetPersonalityFn(self.llfn(), personality); } } - fn cleanup_landing_pad(&mut self, pers_fn: &'ll Value) -> (&'ll Value, &'ll Value) { + fn cleanup_landing_pad(&mut self, pers_fn: Value<'ll>) -> (Value<'ll>, Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let landing_pad = self.landing_pad(ty, pers_fn, 0); unsafe { @@ -1270,13 +1270,13 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { (self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1)) } - fn filter_landing_pad(&mut self, pers_fn: &'ll Value) { + fn filter_landing_pad(&mut self, pers_fn: Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let landing_pad = self.landing_pad(ty, pers_fn, 1); self.add_clause(landing_pad, self.const_array(self.type_ptr(), &[])); } - fn resume(&mut self, exn0: &'ll Value, exn1: &'ll Value) { + fn resume(&mut self, exn0: Value<'ll>, exn1: Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let mut exn = self.const_poison(ty); exn = self.insert_value(exn, exn0, 0); @@ -1286,7 +1286,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> { + fn cleanup_pad(&mut self, parent: Option>, args: &[Value<'ll>]) -> Funclet<'ll> { let ret = unsafe { llvm::LLVMBuildCleanupPad( self.llbuilder(), @@ -1306,7 +1306,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> { + fn catch_pad(&mut self, parent: Value<'ll>, args: &[Value<'ll>]) -> Funclet<'ll> { let ret = unsafe { llvm::LLVMBuildCatchPad( self.llbuilder(), @@ -1321,10 +1321,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn catch_switch( &mut self, - parent: Option<&'ll Value>, + parent: Option>, unwind: Option<&'ll BasicBlock>, handlers: &[&'ll BasicBlock], - ) -> &'ll Value { + ) -> Value<'ll> { let ret = unsafe { llvm::LLVMBuildCatchSwitch( self.llbuilder(), @@ -1343,20 +1343,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { ret } - fn get_funclet_cleanuppad(&self, funclet: &Funclet<'ll>) -> &'ll Value { + fn get_funclet_cleanuppad(&self, funclet: &Funclet<'ll>) -> Value<'ll> { funclet.cleanuppad() } // Atomic Operations fn atomic_cmpxchg( &mut self, - dst: &'ll Value, - cmp: &'ll Value, - src: &'ll Value, + dst: Value<'ll>, + cmp: Value<'ll>, + src: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, failure_order: rustc_middle::ty::AtomicOrdering, weak: bool, - ) -> (&'ll Value, &'ll Value) { + ) -> (Value<'ll>, Value<'ll>) { unsafe { let value = llvm::LLVMBuildAtomicCmpXchg( self.llbuilder(), @@ -1377,11 +1377,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_rmw( &mut self, op: rustc_codegen_ssa::common::AtomicRmwBinOp, - dst: &'ll Value, - src: &'ll Value, + dst: Value<'ll>, + src: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, ret_ptr: bool, - ) -> &'ll Value { + ) -> Value<'ll> { // FIXME: If `ret_ptr` is true and `src` is not a pointer, we *should* tell LLVM that the // LHS is a pointer and the operation should be provenance-preserving, but LLVM does not // currently support that (https://github.com/llvm/llvm-project/issues/120837). @@ -1420,15 +1420,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn set_invariant_load(&mut self, load: &'ll Value) { + fn set_invariant_load(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_invariant_load, &[]); } - fn lifetime_start(&mut self, ptr: &'ll Value, size: Size) { + fn lifetime_start(&mut self, ptr: Value<'ll>, size: Size) { self.call_lifetime_intrinsic("llvm.lifetime.start", ptr, size); } - fn lifetime_end(&mut self, ptr: &'ll Value, size: Size) { + fn lifetime_end(&mut self, ptr: Value<'ll>, size: Size) { self.call_lifetime_intrinsic("llvm.lifetime.end", ptr, size); } @@ -1437,12 +1437,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llty: Type<'ll>, caller_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - return_slot: ReturnSlot<&'ll Value>, - args: &[&'ll Value], + llfn: Value<'ll>, + return_slot: ReturnSlot>, + args: &[Value<'ll>], funclet: Option<&Funclet<'ll>>, callee_instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { // If this function returns indirectly (`PassMode::Indirect`), // the `return_slot` should be the first argument. let args = match return_slot { @@ -1480,7 +1480,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.llbuilder(), llty, llfn, - args.as_ptr() as *const &llvm::Value, + args.as_ptr(), args.len() as c_uint, bundles.as_ptr(), bundles.len() as c_uint, @@ -1524,11 +1524,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn zext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn zext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildZExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) { + fn apply_attrs_to_cleanup_callsite(&mut self, llret: Value<'ll>) { // Cleanup is always the cold path. let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx); attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]); @@ -1536,7 +1536,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> { - fn get_static(&mut self, def_id: DefId) -> &'ll Value { + fn get_static(&mut self, def_id: DefId) -> Value<'ll> { // Forward to the `get_static` method of `CodegenCx` let global = self.cx().get_static(def_id); if self.cx().tcx.is_thread_local_static(def_id) { @@ -1552,7 +1552,7 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> { } impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { - pub(crate) fn llfn(&self) -> &'ll Value { + pub(crate) fn llfn(&self) -> Value<'ll> { unsafe { llvm::LLVMGetBasicBlockParent(self.llbb()) } } @@ -1561,7 +1561,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { span: rustc_span::Span, expected_ty: String, check_kind: u8, - ) -> &'ll Value { + ) -> Value<'ll> { let cx = self.cx(); let tcx = cx.tcx; @@ -1610,24 +1610,24 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { - fn align_metadata(&mut self, load: &'ll Value, align: Align) { + fn align_metadata(&mut self, load: Value<'ll>, align: Align) { let md = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))]; self.set_metadata_node(load, llvm::MD_align, &md); } - fn noundef_metadata(&mut self, load: &'ll Value) { + fn noundef_metadata(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_noundef, &[]); } - pub(crate) fn set_unpredictable(&mut self, inst: &'ll Value) { + pub(crate) fn set_unpredictable(&mut self, inst: Value<'ll>) { self.set_metadata_node(inst, llvm::MD_unpredictable, &[]); } fn write_operand_repeatedly_optimized( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { let zero = self.const_usize(0); let count = self.const_usize(count); @@ -1657,9 +1657,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn write_operand_repeatedly_unoptimized( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { let zero = self.const_usize(0); let count = self.const_usize(count); @@ -1691,13 +1691,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { *self = Self::build(self.cx, next_bb); } - pub(crate) fn minimum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + pub(crate) fn minimum_number_nsz(&mut self, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let call = self.call_intrinsic("llvm.minimumnum", &[self.val_ty(lhs)], &[lhs, rhs]); unsafe { llvm::LLVMRustSetNoSignedZeros(call) }; call } - pub(crate) fn maximum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + pub(crate) fn maximum_number_nsz(&mut self, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let call = self.call_intrinsic("llvm.maximumnum", &[self.val_ty(lhs)], &[lhs, rhs]); unsafe { llvm::LLVMRustSetNoSignedZeros(call) }; call @@ -1705,33 +1705,33 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { pub(crate) fn insert_element( &mut self, - vec: &'ll Value, - elt: &'ll Value, - idx: &'ll Value, - ) -> &'ll Value { + vec: Value<'ll>, + elt: Value<'ll>, + idx: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildInsertElement(self.llbuilder(), vec, elt, idx, UNNAMED) } } pub(crate) fn shuffle_vector( &mut self, - v1: &'ll Value, - v2: &'ll Value, - mask: &'ll Value, - ) -> &'ll Value { + v1: Value<'ll>, + v2: Value<'ll>, + mask: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildShuffleVector(self.llbuilder(), v1, v2, mask, UNNAMED) } } - pub(crate) fn vector_reduce_fadd(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_fadd(&mut self, acc: Value<'ll>, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]) } - pub(crate) fn vector_reduce_fmul(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_fmul(&mut self, acc: Value<'ll>, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]) } pub(crate) fn vector_reduce_fadd_reassoc( &mut self, - acc: &'ll Value, - src: &'ll Value, - ) -> &'ll Value { + acc: Value<'ll>, + src: Value<'ll>, + ) -> Value<'ll> { unsafe { let instr = self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]); @@ -1741,9 +1741,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } pub(crate) fn vector_reduce_fmul_reassoc( &mut self, - acc: &'ll Value, - src: &'ll Value, - ) -> &'ll Value { + acc: Value<'ll>, + src: Value<'ll>, + ) -> Value<'ll> { unsafe { let instr = self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]); @@ -1751,29 +1751,29 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { instr } } - pub(crate) fn vector_reduce_add(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_add(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_mul(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_mul(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_and(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_and(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_or(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_or(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_xor(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_xor(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_min(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value { + pub(crate) fn vector_reduce_min(&mut self, src: Value<'ll>, is_signed: bool) -> Value<'ll> { self.call_intrinsic( if is_signed { "llvm.vector.reduce.smin" } else { "llvm.vector.reduce.umin" }, &[self.val_ty(src)], &[src], ) } - pub(crate) fn vector_reduce_max(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value { + pub(crate) fn vector_reduce_max(&mut self, src: Value<'ll>, is_signed: bool) -> Value<'ll> { self.call_intrinsic( if is_signed { "llvm.vector.reduce.smax" } else { "llvm.vector.reduce.umax" }, &[self.val_ty(src)], @@ -1782,7 +1782,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } } impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { - pub(crate) fn add_clause(&mut self, landing_pad: &'ll Value, clause: &'ll Value) { + pub(crate) fn add_clause(&mut self, landing_pad: Value<'ll>, clause: Value<'ll>) { unsafe { llvm::LLVMAddClause(landing_pad, clause); } @@ -1792,7 +1792,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { &mut self, funclet: &Funclet<'ll>, unwind: &'ll BasicBlock, - ) -> &'ll Value { + ) -> Value<'ll> { let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder(), funclet.cleanuppad(), unwind) }; ret.expect("LLVM does not have support for catchret") @@ -1802,9 +1802,9 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { &mut self, typ: &str, fn_ty: Type<'ll>, - llfn: &'ll Value, - args: &'b [&'ll Value], - ) -> Cow<'b, [&'ll Value]> { + llfn: Value<'ll>, + args: &'b [Value<'ll>], + ) -> Cow<'b, [Value<'ll>]> { assert!( self.cx.type_kind(fn_ty) == TypeKind::Function, "builder::{typ} not passed a function, but {fn_ty:?}" @@ -1839,7 +1839,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { Cow::Owned(casted_args) } - pub(crate) fn va_arg(&mut self, list: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn va_arg(&mut self, list: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildVAArg(self.llbuilder(), list, ty, UNNAMED) } } } @@ -1849,14 +1849,14 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { &mut self, base_name: impl Into>, type_params: &[Type<'ll>], - args: &[&'ll Value], - ) -> &'ll Value { + args: &[Value<'ll>], + ) -> Value<'ll> { let (ty, f) = self.cx.get_intrinsic(base_name.into(), type_params); // No LLVM intrinsic returns its data indirectly (via `sret`). self.call(ty, None, None, f, ReturnSlot::Direct, args, None, None) } - fn call_lifetime_intrinsic(&mut self, intrinsic: &'static str, ptr: &'ll Value, size: Size) { + fn call_lifetime_intrinsic(&mut self, intrinsic: &'static str, ptr: Value<'ll>, size: Size) { let size = size.bytes(); if size == 0 { return; @@ -1876,9 +1876,9 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { pub(crate) fn phi( &mut self, ty: Type<'ll>, - vals: &[&'ll Value], + vals: &[Value<'ll>], bbs: &[&'ll BasicBlock], - ) -> &'ll Value { + ) -> Value<'ll> { assert_eq!(vals.len(), bbs.len()); let phi = unsafe { llvm::LLVMBuildPhi(self.llbuilder(), ty, UNNAMED) }; unsafe { @@ -1887,7 +1887,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - fn add_incoming_to_phi(&mut self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) { + fn add_incoming_to_phi(&mut self, phi: Value<'ll>, val: Value<'ll>, bb: &'ll BasicBlock) { unsafe { llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint); } @@ -1897,9 +1897,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { pub(crate) fn landing_pad( &mut self, ty: Type<'ll>, - pers_fn: &'ll Value, + pers_fn: Value<'ll>, num_clauses: usize, - ) -> &'ll Value { + ) -> Value<'ll> { // Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while, // LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The // personality lives on the parent function anyway. @@ -1914,13 +1914,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { llty: Type<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - args: &[&'ll Value], + llfn: Value<'ll>, + args: &[Value<'ll>], default_dest: &'ll BasicBlock, indirect_dest: &[&'ll BasicBlock], funclet: Option<&Funclet<'ll>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("invoke {:?} with args ({:?})", llfn, args); let args = self.check_call("callbr", llty, llfn, args); @@ -1971,7 +1971,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, instance: Option>, - llfn: &'ll Value, + llfn: Value<'ll>, ) { let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) }; if self.tcx.sess.is_sanitizer_cfi_enabled() @@ -2107,7 +2107,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, instance: Option>, - llfn: &'ll Value, + llfn: Value<'ll>, ) -> Option> { let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) }; let kcfi_bundle = if self.tcx.sess.is_sanitizer_kcfi_enabled() @@ -2151,7 +2151,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { // Emits pauth operand bundle. fn ptrauth_operand_bundle( &mut self, - llfn: &'ll Value, + llfn: Value<'ll>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, ) -> Option> { let schema = self.sess().pointer_authentication_functions()?; @@ -2186,10 +2186,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { #[instrument(level = "debug", skip(self))] pub(crate) fn instrprof_increment( &mut self, - fn_name: &'ll Value, - hash: &'ll Value, - num_counters: &'ll Value, - index: &'ll Value, + fn_name: Value<'ll>, + hash: Value<'ll>, + num_counters: Value<'ll>, + index: Value<'ll>, ) { self.call_intrinsic("llvm.instrprof.increment", &[], &[fn_name, hash, num_counters, index]); } diff --git a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs index 4c83f0a64248f..72ce05213fb7d 100644 --- a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs +++ b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs @@ -136,9 +136,9 @@ pub(crate) fn adjust_activity_to_abi<'tcx>( fn match_args_from_caller_to_enzyme<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, width: u32, - args: &mut Vec<&'ll Value>, + args: &mut Vec>, inputs: &[DiffActivity], - outer_args: &[&'ll Value], + outer_args: &[Value<'ll>], ) { debug!("matching autodiff arguments"); // We now handle the issue that Rust level arguments not always match the llvm-ir level @@ -166,7 +166,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( let diff_activity = inputs[activity_pos as usize]; // Duplicated arguments received a shadow argument, into which enzyme will write the // gradient. - let (activity, duplicated): (&Value, bool) = match diff_activity { + let (activity, duplicated): (Value<'ll>, bool) = match diff_activity { DiffActivity::None => panic!("not a valid input activity"), DiffActivity::Const => (global_const, false), DiffActivity::Active => (global_out, false), @@ -284,15 +284,15 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( // cover some assumptions of enzyme/autodiff, which could lead to UB otherwise. pub(crate) fn generate_enzyme_call<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - fn_to_diff: &'ll Value, + fn_to_diff: Value<'ll>, outer_name: &str, ret_ty: Type<'ll>, - fn_args: &[&'ll Value], + fn_args: &[Value<'ll>], attrs: &RustcAutodiff, dest_layout: ty::layout::TyAndLayout<'tcx>, - dest_place: Option>, + dest_place: Option>>, fnc_tree: FncTree, -) -> IntrinsicResult<'tcx, &'ll Value> { +) -> IntrinsicResult<'tcx, Value<'ll>> { let cx: &SimpleCx<'ll> = &bx.scx; // We have to pick the name depending on whether we want forward or reverse mode autodiff. let mut ad_name: String = match attrs.mode { @@ -346,7 +346,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>( enzyme_ty, ); - let num_args = llvm::LLVMCountParams(&fn_to_diff); + let num_args = llvm::LLVMCountParams(fn_to_diff); let mut args = Vec::with_capacity(num_args as usize + 1); args.push(fn_to_diff); diff --git a/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs b/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs index 46526b6bce421..f26c02fe394eb 100644 --- a/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs +++ b/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs @@ -21,18 +21,18 @@ use crate::llvm::{self, Linkage, Type, TypeKind, Value}; // LLVM kernel-independent globals required for offloading pub(crate) struct OffloadGlobals<'ll> { - pub launcher_fn: &'ll llvm::Value, + pub launcher_fn: llvm::Value<'ll>, pub launcher_ty: llvm::Type<'ll>, pub kernel_args_ty: KernelArgsTy, pub offload_entry_ty: llvm::Type<'ll>, - pub begin_mapper: &'ll llvm::Value, - pub end_mapper: &'ll llvm::Value, + pub begin_mapper: llvm::Value<'ll>, + pub end_mapper: llvm::Value<'ll>, pub mapper_fn_ty: llvm::Type<'ll>, - pub ident_t_global: &'ll llvm::Value, + pub ident_t_global: llvm::Value<'ll>, } impl<'ll> OffloadGlobals<'ll> { @@ -61,22 +61,22 @@ impl<'ll> OffloadGlobals<'ll> { } pub(crate) struct OffloadKernelDims<'ll> { - num_workgroups: &'ll Value, - threads_per_block: &'ll Value, - workgroup_dims: [&'ll Value; 3], - thread_dims: [&'ll Value; 3], + num_workgroups: Value<'ll>, + threads_per_block: Value<'ll>, + workgroup_dims: [Value<'ll>; 3], + thread_dims: [Value<'ll>; 3], } impl<'ll> OffloadKernelDims<'ll> { pub(crate) fn from_operands<'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - workgroup_op: &OperandRef<'tcx, &'ll llvm::Value>, - thread_op: &OperandRef<'tcx, &'ll llvm::Value>, + workgroup_op: &OperandRef<'tcx, llvm::Value<'ll>>, + thread_op: &OperandRef<'tcx, llvm::Value<'ll>>, ) -> Self { fn load_3_u32<'ll>( builder: &mut Builder<'_, 'll, '_>, - place: PlaceValue<&'ll Value>, - ) -> [&'ll Value; 3] { + place: PlaceValue>, + ) -> [Value<'ll>; 3] { let ty = builder.type_i32(); let size = 4; let v0 = builder.load(ty, place.llval, place.align); @@ -100,8 +100,8 @@ impl<'ll> OffloadKernelDims<'ll> { fn mul_dim3<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - [x, y, z]: [&'ll Value; 3], - ) -> &'ll Value { + [x, y, z]: [Value<'ll>; 3], + ) -> Value<'ll> { let xy = builder.mul(x, y); builder.mul(xy, z) } @@ -120,7 +120,7 @@ impl<'ll> OffloadKernelDims<'ll> { // ; Function Attrs: nounwind // declare i32 @__tgt_target_kernel(ptr, i64, i32, i32, ptr, ptr) #2 -fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (&'ll llvm::Value, llvm::Type<'ll>) { +fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (llvm::Value<'ll>, llvm::Type<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32(); @@ -137,7 +137,7 @@ fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (&'ll llvm::Value, llvm::T /// declaration together with its type. pub(crate) fn declare_omp_get_num_devices<'ll>( cx: &CodegenCx<'ll, '_>, -) -> (&'ll llvm::Value, llvm::Type<'ll>) { +) -> (llvm::Value<'ll>, llvm::Type<'ll>) { let ti32 = cx.type_i32(); let tgt_fn_ty = cx.type_func(&[], ti32); let name = "omp_get_num_devices"; @@ -152,7 +152,7 @@ pub(crate) fn declare_omp_get_num_devices<'ll>( // @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8 // FIXME(offload): @0 should include the file name (e.g. lib.rs) in which the function to be // offloaded was defined. -pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll llvm::Value { +pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> llvm::Value<'ll> { let unknown_txt = ";unknown;unknown;0;0;;"; let c_entry_name = CString::new(unknown_txt).unwrap(); let c_val = c_entry_name.as_bytes_with_nul(); @@ -205,9 +205,9 @@ impl TgtOffloadEntry { fn new<'ll>( cx: &CodegenCx<'ll, '_>, - region_id: &'ll Value, - llglobal: &'ll Value, - ) -> [&'ll Value; 9] { + region_id: Value<'ll>, + llglobal: Value<'ll>, + ) -> [Value<'ll>; 9] { let reserved = cx.get_const_i64(0); let version = cx.get_const_i16(1); let kind = cx.get_const_i16(1); @@ -291,12 +291,12 @@ impl KernelArgsTy { fn new<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, num_args: u64, - memtransfer_types: &'ll Value, - geps: [&'ll Value; 3], - workgroup_dims: [&'ll Value; 3], - thread_dims: [&'ll Value; 3], - dyn_cache: &'ll Value, - ) -> [&'ll Value; Self::FIELD_COUNT] { + memtransfer_types: Value<'ll>, + geps: [Value<'ll>; 3], + workgroup_dims: [Value<'ll>; 3], + thread_dims: [Value<'ll>; 3], + dyn_cache: Value<'ll>, + ) -> [Value<'ll>; Self::FIELD_COUNT] { [ // Version cx.get_const_i32(KernelArgsTy::OFFLOAD_VERSION), @@ -336,16 +336,16 @@ impl KernelArgsTy { // Contains LLVM values needed to manage offloading for a single kernel. #[derive(Copy, Clone)] pub(crate) struct OffloadKernelGlobals<'ll> { - pub offload_sizes: &'ll llvm::Value, - pub memtransfer_begin: &'ll llvm::Value, - pub memtransfer_kernel: &'ll llvm::Value, - pub memtransfer_end: &'ll llvm::Value, - pub region_id: &'ll llvm::Value, + pub offload_sizes: llvm::Value<'ll>, + pub memtransfer_begin: llvm::Value<'ll>, + pub memtransfer_kernel: llvm::Value<'ll>, + pub memtransfer_end: llvm::Value<'ll>, + pub region_id: llvm::Value<'ll>, } fn gen_tgt_data_mappers<'ll>( cx: &CodegenCx<'ll, '_>, -) -> (&'ll llvm::Value, &'ll llvm::Value, &'ll llvm::Value, llvm::Type<'ll>) { +) -> (llvm::Value<'ll>, llvm::Value<'ll>, llvm::Value<'ll>, llvm::Type<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32(); @@ -367,7 +367,7 @@ fn gen_tgt_data_mappers<'ll>( (begin_mapper_decl, update_mapper_decl, end_mapper_decl, mapper_fn_ty) } -fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> &'ll llvm::Value { +fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> llvm::Value<'ll> { let ti64 = cx.type_i64(); let mut size_val = Vec::with_capacity(vals.len()); for &val in vals { @@ -380,9 +380,9 @@ fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> &' pub(crate) fn add_unnamed_global<'ll>( cx: &SimpleCx<'ll>, name: &str, - initializer: &'ll llvm::Value, + initializer: llvm::Value<'ll>, l: Linkage, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { let llglobal = add_global(cx, name, initializer, l); llvm::LLVMSetUnnamedAddress(llglobal, llvm::UnnamedAddr::Global); llglobal @@ -391,11 +391,11 @@ pub(crate) fn add_unnamed_global<'ll>( pub(crate) fn add_global<'ll>( cx: &SimpleCx<'ll>, name: &str, - initializer: &'ll llvm::Value, + initializer: llvm::Value<'ll>, l: Linkage, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { let c_name = CString::new(name).unwrap(); - let llglobal: &'ll llvm::Value = llvm::add_global(cx.llmod, cx.val_ty(initializer), &c_name); + let llglobal: llvm::Value<'ll> = llvm::add_global(cx.llmod, cx.val_ty(initializer), &c_name); llvm::set_global_constant(llglobal, true); llvm::set_linkage(llglobal, l); llvm::set_initializer(llglobal, initializer); @@ -513,7 +513,7 @@ fn declare_offload_fn<'ll>( cx: &CodegenCx<'ll, '_>, name: &str, ty: llvm::Type<'ll>, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { crate::declare::declare_simple_fn( cx, name, @@ -538,10 +538,10 @@ pub(crate) fn scalar_width<'ll>(cx: &SimpleCx<'ll>, ty: Type<'ll>) -> u64 { fn get_runtime_size<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - args: &[&'ll Value], + args: &[Value<'ll>], index: usize, meta: &OffloadMetadata, -) -> &'ll Value { +) -> Value<'ll> { match meta.payload_size { OffloadSize::Slice { element_size } => { let length_idx = index + 1; @@ -574,23 +574,23 @@ fn get_runtime_size<'ll, 'tcx>( pub(crate) fn gen_call_handling<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, offload_data: &OffloadKernelGlobals<'ll>, - args: &[&'ll Value], + args: &[Value<'ll>], types: &[Type<'ll>], metadata: &[OffloadMetadata], offload_globals: &OffloadGlobals<'ll>, offload_dims: &OffloadKernelDims<'ll>, - dyn_cache: &'ll Value, - device_id: &'ll Value, + dyn_cache: Value<'ll>, + device_id: Value<'ll>, ) { let cx = builder.cx; - let OffloadKernelGlobals { + let &OffloadKernelGlobals { offload_sizes, memtransfer_begin, memtransfer_kernel, memtransfer_end, region_id, } = offload_data; - let OffloadKernelDims { num_workgroups, threads_per_block, workgroup_dims, thread_dims } = + let &OffloadKernelDims { num_workgroups, threads_per_block, workgroup_dims, thread_dims } = offload_dims; let has_dynamic = metadata.iter().any(|m| !matches!(m.payload_size, OffloadSize::Static(_))); @@ -696,22 +696,22 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>( // offload_{baseptrs,ptrs,sizes}. We will probably improve this along with our gpu frontend pr. fn get_geps<'ll, 'tcx>( _builder: &mut Builder<'_, 'll, 'tcx>, - a1: &'ll Value, - a2: &'ll Value, - a4: &'ll Value, + a1: Value<'ll>, + a2: Value<'ll>, + a4: Value<'ll>, _is_dynamic: bool, - ) -> [&'ll Value; 3] { + ) -> [Value<'ll>; 3] { [a1, a2, a4] } fn generate_mapper_call<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - geps: [&'ll Value; 3], - o_type: &'ll Value, - fn_to_call: &'ll Value, + geps: [Value<'ll>; 3], + o_type: Value<'ll>, + fn_to_call: Value<'ll>, fn_ty: Type<'ll>, num_args: u64, - s_ident_t: &'ll Value, + s_ident_t: Value<'ll>, ) { let cx = builder.cx; let nullptr = cx.const_null(cx.type_ptr()); @@ -739,8 +739,8 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>( num_args, memtransfer_kernel, geps, - *workgroup_dims, - *thread_dims, + workgroup_dims, + thread_dims, dyn_cache, ); diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index df18b029b02c0..743324fab7f98 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -16,7 +16,7 @@ use crate::llvm::{self, Value}; /// Codegens a reference to a fn/method item, monomorphizing and /// inlining as it goes. -pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value { +pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> Value<'ll> { let tcx = cx.tcx(); debug!("get_fn(instance={:?})", instance); diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index b2ce873154bcc..7e47267a29f8b 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -28,9 +28,9 @@ use crate::llvm::{ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>( cx: &CodegenCx<'ll, '_>, instance: Instance<'tcx>, - llfn: &'ll llvm::Value, + llfn: llvm::Value<'ll>, schema: &PointerAuthSchema, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { if cx.tcx.sess.pointer_authentication_functions().is_none() { return llfn; } @@ -106,16 +106,16 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>( /// annotated with which landing pad it's a part of. This is accomplished via /// the `OperandBundleDef` value created for MSVC landing pads. pub(crate) struct Funclet<'ll> { - cleanuppad: &'ll Value, + cleanuppad: Value<'ll>, operand: llvm::OperandBundleBox<'ll>, } impl<'ll> Funclet<'ll> { - pub(crate) fn new(cleanuppad: &'ll Value) -> Self { + pub(crate) fn new(cleanuppad: Value<'ll>) -> Self { Funclet { cleanuppad, operand: llvm::OperandBundleBox::new("funclet", &[cleanuppad]) } } - pub(crate) fn cleanuppad(&self) -> &'ll Value { + pub(crate) fn cleanuppad(&self) -> Value<'ll> { self.cleanuppad } @@ -126,11 +126,11 @@ impl<'ll> Funclet<'ll> { impl<'ll, CX: Borrow>> BackendTypes for GenericCx<'ll, CX> { // FIXME(eddyb) replace this with a `Function` "subclass" of `Value`. - type Function = &'ll Value; + type Function = Value<'ll>; type BasicBlock = &'ll BasicBlock; type Funclet = Funclet<'ll>; - type Value = &'ll Value; + type Value = Value<'ll>; type Type = Type<'ll>; type FunctionSignature = Type<'ll>; @@ -140,20 +140,20 @@ impl<'ll, CX: Borrow>> BackendTypes for GenericCx<'ll, CX> { } impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { - pub(crate) fn const_array(&self, ty: Type<'ll>, elts: &[&'ll Value]) -> &'ll Value { + pub(crate) fn const_array(&self, ty: Type<'ll>, elts: &[Value<'ll>]) -> Value<'ll> { let len = u64::try_from(elts.len()).expect("LLVMConstArray2 elements len overflow"); unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) } } - pub(crate) fn const_bytes(&self, bytes: &[u8]) -> &'ll Value { + pub(crate) fn const_bytes(&self, bytes: &[u8]) -> Value<'ll> { bytes_in_context(self.llcx(), bytes) } - pub(crate) fn null_terminate_const_bytes(&self, bytes: &[u8]) -> &'ll Value { + pub(crate) fn null_terminate_const_bytes(&self, bytes: &[u8]) -> Value<'ll> { null_terminate_bytes_in_context(self.llcx(), bytes) } - pub(crate) fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value { + pub(crate) fn const_get_elt(&self, v: Value<'ll>, idx: u64) -> Value<'ll> { unsafe { let idx = c_uint::try_from(idx).expect("LLVMGetAggregateElement index overflow"); let r = llvm::LLVMGetAggregateElement(v, idx).unwrap(); @@ -164,11 +164,11 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } } - pub(crate) fn const_null(&self, t: Type<'ll>) -> &'ll Value { + pub(crate) fn const_null(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstNull(t) } } - pub(crate) fn const_struct(&self, elts: &[&'ll Value], packed: bool) -> &'ll Value { + pub(crate) fn const_struct(&self, elts: &[Value<'ll>], packed: bool) -> Value<'ll> { struct_in_context(self.llcx(), elts, packed) } } @@ -179,7 +179,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { global_alloc: GlobalAlloc<'tcx>, need_symbol_name: bool, schema: Option<&PointerAuthSchema>, - ) -> Result<&'ll Value, u64> { + ) -> Result, u64> { let alloc = match global_alloc { GlobalAlloc::Function { instance, .. } => { return Ok(self.get_fn_addr(instance, schema)); @@ -262,39 +262,39 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { - fn const_null(&self, t: Type<'ll>) -> &'ll Value { + fn const_null(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstNull(t) } } - fn const_undef(&self, t: Type<'ll>) -> &'ll Value { + fn const_undef(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMGetUndef(t) } } - fn const_poison(&self, t: Type<'ll>) -> &'ll Value { + fn const_poison(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMGetPoison(t) } } - fn const_bool(&self, val: bool) -> &'ll Value { + fn const_bool(&self, val: bool) -> Value<'ll> { self.const_uint(self.type_i1(), val as u64) } - fn const_i8(&self, i: i8) -> &'ll Value { + fn const_i8(&self, i: i8) -> Value<'ll> { self.const_int(self.type_i8(), i as i64) } - fn const_i16(&self, i: i16) -> &'ll Value { + fn const_i16(&self, i: i16) -> Value<'ll> { self.const_int(self.type_i16(), i as i64) } - fn const_i32(&self, i: i32) -> &'ll Value { + fn const_i32(&self, i: i32) -> Value<'ll> { self.const_int(self.type_i32(), i as i64) } - fn const_i64(&self, i: i64) -> &'ll Value { + fn const_i64(&self, i: i64) -> Value<'ll> { self.const_int(self.type_i64(), i as i64) } - fn const_int(&self, t: Type<'ll>, i: i64) -> &'ll Value { + fn const_int(&self, t: Type<'ll>, i: i64) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_int" @@ -302,23 +302,23 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMConstInt(t, i as u64, TRUE) } } - fn const_u8(&self, i: u8) -> &'ll Value { + fn const_u8(&self, i: u8) -> Value<'ll> { self.const_uint(self.type_i8(), i as u64) } - fn const_u32(&self, i: u32) -> &'ll Value { + fn const_u32(&self, i: u32) -> Value<'ll> { self.const_uint(self.type_i32(), i as u64) } - fn const_u64(&self, i: u64) -> &'ll Value { + fn const_u64(&self, i: u64) -> Value<'ll> { self.const_uint(self.type_i64(), i) } - fn const_u128(&self, i: u128) -> &'ll Value { + fn const_u128(&self, i: u128) -> Value<'ll> { self.const_uint_big(self.type_i128(), i) } - fn const_usize(&self, i: u64) -> &'ll Value { + fn const_usize(&self, i: u64) -> Value<'ll> { let bit_size = self.data_layout().pointer_size().bits(); if bit_size < 64 { // make sure it doesn't overflow @@ -328,7 +328,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { self.const_uint(self.isize_ty, i) } - fn const_uint(&self, t: Type<'ll>, i: u64) -> &'ll Value { + fn const_uint(&self, t: Type<'ll>, i: u64) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_uint" @@ -336,7 +336,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMConstInt(t, i, FALSE) } } - fn const_uint_big(&self, t: Type<'ll>, u: u128) -> &'ll Value { + fn const_uint_big(&self, t: Type<'ll>, u: u128) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_uint_big" @@ -347,11 +347,11 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { } } - fn const_real(&self, t: Type<'ll>, val: f64) -> &'ll Value { + fn const_real(&self, t: Type<'ll>, val: f64) -> Value<'ll> { unsafe { llvm::LLVMConstReal(t, val) } } - fn const_str(&self, s: &str) -> (&'ll Value, &'ll Value) { + fn const_str(&self, s: &str) -> (Value<'ll>, Value<'ll>) { let mut const_str_cache = self.const_str_cache.borrow_mut(); let str_global = const_str_cache.get(s).copied().unwrap_or_else(|| { let sc = self.const_bytes(s.as_bytes()); @@ -374,16 +374,16 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { (str_global, self.const_usize(len as u64)) } - fn const_struct(&self, elts: &[&'ll Value], packed: bool) -> &'ll Value { + fn const_struct(&self, elts: &[Value<'ll>], packed: bool) -> Value<'ll> { struct_in_context(self.llcx, elts, packed) } - fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value { + fn const_vector(&self, elts: &[Value<'ll>]) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstVector elements len overflow"); unsafe { llvm::LLVMConstVector(elts.as_ptr(), len) } } - fn const_to_opt_uint(&self, v: &'ll Value) -> Option { + fn const_to_opt_uint(&self, v: Value<'ll>) -> Option { try_as_const_integral(v).and_then(|v| unsafe { let mut i = 0u64; let success = llvm::LLVMRustConstIntGetZExtValue(v, &mut i); @@ -391,7 +391,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { }) } - fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option { + fn const_to_opt_u128(&self, v: Value<'ll>, sign_ext: bool) -> Option { try_as_const_integral(v).and_then(|v| unsafe { let (mut lo, mut hi) = (0u64, 0u64); let success = llvm::LLVMRustConstInt128Get(v, sign_ext, &mut hi, &mut lo); @@ -405,7 +405,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { layout: abi::Scalar, llty: Type<'ll>, schema: Option<&PointerAuthSchema>, - ) -> &'ll Value { + ) -> Value<'ll> { let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() }; match cv { Scalar::Int(int) => { @@ -464,31 +464,31 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { } /// Get the [LLVM type][Type] of a [`Value`]. -pub(crate) fn val_ty<'ll>(v: &'ll Value) -> Type<'ll> { +pub(crate) fn val_ty<'ll>(v: Value<'ll>) -> Type<'ll> { unsafe { llvm::LLVMTypeOf(v) } } -pub(crate) fn bytes_in_context<'ll>(llcx: llvm::Context<'ll>, bytes: &[u8]) -> &'ll Value { +pub(crate) fn bytes_in_context<'ll>(llcx: llvm::Context<'ll>, bytes: &[u8]) -> Value<'ll> { unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), TRUE) } } pub(crate) fn null_terminate_bytes_in_context<'ll>( llcx: llvm::Context<'ll>, bytes: &[u8], -) -> &'ll Value { +) -> Value<'ll> { unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), FALSE) } } -pub(crate) fn named_struct<'ll>(ty: Type<'ll>, elts: &[&'ll Value]) -> &'ll Value { +pub(crate) fn named_struct<'ll>(ty: Type<'ll>, elts: &[Value<'ll>]) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstStructInContext elements len overflow"); unsafe { llvm::LLVMConstNamedStruct(ty, elts.as_ptr(), len) } } fn struct_in_context<'ll>( llcx: llvm::Context<'ll>, - elts: &[&'ll Value], + elts: &[Value<'ll>], packed: bool, -) -> &'ll Value { +) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstStructInContext elements len overflow"); unsafe { llvm::LLVMConstStructInContext(llcx, elts.as_ptr(), len, packed.to_llvm_bool()) } } @@ -498,7 +498,7 @@ fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 { ((hi as u128) << 64) | (lo as u128) } -fn try_as_const_integral(v: &Value) -> Option<&ConstantInt> { +fn try_as_const_integral<'ll>(v: Value<'ll>) -> Option<&'ll ConstantInt> { unsafe { llvm::LLVMIsAConstantInt(v) } } diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 33d48642812e6..4952fdc732e9f 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -40,7 +40,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( alloc: &Allocation, is_static: IsStatic, is_init_fini: IsInitOrFini, -) -> &'ll Value { +) -> Value<'ll> { // We expect that callers of const_alloc_to_llvm will instead directly codegen a pointer or // integer for any &ZST where the ZST is a constant (i.e. not a static). We should never be // producing empty LLVM allocations as they're just adding noise to binaries and forcing less @@ -59,7 +59,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, so `range` // must be within the bounds of `alloc` and not contain or overlap a pointer provenance. fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>( - llvals: &mut Vec<&'ll Value>, + llvals: &mut Vec>, cx: &'a CodegenCx<'ll, 'b>, alloc: &'a Allocation, range: Range, @@ -157,7 +157,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( fn codegen_static_initializer<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, def_id: DefId, -) -> Result<(&'ll Value, ConstAllocation<'tcx>), ErrorHandled> { +) -> Result<(Value<'ll>, ConstAllocation<'tcx>), ErrorHandled> { let alloc = cx.tcx.eval_static_initializer(def_id)?; let attrs = cx.tcx.codegen_fn_attrs(def_id); // FIXME(jchlanda) Decide if this could be better served by `ctor` crate. See the discussion @@ -176,7 +176,7 @@ fn codegen_static_initializer<'ll, 'tcx>( Ok((const_alloc_to_llvm(cx, alloc.inner(), IsStatic::Yes, is_in_init_fini), alloc)) } -fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align: Align) { +fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: Value<'ll>, mut align: Align) { // The target may require greater alignment for globals than the type does. // Note: GCC and Clang also allow `__attribute__((aligned))` on variables, // which can force it to be smaller. Rust doesn't support this yet. @@ -192,7 +192,7 @@ fn check_and_apply_linkage<'ll, 'tcx>( llty: Type<'ll>, sym: &str, def_id: DefId, -) -> &'ll Value { +) -> Value<'ll> { if let Some(linkage) = attrs.import_linkage { debug!("get_static: sym={} linkage={:?}", sym, linkage); @@ -281,11 +281,11 @@ fn check_and_apply_linkage<'ll, 'tcx>( } impl<'ll> CodegenCx<'ll, '_> { - pub(crate) fn const_bitcast(&self, val: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn const_bitcast(&self, val: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstBitCast(val, ty) } } - pub(crate) fn const_pointercast(&self, val: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn const_pointercast(&self, val: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstPointerCast(val, ty) } } @@ -295,10 +295,10 @@ impl<'ll> CodegenCx<'ll, '_> { /// Fails if a symbol with the given name already exists. pub(crate) fn static_addr_of_mut( &self, - cv: &'ll Value, + cv: Value<'ll>, align: Align, kind: Option<&str>, - ) -> &'ll Value { + ) -> Value<'ll> { let gv = match kind { Some(kind) if !self.tcx.sess.fewer_names() => { let name = self.generate_local_symbol_name(kind); @@ -323,10 +323,10 @@ impl<'ll> CodegenCx<'ll, '_> { /// The returned global variable is a pointer in the default address space for globals. pub(crate) fn static_addr_of_impl( &self, - cv: &'ll Value, + cv: Value<'ll>, align: Align, kind: Option<&str>, - ) -> &'ll Value { + ) -> Value<'ll> { if let Some(&gv) = self.const_globals.borrow().get(&cv) { unsafe { // Upgrade the alignment in cases where the same constant is used with different @@ -346,7 +346,7 @@ impl<'ll> CodegenCx<'ll, '_> { } #[instrument(level = "debug", skip(self))] - pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value { + pub(crate) fn get_static(&self, def_id: DefId) -> Value<'ll> { let instance = Instance::mono(self.tcx, def_id); trace!(?instance); @@ -364,7 +364,7 @@ impl<'ll> CodegenCx<'ll, '_> { } #[instrument(level = "debug", skip(self, llty))] - fn get_static_inner(&self, def_id: DefId, llty: Type<'ll>) -> &'ll Value { + fn get_static_inner(&self, def_id: DefId, llty: Type<'ll>) -> Value<'ll> { let instance = Instance::mono(self.tcx, def_id); if let Some(&g) = self.instances.borrow().get(&instance) { trace!("used cached value"); @@ -474,7 +474,7 @@ impl<'ll> CodegenCx<'ll, '_> { fn codegen_static_item(&mut self, def_id: DefId) { assert!( llvm::LLVMGetInitializer( - self.instances.borrow().get(&Instance::mono(self.tcx, def_id)).unwrap() + self.instances.borrow().get(&Instance::mono(self.tcx, def_id)).copied().unwrap() ) .is_none() ); @@ -678,20 +678,20 @@ impl<'ll> CodegenCx<'ll, '_> { } /// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr. - pub(crate) fn add_used_global(&mut self, global: &'ll Value) { + pub(crate) fn add_used_global(&mut self, global: Value<'ll>) { self.used_statics.push(global); } /// Add a global value to a list to be stored in the `llvm.compiler.used` variable, /// an array of ptr. - pub(crate) fn add_compiler_used_global(&self, global: &'ll Value) { + pub(crate) fn add_compiler_used_global(&self, global: Value<'ll>) { self.compiler_used_statics.borrow_mut().push(global); } // We do our best here to match what Clang does when compiling Objective-C natively. // See Clang's `CGObjCCommonMac::CreateCStringLiteral`: // https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/clang/lib/CodeGen/CGObjCMac.cpp#L4134 - fn define_objc_classname(&self, classname: &str) -> &'ll Value { + fn define_objc_classname(&self, classname: &str) -> Value<'ll> { assert_eq!(self.objc_abi_version(), 1); let llval = self.null_terminate_const_bytes(classname.as_bytes()); @@ -742,7 +742,7 @@ impl<'ll> CodegenCx<'ll, '_> { // deduplicate references within a CGU, but we need a reference definition in each referencing // CGU. All attempts at using external references to a single reference definition result in // linker errors. - fn get_objc_classref(&self, classname: Symbol) -> &'ll Value { + fn get_objc_classref(&self, classname: Symbol) -> Value<'ll> { let mut classrefs = self.objc_classrefs.borrow_mut(); if let Some(classref) = classrefs.get(&classname).copied() { return classref; @@ -800,7 +800,7 @@ impl<'ll> CodegenCx<'ll, '_> { // Newer versions of Apple Clang generate calls to `@"objc_msgSend$methname"` selector stub // functions. We don't currently do that. The code we generate is closer to what Apple Clang // generates with the `-fno-objc-msgsend-selector-stubs` option. - fn get_objc_selref(&self, methname: Symbol) -> &'ll Value { + fn get_objc_selref(&self, methname: Symbol) -> Value<'ll> { let mut selrefs = self.objc_selrefs.borrow_mut(); if let Some(selref) = selrefs.get(&methname).copied() { return selref; @@ -911,7 +911,7 @@ impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> { /// /// The pointer will always be in the default address space. If global variables default to a /// different address space, an addrspacecast is inserted. - fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> &'ll Value { + fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> Value<'ll> { // FIXME: should we cache `const_alloc_to_llvm` to avoid repeating this for the // same `ConstAllocation`? let cv = const_alloc_to_llvm(self, alloc.inner(), IsStatic::No, IsInitOrFini::No); diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 2156ac783758a..56f0be1a89e2a 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -101,30 +101,30 @@ pub(crate) struct FullCx<'ll, 'tcx> { pub codegen_unit: &'tcx CodegenUnit<'tcx>, /// Cache instances of monomorphic and polymorphic items - pub instances: RefCell, &'ll Value>>, + pub instances: RefCell, Value<'ll>>>, /// Cache instances of intrinsics - pub intrinsic_instances: RefCell, &'ll Value>>, + pub intrinsic_instances: RefCell, Value<'ll>>>, /// Cache generated vtables - pub vtables: RefCell, Option>), &'ll Value>>, + pub vtables: RefCell, Option>), Value<'ll>>>, /// Cache of constant strings, - pub const_str_cache: RefCell>, + pub const_str_cache: RefCell>>, /// Cache of emitted const globals (value -> global) - pub const_globals: RefCell>, + pub const_globals: RefCell, Value<'ll>>>, /// List of globals for static variables which need to be passed to the /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete. /// (We have to make sure we don't invalidate any Values referring /// to constants.) - pub statics_to_rauw: RefCell>, + pub statics_to_rauw: RefCell, Value<'ll>)>>, /// Statics that will be placed in the llvm.used variable /// See for details - pub used_statics: Vec<&'ll Value>, + pub used_statics: Vec>, /// Statics that will be placed in the llvm.compiler.used variable /// See for details - pub compiler_used_statics: RefCell>, + pub compiler_used_statics: RefCell>>, /// Mapping of non-scalar types to llvm types. pub type_lowering: RefCell, Option), Type<'ll>>>, @@ -137,11 +137,11 @@ pub(crate) struct FullCx<'ll, 'tcx> { pub dbg_cx: Option>, pub sanitizer_ignorelist: Option, - eh_personality: Cell>, - pub rust_try_fn: Cell, &'ll Value)>>, + eh_personality: Cell>>, + pub rust_try_fn: Cell, Value<'ll>)>>, intrinsics: - RefCell, SmallVec<[Type<'ll>; 2]>), (Type<'ll>, &'ll Value)>>, + RefCell, SmallVec<[Type<'ll>; 2]>), (Type<'ll>, Value<'ll>)>>, /// A counter that is used for generating local symbol names local_gen_sym_counter: Cell, @@ -153,16 +153,16 @@ pub(crate) struct FullCx<'ll, 'tcx> { /// different type and clear the symbol name of the original global. /// `global_asm!` needs to be able to find this new global so that it can /// compute the correct mangled symbol name to insert into the asm. - pub renamed_statics: RefCell>, + pub renamed_statics: RefCell>>, /// Cached Objective-C class type pub objc_class_t: Cell>>, /// Cache of Objective-C class references - pub objc_classrefs: RefCell>, + pub objc_classrefs: RefCell>>, /// Cache of Objective-C selector references - pub objc_selrefs: RefCell>, + pub objc_selrefs: RefCell>>, /// Globals shared by the offloading runtime pub offload_globals: RefCell>>, @@ -739,7 +739,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { ) } - pub(crate) fn statics_to_rauw(&self) -> &RefCell> { + pub(crate) fn statics_to_rauw(&self) -> &RefCell, Value<'ll>)>> { &self.statics_to_rauw } @@ -750,7 +750,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled") } - pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) { + pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[Value<'ll>]) { let array = self.const_array(self.type_ptr(), values); let g = llvm::add_global(self.llmod, self.val_ty(array), name); @@ -875,10 +875,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } } impl<'ll> SimpleCx<'ll> { - pub(crate) fn get_type_of_global(&self, val: &'ll Value) -> Type<'ll> { + pub(crate) fn get_type_of_global(&self, val: Value<'ll>) -> Type<'ll> { unsafe { llvm::LLVMGlobalGetValueType(val) } } - pub(crate) fn val_ty(&self, v: &'ll Value) -> Type<'ll> { + pub(crate) fn val_ty(&self, v: Value<'ll>) -> Type<'ll> { common::val_ty(v) } } @@ -894,27 +894,27 @@ impl<'ll> SimpleCx<'ll> { } impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { - pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> &'ll Value { + pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> Value<'ll> { llvm::LLVMMetadataAsValue(self.llcx(), metadata) } - pub(crate) fn get_const_int(&self, ty: Type<'ll>, val: u64) -> &'ll Value { + pub(crate) fn get_const_int(&self, ty: Type<'ll>, val: u64) -> Value<'ll> { unsafe { llvm::LLVMConstInt(ty, val, llvm::FALSE) } } - pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i64(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i64(), n) } - pub(crate) fn get_const_i32(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i32(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i32(), n) } - pub(crate) fn get_const_i16(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i16(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i16(), n) } - pub(crate) fn get_const_i8(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i8(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i8(), n) } @@ -926,7 +926,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { unsafe { llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr(), name.len()) } } - pub(crate) fn get_functions(&self) -> Vec<&'ll Value> { + pub(crate) fn get_functions(&self) -> Vec> { let mut functions = vec![]; let mut func = unsafe { llvm::LLVMGetFirstFunction(self.llmod()) }; while let Some(f) = func { @@ -940,7 +940,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn vtables( &self, - ) -> &RefCell, Option>), &'ll Value>> { + ) -> &RefCell, Option>), Value<'ll>>> { &self.vtables } @@ -948,12 +948,12 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { &self, ty: Ty<'tcx>, poly_trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable); } - fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value { + fn get_fn(&self, instance: Instance<'tcx>) -> Value<'ll> { get_fn(self, instance) } @@ -961,7 +961,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { &self, instance: Instance<'tcx>, pointer_auth_schema: Option<&PointerAuthSchema>, - ) -> &'ll Value { + ) -> Value<'ll> { // When pointer authentication metadata is provided, `get_fn_addr` will // attempt to sign the pointer using LLVM's `ConstPtrAuth` constant // expression. @@ -981,7 +981,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } - fn eh_personality(&self) -> &'ll Value { + fn eh_personality(&self) -> Value<'ll> { // The exception handling personality function. // // If our compilation unit has the `eh_personality` lang item somewhere @@ -1058,20 +1058,20 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { self.tcx.sess } - fn set_frame_pointer_type(&self, llfn: &'ll Value) { + fn set_frame_pointer_type(&self, llfn: Value<'ll>) { if let Some(attr) = attributes::frame_pointer_type_attr(self, self.sess()) { attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[attr]); } } - fn apply_target_cpu_attr(&self, llfn: &'ll Value) { + fn apply_target_cpu_attr(&self, llfn: Value<'ll>) { let mut attrs = SmallVec::<[_; 2]>::new(); attrs.push(attributes::target_cpu_attr(self, self.sess())); attrs.extend(attributes::tune_cpu_attr(self, self.sess())); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); } - fn apply_default_optimisation_attrs(&self, llfn: &'ll Value) { + fn apply_default_optimisation_attrs(&self, llfn: Value<'ll>) { let attrs = attributes::default_optimisation_attrs(self, self.sess()); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); } @@ -1108,7 +1108,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: Cow<'static, str>, type_params: &[Type<'ll>], - ) -> (Type<'ll>, &'ll Value) { + ) -> (Type<'ll>, Value<'ll>) { *self .intrinsics .borrow_mut() @@ -1122,7 +1122,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: &str, type_params: &[Type<'ll>], - ) -> (Type<'ll>, &'ll Value) { + ) -> (Type<'ll>, Value<'ll>) { match base_name { // This isn't an "LLVM intrinsic", but LLVM's optimization passes // recognize it like one (including turning it into `bcmp` sometimes) @@ -1204,12 +1204,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } /// A wrapper for [`llvm::LLVMSetMetadata`], but it takes `Metadata` as a parameter instead of `Value`. - pub(crate) fn set_metadata<'a>( - &self, - val: &'a Value, - kind_id: MetadataKindId, - md: &'ll Metadata, - ) { + pub(crate) fn set_metadata(&self, val: Value<'ll>, kind_id: MetadataKindId, md: &'ll Metadata) { let node = self.get_metadata_value(md); llvm::LLVMSetMetadata(val, kind_id, node); } @@ -1220,7 +1215,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMSetMetadata` (to set that node as metadata of `kind_id` for `instruction`) pub(crate) fn set_metadata_node( &self, - instruction: &'ll Value, + instruction: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) -> &'ll Metadata { @@ -1249,7 +1244,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_add_metadata_node( &self, - global: &'ll Value, + global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) { @@ -1262,7 +1257,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMGlobalSetMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_set_metadata_node( &self, - global: &'ll Value, + global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) { diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs index 92abe16eb4109..4467204abc7cd 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs @@ -27,9 +27,9 @@ pub(crate) fn covfun_section_name<'ll>(llmod: llvm::Module<'ll>) -> CString { } pub(crate) fn create_pgo_func_name_var<'ll>( - llfn: &'ll llvm::Value, + llfn: llvm::Value<'ll>, mangled_fn_name: &str, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { unsafe { llvm::LLVMRustCoverageCreatePGOFuncNameVar( llfn, diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index b33e6dbb3409a..e677b5fa62250 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -26,7 +26,7 @@ pub(crate) struct CguCoverageContext<'ll, 'tcx> { /// emitting covfun records. Every covfun record holds a hash of its /// symbol name, and `llvm-cov` will exit fatally if it can't resolve that /// hash back to an entry in the binary's `__llvm_prf_names` linker section. - pub(crate) pgo_func_name_var_map: RefCell, &'ll llvm::Value>>, + pub(crate) pgo_func_name_var_map: RefCell, llvm::Value<'ll>>>, covfun_section_name: OnceCell, } @@ -71,10 +71,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// /// This has the side-effect of causing coverage codegen to consider this /// function "used", making it eligible to emit an associated covfun record. - fn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> &'ll llvm::Value { + fn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> llvm::Value<'ll> { debug!("getting pgo_func_name_var for instance={:?}", instance); let mut pgo_func_name_var_map = self.coverage_cx().pgo_func_name_var_map.borrow_mut(); - pgo_func_name_var_map.entry(instance).or_insert_with(|| { + *pgo_func_name_var_map.entry(instance).or_insert_with(|| { let llfn = self.get_fn(instance); let mangled_fn_name: &str = self.tcx.symbol_name(instance).name; llvm_cov::create_pgo_func_name_var(llfn, mangled_fn_name) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs b/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs index 9237c8be87473..c6cd73673de67 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs @@ -52,7 +52,7 @@ pub(crate) trait DIBuilderExt<'ll> { line_number: c_uint, ty: &'ll llvm::Metadata, is_local_to_unit: bool, - val: &'ll llvm::Value, + val: llvm::Value<'ll>, decl: Option<&'ll llvm::Metadata>, align: Option, ) -> &'ll llvm::Metadata { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index 7665c824f1c48..c5c535ff26e59 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -28,7 +28,7 @@ pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Buil /// section. pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( cx: &CodegenCx<'ll, '_>, -) -> &'ll Value { +) -> Value<'ll> { let c_section_var_name = c"__rustc_debug_gdb_scripts_section__"; let section_var_name = c_section_var_name.to_str().unwrap(); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 585d0b20420a4..ff0b924f5701e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1513,7 +1513,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>( pub(crate) fn build_global_var_di_node<'ll>( cx: &CodegenCx<'ll, '_>, def_id: DefId, - global: &'ll Value, + global: Value<'ll>, ) { if cx.dbg_cx.is_none() { return; @@ -1722,7 +1722,7 @@ fn build_unsafe_binder_type_di_node<'ll, 'tcx>( /// global variable (which is simply returned), or an addrspacecast constant expression. /// If the given value is an addrspacecast, the cast is removed and the global variable behind /// the cast is returned. -fn find_vtable_behind_cast<'ll>(vtable: &'ll Value) -> &'ll Value { +fn find_vtable_behind_cast<'ll>(vtable: Value<'ll>) -> Value<'ll> { // The vtable is a global variable, which may be behind an addrspacecast. unsafe { if let Some(c) = llvm::LLVMIsAConstantExpr(vtable) { @@ -1738,7 +1738,7 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { // FIXME(flip1995): The virtual function elimination optimization only works with full LTO in // LLVM at the moment. @@ -1803,7 +1803,7 @@ pub(crate) fn create_vtable_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, poly_trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { if cx.dbg_cx.is_none() { return; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index fe7f38fb195bc..100037d55b79d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -982,7 +982,7 @@ fn create_static_member_type<'ll>( line_number: c_uint, ty: &'ll llvm::Metadata, flags: DIFlags, - value: Option<&'ll llvm::Value>, + value: Option>, align: Align, ) -> &'ll llvm::Metadata { unsafe { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 5fe5ee3e92fea..687d3bbd6b780 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -130,7 +130,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { &mut self, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, - maybe_definition_llfn: Option<&'ll Value>, + maybe_definition_llfn: Option>, ) -> &'ll DIScope { let tcx = self.tcx; @@ -590,7 +590,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { gdb::insert_reference_to_gdb_debug_scripts_section_global(self) } - fn set_var_name(&mut self, value: &'ll Value, name: &str) { + fn set_var_name(&mut self, value: Value<'ll>, name: &str) { // Avoid wasting time if LLVM value names aren't even enabled. if self.sess().fewer_names() { return; diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index a0c9faf47a1a5..e6fef61285c6b 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -40,7 +40,7 @@ pub(crate) fn declare_simple_fn<'ll>( unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility, ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty); let llfn = unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_ptr(), name.len(), ty) }; @@ -62,7 +62,7 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>( unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility, ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty); let llfn = declare_simple_fn(cx, name, callconv, unnamed, visibility, ty); @@ -91,7 +91,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// /// If there’s a value with the same name already declared, the function will /// return its Value instead. - pub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> Value<'ll> { debug!("declare_global(name={:?})", name); unsafe { llvm::LLVMRustGetOrInsertGlobal((**self).borrow().llmod, name.as_ptr(), name.len(), ty) @@ -107,7 +107,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { name: &str, ty: Type<'ll>, addr_space: AddressSpace, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("declare_global(name={name:?}, addrspace={addr_space:?})"); unsafe { llvm::LLVMRustGetOrInsertGlobalInAddrspace( @@ -134,7 +134,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name: &str, unnamed: llvm::UnnamedAddr, fn_type: Type<'ll>, - ) -> &'ll Value { + ) -> Value<'ll> { // Visibility should always be default for declarations, otherwise the linker may report an // error. declare_raw_fn(self, name, llvm::CCallConv, unnamed, Visibility::Default, fn_type) @@ -153,7 +153,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr, fn_type: Type<'ll>, - ) -> &'ll Value { + ) -> Value<'ll> { let visibility = Visibility::from_generic(self.tcx.sess.default_visibility()); declare_raw_fn(self, name, callconv, unnamed, visibility, fn_type) } @@ -167,7 +167,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi); // Some calling conventions (such as fastcall and vectorcall) decorate // symbols with the argument byte count. Use rustc's original argument @@ -256,7 +256,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// return `None` if the name already has a definition associated with it. In that /// case an error should be reported to the user, because it usually happens due /// to user’s fault (e.g., misuse of `#[no_mangle]` or `#[export_name]` attributes). - pub(crate) fn define_global(&self, name: &str, ty: Type<'ll>) -> Option<&'ll Value> { + pub(crate) fn define_global(&self, name: &str, ty: Type<'ll>) -> Option> { if self.get_defined_value(name).is_some() { None } else { @@ -265,14 +265,14 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } /// Gets declared value by name. - pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> { + pub(crate) fn get_declared_value(&self, name: &str) -> Option> { debug!("get_declared_value(name={:?})", name); unsafe { llvm::LLVMRustGetNamedValue(self.llmod(), name.as_ptr(), name.len()) } } /// Gets defined or externally defined (AvailableExternally linkage) value by /// name. - pub(crate) fn get_defined_value(&self, name: &str) -> Option<&'ll Value> { + pub(crate) fn get_defined_value(&self, name: &str) -> Option> { self.get_declared_value(name).and_then(|val| { let declaration = llvm::is_declaration(val); if !declaration { Some(val) } else { None } diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index d163b7304fbdd..c499cfc811a22 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -51,8 +51,8 @@ use crate::va_arg::emit_va_arg; fn call_simple_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: Symbol, - args: &[OperandRef<'tcx, &'ll Value>], -) -> Option<&'ll Value> { + args: &[OperandRef<'tcx, Value<'ll>>], +) -> Option> { let llvm_version = crate::llvm_util::get_version(); // minimum/maximum were broken for f64/f128 before // . @@ -85,7 +85,7 @@ fn call_simple_intrinsic<'ll, 'tcx>( } impl<'ll, 'tcx> Builder<'_, 'll, 'tcx> { - fn black_box(&mut self, result: PlaceRef<'tcx, &'ll Value>, span: Span) { + fn black_box(&mut self, result: PlaceRef<'tcx, Value<'ll>>, span: Span) { let result_val_span = [result.val.llval]; // We need to "use" the argument in some way LLVM can't introspect, and on // targets that support it we can typically leverage inline assembly to do @@ -124,11 +124,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn codegen_intrinsic_call( &mut self, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], result_layout: ty::layout::TyAndLayout<'tcx>, - result_place: Option>, + result_place: Option>>, span: Span, - ) -> IntrinsicResult<'tcx, &'ll Value> { + ) -> IntrinsicResult<'tcx, Value<'ll>> { let tcx = self.tcx; let llvm_version = crate::llvm_util::get_version(); @@ -209,7 +209,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { assert_eq!(args[1].layout, args[2].layout); let select = |bx: &mut Self, true_val, false_val| { let result = bx.select(cond, true_val, false_val); - bx.set_unpredictable(&result); + bx.set_unpredictable(result); result }; match (args[1].val, args[2].val) { @@ -952,13 +952,13 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { debug!("call intrinsic {:?} with args ({:?})", instance, llargs); for (dest_ty, arg) in iter::zip(self.func_params_types(fn_ty), &mut llargs) { - let src_ty = self.val_ty(arg); + let src_ty = self.val_ty(*arg); assert!( can_autocast(self, src_ty, dest_ty), "Cannot match `{dest_ty:?}` (expected) with {src_ty:?} (found) in `{fn_ptr:?}" ); - *arg = autocast(self, arg, src_ty, dest_ty); + *arg = autocast(self, *arg, src_ty, dest_ty); } let llret = unsafe { @@ -1013,7 +1013,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn type_checked_load( &mut self, - llvtable: &'ll Value, + llvtable: Value<'ll>, vtable_byte_offset: u64, typeid: &[u8], ) -> Self::Value { @@ -1028,7 +1028,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { self.extract_value(type_checked_load, 0) } - fn va_start(&mut self, va_list: &'ll Value) { + fn va_start(&mut self, va_list: Value<'ll>) { self.call_intrinsic("llvm.va_start", &[self.val_ty(va_list)], &[va_list]); } @@ -1119,10 +1119,10 @@ fn can_autocast<'ll>(cx: &CodegenCx<'ll, '_>, rust_ty: Type<'ll>, llvm_ty: Type< fn autocast<'ll>( bx: &mut Builder<'_, 'll, '_>, - val: &'ll Value, + val: Value<'ll>, src_ty: Type<'ll>, dest_ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { if src_ty == dest_ty { return val; } @@ -1202,7 +1202,7 @@ fn intrinsic_fn<'ll, 'tcx>( rust_return_ty: Type<'ll>, rust_argument_tys: Vec>, instance: ty::Instance<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let tcx = bx.tcx; let rust_fn_ty = bx.type_func(&rust_argument_tys, rust_return_ty); @@ -1301,10 +1301,10 @@ fn intrinsic_fn<'ll, 'tcx>( fn catch_unwind_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { if !bx.sess().panic_strategy().unwinds() { let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void()); bx.call(try_func_ty, None, None, try_func, ReturnSlot::Direct, &[data], None, None); @@ -1329,10 +1329,10 @@ fn catch_unwind_intrinsic<'ll, 'tcx>( // as the old ones are still more optimized. fn codegen_msvc_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { bx.set_personality_fn(bx.eh_personality()); @@ -1515,10 +1515,10 @@ fn codegen_msvc_try<'ll, 'tcx>( // WASM's definition of the `rust_try` function. fn codegen_wasm_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { bx.set_personality_fn(bx.eh_personality()); @@ -1626,10 +1626,10 @@ fn codegen_wasm_try<'ll, 'tcx>( // the right personality function. fn codegen_gnu_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { // Codegens the shims described above: // @@ -1705,7 +1705,7 @@ fn gen_fn<'a, 'll, 'tcx>( name: &str, rust_fn_sig: ty::PolyFnSig<'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>), -) -> (Type<'ll>, &'ll Value) { +) -> (Type<'ll>, Value<'ll>) { let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty()); let llty = fn_abi.llvm_type(cx); let llfn = cx.declare_fn(name, fn_abi, None); @@ -1727,7 +1727,7 @@ fn gen_fn<'a, 'll, 'tcx>( fn get_rust_try_fn<'a, 'll, 'tcx>( cx: &'a CodegenCx<'ll, 'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>), -) -> (Type<'ll>, &'ll Value) { +) -> (Type<'ll>, Value<'ll>) { if let Some(llfn) = cx.rust_try_fn.get() { return llfn; } @@ -1769,9 +1769,9 @@ fn get_rust_try_fn<'a, 'll, 'tcx>( fn codegen_retag_inner<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: &'static str, - ptr: &'ll Value, - info: &RetagInfo<&'ll Value>, -) -> &'ll Value { + ptr: Value<'ll>, + info: &RetagInfo>, +) -> Value<'ll> { let size = bx.const_usize(info.size.bytes()); let perms = bx.const_u8(info.flags.bits()); @@ -1787,10 +1787,10 @@ fn codegen_retag_inner<'ll, 'tcx>( fn codegen_autodiff<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], result_layout: ty::layout::TyAndLayout<'tcx>, - result_place: Option>, -) -> IntrinsicResult<'tcx, &'ll Value> { + result_place: Option>>, +) -> IntrinsicResult<'tcx, Value<'ll>> { let tcx = bx.tcx; if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) { let _ = tcx.dcx().emit_err(AutoDiffWithoutEnable); @@ -1877,7 +1877,7 @@ fn codegen_offload<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, tcx: TyCtxt<'tcx>, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], ) { let cx = bx.cx; let fn_args = instance.args; @@ -1949,16 +1949,16 @@ fn codegen_offload<'ll, 'tcx>( &metadata, offload_globals, &offload_dims, - &dyn_cache, - &device_id, + dyn_cache, + device_id, ); } fn get_args_from_tuple<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - tuple_op: OperandRef<'tcx, &'ll Value>, + tuple_op: OperandRef<'tcx, Value<'ll>>, fn_instance: Instance<'tcx>, -) -> Vec<&'ll Value> { +) -> Vec> { let cx = bx.cx; let fn_abi = cx.fn_abi_of_instance(fn_instance, ty::List::empty()); @@ -2011,11 +2011,11 @@ fn generic_simd_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: Symbol, fn_args: GenericArgs<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], ret_ty: Ty<'tcx>, llret_ty: Type<'ll>, span: Span, -) -> Result<&'ll Value, ErrorGuaranteed> { +) -> Result, ErrorGuaranteed> { macro_rules! return_error { ($diag: expr) => {{ let err = bx.sess().dcx().emit_err($diag); @@ -2087,10 +2087,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>( /// efficiently converted to an all ones / all zeroes mask by comparing whether each element is negative. fn vector_mask_to_bitmask<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, - i_xn: &'ll Value, + i_xn: Value<'ll>, in_elem_bitwidth: u64, in_len: u64, - ) -> &'ll Value { + ) -> Value<'ll> { // Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position. let shift_idx = bx.cx.const_int(bx.type_ix(in_elem_bitwidth), (in_elem_bitwidth - 1) as _); let shift_indices = vec![shift_idx; in_len as _]; @@ -2463,8 +2463,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>( in_len: u64, bx: &mut Builder<'_, 'll, 'tcx>, span: Span, - args: &[OperandRef<'tcx, &'ll Value>], - ) -> Result<&'ll Value, ErrorGuaranteed> { + args: &[OperandRef<'tcx, Value<'ll>>], + ) -> Result, ErrorGuaranteed> { macro_rules! return_error { ($diag: expr) => {{ let err = bx.sess().dcx().emit_err($diag); diff --git a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs index 978a718cda590..8060308b5d34e 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs @@ -23,7 +23,7 @@ pub(crate) struct OptimizationDiagnostic<'ll> { pub kind: OptimizationDiagnosticKind, pub pass_name: String, #[expect(dead_code)] - pub function: &'ll Value, + pub function: Value<'ll>, pub line: c_uint, pub column: c_uint, pub filename: String, diff --git a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs index 549cf5be70387..46edf657a4d24 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs @@ -36,53 +36,60 @@ pub(crate) struct TypeTree { #[link(name = "llvm-wrapper", kind = "static")] unsafe extern "C" { // Enzyme - pub(crate) safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool; - pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value); - pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>; - pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>; - pub(crate) fn LLVMRustEraseInstFromParent(V: &Value); - pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value; - pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool; - pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool; + pub(crate) safe fn LLVMRustHasMetadata<'ll>(I: Value<'ll>, KindID: MetadataKindId) -> bool; + pub(crate) fn LLVMRustEraseInstUntilInclusive<'ll>(BB: &'ll BasicBlock, I: Value<'ll>); + pub(crate) fn LLVMRustGetLastInstruction<'ll>(BB: &'ll BasicBlock) -> Option>; + pub(crate) fn LLVMRustDIGetInstMetadata<'ll>(I: Value<'ll>) -> Option<&'ll Metadata>; + pub(crate) fn LLVMRustEraseInstFromParent<'ll>(V: Value<'ll>); + pub(crate) fn LLVMRustGetTerminator<'ll>(B: &'ll BasicBlock) -> Value<'ll>; + pub(crate) fn LLVMRustVerifyFunction<'ll>( + V: Value<'ll>, + action: LLVMRustVerifierFailureAction, + ) -> Bool; + pub(crate) fn LLVMRustHasAttributeAtIndex<'ll>( + V: Value<'ll>, + i: c_uint, + Kind: AttributeKind, + ) -> bool; pub(crate) fn LLVMRustGetArrayNumElements<'ll>(Ty: Type<'ll>) -> u64; - pub(crate) fn LLVMRustHasFnAttribute( - F: &Value, + pub(crate) fn LLVMRustHasFnAttribute<'ll>( + F: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: libc::size_t, ) -> bool; - pub(crate) fn LLVMRustRemoveFnAttribute( - F: &Value, + pub(crate) fn LLVMRustRemoveFnAttribute<'ll>( + F: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: libc::size_t, ); - pub(crate) fn LLVMGetFirstFunction<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>; - pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex( - Fn: &Value, + pub(crate) fn LLVMGetFirstFunction<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextFunction<'ll>(Fn: Value<'ll>) -> Option>; + pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex<'ll>( + Fn: Value<'ll>, index: c_uint, kind: AttributeKind, ); - pub(crate) fn LLVMRustPositionBefore<'a>(B: &'a Builder<'_>, I: &'a Value); - pub(crate) fn LLVMRustPositionAfter<'a>(B: &'a Builder<'_>, I: &'a Value); - pub(crate) fn LLVMRustGetFunctionCall( - F: &Value, + pub(crate) fn LLVMRustPositionBefore<'ll>(B: &Builder<'ll>, I: Value<'ll>); + pub(crate) fn LLVMRustPositionAfter<'ll>(B: &Builder<'ll>, I: Value<'ll>); + pub(crate) fn LLVMRustGetFunctionCall<'ll>( + F: Value<'ll>, name: *const c_char, NameLen: libc::size_t, - ) -> Option<&Value>; + ) -> Option>; - pub(crate) safe fn LLVMRustIsCall(V: &Value) -> bool; + pub(crate) safe fn LLVMRustIsCall<'ll>(V: Value<'ll>) -> bool; } unsafe extern "C" { // Enzyme pub(crate) fn LLVMDumpModule<'ll>(M: Module<'ll>); - pub(crate) fn LLVMDumpValue(V: &Value); - pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint; - pub(crate) fn LLVMGetParams(Fnc: &Value, params: *mut &Value); + pub(crate) fn LLVMDumpValue<'ll>(V: Value<'ll>); + pub(crate) fn LLVMGetFunctionCallConv<'ll>(F: Value<'ll>) -> c_uint; + pub(crate) fn LLVMGetParams<'ll>(Fnc: Value<'ll>, params: *mut Value<'ll>); pub(crate) fn LLVMGetNamedFunction<'ll>( M: Module<'ll>, Name: *const c_char, - ) -> Option<&'ll Value>; + ) -> Option>; } #[repr(C)] diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 11b276f565d4b..c53dfe6fe5d05 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -21,7 +21,7 @@ use bitflags::bitflags; use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t}; pub(crate) use self::branded::{ - Context, ContextRaw, Module, ModuleRaw, Type, wrap_llcx, wrap_llmod, + Context, ContextRaw, Module, ModuleRaw, Type, Value, wrap_llcx, wrap_llmod, }; use super::RustString; use super::debuginfo::{ @@ -707,7 +707,6 @@ struct InvariantOpaque<'a> { // Opaque pointer types unsafe extern "C" { - pub(crate) type Value; pub(crate) type ConstantInt; pub(crate) type Attribute; pub(crate) type Metadata; @@ -929,7 +928,7 @@ unsafe extern "C" { IsAlignStack: llvm::Bool, Dialect: AsmDialect, CanThrow: llvm::Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) safe fn LLVMGetTypeKind<'ll>(Ty: Type<'ll>) -> RawEnum; @@ -992,35 +991,39 @@ unsafe extern "C" { pub(crate) fn LLVMVoidTypeInContext<'ll>(C: Context<'ll>) -> Type<'ll>; // Operations on all values - pub(crate) fn LLVMTypeOf<'ll>(Val: &'ll Value) -> Type<'ll>; - pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char; - pub(crate) fn LLVMSetValueName2( - Val: &Value, + pub(crate) fn LLVMTypeOf<'ll>(Val: Value<'ll>) -> Type<'ll>; + pub(crate) fn LLVMGetValueName2<'ll>(Val: Value<'ll>, Length: *mut size_t) -> *const c_char; + pub(crate) fn LLVMSetValueName2<'ll>( + Val: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, ); - pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value); - pub(crate) safe fn LLVMGetMetadata<'a>( - Val: &'a Value, + pub(crate) fn LLVMReplaceAllUsesWith<'ll>(OldVal: Value<'ll>, NewVal: Value<'ll>); + pub(crate) safe fn LLVMGetMetadata<'ll>( + Val: Value<'ll>, KindID: MetadataKindId, - ) -> Option<&'a Value>; - pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value); - pub(crate) fn LLVMGlobalSetMetadata<'a>( - Val: &'a Value, + ) -> Option>; + pub(crate) safe fn LLVMSetMetadata<'ll>( + Val: Value<'ll>, KindID: MetadataKindId, - Metadata: &'a Metadata, + Node: Value<'ll>, + ); + pub(crate) fn LLVMGlobalSetMetadata<'ll>( + Val: Value<'ll>, + KindID: MetadataKindId, + Metadata: &'ll Metadata, ); pub(crate) fn LLVMGlobalAddMetadata<'ll>( - Global: &'ll Value, + Global: Value<'ll>, Kind: MetadataKindId, MD: &'ll Metadata, ); - pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; + pub(crate) safe fn LLVMValueAsMetadata<'ll>(Node: Value<'ll>) -> &'ll Metadata; // Operations on constants of any type - pub(crate) fn LLVMConstNull<'ll>(Ty: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMGetUndef<'ll>(Ty: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMGetPoison<'ll>(Ty: Type<'ll>) -> &'ll Value; + pub(crate) fn LLVMConstNull<'ll>(Ty: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMGetUndef<'ll>(Ty: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMGetPoison<'ll>(Ty: Type<'ll>) -> Value<'ll>; // Operations on metadata pub(crate) fn LLVMMDStringInContext2<'ll>( @@ -1036,113 +1039,123 @@ unsafe extern "C" { pub(crate) fn LLVMAddNamedMetadataOperand<'ll>( M: Module<'ll>, Name: *const c_char, - Val: &'ll Value, + Val: Value<'ll>, + ); + pub(crate) fn LLVMReplaceMDNodeOperandWith<'ll>( + Val: Value<'ll>, + index: u32, + replacement: &'ll Metadata, ); - pub(crate) fn LLVMReplaceMDNodeOperandWith(Val: &Value, index: u32, replacement: &Metadata); // Operations on scalar constants pub(crate) fn LLVMConstInt<'ll>( IntTy: Type<'ll>, N: c_ulonglong, SignExtend: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstIntOfArbitraryPrecision<'ll>( IntTy: Type<'ll>, Wn: c_uint, Ws: *const u64, - ) -> &'ll Value; - pub(crate) fn LLVMConstReal<'ll>(RealTy: Type<'ll>, N: f64) -> &'ll Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstReal<'ll>(RealTy: Type<'ll>, N: f64) -> Value<'ll>; // Operations on composite constants pub(crate) fn LLVMConstArray2<'ll>( ElementTy: Type<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Length: u64, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMArrayType2<'ll>(ElementType: Type<'ll>, ElementCount: u64) -> Type<'ll>; pub(crate) fn LLVMConstStringInContext2<'ll>( C: Context<'ll>, Str: *const c_uchar, // See "PTR_LEN_STR". Length: size_t, DontNullTerminate: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstStructInContext<'ll>( C: Context<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Count: c_uint, Packed: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstNamedStruct<'ll>( StructTy: Type<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Count: c_uint, - ) -> &'ll Value; - pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstVector<'ll>( + ScalarConstantVals: *const Value<'ll>, + Size: c_uint, + ) -> Value<'ll>; // Constant expressions pub(crate) fn LLVMConstInBoundsGEP2<'ll>( ty: Type<'ll>, - ConstantVal: &'ll Value, - ConstantIndices: *const &'ll Value, + ConstantVal: Value<'ll>, + ConstantIndices: *const Value<'ll>, NumIndices: c_uint, - ) -> &'ll Value; - pub(crate) fn LLVMConstPtrToInt<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMConstIntToPtr<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMConstBitCast<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstPtrToInt<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMConstIntToPtr<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMConstBitCast<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; pub(crate) fn LLVMConstPointerCast<'ll>( - ConstantVal: &'ll Value, + ConstantVal: Value<'ll>, ToType: Type<'ll>, - ) -> &'ll Value; - pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>; - pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode; - pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>; + ) -> Value<'ll>; + pub(crate) fn LLVMGetAggregateElement<'ll>( + ConstantVal: Value<'ll>, + Idx: c_uint, + ) -> Option>; + pub(crate) fn LLVMGetConstOpcode<'ll>(ConstantVal: Value<'ll>) -> Opcode; + pub(crate) fn LLVMIsAConstantExpr<'ll>(Val: Value<'ll>) -> Option>; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool; - pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage); - pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char); - pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility); - pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint; - pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint); - pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass); - pub(crate) fn LLVMGlobalGetValueType<'ll>(Global: &'ll Value) -> Type<'ll>; + pub(crate) fn LLVMIsDeclaration<'ll>(Global: Value<'ll>) -> Bool; + pub(crate) fn LLVMGetLinkage<'ll>(Global: Value<'ll>) -> RawEnum; + pub(crate) fn LLVMSetLinkage<'ll>(Global: Value<'ll>, RustLinkage: Linkage); + pub(crate) fn LLVMSetSection<'ll>(Global: Value<'ll>, Section: *const c_char); + pub(crate) fn LLVMGetVisibility<'ll>(Global: Value<'ll>) -> RawEnum; + pub(crate) fn LLVMSetVisibility<'ll>(Global: Value<'ll>, Viz: Visibility); + pub(crate) fn LLVMGetAlignment<'ll>(Global: Value<'ll>) -> c_uint; + pub(crate) fn LLVMSetAlignment<'ll>(Global: Value<'ll>, Bytes: c_uint); + pub(crate) fn LLVMSetDLLStorageClass<'ll>(V: Value<'ll>, C: DLLStorageClass); + pub(crate) fn LLVMGlobalGetValueType<'ll>(Global: Value<'ll>) -> Type<'ll>; // Operations on global variables - pub(crate) safe fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>; + pub(crate) safe fn LLVMIsAGlobalVariable<'ll>(GlobalVar: Value<'ll>) -> Option>; pub(crate) fn LLVMAddGlobal<'ll>( M: Module<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMGetNamedGlobal<'ll>( M: Module<'ll>, Name: *const c_char, - ) -> Option<&'ll Value>; - pub(crate) fn LLVMGetFirstGlobal<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value); - pub(crate) safe fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value); - pub(crate) safe fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool; - pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode); - pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; - pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); - pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); - pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, kind: TailCallKind); - pub(crate) safe fn LLVMSetExternallyInitialized(GlobalVar: &Value, IsExtInit: Bool); + ) -> Option>; + pub(crate) fn LLVMGetFirstGlobal<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextGlobal<'ll>(GlobalVar: Value<'ll>) -> Option>; + pub(crate) fn LLVMDeleteGlobal<'ll>(GlobalVar: Value<'ll>); + pub(crate) safe fn LLVMGetInitializer<'ll>(GlobalVar: Value<'ll>) -> Option>; + pub(crate) fn LLVMSetInitializer<'ll>(GlobalVar: Value<'ll>, ConstantVal: Value<'ll>); + pub(crate) safe fn LLVMIsThreadLocal<'ll>(GlobalVar: Value<'ll>) -> Bool; + pub(crate) fn LLVMSetThreadLocalMode<'ll>(GlobalVar: Value<'ll>, Mode: ThreadLocalMode); + pub(crate) safe fn LLVMIsGlobalConstant<'ll>(GlobalVar: Value<'ll>) -> Bool; + pub(crate) safe fn LLVMSetGlobalConstant<'ll>(GlobalVar: Value<'ll>, IsConstant: Bool); + pub(crate) safe fn LLVMSetTailCall<'ll>(CallInst: Value<'ll>, IsTailCall: Bool); + pub(crate) safe fn LLVMSetTailCallKind<'ll>(CallInst: Value<'ll>, kind: TailCallKind); + pub(crate) safe fn LLVMSetExternallyInitialized<'ll>(GlobalVar: Value<'ll>, IsExtInit: Bool); // Operations on global aliases pub(crate) fn LLVMAddAlias2<'ll>( M: Module<'ll>, ValueTy: Type<'ll>, AddressSpace: c_uint, - Aliasee: &Value, + Aliasee: Value<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMGetFirstGlobalAlias<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextGlobalAlias(GlobalAlias: &Value) -> Option<&Value>; + ) -> Value<'ll>; + pub(crate) fn LLVMGetFirstGlobalAlias<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextGlobalAlias<'ll>(GlobalAlias: Value<'ll>) -> Option>; // Operations on attributes pub(crate) fn LLVMCreateStringAttribute<'ll>( @@ -1154,19 +1167,19 @@ unsafe extern "C" { ) -> &'ll Attribute; // Operations on functions - pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint); + pub(crate) fn LLVMSetFunctionCallConv<'ll>(Fn: Value<'ll>, CC: c_uint); pub(crate) fn LLVMAddFunction<'ll>( Mod: Module<'ll>, Name: *const c_char, FunctionTy: Type<'ll>, - ) -> &'ll Value; - pub(crate) fn LLVMDeleteFunction(Fn: &Value); + ) -> Value<'ll>; + pub(crate) fn LLVMDeleteFunction<'ll>(Fn: Value<'ll>); pub(crate) fn LLVMGetOrInsertFunction<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, FunctionTy: Type<'ll>, - ) -> &'ll Value; + ) -> Value<'ll>; // Operations about llvm intrinsics pub(crate) fn LLVMLookupIntrinsicID( @@ -1179,43 +1192,43 @@ unsafe extern "C" { ID: NonZero, ParamTypes: *const Type<'ll>, ParamCount: size_t, - ) -> &'ll Value; - pub(crate) fn LLVMRustUpgradeIntrinsicFunction<'a>( - Fn: &'a Value, - NewFn: &mut Option<&'a Value>, + ) -> Value<'ll>; + pub(crate) fn LLVMRustUpgradeIntrinsicFunction<'ll>( + Fn: Value<'ll>, + NewFn: &mut Option>, ) -> bool; pub(crate) fn LLVMRustIsTargetIntrinsic(ID: NonZero) -> bool; // Operations on parameters - pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>; - pub(crate) safe fn LLVMCountParams(Fn: &Value) -> c_uint; - pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value; + pub(crate) fn LLVMIsAArgument<'ll>(Val: Value<'ll>) -> Option>; + pub(crate) safe fn LLVMCountParams<'ll>(Fn: Value<'ll>) -> c_uint; + pub(crate) fn LLVMGetParam<'ll>(Fn: Value<'ll>, Index: c_uint) -> Value<'ll>; // Operations on basic blocks - pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value; + pub(crate) fn LLVMGetBasicBlockParent<'ll>(BB: &'ll BasicBlock) -> Value<'ll>; pub(crate) fn LLVMAppendBasicBlockInContext<'ll>( C: Context<'ll>, - Fn: &'ll Value, + Fn: Value<'ll>, Name: *const c_char, ) -> &'ll BasicBlock; // Operations on instructions - pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>; - pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock; - pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>; + pub(crate) fn LLVMIsAInstruction<'ll>(Val: Value<'ll>) -> Option>; + pub(crate) fn LLVMGetFirstBasicBlock<'ll>(Fn: Value<'ll>) -> &'ll BasicBlock; + pub(crate) fn LLVMGetOperand<'ll>(Val: Value<'ll>, Index: c_uint) -> Option>; // Operations on call sites - pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint); + pub(crate) fn LLVMSetInstructionCallConv<'ll>(Instr: Value<'ll>, CC: c_uint); // Operations on load/store instructions (only) - pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool); - pub(crate) fn LLVMSetOrdering(MemoryAccessInst: &Value, Ordering: AtomicOrdering); + pub(crate) fn LLVMSetVolatile<'ll>(MemoryAccessInst: Value<'ll>, volatile: Bool); + pub(crate) fn LLVMSetOrdering<'ll>(MemoryAccessInst: Value<'ll>, Ordering: AtomicOrdering); // Operations on phi nodes - pub(crate) fn LLVMAddIncoming<'a>( - PhiNode: &'a Value, - IncomingValues: *const &'a Value, - IncomingBlocks: *const &'a BasicBlock, + pub(crate) fn LLVMAddIncoming<'ll>( + PhiNode: Value<'ll>, + IncomingValues: *const Value<'ll>, + IncomingBlocks: *const &'ll BasicBlock, Count: c_uint, ); @@ -1230,455 +1243,465 @@ unsafe extern "C" { pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>; // Terminators - pub(crate) safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value; - pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value; - pub(crate) fn LLVMBuildCondBr<'a>( - B: &Builder<'a>, - If: &'a Value, - Then: &'a BasicBlock, - Else: &'a BasicBlock, - ) -> &'a Value; - pub(crate) fn LLVMBuildSwitch<'a>( - B: &Builder<'a>, - V: &'a Value, - Else: &'a BasicBlock, + pub(crate) safe fn LLVMBuildRetVoid<'ll>(B: &Builder<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildRet<'ll>(B: &Builder<'ll>, V: Value<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildBr<'ll>(B: &Builder<'ll>, Dest: &'ll BasicBlock) -> Value<'ll>; + pub(crate) fn LLVMBuildCondBr<'ll>( + B: &Builder<'ll>, + If: Value<'ll>, + Then: &'ll BasicBlock, + Else: &'ll BasicBlock, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSwitch<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Else: &'ll BasicBlock, NumCases: c_uint, - ) -> &'a Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildLandingPad<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - PersFn: Option<&'ll Value>, + PersFn: Option>, NumClauses: c_uint, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value; + ) -> Value<'ll>; + pub(crate) fn LLVMBuildResume<'ll>(B: &Builder<'ll>, Exn: Value<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildUnreachable<'ll>(B: &Builder<'ll>) -> Value<'ll>; - pub(crate) fn LLVMBuildCleanupPad<'a>( - B: &Builder<'a>, - ParentPad: Option<&'a Value>, - Args: *const &'a Value, + pub(crate) fn LLVMBuildCleanupPad<'ll>( + B: &Builder<'ll>, + ParentPad: Option>, + Args: *const Value<'ll>, NumArgs: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCleanupRet<'a>( - B: &Builder<'a>, - CleanupPad: &'a Value, - BB: Option<&'a BasicBlock>, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchPad<'a>( - B: &Builder<'a>, - ParentPad: &'a Value, - Args: *const &'a Value, + ) -> Option>; + pub(crate) fn LLVMBuildCleanupRet<'ll>( + B: &Builder<'ll>, + CleanupPad: Value<'ll>, + BB: Option<&'ll BasicBlock>, + ) -> Option>; + pub(crate) fn LLVMBuildCatchPad<'ll>( + B: &Builder<'ll>, + ParentPad: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchRet<'a>( - B: &Builder<'a>, - CatchPad: &'a Value, - BB: &'a BasicBlock, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchSwitch<'a>( - Builder: &Builder<'a>, - ParentPad: Option<&'a Value>, - UnwindBB: Option<&'a BasicBlock>, + ) -> Option>; + pub(crate) fn LLVMBuildCatchRet<'ll>( + B: &Builder<'ll>, + CatchPad: Value<'ll>, + BB: &'ll BasicBlock, + ) -> Option>; + pub(crate) fn LLVMBuildCatchSwitch<'ll>( + Builder: &Builder<'ll>, + ParentPad: Option>, + UnwindBB: Option<&'ll BasicBlock>, NumHandlers: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock); - pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value); + ) -> Option>; + pub(crate) fn LLVMAddHandler<'ll>(CatchSwitch: Value<'ll>, Dest: &'ll BasicBlock); + pub(crate) fn LLVMSetPersonalityFn<'ll>(Func: Value<'ll>, Pers: Value<'ll>); // Add a case to the switch instruction - pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock); + pub(crate) fn LLVMAddCase<'ll>(Switch: Value<'ll>, OnVal: Value<'ll>, Dest: &'ll BasicBlock); // Add a clause to the landing pad instruction - pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value); + pub(crate) fn LLVMAddClause<'ll>(LandingPad: Value<'ll>, ClauseVal: Value<'ll>); // Set the cleanup on a landing pad instruction - pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool); + pub(crate) fn LLVMSetCleanup<'ll>(LandingPad: Value<'ll>, Val: Bool); // Arithmetic - pub(crate) fn LLVMBuildAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildUDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExactUDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExactSDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildURem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSRem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFRem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildShl<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildLShr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildAShr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildAnd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildOr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildXor<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; - pub(crate) fn LLVMBuildFNeg<'a>( - B: &Builder<'a>, - V: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; + pub(crate) fn LLVMBuildAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildUDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExactUDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExactSDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildURem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSRem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFRem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildShl<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildLShr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildAShr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildAnd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildOr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildXor<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNeg<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFNeg<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNot<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; // Extra flags on arithmetic - pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool); - pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool); - pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool); + pub(crate) fn LLVMSetIsDisjoint<'ll>(Instr: Value<'ll>, IsDisjoint: Bool); + pub(crate) fn LLVMSetNUW<'ll>(ArithInst: Value<'ll>, HasNUW: Bool); + pub(crate) fn LLVMSetNSW<'ll>(ArithInst: Value<'ll>, HasNSW: Bool); // Memory pub(crate) fn LLVMBuildAlloca<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildLoad2<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - PointerVal: &'ll Value, + PointerVal: Value<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; - pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value; + pub(crate) fn LLVMBuildStore<'ll>( + B: &Builder<'ll>, + Val: Value<'ll>, + Ptr: Value<'ll>, + ) -> Value<'ll>; pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Pointer: &'ll Value, - Indices: *const &'ll Value, + Pointer: Value<'ll>, + Indices: *const Value<'ll>, NumIndices: c_uint, Name: *const c_char, Flags: GEPNoWrapFlags, - ) -> &'ll Value; + ) -> Value<'ll>; // Casts pub(crate) fn LLVMBuildTrunc<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildZExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildSExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPToUI<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPToSI<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildUIToFP<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildSIToFP<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPTrunc<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildPtrToInt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildIntToPtr<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildBitCast<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildPointerCast<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildIntCast2<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, IsSigned: Bool, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; // Comparisons - pub(crate) fn LLVMBuildICmp<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildICmp<'ll>( + B: &Builder<'ll>, Op: c_uint, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFCmp<'a>( - B: &Builder<'a>, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFCmp<'ll>( + B: &Builder<'ll>, Op: c_uint, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; // Miscellaneous instructions pub(crate) fn LLVMBuildPhi<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildSelect<'a>( - B: &Builder<'a>, - If: &'a Value, - Then: &'a Value, - Else: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSelect<'ll>( + B: &Builder<'ll>, + If: Value<'ll>, + Then: Value<'ll>, + Else: Value<'ll>, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildVAArg<'ll>( B: &Builder<'ll>, - list: &'ll Value, + list: Value<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildExtractElement<'a>( - B: &Builder<'a>, - VecVal: &'a Value, - Index: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildInsertElement<'a>( - B: &Builder<'a>, - VecVal: &'a Value, - EltVal: &'a Value, - Index: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildShuffleVector<'a>( - B: &Builder<'a>, - V1: &'a Value, - V2: &'a Value, - Mask: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExtractValue<'a>( - B: &Builder<'a>, - AggVal: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExtractElement<'ll>( + B: &Builder<'ll>, + VecVal: Value<'ll>, + Index: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildInsertElement<'ll>( + B: &Builder<'ll>, + VecVal: Value<'ll>, + EltVal: Value<'ll>, + Index: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildShuffleVector<'ll>( + B: &Builder<'ll>, + V1: Value<'ll>, + V2: Value<'ll>, + Mask: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExtractValue<'ll>( + B: &Builder<'ll>, + AggVal: Value<'ll>, Index: c_uint, Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildInsertValue<'a>( - B: &Builder<'a>, - AggVal: &'a Value, - EltVal: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildInsertValue<'ll>( + B: &Builder<'ll>, + AggVal: Value<'ll>, + EltVal: Value<'ll>, Index: c_uint, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; // Atomic Operations - pub(crate) fn LLVMBuildAtomicCmpXchg<'a>( - B: &Builder<'a>, - LHS: &'a Value, - CMP: &'a Value, - RHS: &'a Value, + pub(crate) fn LLVMBuildAtomicCmpXchg<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + CMP: Value<'ll>, + RHS: Value<'ll>, Order: AtomicOrdering, FailureOrder: AtomicOrdering, SingleThreaded: Bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool); + pub(crate) fn LLVMSetWeak<'ll>(CmpXchgInst: Value<'ll>, IsWeak: Bool); - pub(crate) fn LLVMBuildAtomicRMW<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildAtomicRMW<'ll>( + B: &Builder<'ll>, Op: AtomicRmwBinOp, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Order: AtomicOrdering, SingleThreaded: Bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMBuildFence<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildFence<'ll>( + B: &Builder<'ll>, Order: AtomicOrdering, SingleThreaded: Bool, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; /// Writes a module to the specified path. Returns 0 on success. pub(crate) fn LLVMWriteBitcodeToFile<'ll>(M: Module<'ll>, Path: *const c_char) -> c_int; @@ -1701,58 +1724,58 @@ unsafe extern "C" { pub(crate) fn LLVMCountStructElementTypes<'ll>(StructTy: Type<'ll>) -> c_uint; pub(crate) fn LLVMGetStructElementTypes<'ll>(StructTy: Type<'ll>, Dest: *mut Type<'ll>); - pub(crate) safe fn LLVMMetadataAsValue<'ll>(C: Context<'ll>, MD: &'ll Metadata) -> &'ll Value; + pub(crate) safe fn LLVMMetadataAsValue<'ll>(C: Context<'ll>, MD: &'ll Metadata) -> Value<'ll>; - pub(crate) safe fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr); + pub(crate) safe fn LLVMSetUnnamedAddress<'ll>(Global: Value<'ll>, UnnamedAddr: UnnamedAddr); - pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>; + pub(crate) fn LLVMIsAConstantInt<'ll>(value_ref: Value<'ll>) -> Option<&'ll ConstantInt>; pub(crate) fn LLVMGetOrInsertComdat<'ll>(M: Module<'ll>, Name: *const c_char) -> &'ll Comdat; - pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat); + pub(crate) fn LLVMSetComdat<'ll>(V: Value<'ll>, C: &Comdat); - pub(crate) fn LLVMCreateOperandBundle( + pub(crate) fn LLVMCreateOperandBundle<'ll>( Tag: *const c_uchar, // See "PTR_LEN_STR". TagLen: size_t, - Args: *const &'_ Value, + Args: *const Value<'ll>, NumArgs: c_uint, - ) -> *mut OperandBundle<'_>; + ) -> *mut OperandBundle<'ll>; pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull>); pub(crate) fn LLVMBuildCallWithOperandBundles<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, - Args: *const &'ll Value, + Fn: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildInvokeWithOperandBundles<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, - Args: *const &'ll Value, + Fn: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Then: &'ll BasicBlock, Catch: &'ll BasicBlock, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildCallBr<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, + Fn: Value<'ll>, DefaultDest: &'ll BasicBlock, IndirectDests: *const &'ll BasicBlock, NumIndirectDests: c_uint, - Args: *const &'ll Value, + Args: *const Value<'ll>, NumArgs: c_uint, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; } // FFI bindings for `DIBuilder` functions in the LLVM-C API. @@ -1902,7 +1925,7 @@ unsafe extern "C" { LineNumber: c_uint, Type: &'ll Metadata, Flags: DIFlags, - ConstantVal: Option<&'ll Value>, + ConstantVal: Option>, AlignInBits: u32, ) -> &'ll Metadata; @@ -1961,7 +1984,7 @@ unsafe extern "C" { pub(crate) fn LLVMDIBuilderInsertDeclareRecordAtEnd<'ll>( Builder: &DIBuilder<'ll>, - Storage: &'ll Value, + Storage: Value<'ll>, VarInfo: &'ll Metadata, Expr: &'ll Metadata, DebugLoc: &'ll Metadata, @@ -1970,7 +1993,7 @@ unsafe extern "C" { pub(crate) fn LLVMDIBuilderInsertDbgValueRecordAtEnd<'ll>( Builder: &DIBuilder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, VarInfo: &'ll Metadata, Expr: &'ll Metadata, DebugLoc: &'ll Metadata, @@ -2010,8 +2033,8 @@ unsafe extern "C" { pub(crate) fn LLVMRustDisableSystemDialogsOnCrash(); // Operations on all values - pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; - pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value; + pub(crate) fn LLVMRustIsNonGVFunctionPointerTy<'ll>(Val: Value<'ll>) -> bool; + pub(crate) fn LLVMRustStripPointerCasts<'ll>(Val: Value<'ll>) -> Value<'ll>; // Operations on scalar constants pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool; @@ -2023,7 +2046,7 @@ unsafe extern "C" { ) -> bool; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool); + pub(crate) fn LLVMRustSetDSOLocal<'ll>(Global: Value<'ll>, is_dso_local: bool); // Operations on global variables pub(crate) fn LLVMRustGetOrInsertGlobal<'ll>( @@ -2031,19 +2054,19 @@ unsafe extern "C" { Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, T: Type<'ll>, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustGetOrInsertGlobalInAddrspace<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, T: Type<'ll>, AddressSpace: c_uint, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustGetNamedValue<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, - ) -> Option<&'ll Value>; + ) -> Option>; // Operations on attributes pub(crate) fn LLVMRustCreateAttrNoValue<'ll>( @@ -2096,55 +2119,55 @@ unsafe extern "C" { ) -> &'ll Attribute; // Operations on functions - pub(crate) fn LLVMRustAddFunctionAttributes<'a>( - Fn: &'a Value, + pub(crate) fn LLVMRustAddFunctionAttributes<'ll>( + Fn: Value<'ll>, index: c_uint, - Attrs: *const &'a Attribute, + Attrs: *const &'ll Attribute, AttrsLen: size_t, ); // Operations on call sites - pub(crate) fn LLVMRustAddCallSiteAttributes<'a>( - Instr: &'a Value, + pub(crate) fn LLVMRustAddCallSiteAttributes<'ll>( + Instr: Value<'ll>, index: c_uint, - Attrs: *const &'a Attribute, + Attrs: *const &'ll Attribute, AttrsLen: size_t, ); - pub(crate) fn LLVMRustSetFastMath(Instr: &Value); - pub(crate) fn LLVMRustSetAlgebraicMath(Instr: &Value); - pub(crate) fn LLVMRustSetAllowReassoc(Instr: &Value); - pub(crate) fn LLVMRustSetNoSignedZeros(Instr: &Value); + pub(crate) fn LLVMRustSetFastMath<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetAlgebraicMath<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetAllowReassoc<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetNoSignedZeros<'ll>(Instr: Value<'ll>); // Miscellaneous instructions - pub(crate) fn LLVMRustBuildMemCpy<'a>( - B: &Builder<'a>, - Dst: &'a Value, + pub(crate) fn LLVMRustBuildMemCpy<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Src: &'a Value, + Src: Value<'ll>, SrcAlign: c_uint, - Size: &'a Value, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemMove<'a>( - B: &Builder<'a>, - Dst: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMRustBuildMemMove<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Src: &'a Value, + Src: Value<'ll>, SrcAlign: c_uint, - Size: &'a Value, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemSet<'a>( - B: &Builder<'a>, - Dst: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMRustBuildMemSet<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Val: &'a Value, - Size: &'a Value, + Val: Value<'ll>, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMRustBuildVScale<'ll>(B: &Builder<'ll>, Ty: Type<'ll>) -> &'ll Value; + pub(crate) fn LLVMRustBuildVScale<'ll>(B: &Builder<'ll>, Ty: Type<'ll>) -> Value<'ll>; pub(crate) fn LLVMRustTimeTraceProfilerInitialize(); @@ -2206,11 +2229,11 @@ unsafe extern "C" { BufferOut: &RustString, ); - pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar( - F: &Value, + pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar<'ll>( + F: Value<'ll>, FuncName: *const c_uchar, // See "PTR_LEN_STR". FuncNameLen: size_t, - ) -> &Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustCoverageHashBytes( Bytes: *const c_uchar, // See "PTR_LEN_STR". NumBytes: size_t, @@ -2295,23 +2318,23 @@ unsafe extern "C" { /// We can't use LLVM-C's `LLVMDIBuilderCreateFunction` because it only /// supports a subset of `DISubprogram::DISPFlags`. - pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>( - Builder: &DIBuilder<'a>, - Scope: &'a DIDescriptor, + pub(crate) fn LLVMRustDIBuilderCreateFunction<'ll>( + Builder: &DIBuilder<'ll>, + Scope: &'ll DIDescriptor, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, LinkageName: *const c_uchar, // See "PTR_LEN_STR". LinkageNameLen: size_t, - File: &'a DIFile, + File: &'ll DIFile, LineNo: c_uint, - Ty: &'a DIType, + Ty: &'ll DIType, ScopeLine: c_uint, Flags: DIFlags, SPFlags: DISPFlags, - MaybeFn: Option<&'a Value>, - TParam: &'a DIArray, - Decl: Option<&'a DIDescriptor>, - ) -> &'a DISubprogram; + MaybeFn: Option>, + TParam: &'ll DIArray, + Decl: Option<&'ll DIDescriptor>, + ) -> &'ll DISubprogram; /// As of LLVM 22 there is no corresponding LLVM-C function. pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>( @@ -2330,20 +2353,20 @@ unsafe extern "C" { ) -> &'a DISubprogram; /// As of LLVM 22 there is no corresponding LLVM-C function. - pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>( - Builder: &DIBuilder<'a>, - Scope: &'a DIScope, + pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'ll>( + Builder: &DIBuilder<'ll>, + Scope: &'ll DIScope, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, - File: &'a DIFile, + File: &'ll DIFile, LineNumber: c_uint, SizeInBits: u64, AlignInBits: u32, OffsetInBits: u64, - Discriminant: Option<&'a Value>, + Discriminant: Option>, Flags: DIFlags, - Ty: &'a DIType, - ) -> &'a DIType; + Ty: &'ll DIType, + ) -> &'ll DIType; /// As of LLVM 22 there is no corresponding LLVM-C function. pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>( @@ -2423,7 +2446,7 @@ unsafe extern "C" { ) -> Option<&'a DILocation>; pub(crate) fn LLVMRustWriteTypeToString<'ll>(Type: Type<'ll>, s: &RustString); - pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString); + pub(crate) fn LLVMRustWriteValueToString<'ll>(value_ref: Value<'ll>, s: &RustString); pub(crate) fn LLVMRustTargetHasMnemonic(T: &TargetMachine, s: *const c_char) -> bool; @@ -2543,10 +2566,10 @@ unsafe extern "C" { pub(crate) fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString); - pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'a>( - DI: &'a DiagnosticInfo, + pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'ll>( + DI: &'ll DiagnosticInfo, pass_name_out: &RustString, - function_out: &mut Option<&'a Value>, + function_out: &mut Option>, loc_line_out: &mut c_uint, loc_column_out: &mut c_uint, loc_filename_out: &RustString, @@ -2579,7 +2602,7 @@ unsafe extern "C" { pub(crate) fn LLVMRustSetDataLayoutFromTargetMachine<'ll>(M: Module<'ll>, TM: &TargetMachine); - pub(crate) fn LLVMRustPositionBuilderPastAllocas<'a>(B: &Builder<'a>, Fn: &'a Value); + pub(crate) fn LLVMRustPositionBuilderPastAllocas<'ll>(B: &Builder<'ll>, Fn: Value<'ll>); pub(crate) fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock); pub(crate) fn LLVMRustSetModulePICLevel<'ll>(M: Module<'ll>); @@ -2665,9 +2688,9 @@ unsafe extern "C" { pgo_available: bool, ); - pub(crate) fn LLVMRustGetMangledName(V: &Value, out: &RustString); + pub(crate) fn LLVMRustGetMangledName<'ll>(V: Value<'ll>, out: &RustString); - pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32; + pub(crate) fn LLVMRustGetElementTypeArgIndex<'ll>(CallSite: Value<'ll>) -> i32; pub(crate) safe fn LLVMRustLLVMHasZlibCompression() -> bool; pub(crate) safe fn LLVMRustLLVMHasZstdCompression() -> bool; @@ -2686,14 +2709,14 @@ unsafe extern "C" { pub(crate) fn LLVMRustIsAnyArm64Coff(buf_ptr: *const u8, buf_len: usize) -> bool; - pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value); - pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value); + pub(crate) fn LLVMRustSetNoSanitizeAddress<'ll>(Global: Value<'ll>); + pub(crate) fn LLVMRustSetNoSanitizeHWAddress<'ll>(Global: Value<'ll>); - pub(crate) fn LLVMRustConstPtrAuth( - ptr: *const Value, + pub(crate) fn LLVMRustConstPtrAuth<'ll>( + ptr: Value<'ll>, key: u32, disc: u64, - addr_diversity: *const Value, - deactivation_symbol: *const Value, - ) -> *const Value; + addr_diversity: Option>, + deactivation_symbol: Option>, + ) -> Value<'ll>; } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs index 4086c41459a4c..3cdcc78fa760d 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs @@ -75,3 +75,17 @@ unsafe extern "C" { /// Pointee type of the raw pointer wrapped by [`Type`]. type TypeRaw; } + +/// Corresponds to `LLVMValueRef`. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[repr(transparent)] +#[rustc_pass_by_value] +pub(crate) struct Value<'ll> { + llval_raw: ptr::NonNull, + _invariant_ll: PhantomInvariantLifetime<'ll>, +} + +unsafe extern "C" { + /// Pointee type of the raw pointer wrapped by [`Value`]. + type ValueRaw; +} diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 168cc40ee579c..c662ad09f49d7 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -34,7 +34,7 @@ impl LLVMRustResult { } pub(crate) fn AddFunctionAttributes<'ll>( - llfn: &'ll Value, + llfn: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute], ) { @@ -43,16 +43,16 @@ pub(crate) fn AddFunctionAttributes<'ll>( } } -pub(crate) fn HasStringAttribute<'ll>(llfn: &'ll Value, name: &str) -> bool { +pub(crate) fn HasStringAttribute<'ll>(llfn: Value<'ll>, name: &str) -> bool { unsafe { LLVMRustHasFnAttribute(llfn, name.as_ptr(), name.len()) } } -pub(crate) fn RemoveStringAttrFromFn<'ll>(llfn: &'ll Value, name: &str) { +pub(crate) fn RemoveStringAttrFromFn<'ll>(llfn: Value<'ll>, name: &str) { unsafe { LLVMRustRemoveFnAttribute(llfn, name.as_ptr(), name.len()) } } pub(crate) fn AddCallSiteAttributes<'ll>( - callsite: &'ll Value, + callsite: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute], ) { @@ -194,12 +194,12 @@ impl AttributePlace { } } -pub(crate) fn SetInstructionCallConv(instr: &Value, cc: CallConv) { +pub(crate) fn SetInstructionCallConv<'ll>(instr: Value<'ll>, cc: CallConv) { unsafe { LLVMSetInstructionCallConv(instr, cc as c_uint); } } -pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) { +pub(crate) fn SetFunctionCallConv<'ll>(fn_: Value<'ll>, cc: CallConv) { unsafe { LLVMSetFunctionCallConv(fn_, cc as c_uint); } @@ -211,18 +211,18 @@ pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) { // value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the // function. // For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52 -pub(crate) fn SetUniqueComdat<'ll>(llmod: Module<'ll>, val: &'ll Value) { +pub(crate) fn SetUniqueComdat<'ll>(llmod: Module<'ll>, val: Value<'ll>) { let name_buf = get_value_name(val); let name = CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap(); set_comdat(llmod, val, &name); } -pub(crate) fn set_unnamed_address(global: &Value, unnamed: UnnamedAddr) { +pub(crate) fn set_unnamed_address<'ll>(global: Value<'ll>, unnamed: UnnamedAddr) { LLVMSetUnnamedAddress(global, unnamed); } -pub(crate) fn set_thread_local_mode(global: &Value, mode: ThreadLocalMode) { +pub(crate) fn set_thread_local_mode<'ll>(global: Value<'ll>, mode: ThreadLocalMode) { unsafe { LLVMSetThreadLocalMode(global, mode); } @@ -242,17 +242,17 @@ impl MemoryEffects { } } -pub(crate) fn set_section(llglobal: &Value, section_name: &CStr) { +pub(crate) fn set_section<'ll>(llglobal: Value<'ll>, section_name: &CStr) { unsafe { LLVMSetSection(llglobal, section_name.as_ptr()); } } -pub(crate) fn add_global<'ll>(llmod: Module<'ll>, ty: Type<'ll>, name_cstr: &CStr) -> &'ll Value { +pub(crate) fn add_global<'ll>(llmod: Module<'ll>, ty: Type<'ll>, name_cstr: &CStr) -> Value<'ll> { unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) } } -pub(crate) fn set_initializer(llglobal: &Value, constant_val: &Value) { +pub(crate) fn set_initializer<'ll>(llglobal: Value<'ll>, constant_val: Value<'ll>) { unsafe { assert_eq!( crate::llvm::LLVMGlobalGetValueType(llglobal), @@ -264,41 +264,41 @@ pub(crate) fn set_initializer(llglobal: &Value, constant_val: &Value) { } } -pub(crate) fn set_global_constant(llglobal: &Value, is_constant: bool) { +pub(crate) fn set_global_constant<'ll>(llglobal: Value<'ll>, is_constant: bool) { LLVMSetGlobalConstant(llglobal, is_constant.to_llvm_bool()); } -pub(crate) fn get_linkage(llglobal: &Value) -> Linkage { +pub(crate) fn get_linkage<'ll>(llglobal: Value<'ll>) -> Linkage { unsafe { LLVMGetLinkage(llglobal) }.to_rust() } -pub(crate) fn set_linkage(llglobal: &Value, linkage: Linkage) { +pub(crate) fn set_linkage<'ll>(llglobal: Value<'ll>, linkage: Linkage) { unsafe { LLVMSetLinkage(llglobal, linkage); } } -pub(crate) fn is_declaration(llglobal: &Value) -> bool { +pub(crate) fn is_declaration<'ll>(llglobal: Value<'ll>) -> bool { unsafe { LLVMIsDeclaration(llglobal) }.is_true() } -pub(crate) fn get_visibility(llglobal: &Value) -> Visibility { +pub(crate) fn get_visibility<'ll>(llglobal: Value<'ll>) -> Visibility { unsafe { LLVMGetVisibility(llglobal) }.to_rust() } -pub(crate) fn set_visibility(llglobal: &Value, visibility: Visibility) { +pub(crate) fn set_visibility<'ll>(llglobal: Value<'ll>, visibility: Visibility) { unsafe { LLVMSetVisibility(llglobal, visibility); } } -pub(crate) fn set_alignment(llglobal: &Value, align: Align) { +pub(crate) fn set_alignment<'ll>(llglobal: Value<'ll>, align: Align) { unsafe { ffi::LLVMSetAlignment(llglobal, align.bytes() as c_uint); } } -pub(crate) fn set_externally_initialized(llglobal: &Value, is_ext_init: bool) { +pub(crate) fn set_externally_initialized<'ll>(llglobal: Value<'ll>, is_ext_init: bool) { LLVMSetExternallyInitialized(llglobal, is_ext_init.to_llvm_bool()); } @@ -306,19 +306,19 @@ pub(crate) fn set_externally_initialized(llglobal: &Value, is_ext_init: bool) { /// /// Inserts the comdat into `llmod` if it does not exist. /// It is an error to call this if the target does not support comdat. -pub(crate) fn set_comdat<'ll>(llmod: Module<'ll>, llglobal: &'ll Value, name: &CStr) { +pub(crate) fn set_comdat<'ll>(llmod: Module<'ll>, llglobal: Value<'ll>, name: &CStr) { unsafe { let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr()); LLVMSetComdat(llglobal, comdat); } } -pub(crate) fn count_params(llfn: &Value) -> c_uint { +pub(crate) fn count_params<'ll>(llfn: Value<'ll>) -> c_uint { LLVMCountParams(llfn) } /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun. -pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value { +pub(crate) fn get_param<'ll>(llfn: Value<'ll>, index: c_uint) -> Value<'ll> { unsafe { assert!( index < LLVMCountParams(llfn), @@ -333,7 +333,7 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value { /// Safe wrapper for `LLVMGetValueName2` /// Needs to allocate the value, because `set_value_name` will invalidate /// the pointer. -pub(crate) fn get_value_name(value: &Value) -> Vec { +pub(crate) fn get_value_name<'ll>(value: Value<'ll>) -> Vec { unsafe { let mut len = 0; let data = LLVMGetValueName2(value, &mut len); @@ -364,7 +364,7 @@ impl Intrinsic { self, llmod: Module<'ll>, type_params: &[Type<'ll>], - ) -> &'ll Value { + ) -> Value<'ll> { unsafe { LLVMGetIntrinsicDeclaration(llmod, self.id, type_params.as_ptr(), type_params.len()) } @@ -372,7 +372,7 @@ impl Intrinsic { } /// Safe wrapper for `LLVMSetValueName2` from a byte slice -pub(crate) fn set_value_name(value: &Value, name: &[u8]) { +pub(crate) fn set_value_name<'ll>(value: Value<'ll>, name: &[u8]) { assert!(!name.contains(&0)); unsafe { LLVMSetValueName2(value, name.as_ptr(), name.len()) }; } @@ -407,12 +407,12 @@ pub(crate) fn last_error() -> Option { /// Owning pointer to an [`OperandBundle`] that will dispose of the bundle /// when dropped. -pub(crate) struct OperandBundleBox<'a> { - raw: ptr::NonNull>, +pub(crate) struct OperandBundleBox<'ll> { + raw: ptr::NonNull>, } -impl<'a> OperandBundleBox<'a> { - pub(crate) fn new(name: &str, vals: &[&'a Value]) -> Self { +impl<'ll> OperandBundleBox<'ll> { + pub(crate) fn new(name: &str, vals: &[Value<'ll>]) -> Self { let raw = unsafe { LLVMCreateOperandBundle(name.as_ptr(), name.len(), vals.as_ptr(), vals.len() as c_uint) }; @@ -423,7 +423,7 @@ impl<'a> OperandBundleBox<'a> { /// /// This can't be a `Deref` implementation because `OperandBundle` transitively /// contains an extern type, which is incompatible with `Deref::Target: ?Sized`. - pub(crate) fn as_ref(&self) -> &OperandBundle<'a> { + pub(crate) fn as_ref(&self) -> &OperandBundle<'ll> { // SAFETY: The returned reference is opaque and can only used for FFI. // It is valid for as long as `&self` is. unsafe { self.raw.as_ref() } @@ -467,13 +467,13 @@ pub(crate) fn add_module_flag_str<'ll>( } } -pub(crate) fn set_dllimport_storage_class<'ll>(v: &'ll Value) { +pub(crate) fn set_dllimport_storage_class<'ll>(v: Value<'ll>) { unsafe { LLVMSetDLLStorageClass(v, DLLStorageClass::DllImport); } } -pub(crate) fn set_dso_local<'ll>(v: &'ll Value) { +pub(crate) fn set_dso_local<'ll>(v: Value<'ll>) { unsafe { LLVMRustSetDSOLocal(v, true); } @@ -505,24 +505,18 @@ pub(crate) fn add_alias<'ll>( module: Module<'ll>, ty: Type<'ll>, address_space: AddressSpace, - aliasee: &Value, + aliasee: Value<'ll>, name: &CStr, -) -> &'ll Value { +) -> Value<'ll> { unsafe { LLVMAddAlias2(module, ty, address_space.0, aliasee, name.as_ptr()) } } /// Safe wrapper for `LLVMRustConstPtrAuth`. pub(crate) fn const_ptr_auth<'ll>( - ptr: &'ll Value, + ptr: Value<'ll>, key: u32, disc: u64, - addr_diversity: Option<&'ll Value>, -) -> &'ll Value { - unsafe { - let addr_div_ptr = addr_diversity.map_or(std::ptr::null(), |v| v as *const Value); - let deactivation_symbol = std::ptr::null(); - let result = - LLVMRustConstPtrAuth(ptr as *const Value, key, disc, addr_div_ptr, deactivation_symbol); - &*result - } + addr_diversity: Option>, +) -> Value<'ll> { + unsafe { LLVMRustConstPtrAuth(ptr, key, disc, addr_diversity, None) } } diff --git a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs index 4f2369aef0d53..d66554491b6c3 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs @@ -4,7 +4,8 @@ use std::sync::OnceLock; use super::ffi::{Module, Value}; -type LLVMRustOffloadMapperFn = unsafe extern "C" fn(&Value, &Value, *const &Value); +type LLVMRustOffloadMapperFn = + for<'ll> unsafe extern "C" fn(Value<'ll>, Value<'ll>, *const Value<'ll>); type LLVMRustOffloadWrapImagesFn = for<'ll> unsafe extern "C" fn(Module<'ll>, *const c_char) -> bool; @@ -50,7 +51,12 @@ impl RustOffloadWrapper { .expect("RustOffloadWrapper not initialized. Call get_or_init with sysroot first.") } - pub(crate) unsafe fn llvm_rust_offload_wrapper(&self, v1: &Value, v2: &Value, vs: &[&Value]) { + pub(crate) unsafe fn llvm_rust_offload_wrapper<'ll>( + &self, + v1: Value<'ll>, + v2: Value<'ll>, + vs: &[Value<'ll>], + ) { unsafe { (self.LLVMRustOffloadMapper)(v1, v2, vs.as_ptr()) } } diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 82bd5584211c0..cf674b1fd2f71 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -82,7 +82,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { linkage: Linkage, visibility: Visibility, symbol_name: &str, - ) -> &'ll llvm::Value { + ) -> llvm::Value<'ll> { let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = self.fn_abi_of_instance(instance, ty::List::empty()); let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance)); llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage)); @@ -132,7 +132,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// So, this function is for static aliases. See [`add_function_aliases`](Self::add_function_aliases) for the alternative. fn add_static_aliases( &self, - aliasee: &'ll llvm::Value, + aliasee: llvm::Value<'ll>, aliases: &[(DefId, Linkage, Visibility)], ) { let ty = self.get_type_of_global(aliasee); @@ -166,7 +166,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { fn add_function_aliases( &self, aliasee_instance: Instance<'tcx>, - aliasee: &'ll llvm::Value, + aliasee: llvm::Value<'ll>, attrs: &Cow<'_, CodegenFnAttrs>, aliases: &[(DefId, Linkage, Visibility)], ) { @@ -233,7 +233,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// A definition or declaration can be assumed to be local to a group of /// libraries that form a single DSO or executable. /// Marks the local as DSO if so. - pub(crate) fn assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool { + pub(crate) fn assume_dso_local(&self, llval: llvm::Value<'ll>, is_declaration: bool) -> bool { let assume = self.should_assume_dso_local(llval, is_declaration); if assume { llvm::set_dso_local(llval); @@ -241,7 +241,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { assume } - fn set_visibility(&self, lldecl: &llvm::Value, linkage: Linkage, visibility: Visibility) { + fn set_visibility(&self, lldecl: llvm::Value<'ll>, linkage: Linkage, visibility: Visibility) { // If we're compiling the compiler-builtins crate, i.e., the equivalent of // compiler-rt, then we want to implicitly compile everything with hidden // visibility as we're going to link this object all over the place but @@ -253,7 +253,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } } - fn should_assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool { + fn should_assume_dso_local(&self, llval: llvm::Value<'ll>, is_declaration: bool) -> bool { let linkage = llvm::get_linkage(llval); let visibility = llvm::get_visibility(llval); diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index 55c546538611b..d69559593e227 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -56,7 +56,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { unsafe { llvm::LLVMScalableVectorType(ty, count as c_uint) } } - pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> Value<'ll> { let name = SmallCStr::new(name); unsafe { llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty) } } @@ -274,7 +274,7 @@ impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { } } - fn val_ty(&self, v: &'ll Value) -> Type<'ll> { + fn val_ty(&self, v: Value<'ll>) -> Type<'ll> { common::val_ty(v) } } @@ -320,24 +320,24 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { } impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { - fn add_type_metadata(&self, function: &'ll Value, typeid: &[u8]) { + fn add_type_metadata(&self, function: Value<'ll>, typeid: &[u8]) { let typeid_metadata = self.create_metadata(typeid); let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata]; self.global_add_metadata_node(function, llvm::MD_type, &v); } - fn set_type_metadata(&self, function: &'ll Value, typeid: &[u8]) { + fn set_type_metadata(&self, function: Value<'ll>, typeid: &[u8]) { let typeid_metadata = self.create_metadata(typeid); let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata]; self.global_set_metadata_node(function, llvm::MD_type, &v); } - fn add_kcfi_type_metadata(&self, function: &'ll Value, kcfi_typeid: u32) { + fn add_kcfi_type_metadata(&self, function: Value<'ll>, kcfi_typeid: u32) { let kcfi_type_metadata = [llvm::LLVMValueAsMetadata(self.const_u32(kcfi_typeid))]; self.global_add_metadata_node(function, llvm::MD_kcfi_type, &kcfi_type_metadata); } - fn set_kcfi_type_metadata(&self, function: &'ll Value, kcfi_typeid: u32) { + fn set_kcfi_type_metadata(&self, function: Value<'ll>, kcfi_typeid: u32) { let kcfi_type_metadata = [llvm::LLVMValueAsMetadata(self.const_u32(kcfi_typeid))]; self.global_set_metadata_node(function, llvm::MD_kcfi_type, &kcfi_type_metadata); } diff --git a/compiler/rustc_codegen_llvm/src/typetree.rs b/compiler/rustc_codegen_llvm/src/typetree.rs index efda11f399ba4..48959a0ae6739 100644 --- a/compiler/rustc_codegen_llvm/src/typetree.rs +++ b/compiler/rustc_codegen_llvm/src/typetree.rs @@ -75,7 +75,7 @@ enum TTLocation { Callsite, } -pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: &'ll Value, tt: FncTree) { +pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: Value<'ll>, tt: FncTree) { // TypeTree processing uses functions from Enzyme. This feature is not strictly necessary, // but skipping this function increases the chance that Enzyme fails to compile some code. diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index 7c2c20c2671e4..e06cdaca0ae5a 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -17,18 +17,18 @@ use crate::type_of::LayoutLlvmExt; fn round_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, - mut value: &'ll Value, + mut value: Value<'ll>, align: Align, -) -> &'ll Value { +) -> Value<'ll> { value = bx.add(value, bx.cx().const_i32(align.bytes() as i32 - 1)); return bx.and(value, bx.cx().const_i32(-(align.bytes() as i32))); } fn round_pointer_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, - addr: &'ll Value, + addr: Value<'ll>, align: Align, -) -> &'ll Value { +) -> Value<'ll> { let ptr = bx.inbounds_ptradd(addr, bx.const_i32(align.bytes() as i32 - 1)); let pointer_width = bx.tcx().sess.target.pointer_width; let mask = align.bytes().wrapping_neg() & (u64::MAX >> (64 - pointer_width)); @@ -41,13 +41,13 @@ fn round_pointer_up_to_alignment<'ll>( fn emit_direct_ptr_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, size: Size, align: Align, slot_size: Align, allow_higher_align: bool, force_right_adjust: bool, -) -> (&'ll Value, Align) { +) -> (Value<'ll>, Align) { let va_list_ty = bx.type_ptr(); let va_list_addr = list.immediate(); @@ -155,13 +155,13 @@ enum ForceRightAdjust { fn emit_ptr_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, pass_mode: PassMode, slot_size: SlotSize, allow_higher_align: AllowHigherAlign, force_right_adjust: ForceRightAdjust, -) -> &'ll Value { +) -> Value<'ll> { let indirect = matches!(pass_mode, PassMode::Indirect); let allow_higher_align = matches!(allow_higher_align, AllowHigherAlign::Yes); let force_right_adjust = matches!(force_right_adjust, ForceRightAdjust::Yes); @@ -195,9 +195,9 @@ fn emit_ptr_va_arg<'ll, 'tcx>( fn emit_aapcs_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the AAPCS64 calling convention for va_args see @@ -315,9 +315,9 @@ fn is_powerpc_softfloat_abi(target: &Target) -> bool { fn emit_powerpc_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // struct __va_list_tag { @@ -443,9 +443,9 @@ fn emit_powerpc_va_arg<'ll, 'tcx>( fn emit_s390x_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the s390x ELF ABI calling convention for va_args see @@ -551,9 +551,9 @@ fn emit_s390x_va_arg<'ll, 'tcx>( fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the systemv x86_64 ABI calling convention for va_args, see @@ -797,10 +797,10 @@ fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>( /// Copy into a temporary if the type is more aligned than the register save area. fn copy_to_temporary_if_more_aligned<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - reg_addr: &'ll Value, + reg_addr: Value<'ll>, layout: TyAndLayout<'tcx>, src_align: Align, -) -> &'ll Value { +) -> Value<'ll> { if layout.layout.align > src_align { assert!(layout.ty.is_integral()); @@ -816,9 +816,9 @@ fn copy_to_temporary_if_more_aligned<'ll, 'tcx>( fn x86_64_sysv64_va_arg_from_memory<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - va_list_addr: &'ll Value, + va_list_addr: Value<'ll>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); let ptr_align_abi = dl.data_layout().pointer_align(); @@ -855,9 +855,9 @@ fn x86_64_sysv64_va_arg_from_memory<'ll, 'tcx>( fn emit_hexagon_va_arg_musl<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Hexagon musl target. // Based on LLVM's HexagonBuiltinVaList implementation. // @@ -934,9 +934,9 @@ fn emit_hexagon_va_arg_musl<'ll, 'tcx>( fn emit_hexagon_va_arg_bare_metal<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Hexagon bare-metal (non-musl) targets. // Based on LLVM's EmitVAArgForHexagon implementation. // @@ -971,9 +971,9 @@ fn emit_hexagon_va_arg_bare_metal<'ll, 'tcx>( fn emit_xtensa_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Xtensa. There doesn't seem to be an authoritative source for // this, other than "what GCC does". // @@ -1072,9 +1072,9 @@ fn emit_xtensa_va_arg<'ll, 'tcx>( /// pub(super) fn emit_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - addr: OperandRef<'tcx, &'ll Value>, + addr: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Some ABIs have special behavior for zero-sized types. currently `VaArgSafe` is not // implemented for any zero-sized types, so this assert should always hold. assert!(!layout.is_zst()); diff --git a/compiler/rustc_codegen_llvm/src/value.rs b/compiler/rustc_codegen_llvm/src/value.rs index 37f05f10c50cd..221b51851fa30 100644 --- a/compiler/rustc_codegen_llvm/src/value.rs +++ b/compiler/rustc_codegen_llvm/src/value.rs @@ -1,27 +1,12 @@ -use std::hash::{Hash, Hasher}; -use std::{fmt, ptr}; +use std::fmt; use crate::llvm::{self, Value}; -impl PartialEq for Value { - fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) - } -} - -impl Eq for Value {} - -impl Hash for Value { - fn hash(&self, hasher: &mut H) { - (self as *const Self).hash(hasher); - } -} - -impl fmt::Debug for Value { +impl<'ll> fmt::Debug for Value<'ll> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str( &llvm::build_string(|s| unsafe { - llvm::LLVMRustWriteValueToString(self, s); + llvm::LLVMRustWriteValueToString(*self, s); }) .expect("non-UTF8 value description from LLVM"), )