Skip to content

Commit d8af8b6

Browse files
committedSep 5, 2018
Auto merge of #53878 - alexcrichton:wasm-atomics-feature, r=eddyb
rustc: Prepare the `atomics` feature for wasm This commit adds a few changes for atomic instructions on the `wasm32-unknown-unknown` target. Atomic instructions are not yet stable in WebAssembly itself but there are multiple implementations and LLVM has support for the proposed instruction set, so let's work on exposing it! Here there are a few inclusions: * The `atomics` feature was whitelisted for LLVM, allowing code in Rust to enable/disable/gate on this. * The `singlethread` option is turned off for wasm when the `atomics` feature is enabled. This means that by default wasm won't be lowering with atomics, but when atomics are enabled globally we'll turn off single-threaded mode to actually codegen atomics. This probably isn't what we'll want in the long term but for now it should work. * Finally the maximum atomic width is increased to 64 to reflect the current wasm spec.
2 parents b0297f3 + fc497d0 commit d8af8b6

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed
 

‎src/librustc_codegen_llvm/back/write.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,22 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
176176
None => llvm::CodeModel::None,
177177
};
178178

179-
let singlethread = sess.target.target.options.singlethread;
179+
let features = attributes::llvm_target_features(sess).collect::<Vec<_>>();
180+
let mut singlethread = sess.target.target.options.singlethread;
181+
182+
// On the wasm target once the `atomics` feature is enabled that means that
183+
// we're no longer single-threaded, or otherwise we don't want LLVM to
184+
// lower atomic operations to single-threaded operations.
185+
if singlethread &&
186+
sess.target.target.llvm_target.contains("wasm32") &&
187+
features.iter().any(|s| *s == "+atomics")
188+
{
189+
singlethread = false;
190+
}
180191

181192
let triple = SmallCStr::new(&sess.target.target.llvm_target);
182193
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
183-
let features = attributes::llvm_target_features(sess)
184-
.collect::<Vec<_>>()
185-
.join(",");
194+
let features = features.join(",");
186195
let features = CString::new(features).unwrap();
187196
let is_pie_binary = !find_features && is_pie_binary(sess);
188197
let trap_unreachable = sess.target.target.options.trap_unreachable;

‎src/librustc_codegen_llvm/llvm_util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const MIPS_WHITELIST: &[(&str, Option<&str>)] = &[
177177

178178
const WASM_WHITELIST: &[(&str, Option<&str>)] = &[
179179
("simd128", Some("wasm_target_feature")),
180+
("atomics", Some("wasm_target_feature")),
180181
];
181182

182183
/// When rustdoc is running, provide a list of all known features so that all their respective

‎src/librustc_target/spec/wasm32_unknown_unknown.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ pub fn target() -> Result<Target, String> {
3636
dll_suffix: ".wasm".to_string(),
3737
linker_is_gnu: false,
3838

39-
// A bit of a lie, but "eh"
40-
max_atomic_width: Some(32),
39+
max_atomic_width: Some(64),
4140

4241
// Unwinding doesn't work right now, so the whole target unconditionally
4342
// defaults to panic=abort. Note that this is guaranteed to change in

0 commit comments

Comments
 (0)