@@ -2274,31 +2274,6 @@ fn make_free_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
2274
2274
rslt. bcx . build . RetVoid ( ) ;
2275
2275
}
2276
2276
2277
- fn maybe_free_ivec_heap_part ( & @block_ctxt cx , ValueRef v0, ty:: t unit_ty )
2278
- -> result {
2279
- auto llunitty = type_of_or_i8 ( cx, unit_ty) ;
2280
-
2281
- auto stack_len = cx. build . Load ( cx. build . InBoundsGEP ( v0, [ C_int ( 0 ) ,
2282
- C_uint ( abi:: ivec_elt_len) ] ) ) ;
2283
- auto maybe_on_heap_cx = new_sub_block_ctxt ( cx, "maybe_on_heap" ) ;
2284
- auto next_cx = new_sub_block_ctxt ( cx, "next" ) ;
2285
- auto maybe_on_heap = cx. build . ICmp ( lib:: llvm:: LLVMIntEQ , stack_len,
2286
- C_int ( 0 ) ) ;
2287
- cx. build . CondBr ( maybe_on_heap, maybe_on_heap_cx. llbb , next_cx. llbb ) ;
2288
-
2289
- // Might be on the heap. Load the heap pointer and free it. (It's ok to
2290
- // free a null pointer.)
2291
- auto stub_ptr = maybe_on_heap_cx. build . PointerCast ( v0,
2292
- T_ptr ( T_ivec_heap ( llunitty) ) ) ;
2293
- auto heap_ptr = maybe_on_heap_cx. build . Load (
2294
- maybe_on_heap_cx. build . InBoundsGEP ( stub_ptr,
2295
- [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_stub_elt_ptr) ] ) ) ;
2296
- auto after_free_cx = trans_non_gc_free ( maybe_on_heap_cx, heap_ptr) . bcx ;
2297
- after_free_cx. build . Br ( next_cx. llbb ) ;
2298
-
2299
- ret res( next_cx, C_nil ( ) ) ;
2300
- }
2301
-
2302
2277
fn make_drop_glue ( & @block_ctxt cx , ValueRef v0, & ty:: t t) {
2303
2278
// NB: v0 is an *alias* of type t here, not a direct value.
2304
2279
auto rslt;
@@ -2311,11 +2286,6 @@ fn make_drop_glue(&@block_ctxt cx, ValueRef v0, &ty::t t) {
2311
2286
rslt = decr_refcnt_maybe_free ( cx, v0, v0, t) ;
2312
2287
}
2313
2288
2314
- case ( ty:: ty_ivec ( ?tm) ) {
2315
- rslt = iter_structural_ty ( cx, v0, t, drop_ty) ;
2316
- rslt = maybe_free_ivec_heap_part ( rslt. bcx , v0, tm. ty ) ;
2317
- }
2318
-
2319
2289
case ( ty:: ty_box ( _) ) {
2320
2290
rslt = decr_refcnt_maybe_free ( cx, v0, v0, t) ;
2321
2291
}
@@ -3718,10 +3688,10 @@ fn trans_vec_append(&@block_ctxt cx, &ty::t t,
3718
3688
dst, src, skip_null] ) ) ;
3719
3689
}
3720
3690
3721
- // Returns a tuple consisting of a pointer to the newly-reserved space and a
3722
- // block context. Updates the length appropriately .
3691
+ // Returns a tuple consisting of a pointer to the length (to be updated), a
3692
+ // pointer to the newly-reserved space, and a block context .
3723
3693
fn reserve_ivec_space( & @block_ctxt cx, TypeRef llunitty, ValueRef v,
3724
- ValueRef len_needed) -> result {
3694
+ ValueRef len_needed) -> tup ( ValueRef , ValueRef , @block_ctxt ) {
3725
3695
auto stack_len_ptr = cx. build. InBoundsGEP ( v, [ C_int ( 0 ) ,
3726
3696
C_uint ( abi:: ivec_elt_len) ] ) ;
3727
3697
auto stack_len = cx. build. Load ( stack_len_ptr) ;
@@ -3755,7 +3725,7 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3755
3725
3756
3726
// We're definitely on the heap. Check whether we need to resize.
3757
3727
auto heap_len_ptr = on_heap_cx. build. InBoundsGEP ( heap_ptr, [ C_int ( 0 ) ,
3758
- C_uint ( abi :: ivec_heap_elt_len ) ] ) ;
3728
+ C_int ( 0 ) ] ) ;
3759
3729
auto heap_len = on_heap_cx. build. Load ( heap_len_ptr) ;
3760
3730
auto new_heap_len = on_heap_cx. build. Add ( heap_len, len_needed) ;
3761
3731
auto heap_len_unscaled = on_heap_cx. build. UDiv ( heap_len,
@@ -3770,7 +3740,6 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3770
3740
// Case (1): We're on the heap and don't need to resize.
3771
3741
auto heap_data_no_resize = heap_no_resize_cx. build. InBoundsGEP ( heap_ptr,
3772
3742
[ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , heap_len_unscaled] ) ;
3773
- heap_no_resize_cx. build. Store ( new_heap_len, heap_len_ptr) ;
3774
3743
heap_no_resize_cx. build. Br ( next_cx. llbb) ;
3775
3744
3776
3745
// Case (2): We're on the heap and need to resize. This path is rare, so
@@ -3802,7 +3771,6 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3802
3771
// Case (3): We're on the stack and don't need to spill.
3803
3772
auto stack_data_no_spill = stack_no_spill_cx. build. InBoundsGEP ( v,
3804
3773
[ C_int ( 0 ) , C_uint ( abi:: ivec_elt_elems) , stack_len_unscaled] ) ;
3805
- stack_no_spill_cx. build. Store ( new_stack_len, stack_len_ptr) ;
3806
3774
stack_no_spill_cx. build. Br ( next_cx. llbb) ;
3807
3775
3808
3776
// Case (4): We're on the stack and need to spill. Like case (2), this
@@ -3826,12 +3794,16 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3826
3794
stack_spill_cx. build. Br ( next_cx. llbb) ;
3827
3795
3828
3796
// Phi together the different data pointers to get the result.
3797
+ auto len_ptr = next_cx. build. Phi ( T_ptr ( T_int ( ) ) ,
3798
+ [ heap_len_ptr, heap_len_ptr, stack_len_ptr, heap_len_ptr_spill] ,
3799
+ [ heap_no_resize_cx. llbb, heap_resize_cx. llbb, stack_no_spill_cx. llbb,
3800
+ stack_spill_cx. llbb] ) ;
3829
3801
auto data_ptr = next_cx. build. Phi ( T_ptr ( llunitty) ,
3830
3802
[ heap_data_no_resize, heap_data_resize, stack_data_no_spill,
3831
3803
heap_data_spill] ,
3832
3804
[ heap_no_resize_cx. llbb, heap_resize_cx. llbb, stack_no_spill_cx. llbb,
3833
3805
stack_spill_cx. llbb] ) ;
3834
- ret res ( next_cx , data_ptr) ;
3806
+ ret tup ( len_ptr , data_ptr, next_cx ) ;
3835
3807
}
3836
3808
3837
3809
fn trans_ivec_append( & @block_ctxt cx, & ty:: t t, ValueRef lhs, ValueRef rhs)
@@ -3865,9 +3837,11 @@ fn trans_ivec_append(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs)
3865
3837
auto rhs_data = rhs_len_and_data. _1;
3866
3838
bcx = rhs_len_and_data. _2;
3867
3839
3868
- rslt = reserve_ivec_space( bcx, llunitty, lhs, rhs_len) ;
3869
- auto lhs_data = rslt. val;
3870
- bcx = rslt. bcx;
3840
+ auto lhs_len_ptr_and_data =
3841
+ reserve_ivec_space( bcx, llunitty, lhs, rhs_len) ;
3842
+ auto lhs_len_ptr = lhs_len_ptr_and_data. _0;
3843
+ auto lhs_data = lhs_len_ptr_and_data. _1;
3844
+ bcx = lhs_len_ptr_and_data. _2;
3871
3845
3872
3846
// Work out the end pointer.
3873
3847
auto lhs_unscaled_idx = bcx. build. UDiv ( rhs_len, llsize_of( llunitty) ) ;
@@ -3901,6 +3875,11 @@ fn trans_ivec_append(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs)
3901
3875
[ C_int ( 1 ) ] ) , src_ptr) ;
3902
3876
post_copy_cx. build. Br ( copy_loop_header_cx. llbb) ;
3903
3877
3878
+ // Write in the new length.
3879
+ auto new_len = next_cx. build. Add ( next_cx. build. Load ( lhs_len_ptr) ,
3880
+ rhs_len) ;
3881
+ next_cx. build. Store ( new_len, lhs_len_ptr) ;
3882
+
3904
3883
ret res( next_cx, C_nil ( ) ) ;
3905
3884
}
3906
3885
@@ -5857,8 +5836,11 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5857
5836
auto rslt = size_of( bcx, unit_ty) ;
5858
5837
auto unit_sz = rslt. val;
5859
5838
bcx = rslt. bcx;
5839
+ rslt = align_of( bcx, unit_ty) ;
5840
+ auto unit_align = rslt. val;
5841
+ bcx = rslt. bcx;
5860
5842
5861
- auto llalen = bcx. build. Mul ( unit_sz , C_uint ( abi:: ivec_default_length) ) ;
5843
+ auto llalen = bcx. build. Mul ( unit_align , C_uint ( abi:: ivec_default_length) ) ;
5862
5844
5863
5845
auto llunitty = type_of_or_i8( bcx, unit_ty) ;
5864
5846
auto llvecptr;
@@ -5903,7 +5885,7 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5903
5885
llfirsteltptr = C_null ( T_ptr ( llunitty) ) ;
5904
5886
} else {
5905
5887
auto llheapsz = bcx. build. Add ( llsize_of( llheapty) , lllen) ;
5906
- rslt = trans_raw_malloc( bcx, T_ptr ( llheapty) , llheapsz) ;
5888
+ rslt = trans_raw_malloc( bcx, llheapty, llheapsz) ;
5907
5889
bcx = rslt. bcx;
5908
5890
auto llheapptr = rslt. val;
5909
5891
@@ -5926,7 +5908,7 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5926
5908
auto lleltptr;
5927
5909
if ( ty:: type_has_dynamic_size ( bcx. fcx . lcx . ccx . tcx , unit_ty) ) {
5928
5910
lleltptr = bcx. build . InBoundsGEP ( llfirsteltptr,
5929
- [ bcx. build . Mul ( C_uint ( i) , unit_sz ) ] ) ;
5911
+ [ bcx. build . Mul ( C_uint ( i) , unit_align ) ] ) ;
5930
5912
} else {
5931
5913
lleltptr = bcx. build . InBoundsGEP ( llfirsteltptr, [ C_uint ( i) ] ) ;
5932
5914
}
0 commit comments