@@ -5,11 +5,12 @@ import back::abi;
55import base :: { call_memmove,
66 INIT , copy_val, load_if_immediate, get_tydesc,
77 sub_block, do_spill_noroot,
8- dest, bcx_icx} ;
8+ dest, bcx_icx, non_gc_box_cast } ;
99import syntax:: codemap:: span;
1010import shape:: llsize_of;
1111import build:: * ;
1212import common:: * ;
13+ import util:: ppaux:: ty_to_str;
1314
1415fn get_fill ( bcx : block , vptr : ValueRef ) -> ValueRef {
1516 let _icx = bcx. insn_ctxt ( "tvec::get_fill" ) ;
@@ -22,28 +23,14 @@ fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
2223 Load ( bcx, GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_alloc] ) )
2324}
2425
25- fn get_bodyptr ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ) -> ValueRef {
26- let ccx = bcx. ccx ( ) ;
27- alt ty:: get ( vec_ty) . struct {
28- ty:: ty_evec ( _, ty:: vstore_uniq) | ty:: ty_estr ( ty:: vstore_uniq)
29- | ty:: ty_vec ( _) | ty:: ty_str {
30- let boxptr = PointerCast ( bcx, vptr, T_ptr ( T_box_header ( ccx) ) ) ;
31- let bodyptr = GEPi ( bcx, boxptr, [ 1 u] ) ;
32- let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , vec_ty) ;
33- let llunit_ty = type_of:: type_of ( ccx, unit_ty) ;
34- PointerCast ( bcx, bodyptr, T_ptr ( T_vec ( ccx, llunit_ty) ) )
35- }
36- _ {
37- vptr
38- }
39- }
26+ fn get_bodyptr ( bcx : block , vptr : ValueRef ) -> ValueRef {
27+ non_gc_box_cast ( bcx, GEPi ( bcx, vptr, [ 0 u, abi:: box_field_body] ) )
4028}
4129
42- fn get_dataptr ( bcx : block , vptr : ValueRef , unit_ty : TypeRef )
30+ fn get_dataptr ( bcx : block , vptr : ValueRef )
4331 -> ValueRef {
4432 let _icx = bcx. insn_ctxt ( "tvec::get_dataptr" ) ;
45- let ptr = GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_elems] ) ;
46- PointerCast ( bcx, ptr, T_ptr ( unit_ty) )
33+ GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_elems, 0 u] )
4734}
4835
4936fn pointer_add ( bcx : block , ptr : ValueRef , bytes : ValueRef ) -> ValueRef {
@@ -83,7 +70,7 @@ fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
8370fn duplicate_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ) -> result {
8471 let _icx = bcx. insn_ctxt ( "tvec::duplicate_uniq" ) ;
8572 let ccx = bcx. ccx ( ) ;
86- let body_ptr = get_bodyptr ( bcx, vptr, vec_ty ) ;
73+ let body_ptr = get_bodyptr ( bcx, vptr) ;
8774 let fill = get_fill ( bcx, body_ptr) ;
8875 let size = Add ( bcx, fill, llsize_of ( ccx, ccx. opaque_vec_type ) ) ;
8976
@@ -159,8 +146,7 @@ fn trans_evec(bcx: block, args: [@ast::expr],
159146 ast:: vstore_uniq {
160147 let { bcx, val} = alloc_uniq ( bcx, unit_ty, args. len ( ) ) ;
161148 add_clean_free ( bcx, val, true ) ;
162- let body = get_bodyptr ( bcx, val, vec_ty) ;
163- let dataptr = get_dataptr ( bcx, body, llunitty) ;
149+ let dataptr = get_dataptr ( bcx, get_bodyptr ( bcx, val) ) ;
164150 { bcx: bcx, val: val, dataptr: dataptr}
165151 }
166152 ast:: vstore_box {
@@ -241,10 +227,8 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
241227 ( base, len)
242228 }
243229 ty:: vstore_uniq {
244- let body = tvec : : get_bodyptr ( cx, v, vec_ty) ;
245- let base = tvec:: get_dataptr ( cx, body, llunitty) ;
246- let len = tvec:: get_fill ( cx, body) ;
247- ( base, len)
230+ let body = tvec : : get_bodyptr ( cx, v) ;
231+ ( tvec:: get_dataptr ( cx, body) , tvec:: get_fill ( cx, body) )
248232 }
249233 ty:: vstore_box {
250234 cx. ccx ( ) . sess . unimpl ( "unhandled tvec::get_base_and_len" ) ;
@@ -297,14 +281,11 @@ fn trans_append(bcx: block, vec_ty: ty::t, lhsptr: ValueRef,
297281 let ccx = bcx. ccx ( ) ;
298282 let unit_ty = ty:: sequence_element_type ( ccx. tcx , vec_ty) ;
299283 let strings = ty:: type_is_str ( vec_ty) ;
300- let llunitty = type_of:: type_of ( ccx, unit_ty) ;
301284
302285 let lhs = Load ( bcx, lhsptr) ;
303286 let self_append = ICmp ( bcx, lib:: llvm:: IntEQ , lhs, rhs) ;
304- let lbody = get_bodyptr ( bcx, lhs, vec_ty) ;
305- let rbody = get_bodyptr ( bcx, rhs, vec_ty) ;
306- let lfill = get_fill ( bcx, lbody) ;
307- let rfill = get_fill ( bcx, rbody) ;
287+ let lfill = get_fill ( bcx, get_bodyptr ( bcx, lhs) ) ;
288+ let rfill = get_fill ( bcx, get_bodyptr ( bcx, rhs) ) ;
308289 let mut new_fill = Add ( bcx, lfill, rfill) ;
309290 if strings { new_fill = Sub ( bcx, new_fill, C_int ( ccx, 1 ) ) ; }
310291 let opaque_lhs = PointerCast ( bcx, lhsptr,
@@ -315,9 +296,9 @@ fn trans_append(bcx: block, vec_ty: ty::t, lhsptr: ValueRef,
315296 let lhs = Load ( bcx, lhsptr) ;
316297 let rhs = Select ( bcx, self_append, lhs, rhs) ;
317298
318- let lbody = get_bodyptr ( bcx, lhs, vec_ty ) ;
299+ let lbody = get_bodyptr ( bcx, lhs) ;
319300
320- let lhs_data = get_dataptr ( bcx, lbody, llunitty ) ;
301+ let lhs_data = get_dataptr ( bcx, lbody) ;
321302 let mut lhs_off = lfill;
322303 if strings { lhs_off = Sub ( bcx, lhs_off, C_int ( ccx, 1 ) ) ; }
323304 let write_ptr = pointer_add ( bcx, lhs_data, lhs_off) ;
@@ -342,7 +323,7 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
342323 let scratch = base:: alloca ( bcx, elt_llty) ;
343324 for vec:: each( vals) { |val|
344325 bcx = base:: trans_expr_save_in ( bcx, val, scratch) ;
345- let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) , vec_ty ) ;
326+ let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) ) ;
346327 let old_fill = get_fill ( bcx, vptr) ;
347328 let new_fill = Add ( bcx, old_fill, elt_sz) ;
348329 let do_grow = ICmp ( bcx, lib:: llvm:: IntUGT , new_fill,
@@ -353,9 +334,9 @@ fn trans_append_literal(bcx: block, vptrptr: ValueRef, vec_ty: ty::t,
353334 Call ( bcx, ccx. upcalls . vec_grow , [ pt, new_fill] ) ;
354335 bcx
355336 } ;
356- let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) , vec_ty ) ;
337+ let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) ) ;
357338 set_fill ( bcx, vptr, new_fill) ;
358- let targetptr = pointer_add ( bcx, get_dataptr ( bcx, vptr, elt_llty ) ,
339+ let targetptr = pointer_add ( bcx, get_dataptr ( bcx, vptr) ,
359340 old_fill) ;
360341 call_memmove ( bcx, targetptr, scratch, elt_sz) ;
361342 }
@@ -379,18 +360,15 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
379360 ret base:: store_in_dest ( bcx, n, dest) ;
380361 }
381362
382- let lhs_body = get_bodyptr ( bcx, lhs, vec_ty) ;
383- let rhs_body = get_bodyptr ( bcx, rhs, vec_ty) ;
384-
385- let lhs_fill = get_fill ( bcx, lhs_body) ;
386- let rhs_fill = get_fill ( bcx, rhs_body) ;
363+ let lhs_fill = get_fill ( bcx, get_bodyptr ( bcx, lhs) ) ;
364+ let rhs_fill = get_fill ( bcx, get_bodyptr ( bcx, rhs) ) ;
387365 let new_fill = Add ( bcx, lhs_fill, rhs_fill) ;
388366 let mut { bcx: bcx , val : new_vec_ptr } =
389367 alloc_uniq_raw ( bcx, unit_ty, new_fill, new_fill) ;
390368
391- let new_vec_body_ptr = get_bodyptr ( bcx, new_vec_ptr, vec_ty ) ;
369+ let new_vec_body_ptr = get_bodyptr ( bcx, new_vec_ptr) ;
392370 let write_ptr_ptr = do_spill_noroot
393- ( bcx, get_dataptr ( bcx, new_vec_body_ptr, llunitty ) ) ;
371+ ( bcx, get_dataptr ( bcx, new_vec_body_ptr) ) ;
394372 let copy_fn = fn @( bcx: block, addr: ValueRef ,
395373 _ty: ty:: t) -> block {
396374 let ccx = bcx. ccx ( ) ;
@@ -443,19 +421,14 @@ fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
443421fn iter_vec_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
444422 fill : ValueRef , f : iter_vec_block ) -> block {
445423 let _icx = bcx. insn_ctxt ( "tvec::iter_vec_uniq" ) ;
446- let ccx = bcx. ccx ( ) ;
447- let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , vec_ty) ;
448- let llunitty = type_of:: type_of ( ccx, unit_ty) ;
449- let body_ptr = get_bodyptr ( bcx, vptr, vec_ty) ;
450- let data_ptr = get_dataptr ( bcx, body_ptr, llunitty) ;
424+ let data_ptr = get_dataptr ( bcx, get_bodyptr ( bcx, vptr) ) ;
451425 iter_vec_raw ( bcx, data_ptr, vec_ty, fill, f)
452426}
453427
454428fn iter_vec ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
455429 f : iter_vec_block ) -> block {
456430 let _icx = bcx. insn_ctxt ( "tvec::iter_vec" ) ;
457- let body_ptr = get_bodyptr ( bcx, vptr, vec_ty) ;
458- let fill = get_fill ( bcx, body_ptr) ;
431+ let fill = get_fill ( bcx, get_bodyptr ( bcx, vptr) ) ;
459432 ret iter_vec_uniq ( bcx, vptr, vec_ty, fill, f) ;
460433}
461434
0 commit comments