@@ -3718,10 +3718,10 @@ fn trans_vec_append(&@block_ctxt cx, &ty::t t,
3718
3718
dst, src, skip_null] ) ) ;
3719
3719
}
3720
3720
3721
- // Returns a tuple consisting of a pointer to the length (to be updated), a
3722
- // pointer to the newly-reserved space, and a block context .
3721
+ // Returns a tuple consisting of a pointer to the newly-reserved space and a
3722
+ // block context. Updates the length appropriately .
3723
3723
fn reserve_ivec_space( & @block_ctxt cx, TypeRef llunitty, ValueRef v,
3724
- ValueRef len_needed) -> tup ( ValueRef , ValueRef , @block_ctxt ) {
3724
+ ValueRef len_needed) -> result {
3725
3725
auto stack_len_ptr = cx. build. InBoundsGEP ( v, [ C_int ( 0 ) ,
3726
3726
C_uint ( abi:: ivec_elt_len) ] ) ;
3727
3727
auto stack_len = cx. build. Load ( stack_len_ptr) ;
@@ -3755,7 +3755,7 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3755
3755
3756
3756
// We're definitely on the heap. Check whether we need to resize.
3757
3757
auto heap_len_ptr = on_heap_cx. build. InBoundsGEP ( heap_ptr, [ C_int ( 0 ) ,
3758
- C_int ( 0 ) ] ) ;
3758
+ C_uint ( abi :: ivec_heap_elt_len ) ] ) ;
3759
3759
auto heap_len = on_heap_cx. build. Load ( heap_len_ptr) ;
3760
3760
auto new_heap_len = on_heap_cx. build. Add ( heap_len, len_needed) ;
3761
3761
auto heap_len_unscaled = on_heap_cx. build. UDiv ( heap_len,
@@ -3770,6 +3770,7 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3770
3770
// Case (1): We're on the heap and don't need to resize.
3771
3771
auto heap_data_no_resize = heap_no_resize_cx. build. InBoundsGEP ( heap_ptr,
3772
3772
[ 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) ;
3773
3774
heap_no_resize_cx. build. Br ( next_cx. llbb) ;
3774
3775
3775
3776
// Case (2): We're on the heap and need to resize. This path is rare, so
@@ -3801,6 +3802,7 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3801
3802
// Case (3): We're on the stack and don't need to spill.
3802
3803
auto stack_data_no_spill = stack_no_spill_cx. build. InBoundsGEP ( v,
3803
3804
[ 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) ;
3804
3806
stack_no_spill_cx. build. Br ( next_cx. llbb) ;
3805
3807
3806
3808
// Case (4): We're on the stack and need to spill. Like case (2), this
@@ -3824,16 +3826,12 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3824
3826
stack_spill_cx. build. Br ( next_cx. llbb) ;
3825
3827
3826
3828
// Phi together the different data pointers to get the result.
3827
- auto len_ptr = next_cx. build. Phi ( T_ptr ( T_int ( ) ) ,
3828
- [ heap_len_ptr, heap_len_ptr, stack_len_ptr, heap_len_ptr_spill] ,
3829
- [ heap_no_resize_cx. llbb, heap_resize_cx. llbb, stack_no_spill_cx. llbb,
3830
- stack_spill_cx. llbb] ) ;
3831
3829
auto data_ptr = next_cx. build. Phi ( T_ptr ( llunitty) ,
3832
3830
[ heap_data_no_resize, heap_data_resize, stack_data_no_spill,
3833
3831
heap_data_spill] ,
3834
3832
[ heap_no_resize_cx. llbb, heap_resize_cx. llbb, stack_no_spill_cx. llbb,
3835
3833
stack_spill_cx. llbb] ) ;
3836
- ret tup ( len_ptr , data_ptr, next_cx ) ;
3834
+ ret res ( next_cx , data_ptr) ;
3837
3835
}
3838
3836
3839
3837
fn trans_ivec_append( & @block_ctxt cx, & ty:: t t, ValueRef lhs, ValueRef rhs)
@@ -3867,11 +3865,9 @@ fn trans_ivec_append(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs)
3867
3865
auto rhs_data = rhs_len_and_data. _1;
3868
3866
bcx = rhs_len_and_data. _2;
3869
3867
3870
- auto lhs_len_ptr_and_data =
3871
- reserve_ivec_space( bcx, llunitty, lhs, rhs_len) ;
3872
- auto lhs_len_ptr = lhs_len_ptr_and_data. _0;
3873
- auto lhs_data = lhs_len_ptr_and_data. _1;
3874
- bcx = lhs_len_ptr_and_data. _2;
3868
+ rslt = reserve_ivec_space( bcx, llunitty, lhs, rhs_len) ;
3869
+ auto lhs_data = rslt. val;
3870
+ bcx = rslt. bcx;
3875
3871
3876
3872
// Work out the end pointer.
3877
3873
auto lhs_unscaled_idx = bcx. build. UDiv ( rhs_len, llsize_of( llunitty) ) ;
@@ -3905,11 +3901,6 @@ fn trans_ivec_append(&@block_ctxt cx, &ty::t t, ValueRef lhs, ValueRef rhs)
3905
3901
[ C_int ( 1 ) ] ) , src_ptr) ;
3906
3902
post_copy_cx. build. Br ( copy_loop_header_cx. llbb) ;
3907
3903
3908
- // Write in the new length.
3909
- auto new_len = next_cx. build. Add ( next_cx. build. Load ( lhs_len_ptr) ,
3910
- rhs_len) ;
3911
- next_cx. build. Store ( new_len, lhs_len_ptr) ;
3912
-
3913
3904
ret res( next_cx, C_nil ( ) ) ;
3914
3905
}
3915
3906
@@ -5866,11 +5857,8 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5866
5857
auto rslt = size_of( bcx, unit_ty) ;
5867
5858
auto unit_sz = rslt. val;
5868
5859
bcx = rslt. bcx;
5869
- rslt = align_of( bcx, unit_ty) ;
5870
- auto unit_align = rslt. val;
5871
- bcx = rslt. bcx;
5872
5860
5873
- auto llalen = bcx. build. Mul ( unit_align , C_uint ( abi:: ivec_default_length) ) ;
5861
+ auto llalen = bcx. build. Mul ( unit_sz , C_uint ( abi:: ivec_default_length) ) ;
5874
5862
5875
5863
auto llunitty = type_of_or_i8( bcx, unit_ty) ;
5876
5864
auto llvecptr;
@@ -5938,7 +5926,7 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5938
5926
auto lleltptr;
5939
5927
if ( ty:: type_has_dynamic_size ( bcx. fcx . lcx . ccx . tcx , unit_ty) ) {
5940
5928
lleltptr = bcx. build . InBoundsGEP ( llfirsteltptr,
5941
- [ bcx. build . Mul ( C_uint ( i) , unit_align ) ] ) ;
5929
+ [ bcx. build . Mul ( C_uint ( i) , unit_sz ) ] ) ;
5942
5930
} else {
5943
5931
lleltptr = bcx. build . InBoundsGEP ( llfirsteltptr, [ C_uint ( i) ] ) ;
5944
5932
}
0 commit comments