Skip to content

Commit 07530c1

Browse files
committed
---
yaml --- r: 3235 b: refs/heads/master c: 4f13879 h: refs/heads/master i: 3233: 449f1a4 3231: 5551c55 v: v3
1 parent 174bd2c commit 07530c1

File tree

2 files changed

+75
-39
lines changed

2 files changed

+75
-39
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: 877f001512b2ce16d86d5d4cf16d81e509294d79
2+
refs/heads/master: 4f13879218c736e77350d56b9a053d3f009e2ddb

trunk/src/comp/middle/trans.rs

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,28 @@ type fn_ctxt =
191191
// administrative activities that have to happen in only one place in
192192
// the function, due to LLVM's quirks.
193193

194-
// A block for all the function's allocas, so that LLVM will coalesce
195-
// them into a single alloca call.
196-
mutable BasicBlockRef llallocas,
194+
// A block for all the function's static allocas, so that LLVM will
195+
// coalesce them into a single alloca call.
196+
mutable BasicBlockRef llstaticallocas,
197197

198198
// A block containing code that copies incoming arguments to space
199-
// already allocated by code in the llallocas block. (LLVM requires
200-
// that arguments be copied to local allocas before allowing most any
201-
// operation to be performed on them.)
199+
// already allocated by code in one of the llallocas blocks. (LLVM
200+
// requires that arguments be copied to local allocas before allowing
201+
// most any operation to be performed on them.)
202202
mutable BasicBlockRef llcopyargs,
203203

204-
// A block containing derived tydescs received from the runtime. See
205-
// description of derived_tydescs, below.
204+
// The first block containing derived tydescs received from the
205+
// runtime. See description of derived_tydescs, below.
206+
mutable BasicBlockRef llderivedtydescs_first,
207+
208+
// The last block of the llderivedtydescs group.
206209
mutable BasicBlockRef llderivedtydescs,
207210

211+
// A block for all of the dynamically sized allocas. This must be
212+
// after llderivedtydescs, because these sometimes depend on
213+
// information computed from derived tydescs.
214+
mutable BasicBlockRef lldynamicallocas,
215+
208216
// FIXME: Is llcopyargs actually the block containing the allocas for
209217
// incoming function arguments? Or is it merely the block containing
210218
// code that copies incoming args to space already alloca'd by code in
@@ -1173,11 +1181,11 @@ fn align_of(&@block_ctxt cx, &ty::t t) -> result {
11731181
}
11741182

11751183
fn alloca(&@block_ctxt cx, TypeRef t) -> ValueRef {
1176-
ret new_builder(cx.fcx.llallocas).Alloca(t);
1184+
ret new_builder(cx.fcx.llstaticallocas).Alloca(t);
11771185
}
11781186

11791187
fn array_alloca(&@block_ctxt cx, TypeRef t, ValueRef n) -> ValueRef {
1180-
ret new_builder(cx.fcx.llallocas).ArrayAlloca(t, n);
1188+
ret new_builder(cx.fcx.lldynamicallocas).ArrayAlloca(t, n);
11811189
}
11821190

11831191

@@ -3556,7 +3564,7 @@ mod ivec {
35563564

35573565
auto bcx;
35583566
if (dynamic) {
3559-
bcx = llallocas_block_ctxt(cx.fcx);
3567+
bcx = llderivedtydescs_block_ctxt(cx.fcx);
35603568
} else {
35613569
bcx = cx;
35623570
}
@@ -3565,26 +3573,25 @@ mod ivec {
35653573
auto rslt = size_of(bcx, unit_ty);
35663574
bcx = rslt.bcx;
35673575
llunitsz = rslt.val;
3568-
if (dynamic) { bcx.fcx.llallocas = bcx.llbb; }
3576+
3577+
if (dynamic) { cx.fcx.llderivedtydescs = bcx.llbb; }
35693578

35703579
auto llalen = bcx.build.Mul(llunitsz,
35713580
C_uint(abi::ivec_default_length));
35723581

35733582
auto llptr;
35743583
auto llunitty = type_of_or_i8(bcx, unit_ty);
3584+
auto bcx_result;
35753585
if (dynamic) {
35763586
auto llarraysz = bcx.build.Add(llsize_of(T_opaque_ivec()),
35773587
llalen);
35783588
auto llvecptr = array_alloca(bcx, T_i8(), llarraysz);
3579-
llptr = bcx.build.PointerCast(llvecptr, T_ptr(T_opaque_ivec()));
3580-
} else {
3581-
llptr = alloca(bcx, T_ivec(llunitty));
3582-
}
35833589

3584-
auto bcx_result;
3585-
if (dynamic) {
35863590
bcx_result = cx;
3591+
llptr = bcx_result.build.PointerCast(llvecptr,
3592+
T_ptr(T_opaque_ivec()));
35873593
} else {
3594+
llptr = alloca(bcx, T_ivec(llunitty));
35883595
bcx_result = bcx;
35893596
}
35903597

@@ -6753,27 +6760,51 @@ iter block_locals(&ast::block b) -> @ast::local {
67536760
}
67546761
}
67556762

6756-
fn llallocas_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
6763+
fn llstaticallocas_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
6764+
let vec[cleanup] cleanups = [];
6765+
ret @rec(llbb=fcx.llstaticallocas,
6766+
build=new_builder(fcx.llstaticallocas),
6767+
parent=parent_none,
6768+
kind=SCOPE_BLOCK,
6769+
mutable cleanups=cleanups,
6770+
sp=fcx.sp,
6771+
fcx=fcx);
6772+
}
6773+
6774+
fn llderivedtydescs_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
6775+
let vec[cleanup] cleanups = [];
6776+
ret @rec(llbb=fcx.llderivedtydescs,
6777+
build=new_builder(fcx.llderivedtydescs),
6778+
parent=parent_none,
6779+
kind=SCOPE_BLOCK,
6780+
mutable cleanups=cleanups,
6781+
sp=fcx.sp,
6782+
fcx=fcx);
6783+
}
6784+
6785+
fn lldynamicallocas_block_ctxt(&@fn_ctxt fcx) -> @block_ctxt {
67576786
let vec[cleanup] cleanups = [];
6758-
ret @rec(llbb=fcx.llallocas,
6759-
build=new_builder(fcx.llallocas),
6787+
ret @rec(llbb=fcx.lldynamicallocas,
6788+
build=new_builder(fcx.lldynamicallocas),
67606789
parent=parent_none,
67616790
kind=SCOPE_BLOCK,
67626791
mutable cleanups=cleanups,
67636792
sp=fcx.sp,
67646793
fcx=fcx);
67656794
}
67666795

6796+
6797+
67676798
fn alloc_ty(&@block_ctxt cx, &ty::t t) -> result {
67686799
auto val = C_int(0);
67696800
if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, t)) {
67706801
// NB: we have to run this particular 'size_of' in a
6771-
// block_ctxt built on the llallocas block for the fn,
6802+
// block_ctxt built on the llderivedtydescs block for the fn,
67726803
// so that the size dominates the array_alloca that
67736804
// comes next.
67746805

6775-
auto n = size_of(llallocas_block_ctxt(cx.fcx), t);
6776-
cx.fcx.llallocas = n.bcx.llbb;
6806+
auto n = size_of(llderivedtydescs_block_ctxt(cx.fcx), t);
6807+
cx.fcx.llderivedtydescs = n.bcx.llbb;
67776808
val = array_alloca(cx, T_i8(), n.val);
67786809
} else { val = alloca(cx, type_of(cx.fcx.lcx.ccx, cx.sp, t)); }
67796810
// NB: since we've pushed all size calculations in this
@@ -6862,13 +6893,14 @@ fn new_local_ctxt(&@crate_ctxt ccx) -> @local_ctxt {
68626893
}
68636894

68646895

6865-
// Creates the standard trio of basic blocks: allocas, copy-args, and derived
6866-
// tydescs.
6896+
// Creates the standard quartet of basic blocks: static allocas, copy args,
6897+
// derived tydescs, and dynamic allocas.
68676898
fn mk_standard_basic_blocks(ValueRef llfn) ->
6868-
tup(BasicBlockRef, BasicBlockRef, BasicBlockRef) {
6869-
ret tup(llvm::LLVMAppendBasicBlock(llfn, str::buf("allocas")),
6899+
tup(BasicBlockRef, BasicBlockRef, BasicBlockRef, BasicBlockRef) {
6900+
ret tup(llvm::LLVMAppendBasicBlock(llfn, str::buf("static_allocas")),
68706901
llvm::LLVMAppendBasicBlock(llfn, str::buf("copy_args")),
6871-
llvm::LLVMAppendBasicBlock(llfn, str::buf("derived_tydescs")));
6902+
llvm::LLVMAppendBasicBlock(llfn, str::buf("derived_tydescs")),
6903+
llvm::LLVMAppendBasicBlock(llfn, str::buf("dynamic_allocas")));
68726904
}
68736905

68746906

@@ -6893,9 +6925,11 @@ fn new_fn_ctxt(@local_ctxt cx, &span sp, ValueRef llfndecl) -> @fn_ctxt {
68936925
lltaskptr=lltaskptr,
68946926
llenv=llenv,
68956927
llretptr=llretptr,
6896-
mutable llallocas=llbbs._0,
6928+
mutable llstaticallocas=llbbs._0,
68976929
mutable llcopyargs=llbbs._1,
6930+
mutable llderivedtydescs_first=llbbs._2,
68986931
mutable llderivedtydescs=llbbs._2,
6932+
mutable lldynamicallocas=llbbs._3,
68996933
mutable llself=none[val_self_pair],
69006934
mutable lliterbody=none[ValueRef],
69016935
llargs=llargs,
@@ -6973,7 +7007,7 @@ fn create_llargs_for_fn_args(&@fn_ctxt cx, ast::proto proto,
69737007
// allocas immediately upon entry; this permits us to GEP into structures we
69747008
// were passed and whatnot. Apparently mem2reg will mop up.
69757009
fn copy_any_self_to_alloca(@fn_ctxt fcx, option::t[ty_self_pair] ty_self) {
6976-
auto bcx = llallocas_block_ctxt(fcx);
7010+
auto bcx = llstaticallocas_block_ctxt(fcx);
69777011
alt ({ fcx.llself }) {
69787012
case (some(?pair)) {
69797013
alt (ty_self) {
@@ -7045,7 +7079,7 @@ fn ret_ty_of_fn(&@crate_ctxt ccx, ast::ann ann) -> ty::t {
70457079
}
70467080

70477081
fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, val_self_pair llself) {
7048-
auto bcx = llallocas_block_ctxt(fcx);
7082+
auto bcx = llstaticallocas_block_ctxt(fcx);
70497083
let vec[ty::t] field_tys = [];
70507084
for (ast::obj_field f in bcx.fcx.lcx.obj_fields) {
70517085
field_tys += [node_ann_type(bcx.fcx.lcx.ccx, f.ann)];
@@ -7088,20 +7122,22 @@ fn populate_fn_ctxt_from_llself(@fn_ctxt fcx, val_self_pair llself) {
70887122
i = 0;
70897123
for (ast::obj_field f in fcx.lcx.obj_fields) {
70907124
auto rslt = GEP_tup_like(bcx, fields_tup_ty, obj_fields, [0, i]);
7091-
bcx = llallocas_block_ctxt(fcx);
7125+
bcx = llstaticallocas_block_ctxt(fcx);
70927126
auto llfield = rslt.val;
70937127
fcx.llobjfields.insert(f.id, llfield);
70947128
i += 1;
70957129
}
7096-
fcx.llallocas = bcx.llbb;
7130+
fcx.llstaticallocas = bcx.llbb;
70977131
}
70987132

70997133

7100-
// Ties up the llallocas -> llcopyargs -> llderivedtydescs -> lltop edges.
7134+
// Ties up the llstaticallocas -> llcopyargs -> llderivedtydescs ->
7135+
// lldynamicallocas -> lltop edges.
71017136
fn finish_fn(&@fn_ctxt fcx, BasicBlockRef lltop) {
7102-
new_builder(fcx.llallocas).Br(fcx.llcopyargs);
7103-
new_builder(fcx.llcopyargs).Br(fcx.llderivedtydescs);
7104-
new_builder(fcx.llderivedtydescs).Br(lltop);
7137+
new_builder(fcx.llstaticallocas).Br(fcx.llcopyargs);
7138+
new_builder(fcx.llcopyargs).Br(fcx.llderivedtydescs_first);
7139+
new_builder(fcx.llderivedtydescs).Br(fcx.lldynamicallocas);
7140+
new_builder(fcx.lldynamicallocas).Br(lltop);
71057141
}
71067142

71077143

0 commit comments

Comments
 (0)