Skip to content

Commit cd18cd6

Browse files
authored
Unrolled build for #150768
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 #148533
2 parents 605f49b + fe9715b commit cd18cd6

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ use rustc_codegen_ssa::traits::{
2222
ArgAbiBuilderMethods, BaseTypeCodegenMethods, BuilderMethods, ConstCodegenMethods,
2323
IntrinsicCallBuilderMethods, LayoutTypeCodegenMethods,
2424
};
25+
use rustc_data_structures::fx::FxHashSet;
2526
use rustc_middle::bug;
26-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
27+
#[cfg(feature = "master")]
28+
use rustc_middle::ty::layout::FnAbiOf;
29+
use rustc_middle::ty::layout::LayoutOf;
2730
use rustc_middle::ty::{self, Instance, Ty};
2831
use rustc_span::{Span, Symbol, sym};
2932
use rustc_target::callconv::{ArgAbi, PassMode};
3033

31-
use crate::abi::{FnAbiGccExt, GccType};
34+
#[cfg(feature = "master")]
35+
use crate::abi::FnAbiGccExt;
36+
use crate::abi::GccType;
3237
use crate::builder::Builder;
3338
use crate::common::{SignType, TypeReflection};
3439
use crate::context::CodegenCx;
@@ -617,8 +622,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
617622
*func
618623
} else {
619624
self.linkage.set(FunctionType::Extern);
620-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
621-
let fn_ty = fn_abi.gcc_type(self);
622625

623626
let func = match sym {
624627
"llvm.fma.f16" => {
@@ -631,13 +634,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
631634

632635
self.intrinsics.borrow_mut().insert(sym.to_string(), func);
633636

634-
self.on_stack_function_params
635-
.borrow_mut()
636-
.insert(func, fn_ty.on_stack_param_indices);
637-
#[cfg(feature = "master")]
638-
for fn_attr in fn_ty.fn_attributes {
639-
func.add_attribute(fn_attr);
640-
}
637+
self.on_stack_function_params.borrow_mut().insert(func, FxHashSet::default());
641638

642639
crate::attributes::from_fn_attrs(self, func, instance);
643640

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,32 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
646646
) -> Self::Value {
647647
let tcx = self.tcx();
648648

649-
// FIXME remove usage of fn_abi
650-
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
651-
assert!(!fn_abi.ret.is_indirect());
652-
let fn_ty = fn_abi.llvm_type(self);
649+
let fn_ty = instance.ty(tcx, self.typing_env());
650+
let fn_sig = match *fn_ty.kind() {
651+
ty::FnDef(def_id, args) => {
652+
tcx.instantiate_bound_regions_with_erased(tcx.fn_sig(def_id).instantiate(tcx, args))
653+
}
654+
_ => unreachable!(),
655+
};
656+
assert!(!fn_sig.c_variadic);
657+
658+
let ret_layout = self.layout_of(fn_sig.output());
659+
let llreturn_ty = if ret_layout.is_zst() {
660+
self.type_void()
661+
} else {
662+
ret_layout.immediate_llvm_type(self)
663+
};
664+
665+
let mut llargument_tys = Vec::with_capacity(fn_sig.inputs().len());
666+
for &arg in fn_sig.inputs() {
667+
let arg_layout = self.layout_of(arg);
668+
if arg_layout.is_zst() {
669+
continue;
670+
}
671+
llargument_tys.push(arg_layout.immediate_llvm_type(self));
672+
}
673+
674+
let fn_ty = self.type_func(&llargument_tys, llreturn_ty);
653675

654676
let fn_ptr = if let Some(&llfn) = self.intrinsic_instances.borrow().get(&instance) {
655677
llfn
@@ -665,12 +687,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
665687
let llfn = declare_raw_fn(
666688
self,
667689
sym,
668-
fn_abi.llvm_cconv(self),
690+
llvm::CCallConv,
669691
llvm::UnnamedAddr::Global,
670692
llvm::Visibility::Default,
671693
fn_ty,
672694
);
673-
fn_abi.apply_attrs_llfn(self, llfn, Some(instance));
674695

675696
llfn
676697
};

0 commit comments

Comments
 (0)