change max_atomic_width type from u64 to Option<u64>

to better express the idea that omitting this field defaults this value
to target_pointer_width
This commit is contained in:
Jorge Aparicio 2016-10-03 23:45:40 -05:00
parent 251f04e90d
commit 6136069609
58 changed files with 69 additions and 74 deletions

View file

@ -926,7 +926,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 max_atomic_width = sess.target.target.max_atomic_width();
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
intern(fam)

View file

@ -25,7 +25,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
features: "+neon,+fp-armv8,+cyclone".to_string(),
eliminate_frame_pointer: false,
max_atomic_width: 128,
max_atomic_width: Some(128),
.. base
},
})

View file

@ -12,7 +12,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.max_atomic_width = 128;
base.max_atomic_width = Some(128);
// As documented in http://developer.android.com/ndk/guides/cpu-features.html
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
base.features = "+neon,+fp-armv8".to_string();

View file

@ -12,7 +12,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 128;
base.max_atomic_width = Some(128);
Ok(Target {
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
target_endian: "little".to_string(),

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.features = "+v7,+vfp3,+d16".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "arm-linux-androideabi".to_string(),

View file

@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
target_endian: "little".to_string(),

View file

@ -12,7 +12,7 @@ use target::{Target, TargetOptions, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
target_endian: "little".to_string(),

View file

@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
// Most of these settings are copied from the arm_unknown_linux_gnueabi
// target.
base.features = "+v6".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it
// to determine the calling convention and float ABI, and it doesn't

View file

@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
// Most of these settings are copied from the arm_unknown_linux_gnueabihf
// target.
base.features = "+v6,+vfp2".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
// It's important we use "gnueabihf" and not "musleabihf" here. LLVM
// uses it to determine the calling convention and float ABI, and it

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_vendor: "apple".to_string(),
options: TargetOptions {
features: "+v7,+vfp3,+neon".to_string(),
max_atomic_width: 64,
max_atomic_width: Some(64),
.. base
}
})

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.features = "+v7,+thumb2,+vfp3,+d16".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "armv7-none-linux-android".to_string(),

View file

@ -26,7 +26,7 @@ pub fn target() -> TargetResult {
// Info about features at https://wiki.debian.org/ArmHardFloatPort
features: "+v7,+vfp3,+d16,+thumb2".to_string(),
cpu: "generic".to_string(),
max_atomic_width: 64,
max_atomic_width: Some(64),
.. base
}
})

View file

@ -17,7 +17,7 @@ pub fn target() -> TargetResult {
// target.
base.features = "+v7,+vfp3,+neon".to_string();
base.cpu = "cortex-a8".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
// It's important we use "gnueabihf" and not "musleabihf" here. LLVM
// uses it to determine the calling convention and float ABI, and LLVM

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_vendor: "apple".to_string(),
options: TargetOptions {
features: "+v7,+vfp4,+neon".to_string(),
max_atomic_width: 64,
max_atomic_width: Some(64),
.. base
}
})

View file

@ -21,7 +21,7 @@ pub fn target() -> Result<Target, String> {
linker_is_gnu: true,
allow_asm: false,
obj_is_bitcode: true,
max_atomic_width: 32,
max_atomic_width: Some(32),
post_link_args: vec!["-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()],
.. Default::default()
};

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
target_env: "".to_string(),
target_vendor: "apple".to_string(),
options: TargetOptions {
max_atomic_width: 64,
max_atomic_width: Some(64),
.. base
}
})

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::apple_base::opts();
base.cpu = "yonah".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
// http://developer.android.com/ndk/guides/abis.html#x86
base.cpu = "pentiumpro".to_string();

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::windows_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::windows_msvc_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::dragonfly_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::freebsd_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::haiku_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_musl_base::opts();
base.cpu = "pentium4".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m32".to_string());
base.pre_link_args.push("-Wl,-melf_i386".to_string());

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
exe_suffix: ".pexe".to_string(),
linker_is_gnu: true,
allow_asm: false,
max_atomic_width: 32,
max_atomic_width: Some(32),
.. Default::default()
};
Ok(Target {

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
// NOTE(mips64r2) matches C toolchain
cpu: "mips64r2".to_string(),
features: "+mips64r2".to_string(),
max_atomic_width: 64,
max_atomic_width: Some(64),
..super::linux_base::opts()
},
})

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
// NOTE(mips64r2) matches C toolchain
cpu: "mips64r2".to_string(),
features: "+mips64r2".to_string(),
max_atomic_width: 64,
max_atomic_width: Some(64),
..super::linux_base::opts()
},
})

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32r2".to_string(),
features: "+mips32r2".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
},
})

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32r2".to_string(),
features: "+mips32r2,+soft-float".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
}
})

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32r2".to_string(),
features: "+mips32r2,+soft-float".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
},
})

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32".to_string(),
features: "+mips32".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
},
})

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32".to_string(),
features: "+mips32,+soft-float".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
}
})

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
options: TargetOptions {
cpu: "mips32".to_string(),
features: "+mips32,+soft-float".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
..super::linux_base::opts()
},
})

View file

