Skip to content

Commit dfb6080

Browse files
committed
rollup merge of #24833: tari/rfc888
Closes #24118, implementing RFC 888.
2 parents 3434469 + 94c9bde commit dfb6080

File tree

7 files changed

+43
-11
lines changed

7 files changed

+43
-11
lines changed

src/libcore/intrinsics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ extern "rust-intrinsic" {
139139
pub fn atomic_fence_rel();
140140
pub fn atomic_fence_acqrel();
141141

142+
/// A compiler-only memory barrier.
143+
///
144+
/// Memory accesses will never be reordered across this barrier by the compiler,
145+
/// but no instructions will be emitted for it. This is appropriate for operations
146+
/// on the same thread that may be preempted, such as when interacting with signal
147+
/// handlers.
148+
#[cfg(not(stage0))] // SNAP 857ef6e
149+
pub fn atomic_singlethreadfence();
150+
#[cfg(not(stage0))] // SNAP 857ef6e
151+
pub fn atomic_singlethreadfence_acq();
152+
#[cfg(not(stage0))] // SNAP 857ef6e
153+
pub fn atomic_singlethreadfence_rel();
154+
#[cfg(not(stage0))] // SNAP 857ef6e
155+
pub fn atomic_singlethreadfence_acqrel();
156+
142157
/// Aborts the execution of the process.
143158
pub fn abort() -> !;
144159

src/librustc_llvm/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub use self::RealPredicate::*;
4242
pub use self::TypeKind::*;
4343
pub use self::AtomicBinOp::*;
4444
pub use self::AtomicOrdering::*;
45+
pub use self::SynchronizationScope::*;
4546
pub use self::FileType::*;
4647
pub use self::MetadataType::*;
4748
pub use self::AsmDialect::*;
@@ -360,6 +361,13 @@ pub enum AtomicOrdering {
360361
SequentiallyConsistent = 7
361362
}
362363

364+
#[repr(C)]
365+
#[derive(Copy, Clone)]
366+
pub enum SynchronizationScope {
367+
SingleThread = 0,
368+
CrossThread = 1
369+
}
370+
363371
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
364372
#[repr(C)]
365373
#[derive(Copy, Clone)]
@@ -1533,7 +1541,9 @@ extern {
15331541
SingleThreaded: Bool)
15341542
-> ValueRef;
15351543

1536-
pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1544+
pub fn LLVMBuildAtomicFence(B: BuilderRef,
1545+
Order: AtomicOrdering,
1546+
Scope: SynchronizationScope);
15371547

15381548

15391549
/* Selected entries from the downcasts. */

src/librustc_trans/trans/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![allow(non_snake_case)]
1313

1414
use llvm;
15-
use llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect, AttrBuilder};
15+
use llvm::{CallConv, AtomicBinOp, AtomicOrdering, SynchronizationScope, AsmDialect, AttrBuilder};
1616
use llvm::{Opcode, IntPredicate, RealPredicate};
1717
use llvm::{ValueRef, BasicBlockRef};
1818
use trans::common::*;
@@ -965,9 +965,9 @@ pub fn CallWithConv(cx: Block,
965965
B(cx).call_with_conv(fn_, args, conv, attributes)
966966
}
967967

968-
pub fn AtomicFence(cx: Block, order: AtomicOrdering) {
968+
pub fn AtomicFence(cx: Block, order: AtomicOrdering, scope: SynchronizationScope) {
969969
if cx.unreachable.get() { return; }
970-
B(cx).atomic_fence(order)
970+
B(cx).atomic_fence(order, scope)
971971
}
972972

973973
pub fn Select(cx: Block, if_: ValueRef, then: ValueRef, else_: ValueRef) -> ValueRef {

src/librustc_trans/trans/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(dead_code)] // FFI wrappers
1212

1313
use llvm;
14-
use llvm::{CallConv, AtomicBinOp, AtomicOrdering, AsmDialect, AttrBuilder};
14+
use llvm::{CallConv, AtomicBinOp, AtomicOrdering, SynchronizationScope, AsmDialect, AttrBuilder};
1515
use llvm::{Opcode, IntPredicate, RealPredicate, False};
1616
use llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
1717
use trans::base;
@@ -989,9 +989,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
989989
}
990990
}
991991

992-
pub fn atomic_fence(&self, order: AtomicOrdering) {
992+
pub fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope) {
993993
unsafe {
994-
llvm::LLVMBuildAtomicFence(self.llbuilder, order);
994+
llvm::LLVMBuildAtomicFence(self.llbuilder, order, scope);
995995
}
996996
}
997997
}

src/librustc_trans/trans/intrinsic.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
763763
}
764764

765765
"fence" => {
766-
AtomicFence(bcx, order);
766+
AtomicFence(bcx, order, llvm::CrossThread);
767+
C_nil(ccx)
768+
}
769+
770+
"singlethreadfence" => {
771+
AtomicFence(bcx, order, llvm::SingleThread);
767772
C_nil(ccx)
768773
}
769774

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4910,7 +4910,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
49104910
(1, vec!(ty::mk_mut_ptr(tcx, param(ccx, 0)), param(ccx, 0)),
49114911
param(ccx, 0))
49124912
}
4913-
"fence" => {
4913+
"fence" | "singlethreadfence" => {
49144914
(0, Vec::new(), ty::mk_nil(tcx))
49154915
}
49164916
op => {

src/rustllvm/RustWrapper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ extern "C" LLVMValueRef LLVMBuildAtomicCmpXchg(LLVMBuilderRef B,
189189
failure_order
190190
));
191191
}
192-
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B, AtomicOrdering order) {
193-
return wrap(unwrap(B)->CreateFence(order));
192+
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B,
193+
AtomicOrdering order,
194+
SynchronizationScope scope) {
195+
return wrap(unwrap(B)->CreateFence(order, scope));
194196
}
195197

196198
extern "C" void LLVMSetDebug(int Enabled) {

0 commit comments

Comments
 (0)