Skip to content

Commit 745fe57

Browse files
committed
Move compiler_builtin check to the use case
1 parent 14430e6 commit 745fe57

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use std::mem;
1010
use cranelift_codegen::ir::{ArgumentPurpose, SigRef};
1111
use cranelift_codegen::isa::CallConv;
1212
use cranelift_module::ModuleError;
13+
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
1314
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
1415
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1516
use rustc_middle::ty::layout::FnAbiOf;
1617
use rustc_middle::ty::print::with_no_trimmed_paths;
1718
use rustc_middle::ty::TypeVisitableExt;
18-
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1919
use rustc_session::Session;
2020
use rustc_span::source_map::Spanned;
2121
use rustc_target::abi::call::{Conv, FnAbi, PassMode};

Diff for: compiler/rustc_codegen_cranelift/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use cranelift_codegen::CodegenError;
55
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
66
use cranelift_module::ModuleError;
77
use rustc_ast::InlineAsmOptions;
8+
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
89
use rustc_index::IndexVec;
910
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1011
use rustc_middle::ty::adjustment::PointerCoercion;
1112
use rustc_middle::ty::layout::FnAbiOf;
1213
use rustc_middle::ty::print::with_no_trimmed_paths;
1314
use rustc_middle::ty::TypeVisitableExt;
14-
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1515

1616
use crate::constant::ConstantCx;
1717
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+28
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,34 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
806806
ongoing_codegen
807807
}
808808

809+
/// Returns whether a call from the current crate to the [`Instance`] would produce a call
810+
/// from `compiler_builtins` to a symbol the linker must resolve.
811+
///
812+
/// Such calls from `compiler_bultins` are effectively impossible for the linker to handle. Some
813+
/// linkers will optimize such that dead calls to unresolved symbols are not an error, but this is
814+
/// not guaranteed. So we used this function in codegen backends to ensure we do not generate any
815+
/// unlinkable calls.
816+
///
817+
/// Note that calls to LLVM intrinsics are uniquely okay because they won't make it to the linker.
818+
pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
819+
tcx: TyCtxt<'tcx>,
820+
instance: Instance<'tcx>,
821+
) -> bool {
822+
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
823+
if let Some(name) = tcx.codegen_fn_attrs(def_id).link_name {
824+
name.as_str().starts_with("llvm.")
825+
} else {
826+
false
827+
}
828+
}
829+
830+
let def_id = instance.def_id();
831+
!def_id.is_local()
832+
&& tcx.is_compiler_builtins(LOCAL_CRATE)
833+
&& !is_llvm_intrinsic(tcx, def_id)
834+
&& !tcx.should_codegen_locally(instance)
835+
}
836+
809837
impl CrateInfo {
810838
pub fn new(tcx: TyCtxt<'_>, target_cpu: String) -> CrateInfo {
811839
let crate_types = tcx.crate_types().to_vec();

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::operand::OperandValue::{Immediate, Pair, Ref, ZeroSized};
33
use super::place::{PlaceRef, PlaceValue};
44
use super::{CachedLlbb, FunctionCx, LocalRef};
55

6-
use crate::base;
6+
use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization};
77
use crate::common::{self, IntPredicate};
88
use crate::errors::CompilerBuiltinsCannotCall;
99
use crate::meth;
@@ -18,7 +18,6 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, ValidityRequirement};
1818
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1919
use rustc_middle::ty::{self, Instance, Ty};
2020
use rustc_middle::{bug, span_bug};
21-
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
2221
use rustc_session::config::OptLevel;
2322
use rustc_span::{source_map::Spanned, sym, Span};
2423
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode, Reg};

Diff for: compiler/rustc_monomorphize/src/lib.rs

-32
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ use rustc_middle::bug;
88
use rustc_middle::query::TyCtxtAt;
99
use rustc_middle::traits;
1010
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
11-
use rustc_middle::ty::Instance;
12-
use rustc_middle::ty::TyCtxt;
1311
use rustc_middle::ty::{self, Ty};
1412
use rustc_middle::util::Providers;
15-
use rustc_span::def_id::DefId;
16-
use rustc_span::def_id::LOCAL_CRATE;
1713
use rustc_span::ErrorGuaranteed;
1814

1915
mod collector;
@@ -46,34 +42,6 @@ fn custom_coerce_unsize_info<'tcx>(
4642
}
4743
}
4844

49-
/// Returns whether a call from the current crate to the [`Instance`] would produce a call
50-
/// from `compiler_builtins` to a symbol the linker must resolve.
51-
///
52-
/// Such calls from `compiler_bultins` are effectively impossible for the linker to handle. Some
53-
/// linkers will optimize such that dead calls to unresolved symbols are not an error, but this is
54-
/// not guaranteed. So we used this function in codegen backends to ensure we do not generate any
55-
/// unlinkable calls.
56-
///
57-
/// Note that calls to LLVM intrinsics are uniquely okay because they won't make it to the linker.
58-
pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
59-
tcx: TyCtxt<'tcx>,
60-
instance: Instance<'tcx>,
61-
) -> bool {
62-
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
63-
if let Some(name) = tcx.codegen_fn_attrs(def_id).link_name {
64-
name.as_str().starts_with("llvm.")
65-
} else {
66-
false
67-
}
68-
}
69-
70-
let def_id = instance.def_id();
71-
!def_id.is_local()
72-
&& tcx.is_compiler_builtins(LOCAL_CRATE)
73-
&& !is_llvm_intrinsic(tcx, def_id)
74-
&& !tcx.should_codegen_locally(instance)
75-
}
76-
7745
pub fn provide(providers: &mut Providers) {
7846
partitioning::provide(providers);
7947
polymorphize::provide(providers);

0 commit comments

Comments
 (0)