@@ -5,11 +5,12 @@ import back::abi;
5
5
import base :: { call_memmove,
6
6
INIT , copy_val, load_if_immediate, get_tydesc,
7
7
sub_block, do_spill_noroot,
8
- dest, bcx_icx} ;
8
+ dest, bcx_icx, non_gc_box_cast } ;
9
9
import syntax:: codemap:: span;
10
10
import shape:: llsize_of;
11
11
import build:: * ;
12
12
import common:: * ;
13
+ import util:: ppaux:: ty_to_str;
13
14
14
15
fn get_fill ( bcx : block , vptr : ValueRef ) -> ValueRef {
15
16
let _icx = bcx. insn_ctxt ( "tvec::get_fill" ) ;
@@ -22,28 +23,14 @@ fn get_alloc(bcx: block, vptr: ValueRef) -> ValueRef {
22
23
Load ( bcx, GEPi ( bcx, vptr, [ 0 u, abi:: vec_elt_alloc] ) )
23
24
}
24
25
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] ) )
40
28
}
41
29
42
- fn get_dataptr ( bcx : block , vptr : ValueRef , unit_ty : TypeRef )
30
+ fn get_dataptr ( bcx : block , vptr : ValueRef )
43
31
-> ValueRef {
44
32
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] )
47
34
}
48
35
49
36
fn 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 {
83
70
fn duplicate_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ) -> result {
84
71
let _icx = bcx. insn_ctxt ( "tvec::duplicate_uniq" ) ;
85
72
let ccx = bcx. ccx ( ) ;
86
- let body_ptr = get_bodyptr ( bcx, vptr, vec_ty ) ;
73
+ let body_ptr = get_bodyptr ( bcx, vptr) ;
87
74
let fill = get_fill ( bcx, body_ptr) ;
88
75
let size = Add ( bcx, fill, llsize_of ( ccx, ccx. opaque_vec_type ) ) ;
89
76
@@ -159,8 +146,7 @@ fn trans_evec(bcx: block, args: [@ast::expr],
159
146
ast:: vstore_uniq {
160
147
let { bcx, val} = alloc_uniq ( bcx, unit_ty, args. len ( ) ) ;
161
148
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) ) ;
164
150
{ bcx: bcx, val: val, dataptr: dataptr}
165
151
}
166
152
ast:: vstore_box {
@@ -241,10 +227,8 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
241
227
( base, len)
242
228
}
243
229
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) )
248
232
}
249
233
ty:: vstore_box {
250
234
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,
297
281
let ccx = bcx. ccx ( ) ;
298
282
let unit_ty = ty:: sequence_element_type ( ccx. tcx , vec_ty) ;
299
283
let strings = ty:: type_is_str ( vec_ty) ;
300
- let llunitty = type_of:: type_of ( ccx, unit_ty) ;
301
284
302
285
let lhs = Load ( bcx, lhsptr) ;
303
286
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) ) ;
308
289
let mut new_fill = Add ( bcx, lfill, rfill) ;
309
290
if strings { new_fill = Sub ( bcx, new_fill, C_int ( ccx, 1 ) ) ; }
310
291
let opaque_lhs = PointerCast ( bcx, lhsptr,
@@ -315,9 +296,9 @@ fn trans_append(bcx: block, vec_ty: ty::t, lhsptr: ValueRef,
315
296
let lhs = Load ( bcx, lhsptr) ;
316
297
let rhs = Select ( bcx, self_append, lhs, rhs) ;
317
298
318
- let lbody = get_bodyptr ( bcx, lhs, vec_ty ) ;
299
+ let lbody = get_bodyptr ( bcx, lhs) ;
319
300
320
- let lhs_data = get_dataptr ( bcx, lbody, llunitty ) ;
301
+ let lhs_data = get_dataptr ( bcx, lbody) ;
321
302
let mut lhs_off = lfill;
322
303
if strings { lhs_off = Sub ( bcx, lhs_off, C_int ( ccx, 1 ) ) ; }
323
304
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,
342
323
let scratch = base:: alloca ( bcx, elt_llty) ;
343
324
for vec:: each( vals) { |val|
344
325
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) ) ;
346
327
let old_fill = get_fill ( bcx, vptr) ;
347
328
let new_fill = Add ( bcx, old_fill, elt_sz) ;
348
329
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,
353
334
Call ( bcx, ccx. upcalls . vec_grow , [ pt, new_fill] ) ;
354
335
bcx
355
336
} ;
356
- let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) , vec_ty ) ;
337
+ let vptr = get_bodyptr ( bcx, Load ( bcx, vptrptr) ) ;
357
338
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) ,
359
340
old_fill) ;
360
341
call_memmove ( bcx, targetptr, scratch, elt_sz) ;
361
342
}
@@ -379,18 +360,15 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
379
360
ret base:: store_in_dest ( bcx, n, dest) ;
380
361
}
381
362
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) ) ;
387
365
let new_fill = Add ( bcx, lhs_fill, rhs_fill) ;
388
366
let mut { bcx: bcx , val : new_vec_ptr } =
389
367
alloc_uniq_raw ( bcx, unit_ty, new_fill, new_fill) ;
390
368
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) ;
392
370
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) ) ;
394
372
let copy_fn = fn @( bcx: block, addr: ValueRef ,
395
373
_ty: ty:: t) -> block {
396
374
let ccx = bcx. ccx ( ) ;
@@ -443,19 +421,14 @@ fn iter_vec_raw(bcx: block, data_ptr: ValueRef, vec_ty: ty::t,
443
421
fn iter_vec_uniq ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
444
422
fill : ValueRef , f : iter_vec_block ) -> block {
445
423
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) ) ;
451
425
iter_vec_raw ( bcx, data_ptr, vec_ty, fill, f)
452
426
}
453
427
454
428
fn iter_vec ( bcx : block , vptr : ValueRef , vec_ty : ty:: t ,
455
429
f : iter_vec_block ) -> block {
456
430
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) ) ;
459
432
ret iter_vec_uniq ( bcx, vptr, vec_ty, fill, f) ;
460
433
}
461
434
0 commit comments