rustllvm: Use target alignment for atomic load/store
This commit is contained in:
parent
26babaafcd
commit
474d9983be
@ -1571,13 +1571,15 @@ pub mod llvm {
|
||||
pub unsafe fn LLVMBuildAtomicLoad(B: BuilderRef,
|
||||
PointerVal: ValueRef,
|
||||
Name: *c_char,
|
||||
Order: AtomicOrdering)
|
||||
Order: AtomicOrdering,
|
||||
Alignment: c_uint)
|
||||
-> ValueRef;
|
||||
|
||||
pub unsafe fn LLVMBuildAtomicStore(B: BuilderRef,
|
||||
Val: ValueRef,
|
||||
Ptr: ValueRef,
|
||||
Order: AtomicOrdering)
|
||||
Order: AtomicOrdering,
|
||||
Alignment: c_uint)
|
||||
-> ValueRef;
|
||||
|
||||
pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
|
||||
|
@ -14,6 +14,7 @@ use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
|
||||
use lib::llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, ModuleRef};
|
||||
use lib;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::machine::llalign_of_min;
|
||||
use syntax::codemap::span;
|
||||
|
||||
use core::hashmap::HashMap;
|
||||
@ -544,7 +545,8 @@ pub fn AtomicLoad(cx: block, PointerVal: ValueRef, order: AtomicOrdering) -> Val
|
||||
return llvm::LLVMGetUndef(ccx.int_type);
|
||||
}
|
||||
count_insn(cx, "load.atomic");
|
||||
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, noname(), order);
|
||||
let align = llalign_of_min(*ccx, ccx.int_type);
|
||||
return llvm::LLVMBuildAtomicLoad(B(cx), PointerVal, noname(), order, align as c_uint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,7 +560,6 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
|
||||
let min = llvm::LLVMConstInt(t, lo, signed);
|
||||
let max = llvm::LLVMConstInt(t, hi, signed);
|
||||
|
||||
|
||||
do vec::as_imm_buf([min, max]) |ptr, len| {
|
||||
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
|
||||
llvm::LLVMMDNode(ptr, len as c_uint));
|
||||
@ -586,7 +587,8 @@ pub fn AtomicStore(cx: block, Val: ValueRef, Ptr: ValueRef, order: AtomicOrderin
|
||||
val_str(cx.ccx().tn, Val),
|
||||
val_str(cx.ccx().tn, Ptr));
|
||||
count_insn(cx, "store.atomic");
|
||||
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order);
|
||||
let align = llalign_of_min(cx.ccx(), cx.ccx().int_type);
|
||||
llvm::LLVMBuildAtomicStore(B(cx), Val, Ptr, order, align as c_uint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,22 +548,24 @@ extern "C" LLVMTypeRef LLVMMetadataType(void) {
|
||||
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B,
|
||||
LLVMValueRef source,
|
||||
const char* Name,
|
||||
AtomicOrdering order) {
|
||||
AtomicOrdering order,
|
||||
unsigned alignment) {
|
||||
LoadInst* li = new LoadInst(unwrap(source),0);
|
||||
li->setVolatile(true);
|
||||
li->setAtomic(order);
|
||||
li->setAlignment(sizeof(intptr_t));
|
||||
li->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(li, Name));
|
||||
}
|
||||
|
||||
extern "C" LLVMValueRef LLVMBuildAtomicStore(LLVMBuilderRef B,
|
||||
LLVMValueRef val,
|
||||
LLVMValueRef target,
|
||||
AtomicOrdering order) {
|
||||
LLVMValueRef val,
|
||||
LLVMValueRef target,
|
||||
AtomicOrdering order,
|
||||
unsigned alignment) {
|
||||
StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
|
||||
si->setVolatile(true);
|
||||
si->setAtomic(order);
|
||||
si->setAlignment(sizeof(intptr_t));
|
||||
si->setAlignment(alignment);
|
||||
return wrap(unwrap(B)->Insert(si));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user