Skip to content

Commit 7be7c23

Browse files
committed
Copy args to allocas, change llargs lookups to 'in mem'. Un-XFAIL tup.rs.
1 parent d7ce242 commit 7be7c23

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ TEST_XFAILS_SELF := $(filter-out \
535535
lazy-init.rs \
536536
multiline-comment.rs \
537537
return-nil.rs \
538+
tup.rs \
538539
u32-decr.rs \
539540
u8-incr.rs \
540541
u8-incr-decr.rs \

src/comp/middle/trans.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ fn trans_name(@block_ctxt cx, &ast.name n, &option.t[ast.def] dopt)
10711071
case (ast.def_arg(?did)) {
10721072
check (cx.fcx.llargs.contains_key(did));
10731073
ret tup(res(cx, cx.fcx.llargs.get(did)),
1074-
false);
1074+
true);
10751075
}
10761076
case (ast.def_local(?did)) {
10771077
check (cx.fcx.lllocals.contains_key(did));
@@ -1521,15 +1521,46 @@ fn new_fn_ctxt(@crate_ctxt cx,
15211521
ccx=cx);
15221522
}
15231523

1524+
1525+
// Recommended LLVM style, strange though this is, is to copy from args to
1526+
// allocas immediately upon entry; this permits us to GEP into structures we
1527+
// were passed and whatnot. Apparently mem2reg will mop up.
1528+
1529+
fn copy_args_to_allocas(@block_ctxt cx, &ast._fn f, &ast.ann ann) {
1530+
1531+
let vec[typeck.arg] arg_ts = vec();
1532+
let @typeck.ty fty = node_ann_type(cx.fcx.ccx, ann);
1533+
alt (fty.struct) {
1534+
case (typeck.ty_fn(?a, _)) { arg_ts += a; }
1535+
}
1536+
1537+
let uint arg_n = 0u;
1538+
1539+
for (ast.arg aarg in f.inputs) {
1540+
auto arg = arg_ts.(arg_n);
1541+
auto arg_t = type_of(cx.fcx.ccx, arg.ty);
1542+
auto alloca = cx.build.Alloca(arg_t);
1543+
auto argval = cx.fcx.llargs.get(aarg.id);
1544+
cx.build.Store(argval, alloca);
1545+
// Overwrite the llargs entry for this arg with its alloca.
1546+
cx.fcx.llargs.insert(aarg.id, alloca);
1547+
arg_n += 1u;
1548+
}
1549+
}
1550+
15241551
fn is_terminated(@block_ctxt cx) -> bool {
15251552
auto inst = llvm.LLVMGetLastInstruction(cx.llbb);
15261553
ret llvm.LLVMIsATerminatorInst(inst) as int != 0;
15271554
}
15281555

1529-
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid) {
1556+
impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
1557+
&ast.ann ann) {
15301558

15311559
auto fcx = new_fn_ctxt(cx, cx.path, f, fid);
15321560
auto bcx = new_top_block_ctxt(fcx);
1561+
1562+
copy_args_to_allocas(bcx, f, ann);
1563+
15331564
auto res = trans_block(bcx, f.body);
15341565
if (!is_terminated(res.bcx)) {
15351566
// FIXME: until LLVM has a unit type, we are moving around
@@ -1540,9 +1571,9 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid) {
15401571

15411572
impure fn trans_item(@crate_ctxt cx, &ast.item item) {
15421573
alt (item.node) {
1543-
case (ast.item_fn(?name, ?f, _, ?fid, _)) {
1574+
case (ast.item_fn(?name, ?f, _, ?fid, ?ann)) {
15441575
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
1545-
trans_fn(sub_cx, f, fid);
1576+
trans_fn(sub_cx, f, fid, ann);
15461577
}
15471578
case (ast.item_mod(?name, ?m, _)) {
15481579
auto sub_cx = @rec(path=cx.path + "." + name with *cx);

0 commit comments

Comments
 (0)