Add #[cfg(target_has_atomic)] to get atomic support for the current target
This commit is contained in:
parent
50909f2d50
commit
04835ea5ec
45 changed files with 90 additions and 10 deletions
|
@ -2091,6 +2091,8 @@ The following configurations must be defined by the implementation:
|
|||
* `target_pointer_width = "..."` - Target pointer width in bits. This is set
|
||||
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
|
||||
64-bit pointers.
|
||||
* `target_has_atomic = "..."` - Set of integer sizes on which the target can perform
|
||||
atomic operations. Values are `"8"`, `"16"`, `"32"`, `"64"` and `"ptr"`.
|
||||
* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or
|
||||
simply `"unknown"`.
|
||||
* `test` - Enabled when compiling the test harness (using the `--test` flag).
|
||||
|
@ -2295,6 +2297,9 @@ The currently implemented features of the reference compiler are:
|
|||
* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor`
|
||||
matcher which is subject to change.
|
||||
|
||||
* `cfg_target_has_atomic` - Allows conditional compilation using the `target_has_atomic`
|
||||
matcher which is subject to change.
|
||||
|
||||
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
|
||||
ways insufficient for concatenating identifiers, and may be
|
||||
removed entirely for something more wholesome.
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#![feature(associated_type_defaults)]
|
||||
#![feature(concat_idents)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(cfg_target_has_atomic)]
|
||||
#![feature(custom_attribute)]
|
||||
#![feature(fundamental)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
|
|
@ -695,6 +695,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
|
|||
let os = &sess.target.target.target_os;
|
||||
let env = &sess.target.target.target_env;
|
||||
let vendor = &sess.target.target.target_vendor;
|
||||
let max_atomic_width = sess.target.target.options.max_atomic_width;
|
||||
|
||||
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
|
||||
intern(fam)
|
||||
|
@ -721,6 +722,15 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
|
|||
if sess.target.target.options.has_elf_tls {
|
||||
ret.push(attr::mk_word_item(InternedString::new("target_thread_local")));
|
||||
}
|
||||
for &i in &[8, 16, 32, 64, 128] {
|
||||
if i <= max_atomic_width {
|
||||
let s = i.to_string();
|
||||
ret.push(mk(InternedString::new("target_has_atomic"), intern(&s)));
|
||||
if &s == wordsz {
|
||||
ret.push(mk(InternedString::new("target_has_atomic"), intern("ptr")));
|
||||
}
|
||||
}
|
||||
}
|
||||
if sess.opts.debug_assertions {
|
||||
ret.push(attr::mk_word_item(InternedString::new("debug_assertions")));
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
features: "+neon,+fp-armv8,+cyclone".to_string(),
|
||||
eliminate_frame_pointer: false,
|
||||
max_atomic_width: 128,
|
||||
.. opts(Arch::Arm64)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
use target::Target;
|
||||
|
||||
pub fn target() -> Target {
|
||||
let mut base = super::android_base::opts();
|
||||
base.max_atomic_width = 128;
|
||||
Target {
|
||||
llvm_target: "aarch64-linux-android".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
|
@ -20,6 +22,6 @@ pub fn target() -> Target {
|
|||
target_os: "android".to_string(),
|
||||
target_env: "".to_string(),
|
||||
target_vendor: "unknown".to_string(),
|
||||
options: super::android_base::opts(),
|
||||
options: base,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
use target::Target;
|
||||
|
||||
pub fn target() -> Target {
|
||||
let base = super::linux_base::opts();
|
||||
let mut base = super::linux_base::opts();
|
||||
base.max_atomic_width = 128;
|
||||
Target {
|
||||
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::android_base::opts();
|
||||
base.features = "+v7,+vfp3,+d16".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "arm-linux-androideabi".to_string(),
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
use target::{Target, TargetOptions};
|
||||
|
||||
pub fn target() -> Target {
|
||||
let base = super::linux_base::opts();
|
||||
let mut base = super::linux_base::opts();
|
||||
base.max_atomic_width = 64;
|
||||
Target {
|
||||
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
use target::{Target, TargetOptions};
|
||||
|
||||
pub fn target() -> Target {
|
||||
let base = super::linux_base::opts();
|
||||
let mut base = super::linux_base::opts();
|
||||
base.max_atomic_width = 64;
|
||||
Target {
|
||||
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
|
||||
target_endian: "little".to_string(),
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn target() -> Target {
|
|||
target_vendor: "apple".to_string(),
|
||||
options: TargetOptions {
|
||||
features: "+v7,+vfp3,+neon".to_string(),
|
||||
max_atomic_width: 64,
|
||||
.. opts(Arch::Armv7)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
features: "+v7,+vfp3,+neon".to_string(),
|
||||
cpu: "cortex-a8".to_string(),
|
||||
max_atomic_width: 64,
|
||||
.. base
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn target() -> Target {
|
|||
target_vendor: "apple".to_string(),
|
||||
options: TargetOptions {
|
||||
features: "+v7,+vfp4,+neon".to_string(),
|
||||
max_atomic_width: 64,
|
||||
.. opts(Arch::Armv7s)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ pub fn target() -> Target {
|
|||
linker_is_gnu: true,
|
||||
allow_asm: false,
|
||||
obj_is_bitcode: true,
|
||||
max_atomic_width: 32,
|
||||
.. Default::default()
|
||||
};
|
||||
Target {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use target::Target;
|
||||
use target::{Target, TargetOptions};
|
||||
use super::apple_ios_base::{opts, Arch};
|
||||
|
||||
pub fn target() -> Target {
|
||||
|
@ -21,6 +21,9 @@ pub fn target() -> Target {
|
|||
target_os: "ios".to_string(),
|
||||
target_env: "".to_string(),
|
||||
target_vendor: "apple".to_string(),
|
||||
options: opts(Arch::I386)
|
||||
options: TargetOptions {
|
||||
max_atomic_width: 64,
|
||||
.. opts(Arch::I386)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::apple_base::opts();
|
||||
base.cpu = "yonah".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::android_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "i686-linux-android".to_string(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::windows_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
|
||||
// space available to x86 Windows binaries on x86_64.
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::windows_msvc_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
|
||||
// space available to x86 Windows binaries on x86_64.
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::dragonfly_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::freebsd_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::linux_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::linux_musl_base::opts();
|
||||
base.cpu = "pentium4".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
base.pre_link_args.push("-Wl,-melf_i386".to_string());
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ pub fn target() -> Target {
|
|||
no_compiler_rt: false,
|
||||
linker_is_gnu: true,
|
||||
allow_asm: false,
|
||||
max_atomic_width: 32,
|
||||
.. Default::default()
|
||||
};
|
||||
Target {
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
cpu: "mips32r2".to_string(),
|
||||
features: "+mips32r2,+soft-float".to_string(),
|
||||
max_atomic_width: 32,
|
||||
..super::linux_base::opts()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
cpu: "mips32r2".to_string(),
|
||||
features: "+mips32r2,+soft-float".to_string(),
|
||||
max_atomic_width: 32,
|
||||
..super::linux_base::opts()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
cpu: "mips32".to_string(),
|
||||
features: "+mips32".to_string(),
|
||||
max_atomic_width: 32,
|
||||
..super::linux_base::opts()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ pub fn target() -> Target {
|
|||
options: TargetOptions {
|
||||
cpu: "mips32".to_string(),
|
||||
features: "+mips32".to_string(),
|
||||
max_atomic_width: 32,
|
||||
..super::linux_base::opts()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,6 +292,10 @@ pub struct TargetOptions {
|
|||
// If we give emcc .o files that are actually .bc files it
|
||||
// will 'just work'.
|
||||
pub obj_is_bitcode: bool,
|
||||
|
||||
/// Maximum integer size in bits that this target can perform atomic
|
||||
/// operations on.
|
||||
pub max_atomic_width: u64,
|
||||
}
|
||||
|
||||
impl Default for TargetOptions {
|
||||
|
@ -340,6 +344,7 @@ impl Default for TargetOptions {
|
|||
allow_asm: true,
|
||||
has_elf_tls: false,
|
||||
obj_is_bitcode: false,
|
||||
max_atomic_width: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -392,6 +397,9 @@ impl Target {
|
|||
options: Default::default(),
|
||||
};
|
||||
|
||||
// Default max-atomic-width to target-pointer-width
|
||||
base.options.max_atomic_width = base.target_pointer_width.parse().unwrap();
|
||||
|
||||
macro_rules! key {
|
||||
($key_name:ident) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
|
@ -404,6 +412,12 @@ impl Target {
|
|||
.map(|o| o.as_boolean()
|
||||
.map(|s| base.options.$key_name = s));
|
||||
} );
|
||||
($key_name:ident, u64) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
obj.find(&name[..])
|
||||
.map(|o| o.as_u64()
|
||||
.map(|s| base.options.$key_name = s));
|
||||
} );
|
||||
($key_name:ident, list) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
obj.find(&name[..]).map(|o| o.as_array()
|
||||
|
@ -451,6 +465,7 @@ impl Target {
|
|||
key!(archive_format);
|
||||
key!(allow_asm, bool);
|
||||
key!(custom_unwind_resume, bool);
|
||||
key!(max_atomic_width, u64);
|
||||
|
||||
base
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ pub fn target() -> Target {
|
|||
let mut base = super::linux_base::opts();
|
||||
base.cpu = "ppc64".to_string();
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "powerpc64-unknown-linux-gnu".to_string(),
|
||||
|
|
|
@ -14,6 +14,7 @@ pub fn target() -> Target {
|
|||
let mut base = super::linux_base::opts();
|
||||
base.cpu = "ppc64le".to_string();
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "powerpc64le-unknown-linux-gnu".to_string(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::linux_base::opts();
|
||||
base.pre_link_args.push("-m32".to_string());
|
||||
base.max_atomic_width = 32;
|
||||
|
||||
Target {
|
||||
llvm_target: "powerpc-unknown-linux-gnu".to_string(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::apple_base::opts();
|
||||
base.cpu = "core2".to_string();
|
||||
base.max_atomic_width = 128; // core2 support cmpxchg16b
|
||||
base.eliminate_frame_pointer = false;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use target::Target;
|
||||
use target::{Target, TargetOptions};
|
||||
use super::apple_ios_base::{opts, Arch};
|
||||
|
||||
pub fn target() -> Target {
|
||||
|
@ -21,6 +21,9 @@ pub fn target() -> Target {
|
|||
target_os: "ios".to_string(),
|
||||
target_env: "".to_string(),
|
||||
target_vendor: "apple".to_string(),
|
||||
options: opts(Arch::X86_64)
|
||||
options: TargetOptions {
|
||||
max_atomic_width: 64,
|
||||
.. opts(Arch::X86_64)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ pub fn target() -> Target {
|
|||
let mut base = super::windows_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "x86_64-pc-windows-gnu".to_string(),
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::windows_msvc_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "x86_64-pc-windows-msvc".to_string(),
|
||||
|
|
|
@ -15,6 +15,7 @@ pub fn target() -> Target {
|
|||
base.pre_link_args.push("-m64".to_string());
|
||||
base.linker = "x86_64-rumprun-netbsd-gcc".to_string();
|
||||
base.ar = "x86_64-rumprun-netbsd-ar".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
base.dynamic_linking = false;
|
||||
base.has_rpath = false;
|
||||
|
|
|
@ -14,6 +14,7 @@ pub fn target() -> Target {
|
|||
let mut base = super::solaris_base::opts();
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
|
||||
Target {
|
||||
llvm_target: "x86_64-pc-solaris".to_string(),
|
||||
|
|
|
@ -12,6 +12,7 @@ use target::Target;
|
|||
|
||||
pub fn target() -> Target {
|
||||
let mut base = super::bitrig_base::opts();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::dragonfly_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::freebsd_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::linux_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::linux_musl_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -12,6 +12,7 @@ use target::Target;
|
|||
|
||||
pub fn target() -> Target {
|
||||
let mut base = super::netbsd_base::opts();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -13,6 +13,7 @@ use target::Target;
|
|||
pub fn target() -> Target {
|
||||
let mut base = super::openbsd_base::opts();
|
||||
base.cpu = "x86-64".to_string();
|
||||
base.max_atomic_width = 64;
|
||||
base.pre_link_args.push("-m64".to_string());
|
||||
|
||||
Target {
|
||||
|
|
|
@ -269,7 +269,10 @@ declare_features! (
|
|||
(active, pub_restricted, "1.9.0", Some(32409)),
|
||||
|
||||
// Allow Drop types in statics/const functions (RFC 1440)
|
||||
(active, drop_types_in_const, "1.9.0", Some(33156))
|
||||
(active, drop_types_in_const, "1.9.0", Some(33156)),
|
||||
|
||||
// Allows cfg(target_has_atomic = "...").
|
||||
(active, cfg_target_has_atomic, "1.9.0", Some(32976))
|
||||
);
|
||||
|
||||
declare_features! (
|
||||
|
@ -577,6 +580,7 @@ const GATED_CFGS: &'static [(&'static str, &'static str, fn(&Features) -> bool)]
|
|||
("target_feature", "cfg_target_feature", cfg_fn!(cfg_target_feature)),
|
||||
("target_vendor", "cfg_target_vendor", cfg_fn!(cfg_target_vendor)),
|
||||
("target_thread_local", "cfg_target_thread_local", cfg_fn!(cfg_target_thread_local)),
|
||||
("target_has_atomic", "cfg_target_has_atomic", cfg_fn!(cfg_target_has_atomic)),
|
||||
];
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue