Skip to content

Commit b00147a

Browse files
committed
Add an AtomicU64 type to std::sync::atomics
This also generalizes all atomic intrinsics over T so we'll be able to add u8 atomics if we really feel the need to (do we really want to?)
1 parent cb40eba commit b00147a

File tree

6 files changed

+398
-97
lines changed

6 files changed

+398
-97
lines changed

src/librustc/middle/trans/builder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use lib::llvm::{Opcode, IntPredicate, RealPredicate, False};
1515
use lib::llvm::{ValueRef, BasicBlockRef, BuilderRef, ModuleRef};
1616
use middle::trans::base;
1717
use middle::trans::common::*;
18-
use middle::trans::machine::llalign_of_min;
18+
use middle::trans::machine::llalign_of_pref;
1919
use middle::trans::type_::Type;
2020
use std::cast;
2121
use std::hashmap::HashMap;
@@ -461,8 +461,10 @@ impl Builder {
461461
pub fn atomic_load(&self, ptr: ValueRef, order: AtomicOrdering) -> ValueRef {
462462
self.count_insn("load.atomic");
463463
unsafe {
464-
let align = llalign_of_min(self.ccx, self.ccx.int_type);
465-
llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order, align as c_uint)
464+
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
465+
let align = llalign_of_pref(self.ccx, ty.element_type());
466+
llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order,
467+
align as c_uint)
466468
}
467469
}
468470

@@ -514,8 +516,9 @@ impl Builder {
514516
self.ccx.tn.val_to_str(val),
515517
self.ccx.tn.val_to_str(ptr));
516518
self.count_insn("store.atomic");
517-
let align = llalign_of_min(self.ccx, self.ccx.int_type);
518519
unsafe {
520+
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
521+
let align = llalign_of_pref(self.ccx, ty.element_type());
519522
llvm::LLVMBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint);
520523
}
521524
}

src/librustc/middle/typeck/check/mod.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,29 +4030,32 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {
40304030

40314031
//We only care about the operation here
40324032
match split[1] {
4033-
"cxchg" => (0, ~[ty::mk_mut_rptr(tcx,
4033+
"cxchg" => (1, ~[ty::mk_mut_rptr(tcx,
40344034
ty::ReLateBound(it.id, ty::BrAnon(0)),
4035-
ty::mk_int()),
4036-
ty::mk_int(),
4037-
ty::mk_int()
4038-
], ty::mk_int()),
4039-
"load" => (0,
4035+
param(ccx, 0)),
4036+
param(ccx, 0),
4037+
param(ccx, 0),
4038+
], param(ccx, 0)),
4039+
"load" => (1,
40404040
~[
4041-
ty::mk_imm_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int())
4041+
ty::mk_imm_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)),
4042+
param(ccx, 0))
40424043
],
4043-
ty::mk_int()),
4044-
"store" => (0,
4044+
param(ccx, 0)),
4045+
"store" => (1,
40454046
~[
4046-
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int()),
4047-
ty::mk_int()
4047+
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)),
4048+
param(ccx, 0)),
4049+
param(ccx, 0)
40484050
],
40494051
ty::mk_nil()),
40504052

4051-
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" |
4053+
"xchg" | "xadd" | "xsub" | "and" | "nand" | "or" | "xor" | "max" |
40524054
"min" | "umax" | "umin" => {
4053-
(0, ~[ty::mk_mut_rptr(tcx,
4055+
(1, ~[ty::mk_mut_rptr(tcx,
40544056
ty::ReLateBound(it.id, ty::BrAnon(0)),
4055-
ty::mk_int()), ty::mk_int() ], ty::mk_int())
4057+
param(ccx, 0)), param(ccx, 0) ],
4058+
param(ccx, 0))
40564059
}
40574060
"fence" => {
40584061
(0, ~[], ty::mk_nil())
@@ -4085,16 +4088,6 @@ pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {
40854088
}
40864089
"needs_drop" => (1u, ~[], ty::mk_bool()),
40874090
"owns_managed" => (1u, ~[], ty::mk_bool()),
4088-
"atomic_xchg" | "atomic_xadd" | "atomic_xsub" |
4089-
"atomic_xchg_acq" | "atomic_xadd_acq" | "atomic_xsub_acq" |
4090-
"atomic_xchg_rel" | "atomic_xadd_rel" | "atomic_xsub_rel" => {
4091-
(0,
4092-
~[
4093-
ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), ty::mk_int()),
4094-
ty::mk_int()
4095-
],
4096-
ty::mk_int())
4097-
}
40984091

40994092
"get_tydesc" => {
41004093
let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {

0 commit comments

Comments
 (0)