Skip to content

Commit

Permalink
Add #[cfg(target_has_atomic)] to get atomic support for the current t…
Browse files Browse the repository at this point in the history
…arget
  • Loading branch information
Amanieu committed May 9, 2016
1 parent 50909f2 commit 04835ea
Show file tree
Hide file tree
Showing 45 changed files with 90 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/doc/reference.md
Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Expand Up @@ -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)]
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/session/config.rs
Expand Up @@ -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)
Expand All @@ -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")));
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/aarch64_apple_ios.rs
Expand Up @@ -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)
},
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_back/target/aarch64_linux_android.rs
Expand Up @@ -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(),
Expand All @@ -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,
}
}
3 changes: 2 additions & 1 deletion src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/arm_linux_androideabi.rs
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_back/target/arm_unknown_linux_gnueabi.rs
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_back/target/arm_unknown_linux_gnueabihf.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/armv7_apple_ios.rs
Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs
Expand Up @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/armv7s_apple_ios.rs
Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/asmjs_unknown_emscripten.rs
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_back/target/i386_apple_ios.rs
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_apple_darwin.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_linux_android.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_pc_windows_gnu.rs
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_pc_windows_msvc.rs
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_dragonfly.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_freebsd.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_linux_gnu.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/i686_unknown_linux_musl.rs
Expand Up @@ -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());

Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/le32_unknown_nacl.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/mips_unknown_linux_gnu.rs
Expand Up @@ -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()
},
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/mips_unknown_linux_musl.rs
Expand Up @@ -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()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/mipsel_unknown_linux_gnu.rs
Expand Up @@ -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()
},
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/mipsel_unknown_linux_musl.rs
Expand Up @@ -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()
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/librustc_back/target/mod.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -340,6 +344,7 @@ impl Default for TargetOptions {
allow_asm: true,
has_elf_tls: false,
obj_is_bitcode: false,
max_atomic_width: 0,
}
}
}
Expand Down Expand Up @@ -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("_", "-");
Expand All @@ -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()
Expand Down Expand Up @@ -451,6 +465,7 @@ impl Target {
key!(archive_format);
key!(allow_asm, bool);
key!(custom_unwind_resume, bool);
key!(max_atomic_width, u64);

base
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/powerpc64_unknown_linux_gnu.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/powerpc_unknown_linux_gnu.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_apple_darwin.rs
Expand Up @@ -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());

Expand Down
7 changes: 5 additions & 2 deletions src/librustc_back/target/x86_64_apple_ios.rs
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_pc_windows_gnu.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_pc_windows_msvc.rs
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/librustc_back/target/x86_64_rumprun_netbsd.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 04835ea

Please sign in to comment.