@ -353,9 +353,8 @@ pub struct TargetOptions {
// 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,
/// Don't use this field; instead use the `.max_atomic_width()` method.
pub max_atomic_width: Option<u64>,
/// Panic strategy: "unwind" or "abort"
pub panic_strategy: PanicStrategy,
@ -407,10 +406,7 @@ impl Default for TargetOptions {
allow_asm: true,
has_elf_tls: false,
obj_is_bitcode: false,
// NOTE 0 is *not* the real default value of max_atomic_width. The default value is
// actually the pointer_width of the target. This default is injected in the
// Target::from_json function.
max_atomic_width: 0,
max_atomic_width: None,
panic_strategy: PanicStrategy::Unwind,
}
}
@ -431,6 +427,12 @@ impl Target {
}
}
/// Maximum integer size in bits that this target can perform atomic
/// operations on.
pub fn max_atomic_width(&self) -> u64 {
self.options.max_atomic_width.unwrap_or(self.target_pointer_width.parse().unwrap())
}
/// Load a target descriptor from a JSON object.
pub fn from_json(obj: Json) -> TargetResult {
// While ugly, this code must remain this way to retain
@ -469,9 +471,6 @@ 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("_", "-");
@ -484,11 +483,11 @@ impl Target {
.map(|o| o.as_boolean()
.map(|s| base.options.$key_name = s));
} );
($key_name:ident, u64) => ( {
($key_name:ident, Option<u64>) => ( {
let name = (stringify!($key_name)).replace("_", "-");
obj.find(&name[..])
.map(|o| o.as_u64()
.map(|s| base.options.$key_name = s));
.map(|s| base.options.$key_name = Some(s)));
} );
($key_name:ident, PanicStrategy) => ( {
let name = (stringify!($key_name)).replace("_", "-");
@ -562,7 +561,7 @@ impl Target {
key!(exe_allocation_crate);
key!(has_elf_tls, bool);
key!(obj_is_bitcode, bool);
key!(max_atomic_width, u64);
key!(max_atomic_width, Option<u64>);
try!(key!(panic_strategy, PanicStrategy));
Ok(base)
@ -708,10 +707,6 @@ impl ToJson for Target {
target_option_val!(max_atomic_width);
target_option_val!(panic_strategy);
if self.options.max_atomic_width.to_string() != self.target_pointer_width {
d.insert("max-atomic-width".to_string(), self.options.max_atomic_width.to_json());
}
Json::Object(d)
}
}

View file

@ -14,7 +14,7 @@ pub fn target() -> TargetResult {
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;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "powerpc64-unknown-linux-gnu".to_string(),

View file

@ -14,7 +14,7 @@ pub fn target() -> TargetResult {
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;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "powerpc64le-unknown-linux-gnu".to_string(),

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.pre_link_args.push("-m32".to_string());
base.max_atomic_width = 32;
base.max_atomic_width = Some(32);
Ok(Target {
llvm_target: "powerpc-unknown-linux-gnu".to_string(),

View file

@ -18,7 +18,7 @@ pub fn target() -> TargetResult {
// cabi_s390x.rs are for now hard-coded to assume the no-vector ABI.
// Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "s390x-unknown-linux-gnu".to_string(),

View file

@ -29,7 +29,7 @@ pub fn target() -> TargetResult {
features: "+strict-align".to_string(),
// There are no atomic instructions available in the instruction set of the ARMv6-M
// architecture
max_atomic_width: 0,
max_atomic_width: Some(0),
.. super::thumb_base::opts()
}
})

View file

@ -33,7 +33,7 @@ pub fn target() -> TargetResult {
target_vendor: "".to_string(),
options: TargetOptions {
max_atomic_width: 32,
max_atomic_width: Some(32),
.. super::thumb_base::opts()
},
})

View file

@ -42,7 +42,7 @@ pub fn target() -> TargetResult {
// Reference:
// ARMv7-M Architecture Reference Manual - A2.5 The optional floating-point extension
features: "+vfp4,+d16,+fp-only-sp".to_string(),
max_atomic_width: 32,
max_atomic_width: Some(32),
.. super::thumb_base::opts()
}
})

View file

@ -24,7 +24,7 @@ pub fn target() -> TargetResult {
target_vendor: "".to_string(),
options: TargetOptions {
max_atomic_width: 32,
max_atomic_width: Some(32),
.. super::thumb_base::opts()
},
})

View file

@ -23,7 +23,7 @@ pub fn target() -> Result<Target, String> {
linker_is_gnu: true,
allow_asm: false,
obj_is_bitcode: true,
max_atomic_width: 32,
max_atomic_width: Some(32),
post_link_args: vec!["-s".to_string(), "BINARYEN=1".to_string(),
"-s".to_string(), "ERROR_ON_UNDEFINED_SYMBOLS=1".to_string()],
.. Default::default()

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::apple_base::opts();
base.cpu = "core2".to_string();
base.max_atomic_width = 128; // core2 support cmpxchg16b
base.max_atomic_width = Some(128); // core2 support cmpxchg16b
base.eliminate_frame_pointer = false;
base.pre_link_args.push("-m64".to_string());

View file

@ -23,7 +23,7 @@ pub fn target() -> TargetResult {
target_env: "".to_string(),
target_vendor: "apple".to_string(),
options: TargetOptions {
max_atomic_width: 64,
max_atomic_width: Some(64),
.. base
}
})

View file

@ -14,7 +14,7 @@ pub fn target() -> TargetResult {
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;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "x86_64-pc-windows-gnu".to_string(),

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::windows_msvc_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "x86_64-pc-windows-msvc".to_string(),

View file

@ -16,7 +16,7 @@ pub fn target() -> TargetResult {
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.max_atomic_width = Some(64);
base.dynamic_linking = false;
base.has_rpath = false;

View file

@ -14,7 +14,7 @@ pub fn target() -> TargetResult {
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;
base.max_atomic_width = Some(64);
Ok(Target {
llvm_target: "x86_64-pc-solaris".to_string(),

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::bitrig_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::dragonfly_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::freebsd_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::haiku_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::linux_musl_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::netbsd_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {

View file

@ -13,7 +13,7 @@ use target::{Target, TargetResult};
pub fn target() -> TargetResult {
let mut base = super::openbsd_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = 64;
base.max_atomic_width = Some(64);
base.pre_link_args.push("-m64".to_string());
Ok(Target {