Skip to content

Commit

Permalink
Generalized SynchronisationScope for BuilderMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
denismerigoux authored and eddyb committed Nov 16, 2018
1 parent b699866 commit b761538
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,12 +1097,12 @@ impl BuilderMethods<'a, 'll, 'tcx, Value, BasicBlock>
}
}

fn atomic_fence(&self, order: traits::AtomicOrdering, scope: SynchronizationScope) {
fn atomic_fence(&self, order: traits::AtomicOrdering, scope: traits::SynchronizationScope) {
unsafe {
llvm::LLVMRustBuildAtomicFence(
self.llbuilder,
AtomicOrdering::from_generic(order),
scope
SynchronizationScope::from_generic(scope)
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use syntax::symbol::Symbol;
use builder::Builder;
use value::Value;

use traits::{BuilderMethods, AtomicRmwBinOp};
use traits::{BuilderMethods, AtomicRmwBinOp, SynchronizationScope};

use rustc::session::Session;
use syntax_pos::Span;
Expand Down Expand Up @@ -521,12 +521,12 @@ pub fn codegen_intrinsic_call(
}

"fence" => {
bx.atomic_fence(order, llvm::SynchronizationScope::CrossThread);
bx.atomic_fence(order, SynchronizationScope::CrossThread);
return;
}

"singlethreadfence" => {
bx.atomic_fence(order, llvm::SynchronizationScope::SingleThread);
bx.atomic_fence(order, SynchronizationScope::SingleThread);
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ pub enum SynchronizationScope {
CrossThread,
}

impl SynchronizationScope {
pub fn from_generic(sc : traits::SynchronizationScope) -> Self {
match sc {
traits::SynchronizationScope::Other => SynchronizationScope::Other,
traits::SynchronizationScope::SingleThread => SynchronizationScope::SingleThread,
traits::SynchronizationScope::CrossThread => SynchronizationScope::CrossThread,
}
}
}

/// LLVMRustFileType
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_codegen_llvm/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use llvm::{SynchronizationScope, AsmDialect};
use llvm::AsmDialect;
use common::*;
use type_::Type;
use libc::c_char;
Expand Down Expand Up @@ -94,6 +94,14 @@ pub enum AtomicOrdering {
SequentiallyConsistent,
}

pub enum SynchronizationScope {
// FIXME: figure out if this variant is needed at all.
#[allow(dead_code)]
Other,
SingleThread,
CrossThread,
}


pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll,
Value : ?Sized,
Expand Down

0 comments on commit b761538

Please sign in to comment.