Rollup merge of #147472 - AMS21:remove_llvm_rust_atomics, r=nikic

refactor: replace `LLVMRustAtomicLoad/Store` with LLVM built-in functions

This simplifies the code and reduces the burden of maintaining our own wrappers.

Work towards https://github.com/rust-lang/rust/issues/46437
This commit is contained in:
Matthias Krüger
2025-10-08 15:39:28 +02:00
committed by GitHub
3 changed files with 7 additions and 70 deletions

View File

@@ -639,13 +639,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
size: Size,
) -> &'ll Value {
unsafe {
let load = llvm::LLVMRustBuildAtomicLoad(
self.llbuilder,
ty,
ptr,
UNNAMED,
AtomicOrdering::from_generic(order),
);
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
// Set atomic ordering
llvm::LLVMSetOrdering(load, AtomicOrdering::from_generic(order));
// LLVM requires the alignment of atomic loads to be at least the size of the type.
llvm::LLVMSetAlignment(load, size.bytes() as c_uint);
load
@@ -872,12 +868,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
debug!("Store {:?} -> {:?}", val, ptr);
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
unsafe {
let store = llvm::LLVMRustBuildAtomicStore(
self.llbuilder,
val,
ptr,
AtomicOrdering::from_generic(order),
);
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
// Set atomic ordering
llvm::LLVMSetOrdering(store, AtomicOrdering::from_generic(order));
// LLVM requires the alignment of atomic stores to be at least the size of the type.
llvm::LLVMSetAlignment(store, size.bytes() as c_uint);
}

View File

@@ -1151,6 +1151,7 @@ unsafe extern "C" {
// Operations on load/store instructions (only)
pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
pub(crate) fn LLVMSetOrdering(MemoryAccessInst: &Value, Ordering: AtomicOrdering);
// Operations on phi nodes
pub(crate) fn LLVMAddIncoming<'a>(
@@ -2090,22 +2091,6 @@ unsafe extern "C" {
RHS: &'a Value,
) -> &'a Value;
// Atomic Operations
pub(crate) fn LLVMRustBuildAtomicLoad<'a>(
B: &Builder<'a>,
ElementType: &'a Type,
PointerVal: &'a Value,
Name: *const c_char,
Order: AtomicOrdering,
) -> &'a Value;
pub(crate) fn LLVMRustBuildAtomicStore<'a>(
B: &Builder<'a>,
Val: &'a Value,
Ptr: &'a Value,
Order: AtomicOrdering,
) -> &'a Value;
pub(crate) fn LLVMRustTimeTraceProfilerInitialize();
pub(crate) fn LLVMRustTimeTraceProfilerFinishThread();