Skip to content

Commit f533276

Browse files
committed
Convert atomic intrinsics away from old argument modes (partial #3200)
1 parent 9423302 commit f533276

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

src/rustc/middle/trans/foreign.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,64 +799,66 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
799799
let fcx = new_fn_ctxt_w_id(ccx, path, decl, item.id,
800800
some(substs), some(item.span));
801801
let mut bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
802-
match check *item.ident {
803-
~"atomic_xchng" => {
802+
match *item.ident {
803+
// NB: Transitionary, de-mode-ing. Remove the first string of each
804+
// pattern when the old intrinsics are gone.
805+
~"atomic_xchng" | ~"atomic_xchg" => {
804806
let old = AtomicRMW(bcx, Xchg,
805807
get_param(decl, first_real_arg),
806808
get_param(decl, first_real_arg + 1u),
807809
SequentiallyConsistent);
808810
Store(bcx, old, fcx.llretptr);
809811
}
810-
~"atomic_xchng_acq" => {
812+
~"atomic_xchng_acq" | ~"atomic_xchg_acq" => {
811813
let old = AtomicRMW(bcx, Xchg,
812814
get_param(decl, first_real_arg),
813815
get_param(decl, first_real_arg + 1u),
814816
Acquire);
815817
Store(bcx, old, fcx.llretptr);
816818
}
817-
~"atomic_xchng_rel" => {
819+
~"atomic_xchng_rel" | ~"atomic_xchg_rel" => {
818820
let old = AtomicRMW(bcx, Xchg,
819821
get_param(decl, first_real_arg),
820822
get_param(decl, first_real_arg + 1u),
821823
Release);
822824
Store(bcx, old, fcx.llretptr);
823825
}
824-
~"atomic_add" => {
826+
~"atomic_add" | ~"atomic_xadd" => {
825827
let old = AtomicRMW(bcx, lib::llvm::Add,
826828
get_param(decl, first_real_arg),
827829
get_param(decl, first_real_arg + 1u),
828830
SequentiallyConsistent);
829831
Store(bcx, old, fcx.llretptr);
830832
}
831-
~"atomic_add_acq" => {
833+
~"atomic_add_acq" | ~"atomic_xadd_acq" => {
832834
let old = AtomicRMW(bcx, lib::llvm::Add,
833835
get_param(decl, first_real_arg),
834836
get_param(decl, first_real_arg + 1u),
835837
Acquire);
836838
Store(bcx, old, fcx.llretptr);
837839
}
838-
~"atomic_add_rel" => {
840+
~"atomic_add_rel" | ~"atomic_xadd_rel" => {
839841
let old = AtomicRMW(bcx, lib::llvm::Add,
840842
get_param(decl, first_real_arg),
841843
get_param(decl, first_real_arg + 1u),
842844
Release);
843845
Store(bcx, old, fcx.llretptr);
844846
}
845-
~"atomic_sub" => {
847+
~"atomic_sub" | ~"atomic_xsub" => {
846848
let old = AtomicRMW(bcx, lib::llvm::Sub,
847849
get_param(decl, first_real_arg),
848850
get_param(decl, first_real_arg + 1u),
849851
SequentiallyConsistent);
850852
Store(bcx, old, fcx.llretptr);
851853
}
852-
~"atomic_sub_acq" => {
854+
~"atomic_sub_acq" | ~"atomic_xsub_acq" => {
853855
let old = AtomicRMW(bcx, lib::llvm::Sub,
854856
get_param(decl, first_real_arg),
855857
get_param(decl, first_real_arg + 1u),
856858
Acquire);
857859
Store(bcx, old, fcx.llretptr);
858860
}
859-
~"atomic_sub_rel" => {
861+
~"atomic_sub_rel" | ~"atomic_xsub_rel" => {
860862
let old = AtomicRMW(bcx, lib::llvm::Sub,
861863
get_param(decl, first_real_arg),
862864
get_param(decl, first_real_arg + 1u),
@@ -980,6 +982,9 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
980982
lv_temporary),
981983
arg_vals(~[frameaddress_val]), ignore);
982984
}
985+
_ => {
986+
ccx.sess.span_bug(item.span, ~"unknown intrinsic");
987+
}
983988
}
984989
build_return(bcx);
985990
finish_fn(fcx, lltop);

src/rustc/middle/trans/type_use.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
6464
none => ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?",
6565
fn_id_loc})
6666
};
67-
match check map_node {
67+
match map_node {
6868
ast_map::node_item(@{node: item_fn(_, _, body), _}, _) |
6969
ast_map::node_method(@{body, _}, _, _) => {
7070
handle_body(cx, body);
@@ -81,7 +81,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
8181
ast_map::node_foreign_item(i@@{node: foreign_item_fn(_, _), _},
8282
abi, _) => {
8383
if abi == foreign_abi_rust_intrinsic {
84-
let flags = match check *i.ident {
84+
let flags = match *i.ident {
8585
~"size_of" | ~"pref_align_of" | ~"min_align_of" |
8686
~"init" | ~"reinterpret_cast" |
8787
~"move_val" | ~"move_val_init" => {
@@ -90,6 +90,11 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
9090
~"get_tydesc" | ~"needs_drop" => {
9191
use_tydesc
9292
}
93+
// NB: new intrinsics
94+
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
95+
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
96+
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" |
97+
// old intrinsics
9398
~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" |
9499
~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" |
95100
~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => {
@@ -98,6 +103,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
98103
~"visit_tydesc" | ~"forget" | ~"addr_of" => {
99104
0u
100105
}
106+
_ => fail ~"unknown intrinsic in type_use"
101107
};
102108
for uint::range(0u, n_tps) |n| { cx.uses[n] |= flags;}
103109
}
@@ -108,7 +114,7 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
108114
ast_map::node_dtor(_, dtor, _, _) => {
109115
handle_body(cx, dtor.node.body);
110116
}
111-
117+
_ => fail ~"unknown node type in type_use"
112118
}
113119
let uses = vec::from_mut(copy cx.uses);
114120
ccx.type_use_cache.insert(fn_id, uses);

src/rustc/middle/ty.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export ty_nil, mk_nil, type_is_nil;
8888
export ty_trait, mk_trait;
8989
export ty_param, mk_param, ty_params_to_tys;
9090
export ty_ptr, mk_ptr, mk_mut_ptr, mk_imm_ptr, mk_nil_ptr, type_is_unsafe_ptr;
91-
export ty_rptr, mk_rptr;
91+
export ty_rptr, mk_rptr, mk_mut_rptr, mk_imm_rptr;
9292
export ty_rec, mk_rec;
9393
export ty_enum, mk_enum, type_is_enum;
9494
export ty_tup, mk_tup;
@@ -764,6 +764,13 @@ fn mk_ptr(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
764764

765765
fn mk_rptr(cx: ctxt, r: region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
766766

767+
fn mk_mut_rptr(cx: ctxt, r: region, ty: t) -> t {
768+
mk_rptr(cx, r, {ty: ty, mutbl: ast::m_mutbl})
769+
}
770+
fn mk_imm_rptr(cx: ctxt, r: region, ty: t) -> t {
771+
mk_rptr(cx, r, {ty: ty, mutbl: ast::m_imm})
772+
}
773+
767774
fn mk_mut_ptr(cx: ctxt, ty: t) -> t { mk_ptr(cx, {ty: ty,
768775
mutbl: ast::m_mutbl}) }
769776

src/rustc/middle/typeck/check.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
24872487
}
24882488
~"needs_drop" => (1u, ~[], ty::mk_bool(tcx)),
24892489
2490+
// NB: Old intrinsics.
24902491
~"atomic_xchng" | ~"atomic_add" | ~"atomic_sub" |
24912492
~"atomic_xchng_acq" | ~"atomic_add_acq" | ~"atomic_sub_acq" |
24922493
~"atomic_xchng_rel" | ~"atomic_add_rel" | ~"atomic_sub_rel" => {
@@ -2495,6 +2496,17 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
24952496
ty::mk_int(tcx))
24962497
}
24972498
2499+
// NB: Transitionary, de-mode-ing.
2500+
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
2501+
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
2502+
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => {
2503+
(0u, ~[arg(ast::by_val,
2504+
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)),
2505+
ty::mk_int(tcx))),
2506+
arg(ast::by_val, ty::mk_int(tcx))],
2507+
ty::mk_int(tcx))
2508+
}
2509+
24982510
~"get_tydesc" => {
24992511
// FIXME (#2712): return *intrinsic::tydesc, not *()
25002512
(1u, ~[], ty::mk_nil_ptr(tcx))

0 commit comments

Comments
 (0)