Skip to content

Commit 4cbef9d

Browse files
committed
Remove outptr from module-internal calls; use standard ABI returns.
1 parent 640d167 commit 4cbef9d

File tree

2 files changed

+33
-46
lines changed

2 files changed

+33
-46
lines changed

src/comp/back/x86.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ fn restore_callee_saves() -> vec[str] {
2626
}
2727

2828
fn load_esp_from_rust_sp() -> vec[str] {
29-
ret vec("movl " + wstr(abi.task_field_rust_sp) + "(%edx), %esp");
29+
ret vec("movl " + wstr(abi.task_field_rust_sp) + "(%ecx), %esp");
3030
}
3131

3232
fn load_esp_from_runtime_sp() -> vec[str] {
33-
ret vec("movl " + wstr(abi.task_field_runtime_sp) + "(%edx), %esp");
33+
ret vec("movl " + wstr(abi.task_field_runtime_sp) + "(%ecx), %esp");
3434
}
3535

3636
fn store_esp_to_rust_sp() -> vec[str] {
37-
ret vec("movl %esp, " + wstr(abi.task_field_rust_sp) + "(%edx)");
37+
ret vec("movl %esp, " + wstr(abi.task_field_rust_sp) + "(%ecx)");
3838
}
3939

4040
fn store_esp_to_runtime_sp() -> vec[str] {
41-
ret vec("movl %esp, " + wstr(abi.task_field_runtime_sp) + "(%edx)");
41+
ret vec("movl %esp, " + wstr(abi.task_field_runtime_sp) + "(%ecx)");
4242
}
4343

4444
fn rust_activate_glue() -> vec[str] {
45-
ret vec("movl 4(%esp), %edx # edx = rust_task")
45+
ret vec("movl 4(%esp), %ecx # ecx = rust_task")
4646
+ save_callee_saves()
4747
+ store_esp_to_runtime_sp()
4848
+ load_esp_from_rust_sp()
@@ -56,7 +56,7 @@ fn rust_activate_glue() -> vec[str] {
5656
}
5757

5858
fn rust_yield_glue() -> vec[str] {
59-
ret vec("movl 0(%esp), %edx # edx = rust_task")
59+
ret vec("movl 0(%esp), %ecx # ecx = rust_task")
6060
+ load_esp_from_rust_sp()
6161
+ save_callee_saves()
6262
+ store_esp_to_rust_sp()
@@ -89,20 +89,20 @@ fn upcall_glue(int n_args) -> vec[str] {
8989
save_callee_saves()
9090

9191
+ vec("movl %esp, %ebp # ebp = rust_sp",
92-
"movl 20(%esp), %edx # edx = rust_task")
92+
"movl 20(%esp), %ecx # ecx = rust_task")
9393

9494
+ store_esp_to_rust_sp()
9595
+ load_esp_from_runtime_sp()
9696

9797
+ vec("subl $" + wstr(n_args + 1) + ", %esp # esp -= args",
9898
"andl $~0xf, %esp # align esp down",
99-
"movl %edx, (%esp) # arg[0] = rust_task ")
99+
"movl %ecx, (%esp) # arg[0] = rust_task ")
100100

101101
+ _vec.init_fn[str](carg, n_args as uint)
102102

103103
+ vec("movl 24(%ebp), %edx # edx = callee",
104104
"call *%edx # call *%edx",
105-
"movl 20(%ebp), %edx # edx = rust_task")
105+
"movl 20(%ebp), %ecx # edx = rust_task")
106106

107107
+ load_esp_from_rust_sp()
108108
+ restore_callee_saves()

src/comp/middle/trans.rs

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ state type trans_ctxt = rec(session.session sess,
5151
str path);
5252

5353
state type fn_ctxt = rec(ValueRef llfn,
54-
ValueRef lloutptr,
5554
ValueRef lltaskptr,
5655
hashmap[ast.def_id, ValueRef] llargs,
5756
hashmap[ast.def_id, ValueRef] lllocals,
@@ -939,28 +938,13 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
939938
case (ast.expr_call(?f, ?args, _)) {
940939
auto f_res = trans_lval(cx, *f);
941940
check (! f_res._1);
942-
943-
// FIXME: Revolting hack to get the type of the outptr. Can get a
944-
// variety of other ways; will wait until we have a typechecker
945-
// perhaps to pick a more tasteful one.
946-
auto outptr = cx.fcx.lloutptr;
947-
alt (cx.fcx.tcx.items.get(f_res._2).node) {
948-
case (ast.item_fn(_, ?ff, _, _)) {
949-
outptr = cx.build.Alloca(type_of(cx.fcx.tcx, ff.output));
950-
}
951-
case (_) {
952-
cx.fcx.tcx.sess.unimpl("call to non-item");
953-
}
954-
}
955941
auto args_res = trans_exprs(f_res._0.bcx, args);
956-
auto llargs = vec(outptr,
957-
cx.fcx.lltaskptr);
942+
auto llargs = vec(cx.fcx.lltaskptr);
958943
llargs += args_res._1;
959944
auto call_val = args_res._0.build.Call(f_res._0.val, llargs);
960945
llvm.LLVMSetInstructionCallConv(call_val,
961946
lib.llvm.LLVMFastCallConv);
962-
ret res(args_res._0,
963-
args_res._0.build.Load(outptr));
947+
ret res(args_res._0, call_val);
964948
}
965949

966950
}
@@ -1021,7 +1005,6 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
10211005
alt (e) {
10221006
case (some[@ast.expr](?x)) {
10231007
r = trans_expr(cx, *x);
1024-
r.bcx.build.Store(r.val, cx.fcx.lloutptr);
10251008
}
10261009
}
10271010

@@ -1040,7 +1023,16 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
10401023
}
10411024
}
10421025

1043-
r.val = r.bcx.build.RetVoid();
1026+
alt (e) {
1027+
case (some[@ast.expr](_)) {
1028+
r.val = r.bcx.build.Ret(r.val);
1029+
ret r;
1030+
}
1031+
}
1032+
1033+
// FIXME: until LLVM has a unit type, we are moving around
1034+
// C_nil values rather than their void type.
1035+
r.val = r.bcx.build.Ret(C_nil());
10441036
ret r;
10451037
}
10461038

@@ -1188,20 +1180,20 @@ fn new_fn_ctxt(@trans_ctxt cx,
11881180
let ValueRef llfn = cx.fn_ids.get(fid);
11891181
cx.fn_names.insert(cx.path, llfn);
11901182

1191-
let ValueRef lloutptr = llvm.LLVMGetParam(llfn, 0u);
1192-
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 1u);
1183+
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 0u);
1184+
let uint arg_n = 1u;
11931185

11941186
let hashmap[ast.def_id, ValueRef] lllocals = new_def_hash[ValueRef]();
11951187
let hashmap[ast.def_id, ValueRef] llargs = new_def_hash[ValueRef]();
11961188

1197-
let uint arg_n = 2u;
11981189
for (ast.arg arg in f.inputs) {
1199-
llargs.insert(arg.id, llvm.LLVMGetParam(llfn, arg_n));
1190+
auto llarg = llvm.LLVMGetParam(llfn, arg_n);
1191+
check (llarg as int != 0);
1192+
llargs.insert(arg.id, llarg);
12001193
arg_n += 1u;
12011194
}
12021195

12031196
ret @rec(llfn=llfn,
1204-
lloutptr=lloutptr,
12051197
lltaskptr=lltaskptr,
12061198
llargs=llargs,
12071199
lllocals=lllocals,
@@ -1219,7 +1211,9 @@ impure fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
12191211
auto bcx = new_top_block_ctxt(fcx);
12201212
auto res = trans_block(bcx, f.body);
12211213
if (!is_terminated(res.bcx)) {
1222-
res.bcx.build.RetVoid();
1214+
// FIXME: until LLVM has a unit type, we are moving around
1215+
// C_nil values rather than their void type.
1216+
res.bcx.build.Ret(C_nil());
12231217
}
12241218
}
12251219

@@ -1247,18 +1241,13 @@ fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
12471241
alt (i.node) {
12481242
case (ast.item_fn(?name, ?f, ?fid, _)) {
12491243
cx.items.insert(fid, i);
1250-
let vec[TypeRef] args =
1251-
vec(T_ptr(type_of(cx, f.output)), // outptr.
1252-
T_taskptr() // taskptr
1253-
);
1254-
let vec[TypeRef] T_explicit_args = vec();
1244+
let TypeRef out = type_of(cx, f.output);
1245+
auto args = vec(T_taskptr());
12551246
for (ast.arg arg in f.inputs) {
1256-
T_explicit_args += type_of(cx, arg.ty);
1247+
args += type_of(cx, arg.ty);
12571248
}
1258-
args += T_explicit_args;
1259-
12601249
let str s = cx.names.next("_rust_fn") + "." + name;
1261-
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, args, T_void());
1250+
let ValueRef llfn = decl_fastcall_fn(cx.llmod, s, args, out);
12621251
cx.fn_ids.insert(fid, llfn);
12631252
}
12641253

@@ -1290,10 +1279,8 @@ fn trans_exit_task_glue(@trans_ctxt cx) {
12901279
let vec[ValueRef] V_args = vec();
12911280

12921281
auto llfn = cx.glues.exit_task_glue;
1293-
let ValueRef lloutptr = C_null(T_int());
12941282
let ValueRef lltaskptr = llvm.LLVMGetParam(llfn, 0u);
12951283
auto fcx = @rec(llfn=llfn,
1296-
lloutptr=lloutptr,
12971284
lltaskptr=lltaskptr,
12981285
llargs=new_def_hash[ValueRef](),
12991286
lllocals=new_def_hash[ValueRef](),

0 commit comments

Comments
 (0)