Add 'compiler/rustc_codegen_cranelift/' from commit '793d26047f
'
git-subtree-dir: compiler/rustc_codegen_cranelift git-subtree-mainline:cf798c1ec6
git-subtree-split:793d26047f
This commit is contained in:
commit
ac4f7deb2f
86 changed files with 16617 additions and 0 deletions
35
compiler/rustc_codegen_cranelift/src/linkage.rs
Normal file
35
compiler/rustc_codegen_cranelift/src/linkage.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub(crate) fn get_clif_linkage(
|
||||
mono_item: MonoItem<'_>,
|
||||
linkage: RLinkage,
|
||||
visibility: Visibility,
|
||||
) -> Linkage {
|
||||
match (linkage, visibility) {
|
||||
(RLinkage::External, Visibility::Default) => Linkage::Export,
|
||||
(RLinkage::Internal, Visibility::Default) => Linkage::Local,
|
||||
(RLinkage::External, Visibility::Hidden) => Linkage::Hidden,
|
||||
_ => panic!("{:?} = {:?} {:?}", mono_item, linkage, visibility),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_static_linkage(tcx: TyCtxt<'_>, def_id: DefId) -> Linkage {
|
||||
let fn_attrs = tcx.codegen_fn_attrs(def_id);
|
||||
|
||||
if let Some(linkage) = fn_attrs.linkage {
|
||||
match linkage {
|
||||
RLinkage::External => Linkage::Export,
|
||||
RLinkage::Internal => Linkage::Local,
|
||||
RLinkage::ExternalWeak | RLinkage::WeakAny => Linkage::Preemptible,
|
||||
_ => panic!("{:?}", linkage),
|
||||
}
|
||||
} else {
|
||||
if tcx.is_reachable_non_generic(def_id) {
|
||||
Linkage::Export
|
||||
} else {
|
||||
Linkage::Hidden
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue