Rollup merge of #150768 - bjorn3:llvm_intrinsic_no_fn_abi, r=wesleywiser
Don't compute FnAbi for LLVM intrinsics in backends ~~This removes support for `extern "unadjusted"` for anything other than LLVM intrinsics. It only makes sense in the context of calling LLVM intrinsics anyway as it exposes the way the LLVM backend internally represents types. Perhaps it should be renamed to `extern "llvm-intrinsic"`?~~ Follow up to https://github.com/rust-lang/rust/pull/148533
This commit is contained in:
commit
0041f221ea
2 changed files with 35 additions and 17 deletions
|
|
@ -22,13 +22,18 @@ use rustc_codegen_ssa::traits::{
|
|||
ArgAbiBuilderMethods, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
|
||||
IntrinsicCallBuilderMethods, LayoutTypeCodegenMethods,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
|
||||
#[cfg(feature = "master")]
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self, Instance, Ty};
|
||||
use rustc_span::{Span, Symbol, sym};
|
||||
use rustc_target::callconv::{ArgAbi, PassMode};
|
||||
|
||||
use crate::abi::{FnAbiGccExt, GccType};
|
||||
#[cfg(feature = "master")]
|
||||
use crate::abi::FnAbiGccExt;
|
||||
use crate::abi::GccType;
|
||||
use crate::builder::Builder;
|
||||
use crate::common::{SignType, TypeReflection};
|
||||
use crate::context::CodegenCx;
|
||||
|
|
@ -617,8 +622,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
|
|||
*func
|
||||
} else {
|
||||
self.linkage.set(FunctionType::Extern);
|
||||
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
|
||||
let fn_ty = fn_abi.gcc_type(self);
|
||||
|
||||
let func = match sym {
|
||||
"llvm.fma.f16" => {
|
||||
|
|
@ -631,13 +634,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
|
|||
|
||||
self.intrinsics.borrow_mut().insert(sym.to_string(), func);
|
||||
|
||||
self.on_stack_function_params
|
||||
.borrow_mut()
|
||||
.insert(func, fn_ty.on_stack_param_indices);
|
||||
#[cfg(feature = "master")]
|
||||
for fn_attr in fn_ty.fn_attributes {
|
||||
func.add_attribute(fn_attr);
|
||||
}
|
||||
self.on_stack_function_params.borrow_mut().insert(func, FxHashSet::default());
|
||||
|
||||
crate::attributes::from_fn_attrs(self, func, instance);
|
||||
|
||||
|
|
|
|||
|
|
@ -646,10 +646,32 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
) -> Self::Value {
|
||||
let tcx = self.tcx();
|
||||
|
||||
// FIXME remove usage of fn_abi
|
||||
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
|
||||
assert!(!fn_abi.ret.is_indirect());
|
||||
let fn_ty = fn_abi.llvm_type(self);
|
||||
let fn_ty = instance.ty(tcx, self.typing_env());
|
||||
let fn_sig = match *fn_ty.kind() {
|
||||
ty::FnDef(def_id, args) => {
|
||||
tcx.instantiate_bound_regions_with_erased(tcx.fn_sig(def_id).instantiate(tcx, args))
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
assert!(!fn_sig.c_variadic);
|
||||
|
||||
let ret_layout = self.layout_of(fn_sig.output());
|
||||
let llreturn_ty = if ret_layout.is_zst() {
|
||||
self.type_void()
|
||||
} else {
|
||||
ret_layout.immediate_llvm_type(self)
|
||||
};
|
||||
|
||||
let mut llargument_tys = Vec::with_capacity(fn_sig.inputs().len());
|
||||
for &arg in fn_sig.inputs() {
|
||||
let arg_layout = self.layout_of(arg);
|
||||
if arg_layout.is_zst() {
|
||||
continue;
|
||||
}
|
||||
llargument_tys.push(arg_layout.immediate_llvm_type(self));
|
||||
}
|
||||
|
||||
let fn_ty = self.type_func(&llargument_tys, llreturn_ty);
|
||||
|
||||
let fn_ptr = if let Some(&llfn) = self.intrinsic_instances.borrow().get(&instance) {
|
||||
llfn
|
||||
|
|
@ -665,12 +687,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
let llfn = declare_raw_fn(
|
||||
self,
|
||||
sym,
|
||||
fn_abi.llvm_cconv(self),
|
||||
llvm::CCallConv,
|
||||
llvm::UnnamedAddr::Global,
|
||||
llvm::Visibility::Default,
|
||||
fn_ty,
|
||||
);
|
||||
fn_abi.apply_attrs_llfn(self, llfn, Some(instance));
|
||||
|
||||
llfn
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue