@@ -2533,6 +2533,23 @@ fn iter_structural_ty(&@block_ctxt cx, ValueRef v, &ty::t t, val_and_ty_fn f)
2533
2533
ret iter_structural_ty_full( cx, v, v, t, bind adaptor_fn( f, _, _, _, _) ) ;
2534
2534
}
2535
2535
2536
+ fn load_inbounds( & @block_ctxt cx, ValueRef p,
2537
+ vec[ ValueRef ] idxs) -> ValueRef {
2538
+ ret cx. build. Load ( cx. build. InBoundsGEP ( p, idxs) ) ;
2539
+ }
2540
+
2541
+ fn store_inbounds( & @block_ctxt cx, ValueRef v,
2542
+ ValueRef p, vec[ ValueRef ] idxs) {
2543
+ cx. build. Store ( v, cx. build. InBoundsGEP ( p, idxs) ) ;
2544
+ }
2545
+
2546
+ // This uses store and inboundsGEP, but it only doing so superficially; it's
2547
+ // really storing an incremented pointer to another pointer.
2548
+ fn incr_ptr( & @block_ctxt cx, ValueRef p,
2549
+ ValueRef incr, ValueRef pp) {
2550
+ cx. build. Store ( cx. build. InBoundsGEP ( p, [ incr] ) , pp) ;
2551
+ }
2552
+
2536
2553
fn iter_structural_ty_full( & @block_ctxt cx, ValueRef av, ValueRef bv,
2537
2554
& ty:: t t, & val_pair_and_ty_fn f) -> result {
2538
2555
fn iter_boxpp( @block_ctxt cx, ValueRef box_a_cell, ValueRef box_b_cell,
@@ -2610,10 +2627,8 @@ fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
2610
2627
increment = C_int ( 1 ) ;
2611
2628
}
2612
2629
2613
- loop_body_cx. build. Store ( loop_body_cx. build. InBoundsGEP ( dest_elem,
2614
- [ increment] ) , dest_elem_ptr) ;
2615
- loop_body_cx. build. Store ( loop_body_cx. build. InBoundsGEP ( src_elem,
2616
- [ increment] ) , src_elem_ptr) ;
2630
+ incr_ptr( loop_body_cx, dest_elem, increment, dest_elem_ptr) ;
2631
+ incr_ptr( loop_body_cx, src_elem, increment, src_elem_ptr) ;
2617
2632
loop_body_cx. build. Br ( loop_header_cx. llbb) ;
2618
2633
2619
2634
ret rslt( next_cx, C_nil ( ) ) ;
@@ -3450,13 +3465,8 @@ mod ivec {
3450
3465
}
3451
3466
3452
3467
auto llunitty = type_of_or_i8( bcx, unit_ty) ;
3453
- auto stack_len =
3454
- {
3455
- auto p = bcx. build. InBoundsGEP ( v,
3456
- [ C_int ( 0 ) ,
3468
+ auto stack_len = load_inbounds( bcx, v, [ C_int ( 0 ) ,
3457
3469
C_uint ( abi:: ivec_elt_len) ] ) ;
3458
- bcx. build. Load ( p)
3459
- } ;
3460
3470
auto stack_elem =
3461
3471
bcx. build. InBoundsGEP ( v,
3462
3472
[ C_int ( 0 ) , C_uint ( abi:: ivec_elt_elems) ,
@@ -3468,12 +3478,10 @@ mod ivec {
3468
3478
bcx. build. CondBr ( on_heap, on_heap_cx. llbb, next_cx. llbb) ;
3469
3479
auto heap_stub =
3470
3480
on_heap_cx. build. PointerCast ( v, T_ptr ( T_ivec_heap ( llunitty) ) ) ;
3471
- auto heap_ptr =
3472
- {
3473
- auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_stub_elt_ptr) ] ;
3474
- on_heap_cx. build. Load ( on_heap_cx. build. InBoundsGEP ( heap_stub,
3475
- v) )
3476
- } ;
3481
+ auto heap_ptr = load_inbounds( on_heap_cx, heap_stub,
3482
+ [ C_int ( 0 ) ,
3483
+ C_uint ( abi:: ivec_heap_stub_elt_ptr) ] ) ;
3484
+
3477
3485
// Check whether the heap pointer is null. If it is, the vector length
3478
3486
// is truly zero.
3479
3487
@@ -3494,18 +3502,16 @@ mod ivec {
3494
3502
zero_len_cx. build. Br ( next_cx. llbb) ;
3495
3503
// If we're here, then we actually have a heapified vector.
3496
3504
3497
- auto heap_len =
3498
- {
3499
- auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_len) ] ;
3500
- auto m = nonzero_len_cx. build. InBoundsGEP ( heap_ptr, v) ;
3501
- nonzero_len_cx. build. Load ( m)
3502
- } ;
3505
+ auto heap_len = load_inbounds( nonzero_len_cx, heap_ptr,
3506
+ [ C_int ( 0 ) ,
3507
+ C_uint ( abi:: ivec_heap_elt_len) ] ) ;
3503
3508
auto heap_elem =
3504
3509
{
3505
3510
auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) ,
3506
3511
C_int ( 0 ) ] ;
3507
3512
nonzero_len_cx. build. InBoundsGEP ( heap_ptr, v)
3508
3513
} ;
3514
+
3509
3515
nonzero_len_cx. build. Br ( next_cx. llbb) ;
3510
3516
// Now we can figure out the length of `v` and get a pointer to its
3511
3517
// first element.
@@ -3529,10 +3535,8 @@ mod ivec {
3529
3535
auto stack_len_ptr =
3530
3536
cx. build. InBoundsGEP ( v, [ C_int ( 0 ) , C_uint ( abi:: ivec_elt_len) ] ) ;
3531
3537
auto stack_len = cx. build. Load ( stack_len_ptr) ;
3532
- auto alen =
3533
- cx. build. Load ( cx. build. InBoundsGEP ( v,
3534
- [ C_int ( 0 ) ,
3535
- C_uint ( abi:: ivec_elt_alen) ] ) ) ;
3538
+ auto alen = load_inbounds( cx, v, [ C_int ( 0 ) ,
3539
+ C_uint ( abi:: ivec_elt_alen) ] ) ;
3536
3540
// There are four cases we have to consider:
3537
3541
// (1) On heap, no resize necessary.
3538
3542
// (2) On heap, need to resize.
@@ -3552,11 +3556,7 @@ mod ivec {
3552
3556
auto stub_ptr =
3553
3557
maybe_on_heap_cx. build. PointerCast ( v,
3554
3558
T_ptr ( T_ivec_heap ( llunitty) ) ) ;
3555
- auto heap_ptr =
3556
- {
3557
- auto m = maybe_on_heap_cx. build. InBoundsGEP ( stub_ptr, stub_p) ;
3558
- maybe_on_heap_cx. build. Load ( m)
3559
- } ;
3559
+ auto heap_ptr = load_inbounds( maybe_on_heap_cx, stub_ptr, stub_p) ;
3560
3560
auto on_heap =
3561
3561
maybe_on_heap_cx. build. ICmp ( lib:: llvm:: LLVMIntNE , heap_ptr,
3562
3562
C_null ( val_ty( heap_ptr) ) ) ;
@@ -3599,10 +3599,8 @@ mod ivec {
3599
3599
[ cx. fcx. lltaskptr, p, new_heap_len] ) ;
3600
3600
}
3601
3601
auto heap_ptr_resize =
3602
- {
3603
- auto m = heap_resize_cx. build. InBoundsGEP ( stub_ptr, stub_p) ;
3604
- heap_resize_cx. build. Load ( m)
3605
- } ;
3602
+ load_inbounds( heap_resize_cx, stub_ptr, stub_p) ;
3603
+
3606
3604
auto heap_data_resize =
3607
3605
{
3608
3606
auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) ,
@@ -3642,15 +3640,10 @@ mod ivec {
3642
3640
}
3643
3641
auto spill_stub =
3644
3642
stack_spill_cx. build. PointerCast ( v, T_ptr ( T_ivec_heap ( llunitty) ) ) ;
3643
+
3645
3644
auto heap_ptr_spill =
3646
- {
3647
- auto p = stack_spill_cx. build. InBoundsGEP ( spill_stub, stub_p) ;
3648
- stack_spill_cx. build. Load ( p)
3649
- } ;
3650
- {
3651
- auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_len) ] ;
3652
- stack_spill_cx. build. InBoundsGEP ( heap_ptr_spill, v)
3653
- } ;
3645
+ load_inbounds( stack_spill_cx, spill_stub, stub_p) ;
3646
+
3654
3647
auto heap_data_spill =
3655
3648
{
3656
3649
auto v = [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) ,
@@ -3745,18 +3738,13 @@ mod ivec {
3745
3738
unit_ty) ;
3746
3739
auto post_copy_cx = rs. bcx;
3747
3740
// Increment both pointers.
3748
-
3749
3741
if ( ty:: type_has_dynamic_size( cx. fcx. lcx. ccx. tcx, t) ) {
3750
3742
// We have to increment by the dynamically-computed size.
3751
- post_copy_cx. build. Store ( post_copy_cx. build. InBoundsGEP (
3752
- copy_dest_ptr, [ unit_sz] ) , dest_ptr) ;
3753
- post_copy_cx. build. Store ( post_copy_cx. build. InBoundsGEP (
3754
- copy_src_ptr, [ unit_sz] ) , src_ptr) ;
3743
+ incr_ptr( post_copy_cx, copy_dest_ptr, unit_sz, dest_ptr) ;
3744
+ incr_ptr( post_copy_cx, copy_src_ptr, unit_sz, src_ptr) ;
3755
3745
} else {
3756
- post_copy_cx. build. Store ( post_copy_cx. build. InBoundsGEP (
3757
- copy_dest_ptr, [ C_int ( 1 ) ] ) , dest_ptr) ;
3758
- post_copy_cx. build. Store ( post_copy_cx. build. InBoundsGEP (
3759
- copy_src_ptr, [ C_int ( 1 ) ] ) , src_ptr) ;
3746
+ incr_ptr( post_copy_cx, copy_dest_ptr, C_int ( 1 ) , dest_ptr) ;
3747
+ incr_ptr( post_copy_cx, copy_src_ptr, C_int ( 1 ) , src_ptr) ;
3760
3748
}
3761
3749
3762
3750
post_copy_cx. build. Br ( copy_loop_header_cx. llbb) ;
0 commit comments