Place intrinsics in individual object files (#349)

Co-authored-by: Tomasz Miąsko <tomasz.miasko@gmail.com>
This commit is contained in:
Tomasz Miąsko 2020-04-11 00:00:50 +02:00 committed by GitHub
parent 72526f3811
commit 2541f27e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 16 deletions

View File

@ -173,8 +173,7 @@ macro_rules! intrinsics {
#[cfg(all(windows, target_arch = "x86_64"))] #[cfg(all(windows, target_arch = "x86_64"))]
pub mod $name { pub mod $name {
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
intrinsics! {
pub extern $abi fn $name( $($argname: $ty),* ) pub extern $abi fn $name( $($argname: $ty),* )
-> ::macros::win64_128bit_abi_hack::U64x2 -> ::macros::win64_128bit_abi_hack::U64x2
{ {
@ -182,7 +181,6 @@ macro_rules! intrinsics {
::macros::win64_128bit_abi_hack::U64x2::from(e) ::macros::win64_128bit_abi_hack::U64x2::from(e)
} }
} }
}
#[cfg(not(all(windows, target_arch = "x86_64")))] #[cfg(not(all(windows, target_arch = "x86_64")))]
intrinsics! { intrinsics! {
@ -209,18 +207,24 @@ macro_rules! intrinsics {
$($rest:tt)* $($rest:tt)*
) => ( ) => (
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret { pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
$($body)* $($body)*
} }
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
pub mod $name { pub mod $name {
intrinsics! { #[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern "aapcs" fn $alias( $($argname: $ty),* ) -> $ret { pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
super::$name($($argname),*) super::$name($($argname),*)
} }
} }
#[cfg(target_arch = "arm")]
pub mod $alias {
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern "aapcs" fn $alias( $($argname: $ty),* ) -> $ret {
super::$name($($argname),*)
}
} }
#[cfg(not(target_arch = "arm"))] #[cfg(not(target_arch = "arm"))]
@ -234,9 +238,15 @@ macro_rules! intrinsics {
intrinsics!($($rest)*); intrinsics!($($rest)*);
); );
// This is the final catch-all rule. At this point we just generate an // This is the final catch-all rule. At this point we generate an
// intrinsic with a conditional `#[no_mangle]` directive to avoid // intrinsic with a conditional `#[no_mangle]` directive to avoid
// interfereing with duplicate symbols and whatnot during testing. // interfering with duplicate symbols and whatnot during testing.
//
// The implementation is placed in a separate module, to take advantage
// of the fact that rustc partitions functions into code generation
// units based on module they are defined in. As a result we will have
// a separate object file for each intrinsic. For further details see
// corresponding PR in rustc https://github.com/rust-lang/rust/pull/70846
// //
// After the intrinsic is defined we just continue with the rest of the // After the intrinsic is defined we just continue with the rest of the
// input we were given. // input we were given.
@ -249,11 +259,18 @@ macro_rules! intrinsics {
$($rest:tt)* $($rest:tt)*
) => ( ) => (
$(#[$($attr)*])* $(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret { pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
$($body)* $($body)*
} }
pub mod $name {
$(#[$($attr)*])*
#[cfg_attr(not(feature = "mangled-names"), no_mangle)]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
super::$name($($argname),*)
}
}
intrinsics!($($rest)*); intrinsics!($($rest)*);
); );
} }