Skip to content

Commit

Permalink
auto merge of #6649 : brson/rust/atomic-load-align, r=graydon
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed May 21, 2013
2 parents 32e30aa + 474d998 commit 6c0a469
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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));
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 6c0a469

Please sign in to comment.