rust-lang/rust · #166693
Make function signatures a separate type in `rustc_codegen_llvm`
compiler/rustc_codegen_llvm/src/abi.rs3 + / 3 −
@@ -24,7 +24,7 @@ use smallvec::SmallVec; use crate::attributes::{self, llfn_attrs_from_instance}; use crate::builder::Builder; use crate::context::CodegenCx;-use crate::llvm::{self, Attribute, AttributePlace, Type, Value};+use crate::llvm::{self, Attribute, AttributePlace, FunctionSignature, Type, Value}; use crate::type_of::LayoutLlvmExt; trait ArgAttributesExt {@@ -532,7 +532,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { } pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {- fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll>;+ fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> FunctionSignature<'ll>; fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll>; fn llvm_cconv(&self, cx: &CodegenCx<'ll, 'tcx>) -> llvm::CallConv; @@ -549,7 +549,7 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> { } impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {- fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> Type<'ll> {+ fn llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> FunctionSignature<'ll> { // Ignore "extra" args from the call site for C variadic functions. // Only the "fixed" args are part of the LLVM function signature. let args =compiler/rustc_codegen_llvm/src/back/write.rs1 + / 1 −
@@ -665,7 +665,7 @@ pub(crate) unsafe fn llvm_optimize<'ll>( cx: &SimpleCx<'ll>, old_fn: llvm::Value<'ll>, ) -> Option<llvm::Value<'ll>> {- let old_fn_ty = cx.get_type_of_global(old_fn);+ let old_fn_ty = cx.get_type_of_function_global(old_fn); let old_param_types = cx.func_params_types(old_fn_ty); let old_param_count = old_param_types.len(); if old_param_count == 0 {compiler/rustc_codegen_llvm/src/builder.rs12 + / 18 −
@@ -35,8 +35,8 @@ use crate::attributes; use crate::common::Funclet; use crate::context::{CodegenCx, FullCx, GenericCx, SCx}; use crate::llvm::{- self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, FromGeneric, GEPNoWrapFlags, Metadata, TRUE,- ToLlvmBool, Type, TypeKind, Value,+ self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, FromGeneric, FunctionSignature,+ GEPNoWrapFlags, Metadata, TRUE, ToLlvmBool, Type, TypeKind, Value, }; use crate::type_of::LayoutLlvmExt; @@ -60,14 +60,14 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> Drop for GenericBuilder<'a, 'll, CX> { impl<'a, 'll> SBuilder<'a, 'll> { pub(crate) fn call( &mut self,- llty: Type<'ll>,+ llty: FunctionSignature<'ll>, llfn: Value<'ll>, args: &[Value<'ll>], funclet: Option<&Funclet<'ll>>, ) -> Value<'ll> { debug!("call {:?} with args ({:?})", llfn, args); - let args = self.check_call("call", llty, llfn, args);+ let args = self.check_call(llty, llfn, args); let funclet_bundle = funclet.map(|funclet| funclet.bundle()); let mut bundles: SmallVec<[_; 2]> = SmallVec::new(); if let Some(funclet_bundle) = funclet_bundle {@@ -461,7 +461,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn invoke( &mut self,- llty: Type<'ll>,+ llty: FunctionSignature<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, llfn: Value<'ll>,@@ -483,7 +483,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } }; debug!("invoke {:?} with args ({:?})", llfn, args);- let args = self.check_call("invoke", llty, llfn, &args);+ let args = self.check_call(llty, llfn, &args); let funclet_bundle = funclet.map(|funclet| funclet.bundle()); let mut bundles: SmallVec<[_; 2]> = SmallVec::new(); if let Some(funclet_bundle) = funclet_bundle {@@ -1433,7 +1433,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn call( &mut self,- llty: Type<'ll>,+ llty: FunctionSignature<'ll>, caller_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, llfn: Value<'ll>,@@ -1453,7 +1453,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } }; debug!("call {:?} with args ({:?})", llfn, args);- let args = self.check_call("call", llty, llfn, &args);+ let args = self.check_call(llty, llfn, &args); let funclet_bundle = funclet.map(|funclet| funclet.bundle()); let mut bundles: SmallVec<[_; 2]> = SmallVec::new(); if let Some(funclet_bundle) = funclet_bundle {@@ -1495,7 +1495,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn tail_call( &mut self,- llty: Self::Type,+ llty: Self::FunctionSignature, caller_attrs: Option<&CodegenFnAttrs>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, llfn: Self::Value,@@ -1804,16 +1804,10 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> { pub(crate) fn check_call<'b>( &mut self,- typ: &str,- fn_ty: Type<'ll>,+ fn_ty: FunctionSignature<'ll>, 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:?}"- );- let param_tys = self.cx.func_params_types(fn_ty); let all_args_match = iter::zip(¶m_tys, args.iter().map(|&v| self.cx.val_ty(v)))@@ -1911,7 +1905,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { pub(crate) fn callbr( &mut self,- llty: Type<'ll>,+ llty: FunctionSignature<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, llfn: Value<'ll>,@@ -1923,7 +1917,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { ) -> Value<'ll> { debug!("invoke {:?} with args ({:?})", llfn, args); - let args = self.check_call("callbr", llty, llfn, args);+ let args = self.check_call(llty, llfn, args); let funclet_bundle = funclet.map(|funclet| funclet.bundle()); let mut bundles: SmallVec<[_; 2]> = SmallVec::new(); if let Some(funclet_bundle) = funclet_bundle {compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs10 + / 8 −
@@ -17,20 +17,20 @@ use crate::builder::Builder; use crate::common::CodegenCx; use crate::context::SimpleCx; use crate::llvm::AttributePlace::Function;-use crate::llvm::{self, Linkage, Type, TypeKind, Value};+use crate::llvm::{self, FunctionSignature, Linkage, Type, TypeKind, Value}; // LLVM kernel-independent globals required for offloading pub(crate) struct OffloadGlobals<'ll> { pub launcher_fn: llvm::Value<'ll>,- pub launcher_ty: llvm::Type<'ll>,+ pub launcher_ty: llvm::FunctionSignature<'ll>, pub kernel_args_ty: KernelArgsTy, pub offload_entry_ty: llvm::Type<'ll>, pub begin_mapper: llvm::Value<'ll>, pub end_mapper: llvm::Value<'ll>,- pub mapper_fn_ty: llvm::Type<'ll>,+ pub mapper_fn_ty: llvm::FunctionSignature<'ll>, pub ident_t_global: llvm::Value<'ll>, }@@ -120,7 +120,9 @@ 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, '_>) -> (llvm::Value<'ll>, llvm::Type<'ll>) {+fn generate_launcher<'ll>(+ cx: &CodegenCx<'ll, '_>,+) -> (llvm::Value<'ll>, llvm::FunctionSignature<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32();@@ -137,7 +139,7 @@ fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (llvm::Value<'ll>, llvm::T /// declaration together with its type. pub(crate) fn declare_omp_get_num_devices<'ll>( cx: &CodegenCx<'ll, '_>,-) -> (llvm::Value<'ll>, llvm::Type<'ll>) {+) -> (llvm::Value<'ll>, llvm::FunctionSignature<'ll>) { let ti32 = cx.type_i32(); let tgt_fn_ty = cx.type_func(&[], ti32); let name = "omp_get_num_devices";@@ -345,7 +347,7 @@ pub(crate) struct OffloadKernelGlobals<'ll> { fn gen_tgt_data_mappers<'ll>( cx: &CodegenCx<'ll, '_>,-) -> (llvm::Value<'ll>, llvm::Value<'ll>, llvm::Value<'ll>, llvm::Type<'ll>) {+) -> (llvm::Value<'ll>, llvm::Value<'ll>, llvm::Value<'ll>, llvm::FunctionSignature<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32();@@ -512,7 +514,7 @@ pub(crate) fn gen_define_handling<'ll>( fn declare_offload_fn<'ll>( cx: &CodegenCx<'ll, '_>, name: &str,- ty: llvm::Type<'ll>,+ ty: llvm::FunctionSignature<'ll>, ) -> llvm::Value<'ll> { crate::declare::declare_simple_fn( cx,@@ -709,7 +711,7 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>( geps: [Value<'ll>; 3], o_type: Value<'ll>, fn_to_call: Value<'ll>,- fn_ty: Type<'ll>,+ fn_ty: FunctionSignature<'ll>, num_args: u64, s_ident_t: Value<'ll>, ) {compiler/rustc_codegen_llvm/src/common.rs3 + / 2 −
@@ -22,7 +22,8 @@ use crate::consts::{IsInitOrFini, IsStatic, const_alloc_to_llvm}; pub(crate) use crate::context::CodegenCx; use crate::context::{GenericCx, SCx}; use crate::llvm::{- self, BasicBlock, ConstantInt, FALSE, TRUE, ToLlvmBool, Type, TypeKind, Value, const_ptr_auth,+ self, BasicBlock, ConstantInt, FALSE, FunctionSignature, TRUE, ToLlvmBool, Type, TypeKind,+ Value, const_ptr_auth, }; pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>(@@ -132,7 +133,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BackendTypes for GenericCx<'ll, CX> { type Value = Value<'ll>; type Type = Type<'ll>;- type FunctionSignature = Type<'ll>;+ type FunctionSignature = FunctionSignature<'ll>; type DIScope = &'ll llvm::debuginfo::DIScope; type DILocation = &'ll llvm::debuginfo::DILocation;compiler/rustc_codegen_llvm/src/context.rs15 + / 8 −
@@ -38,7 +38,7 @@ use crate::back::write::to_llvm_code_model; use crate::builder::gpu_offload::{OffloadGlobals, OffloadKernelGlobals}; use crate::callee::get_fn; use crate::debuginfo::metadata::apply_vcall_visibility_metadata;-use crate::llvm::{self, Metadata, MetadataKindId, Module, Type, Value};+use crate::llvm::{self, FunctionSignature, Metadata, MetadataKindId, Module, Type, Value}; use crate::{attributes, common, coverageinfo, debuginfo, llvm_util}; /// `TyCtxt` (and related cache datastructures) can't be move between threads.@@ -141,10 +141,14 @@ pub(crate) struct FullCx<'ll, 'tcx> { pub sanitizer_ignorelist: Option<SanitizerIgnoreList>, eh_personality: Cell<Option<Value<'ll>>>,- pub rust_try_fn: Cell<Option<(Type<'ll>, Value<'ll>)>>,+ pub rust_try_fn: Cell<Option<(FunctionSignature<'ll>, Value<'ll>)>>, - intrinsics:- RefCell<FxHashMap<(Cow<'static, str>, SmallVec<[Type<'ll>; 2]>), (Type<'ll>, Value<'ll>)>>,+ intrinsics: RefCell<+ FxHashMap<+ (Cow<'static, str>, SmallVec<[Type<'ll>; 2]>),+ (FunctionSignature<'ll>, Value<'ll>),+ >,+ >, /// A counter that is used for generating local symbol names local_gen_sym_counter: Cell<usize>,@@ -890,6 +894,9 @@ impl<'ll> SimpleCx<'ll> { pub(crate) fn get_type_of_global(&self, val: Value<'ll>) -> Type<'ll> { unsafe { llvm::LLVMGlobalGetValueType(val) } }+ pub(crate) fn get_type_of_function_global(&self, val: Value<'ll>) -> FunctionSignature<'ll> {+ FunctionSignature::from_type(self.get_type_of_global(val)).unwrap()+ } pub(crate) fn val_ty(&self, v: Value<'ll>) -> Type<'ll> { common::val_ty(v) }@@ -1087,7 +1094,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); } - fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {+ fn declare_c_main(&self, fn_type: Self::FunctionSignature) -> Option<Self::Function> { let entry_name = self.sess().target.entry_name.as_ref(); if self.get_declared_value(entry_name).is_none() { let llfn = self.declare_entry_fn(@@ -1119,7 +1126,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: Cow<'static, str>, type_params: &[Type<'ll>],- ) -> (Type<'ll>, Value<'ll>) {+ ) -> (FunctionSignature<'ll>, Value<'ll>) { *self .intrinsics .borrow_mut()@@ -1133,7 +1140,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: &str, type_params: &[Type<'ll>],- ) -> (Type<'ll>, Value<'ll>) {+ ) -> (FunctionSignature<'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)@@ -1172,7 +1179,7 @@ impl<'ll> CodegenCx<'ll, '_> { let intrinsic = llvm::Intrinsic::lookup(base_name.as_bytes()) .unwrap_or_else(|| bug!("Unknown intrinsic: `{base_name}`")); let f = intrinsic.get_declaration(self.llmod, type_params);- (self.get_type_of_global(f), f)+ (self.get_type_of_function_global(f), f) } } }compiler/rustc_codegen_llvm/src/declare.rs5 + / 5 −
@@ -27,7 +27,7 @@ use crate::abi::FnAbiLlvmExt; use crate::attributes; use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx}; use crate::llvm::AttributePlace::Function;-use crate::llvm::{self, FromGeneric, Type, Value, Visibility};+use crate::llvm::{self, FromGeneric, FunctionSignature, Type, Value, Visibility}; /// Declare a function with a SimpleCx. ///@@ -39,7 +39,7 @@ pub(crate) fn declare_simple_fn<'ll>( callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility,- ty: Type<'ll>,+ ty: FunctionSignature<'ll>, ) -> Value<'ll> { debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty); let llfn = unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_ptr(), name.len(), ty) };@@ -61,7 +61,7 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>( callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility,- ty: Type<'ll>,+ ty: FunctionSignature<'ll>, ) -> Value<'ll> { debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty); let llfn = declare_simple_fn(cx, name, callconv, unnamed, visibility, ty);@@ -133,7 +133,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { &self, name: &str, unnamed: llvm::UnnamedAddr,- fn_type: Type<'ll>,+ fn_type: FunctionSignature<'ll>, ) -> Value<'ll> { // Visibility should always be default for declarations, otherwise the linker may report an // error.@@ -152,7 +152,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name: &str, callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr,- fn_type: Type<'ll>,+ fn_type: FunctionSignature<'ll>, ) -> Value<'ll> { let visibility = Visibility::from_generic(self.tcx.sess.default_visibility()); declare_raw_fn(self, name, callconv, unnamed, visibility, fn_type)compiler/rustc_codegen_llvm/src/intrinsic.rs7 + / 5 −
@@ -44,7 +44,9 @@ use crate::diagnostics::{ OffloadWithoutEnable, OffloadWithoutFatLTO, UnknownIntrinsic, }; use crate::intrinsic::ty::typetree::fnc_typetrees;-use crate::llvm::{self, Attribute, AttributePlace, Metadata, Type, TypeKind, Value};+use crate::llvm::{+ self, Attribute, AttributePlace, FunctionSignature, Metadata, Type, TypeKind, Value,+}; use crate::type_of::LayoutLlvmExt; use crate::va_arg::emit_va_arg; @@ -977,7 +979,7 @@ impl<'ll, 'tcx> Builder<'_, 'll, 'tcx> { llfn };- let fn_ty = self.get_type_of_global(fn_ptr);+ let fn_ty = self.get_type_of_function_global(fn_ptr); let mut llargs = args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(); @@ -1322,7 +1324,7 @@ fn intrinsic_fn<'ll, 'tcx>( { // FIXME: also do this for overloaded intrinsics let llfn = intrinsic.get_declaration(bx.llmod, &[]);- let llvm_fn_ty = bx.get_type_of_global(llfn);+ let llvm_fn_ty = bx.get_type_of_function_global(llfn); let llvm_return_ty = bx.get_return_type(llvm_fn_ty); let llvm_argument_tys = bx.func_params_types(llvm_fn_ty);@@ -1774,7 +1776,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>, Value<'ll>) {+) -> (FunctionSignature<'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);@@ -1796,7 +1798,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>, Value<'ll>) {+) -> (FunctionSignature<'ll>, Value<'ll>) { if let Some(llfn) = cx.rust_try_fn.get() { return llfn; }compiler/rustc_codegen_llvm/src/llvm/ffi.rs14 + / 13 −
@@ -21,7 +21,8 @@ use bitflags::bitflags; use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t}; pub(crate) use self::branded::{- Attribute, Context, ContextRaw, Module, ModuleRaw, Type, Value, wrap_llcx, wrap_llmod,+ Attribute, Context, ContextRaw, FunctionSignature, Module, ModuleRaw, Type, Value, wrap_llcx,+ wrap_llmod, }; use super::RustString; use super::debuginfo::{@@ -917,7 +918,7 @@ unsafe extern "C" { /// Create the specified uniqued inline asm string. See `InlineAsm::get()`. pub(crate) fn LLVMGetInlineAsm<'ll>(- Ty: Type<'ll>,+ Ty: FunctionSignature<'ll>, AsmString: *const c_uchar, // See "PTR_LEN_STR". AsmStringSize: size_t, Constraints: *const c_uchar, // See "PTR_LEN_STR".@@ -957,11 +958,11 @@ unsafe extern "C" { ParamTypes: *const Type<'ll>, ParamCount: c_uint, IsVarArg: Bool,- ) -> Type<'ll>;- pub(crate) fn LLVMCountParamTypes<'ll>(FunctionTy: Type<'ll>) -> c_uint;- pub(crate) fn LLVMGetParamTypes<'ll>(FunctionTy: Type<'ll>, Dest: *mut Type<'ll>);- pub(crate) fn LLVMGetReturnType<'ll>(FunctionTy: Type<'ll>) -> Type<'ll>;- pub(crate) fn LLVMIsFunctionVarArg<'ll>(FunctionTy: Type<'ll>) -> Bool;+ ) -> FunctionSignature<'ll>;+ pub(crate) fn LLVMCountParamTypes<'ll>(FunctionTy: FunctionSignature<'ll>) -> c_uint;+ pub(crate) fn LLVMGetParamTypes<'ll>(FunctionTy: FunctionSignature<'ll>, Dest: *mut Type<'ll>);+ pub(crate) fn LLVMGetReturnType<'ll>(FunctionTy: FunctionSignature<'ll>) -> Type<'ll>;+ pub(crate) fn LLVMIsFunctionVarArg<'ll>(FunctionTy: FunctionSignature<'ll>) -> Bool; // Operations on struct types pub(crate) fn LLVMStructTypeInContext<'ll>(@@ -1169,14 +1170,14 @@ unsafe extern "C" { pub(crate) fn LLVMAddFunction<'ll>( Mod: Module<'ll>, Name: *const c_char,- FunctionTy: Type<'ll>,+ FunctionTy: FunctionSignature<'ll>, ) -> 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>,+ FunctionTy: FunctionSignature<'ll>, ) -> Value<'ll>; // Operations about llvm intrinsics@@ -1746,7 +1747,7 @@ unsafe extern "C" { pub(crate) fn LLVMBuildCallWithOperandBundles<'ll>( B: &Builder<'ll>,- Ty: Type<'ll>,+ Ty: FunctionSignature<'ll>, Fn: Value<'ll>, Args: *const Value<'ll>, NumArgs: c_uint,@@ -1756,7 +1757,7 @@ unsafe extern "C" { ) -> Value<'ll>; pub(crate) fn LLVMBuildInvokeWithOperandBundles<'ll>( B: &Builder<'ll>,- Ty: Type<'ll>,+ Ty: FunctionSignature<'ll>, Fn: Value<'ll>, Args: *const Value<'ll>, NumArgs: c_uint,@@ -1768,7 +1769,7 @@ unsafe extern "C" { ) -> Value<'ll>; pub(crate) fn LLVMBuildCallBr<'ll>( B: &Builder<'ll>,- Ty: Type<'ll>,+ Ty: FunctionSignature<'ll>, Fn: Value<'ll>, DefaultDest: &'ll BasicBlock, IndirectDests: *const &'ll BasicBlock,@@ -2191,7 +2192,7 @@ unsafe extern "C" { pub(crate) fn LLVMRustPrintStatisticsJSON(OutStr: &RustString); pub(crate) fn LLVMRustInlineAsmVerify<'ll>(- Ty: Type<'ll>,+ Ty: FunctionSignature<'ll>, Constraints: *const c_uchar, // See "PTR_LEN_STR". ConstraintsLen: size_t, ) -> bool;compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs23 + / 1 −
@@ -1,7 +1,7 @@ //! Lifetime-branded references to things manipulated by the LLVM bindings. use std::marker::PhantomData;-use std::ptr;+use std::{fmt, ptr}; /// FIXME(Zalathar): Use the stdlib's `PhantomInvariantLifetime` when its API is settled. type PhantomInvariantLifetime<'a> = PhantomData<fn(&'a ()) -> &'a ()>;@@ -79,6 +79,28 @@ unsafe extern "C" { type TypeRaw; } +#[derive(Clone, Copy, PartialEq, Eq, Hash)]+#[repr(transparent)]+#[cfg_attr(bootstrap, rustc_pass_by_value)]+#[cfg_attr(not(bootstrap), lint::pass_by_value)]+pub(crate) struct FunctionSignature<'ll>(Type<'ll>);++impl<'ll> FunctionSignature<'ll> {+ pub(crate) fn from_type(ty: Type<'ll>) -> Option<Self> {+ if super::LLVMGetTypeKind(ty).to_rust() == super::TypeKind::Function {+ Some(Self(ty))+ } else {+ None+ }+ }+}++impl fmt::Debug for FunctionSignature<'_> {+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {+ fmt::Debug::fmt(&self.0, f)+ }+}+ /// Corresponds to `LLVMValueRef`. #[derive(Clone, Copy, PartialEq, Eq, Hash)] #[repr(transparent)]compiler/rustc_codegen_llvm/src/type_.rs12 + / 8 −
@@ -13,7 +13,7 @@ use rustc_target::callconv::{CastTarget, FnAbi}; use crate::abi::{FnAbiLlvmExt, LlvmType}; use crate::common; use crate::context::{CodegenCx, GenericCx, SCx};-use crate::llvm::{self, FALSE, TRUE, Type, TypeKind, Value};+use crate::llvm::{self, FALSE, FunctionSignature, TRUE, Type, TypeKind, Value}; use crate::type_of::LayoutLlvmExt; impl<'ll> fmt::Debug for Type<'ll> {@@ -65,16 +65,16 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> { unsafe { llvm::LLVMScalableVectorType(ty, count as c_uint) } } - pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> Value<'ll> {+ pub(crate) fn add_func(&self, name: &str, ty: FunctionSignature<'ll>) -> Value<'ll> { let name = SmallCStr::new(name); unsafe { llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty) } } - pub(crate) fn get_return_type(&self, ty: Type<'ll>) -> Type<'ll> {+ pub(crate) fn get_return_type(&self, ty: FunctionSignature<'ll>) -> Type<'ll> { unsafe { llvm::LLVMGetReturnType(ty) } } - pub(crate) fn func_params_types(&self, ty: Type<'ll>) -> Vec<Type<'ll>> {+ pub(crate) fn func_params_types(&self, ty: FunctionSignature<'ll>) -> Vec<Type<'ll>> { unsafe { let n_args = llvm::LLVMCountParamTypes(ty) as usize; let mut args = Vec::with_capacity(n_args);@@ -84,7 +84,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> { } } - pub(crate) fn func_is_variadic(&self, ty: Type<'ll>) -> bool {+ pub(crate) fn func_is_variadic(&self, ty: FunctionSignature<'ll>) -> bool { unsafe { llvm::LLVMIsFunctionVarArg(ty).is_true() } } @@ -150,7 +150,11 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> { (**self).borrow().llmod } - pub(crate) fn type_variadic_func(&self, args: &[Type<'ll>], ret: Type<'ll>) -> Type<'ll> {+ pub(crate) fn type_variadic_func(+ &self,+ args: &[Type<'ll>],+ ret: Type<'ll>,+ ) -> FunctionSignature<'ll> { unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, TRUE) } } @@ -238,7 +242,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { unsafe { llvm::LLVMX86FP80TypeInContext(self.llcx()) } } - fn type_func(&self, args: &[Type<'ll>], ret: Type<'ll>) -> Type<'ll> {+ fn type_func(&self, args: &[Type<'ll>], ret: Type<'ll>) -> FunctionSignature<'ll> { unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, FALSE) } } @@ -313,7 +317,7 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn cast_backend_type(&self, ty: &CastTarget) -> Type<'ll> { ty.llvm_type(self) }- fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Type<'ll> {+ fn fn_decl_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> FunctionSignature<'ll> { fn_abi.llvm_type(self) } fn fn_ptr_backend_type(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Type<'ll> {