Skip to content

Commit 02dc3e6

Browse files
committed
---
yaml --- r: 3586 b: refs/heads/master c: a7d82a7 h: refs/heads/master v: v3
1 parent 4bcd966 commit 02dc3e6

File tree

2 files changed

+41
-53
lines changed

2 files changed

+41
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: c5e28567a2769e4d660d3ebe5f820a38fc4e501a
2+
refs/heads/master: a7d82a7f0fca121a336a84f88499cc2ec4f97447

trunk/src/comp/middle/trans.rs

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,23 @@ fn iter_structural_ty(&@block_ctxt cx, ValueRef v, &ty::t t, val_and_ty_fn f)
25332533
ret iter_structural_ty_full(cx, v, v, t, bind adaptor_fn(f, _, _, _, _));
25342534
}
25352535

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+
25362553
fn iter_structural_ty_full(&@block_ctxt cx, ValueRef av, ValueRef bv,
25372554
&ty::t t, &val_pair_and_ty_fn f) -> result {
25382555
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,
26102627
increment = C_int(1);
26112628
}
26122629

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);
26172632
loop_body_cx.build.Br(loop_header_cx.llbb);
26182633

26192634
ret rslt(next_cx, C_nil());
@@ -3450,13 +3465,8 @@ mod ivec {
34503465
}
34513466

34523467
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),
34573469
C_uint(abi::ivec_elt_len)]);
3458-
bcx.build.Load(p)
3459-
};
34603470
auto stack_elem =
34613471
bcx.build.InBoundsGEP(v,
34623472
[C_int(0), C_uint(abi::ivec_elt_elems),
@@ -3468,12 +3478,10 @@ mod ivec {
34683478
bcx.build.CondBr(on_heap, on_heap_cx.llbb, next_cx.llbb);
34693479
auto heap_stub =
34703480
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+
34773485
// Check whether the heap pointer is null. If it is, the vector length
34783486
// is truly zero.
34793487

@@ -3494,18 +3502,16 @@ mod ivec {
34943502
zero_len_cx.build.Br(next_cx.llbb);
34953503
// If we're here, then we actually have a heapified vector.
34963504

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)]);
35033508
auto heap_elem =
35043509
{
35053510
auto v = [C_int(0), C_uint(abi::ivec_heap_elt_elems),
35063511
C_int(0)];
35073512
nonzero_len_cx.build.InBoundsGEP(heap_ptr,v)
35083513
};
3514+
35093515
nonzero_len_cx.build.Br(next_cx.llbb);
35103516
// Now we can figure out the length of `v` and get a pointer to its
35113517
// first element.
@@ -3529,10 +3535,8 @@ mod ivec {
35293535
auto stack_len_ptr =
35303536
cx.build.InBoundsGEP(v, [C_int(0), C_uint(abi::ivec_elt_len)]);
35313537
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)]);
35363540
// There are four cases we have to consider:
35373541
// (1) On heap, no resize necessary.
35383542
// (2) On heap, need to resize.
@@ -3552,11 +3556,7 @@ mod ivec {
35523556
auto stub_ptr =
35533557
maybe_on_heap_cx.build.PointerCast(v,
35543558
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);
35603560
auto on_heap =
35613561
maybe_on_heap_cx.build.ICmp(lib::llvm::LLVMIntNE, heap_ptr,
35623562
C_null(val_ty(heap_ptr)));
@@ -3599,10 +3599,8 @@ mod ivec {
35993599
[cx.fcx.lltaskptr, p, new_heap_len]);
36003600
}
36013601
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+
36063604
auto heap_data_resize =
36073605
{
36083606
auto v = [C_int(0), C_uint(abi::ivec_heap_elt_elems),
@@ -3642,15 +3640,10 @@ mod ivec {
36423640
}
36433641
auto spill_stub =
36443642
stack_spill_cx.build.PointerCast(v, T_ptr(T_ivec_heap(llunitty)));
3643+
36453644
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+
36543647
auto heap_data_spill =
36553648
{
36563649
auto v = [C_int(0), C_uint(abi::ivec_heap_elt_elems),
@@ -3745,18 +3738,13 @@ mod ivec {
37453738
unit_ty);
37463739
auto post_copy_cx = rs.bcx;
37473740
// Increment both pointers.
3748-
37493741
if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
37503742
// 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);
37553745
} 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);
37603748
}
37613749

37623750
post_copy_cx.build.Br(copy_loop_header_cx.llbb);

0 commit comments

Comments
 (0)