Skip to content

Commit

Permalink
Rollup merge of rust-lang#89808 - tmiasko:llvm-multithreaded, r=nagisa
Browse files Browse the repository at this point in the history
Cleanup LLVM multi-threading checks

The support for runtime multi-threading was removed from LLVM. Calls to
`LLVMStartMultithreaded` became no-ops equivalent to checking if LLVM
was compiled with support for threads http://reviews.llvm.org/D4216.
  • Loading branch information
JohnTitor committed Oct 21, 2021
2 parents 9ac6c45 + aa3bf01 commit ad6ca9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ extern "C" {

pub fn LLVMDisposeMessage(message: *mut c_char);

pub fn LLVMStartMultithreaded() -> Bool;
pub fn LLVMIsMultithreaded() -> Bool;

/// Returns a string describing the last error caused by an LLVMRust* call.
pub fn LLVMRustGetLastError() -> *const c_char;
Expand Down
20 changes: 5 additions & 15 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,25 @@ use std::path::Path;
use std::ptr;
use std::slice;
use std::str;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;

static POISONED: AtomicBool = AtomicBool::new(false);
static INIT: Once = Once::new();

pub(crate) fn init(sess: &Session) {
unsafe {
// Before we touch LLVM, make sure that multithreading is enabled.
if llvm::LLVMIsMultithreaded() != 1 {
bug!("LLVM compiled without support for threads");
}
INIT.call_once(|| {
if llvm::LLVMStartMultithreaded() != 1 {
// use an extra bool to make sure that all future usage of LLVM
// cannot proceed despite the Once not running more than once.
POISONED.store(true, Ordering::SeqCst);
}

configure_llvm(sess);
});

if POISONED.load(Ordering::SeqCst) {
bug!("couldn't enable multi-threaded LLVM");
}
}
}

fn require_inited() {
INIT.call_once(|| bug!("llvm is not initialized"));
if POISONED.load(Ordering::SeqCst) {
bug!("couldn't enable multi-threaded LLVM");
if !INIT.is_completed() {
bug!("LLVM is not initialized");
}
}

Expand Down

0 comments on commit ad6ca9a

Please sign in to comment.