Skip to content

Commit b57a05c

Browse files
committed
---
yaml --- r: 1872 b: refs/heads/master c: 661f1c5 h: refs/heads/master v: v3
1 parent 636900e commit b57a05c

File tree

4 files changed

+77
-57
lines changed

4 files changed

+77
-57
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: b2427509e2d53897b7c7797d5948773b63aed3df
2+
refs/heads/master: 661f1c541e86305a714ea2a27ec7b40ca241aa01

trunk/src/comp/back/abi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const int closure_elt_ty_params = 3;
5858

5959
const int worst_case_glue_call_args = 7;
6060

61-
const int n_upcall_glues = 7;
61+
const int n_native_glues = 7;
6262

6363
const int abi_x86_rustboot_cdecl = 1;
6464
const int abi_x86_rustc_fastcall = 2;
@@ -75,11 +75,11 @@ fn vec_append_glue_name() -> str {
7575
ret "rust_vec_append_glue";
7676
}
7777

78-
fn upcall_glue_name(int n, bool pass_task) -> str {
78+
fn native_glue_name(int n, bool pass_task) -> str {
7979
if (pass_task) {
80-
ret "rust_upcall_rust_" + util.common.istr(n);
80+
ret "rust_native_rust_" + util.common.istr(n);
8181
}
82-
ret "rust_upcall_cdecl_" + util.common.istr(n);
82+
ret "rust_native_cdecl_" + util.common.istr(n);
8383
}
8484

8585
fn activate_glue_name() -> str {

trunk/src/comp/back/x86.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn rust_activate_glue() -> vec[str] {
9090
* start doing whatever the first instruction says. Probably
9191
* saving registers and starting to establish a frame. Harmless
9292
* stuff, doesn't look at task->rust_sp again except when it
93-
* clobbers it during a later upcall.
93+
* clobbers it during a later native call.
9494
*
9595
*
9696
* 2. We are resuming a task that was descheduled by the yield glue
@@ -100,8 +100,9 @@ fn rust_activate_glue() -> vec[str] {
100100
* "esp <- task->rust_sp"
101101
*
102102
* this is the first instruction we 'ret' to after this glue,
103-
* because it is the first instruction following *any* upcall,
104-
* and the task we are activating was descheduled mid-upcall.
103+
* because it is the first instruction following *any* native
104+
* call, and the task we are activating was descheduled
105+
* mid-native-call.
105106
*
106107
* Unfortunately for us, we have already restored esp from
107108
* task->rust_sp and are about to eat the 5 words off the top of
@@ -132,7 +133,7 @@ fn rust_activate_glue() -> vec[str] {
132133

133134
/*
134135
* In most cases, the function we're returning to (activating)
135-
* will have saved any caller-saves before it yielded via upcalling,
136+
* will have saved any caller-saves before it yielded via native call,
136137
* so no work to do here. With one exception: when we're initially
137138
* activating, the task needs to be in the fastcall 2nd parameter
138139
* expected by the rust main function. That's edx.
@@ -145,14 +146,14 @@ fn rust_activate_glue() -> vec[str] {
145146

146147
/* More glue code, this time the 'bottom half' of yielding.
147148
*
148-
* We arrived here because an upcall decided to deschedule the
149-
* running task. So the upcall's return address got patched to the
149+
* We arrived here because an native call decided to deschedule the
150+
* running task. So the native call's return address got patched to the
150151
* first instruction of this glue code.
151152
*
152-
* When the upcall does 'ret' it will come here, and its esp will be
153+
* When the native call does 'ret' it will come here, and its esp will be
153154
* pointing to the last argument pushed on the C stack before making
154-
* the upcall: the 0th argument to the upcall, which is always the
155-
* task ptr performing the upcall. That's where we take over.
155+
* the native call: the 0th argument to the native call, which is always
156+
* the task ptr performing the native call. That's where we take over.
156157
*
157158
* Our goal is to complete the descheduling
158159
*
@@ -179,7 +180,7 @@ fn rust_yield_glue() -> vec[str] {
179180
+ vec("ret");
180181
}
181182

182-
fn upcall_glue(int n_args, bool pass_task) -> vec[str] {
183+
fn native_glue(int n_args, bool pass_task) -> vec[str] {
183184

184185
/*
185186
* 0, 4, 8, 12 are callee-saves
@@ -242,11 +243,11 @@ fn decl_glue(int align, str prefix, str name, vec[str] insns) -> str {
242243
}
243244

244245

245-
fn decl_upcall_glue(int align, str prefix, bool pass_task, uint n) -> str {
246+
fn decl_native_glue(int align, str prefix, bool pass_task, uint n) -> str {
246247
let int i = n as int;
247248
ret decl_glue(align, prefix,
248-
abi.upcall_glue_name(i, pass_task),
249-
upcall_glue(i, pass_task));
249+
abi.native_glue_name(i, pass_task),
250+
native_glue(i, pass_task));
250251
}
251252

252253
fn get_symbol_prefix() -> str {
@@ -272,10 +273,10 @@ fn get_module_asm() -> str {
272273
abi.yield_glue_name(),
273274
rust_yield_glue()))
274275

275-
+ _vec.init_fn[str](bind decl_upcall_glue(align, prefix, true, _),
276-
(abi.n_upcall_glues + 1) as uint)
277-
+ _vec.init_fn[str](bind decl_upcall_glue(align, prefix, false, _),
278-
(abi.n_upcall_glues + 1) as uint);
276+
+ _vec.init_fn[str](bind decl_native_glue(align, prefix, true, _),
277+
(abi.n_native_glues + 1) as uint)
278+
+ _vec.init_fn[str](bind decl_native_glue(align, prefix, false, _),
279+
(abi.n_native_glues + 1) as uint);
279280

280281

281282
ret _str.connect(glues, "\n\n");

trunk/src/comp/middle/trans.rs

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ state obj namegen(mutable int i) {
5353
type glue_fns = rec(ValueRef activate_glue,
5454
ValueRef yield_glue,
5555
ValueRef exit_task_glue,
56-
vec[ValueRef] upcall_glues_rust,
57-
vec[ValueRef] upcall_glues_cdecl,
56+
vec[ValueRef] native_glues_rust,
57+
vec[ValueRef] native_glues_cdecl,
5858
ValueRef no_op_type_glue,
5959
ValueRef memcpy_glue,
6060
ValueRef bzero_glue,
@@ -64,12 +64,31 @@ type tydesc_info = rec(ValueRef tydesc,
6464
ValueRef take_glue,
6565
ValueRef drop_glue);
6666

67+
/*
68+
* A note on nomenclature of linking: "upcall", "extern" and "native".
69+
*
70+
* An "extern" is an LLVM symbol we wind up emitting an undefined external
71+
* reference to. This means "we don't have the thing in this compilation unit,
72+
* please make sure you link it in at runtime". This could be a reference to
73+
* C code found in a C library, or rust code found in a rust crate.
74+
*
75+
* A "native" is a combination of an extern that references C code, plus a
76+
* glue-code stub that "looks like" a rust function, emitted here, plus a
77+
* generic N-ary bit of asm glue (found over in back/x86.rs) that performs a
78+
* control transfer into C from rust. Natives may be normal C library code.
79+
*
80+
* An upcall is a native call generated by the compiler (not corresponding to
81+
* any user-written call in the code) into librustrt, to perform some helper
82+
* task such as bringing a task to life, allocating memory, etc.
83+
*
84+
*/
85+
6786
state type crate_ctxt = rec(session.session sess,
6887
ModuleRef llmod,
6988
target_data td,
7089
type_names tn,
7190
ValueRef crate_ptr,
72-
hashmap[str, ValueRef] upcalls,
91+
hashmap[str, ValueRef] externs,
7392
hashmap[str, ValueRef] intrinsics,
7493
hashmap[str, ValueRef] item_names,
7594
hashmap[ast.def_id, ValueRef] item_ids,
@@ -852,14 +871,14 @@ fn decl_glue(ModuleRef llmod, type_names tn, str s) -> ValueRef {
852871
ret decl_cdecl_fn(llmod, s, T_fn(vec(T_taskptr(tn)), T_void()));
853872
}
854873

855-
fn decl_upcall_glue(ModuleRef llmod, type_names tn,
874+
fn decl_native_glue(ModuleRef llmod, type_names tn,
856875
bool pass_task, uint _n) -> ValueRef {
857876
// It doesn't actually matter what type we come up with here, at the
858-
// moment, as we cast the upcall function pointers to int before passing
859-
// them to the indirect upcall-invocation glue. But eventually we'd like
877+
// moment, as we cast the native function pointers to int before passing
878+
// them to the indirect native-invocation glue. But eventually we'd like
860879
// to call them directly, once we have a calling convention worked out.
861880
let int n = _n as int;
862-
let str s = abi.upcall_glue_name(n, pass_task);
881+
let str s = abi.native_glue_name(n, pass_task);
863882
let vec[TypeRef] args = vec(T_int()); // callee
864883
if (!pass_task) {
865884
args += vec(T_int()); // taskptr, will not be passed
@@ -869,42 +888,42 @@ fn decl_upcall_glue(ModuleRef llmod, type_names tn,
869888
ret decl_fastcall_fn(llmod, s, T_fn(args, T_int()));
870889
}
871890

872-
fn get_upcall(&hashmap[str, ValueRef] upcalls,
891+
fn get_extern(&hashmap[str, ValueRef] externs,
873892
ModuleRef llmod, str name, int n_args) -> ValueRef {
874-
if (upcalls.contains_key(name)) {
875-
ret upcalls.get(name);
893+
if (externs.contains_key(name)) {
894+
ret externs.get(name);
876895
}
877896
auto inputs = _vec.init_elt[TypeRef](T_int(), n_args as uint);
878897
auto output = T_int();
879898
auto f = decl_cdecl_fn(llmod, name, T_fn(inputs, output));
880-
upcalls.insert(name, f);
899+
externs.insert(name, f);
881900
ret f;
882901
}
883902

884903
fn trans_upcall(@block_ctxt cx, str name, vec[ValueRef] args) -> result {
885904
auto cxx = cx.fcx.ccx;
886905
auto lltaskptr = cx.build.PtrToInt(cx.fcx.lltaskptr, T_int());
887906
auto args2 = vec(lltaskptr) + args;
888-
auto t = trans_upcall2(cx.build, cxx.glues, lltaskptr,
889-
cxx.upcalls, cxx.tn, cxx.llmod, name, true, args2);
907+
auto t = trans_native(cx.build, cxx.glues, lltaskptr,
908+
cxx.externs, cxx.tn, cxx.llmod, name, true, args2);
890909
ret res(cx, t);
891910
}
892911

893-
fn trans_upcall2(builder b, @glue_fns glues, ValueRef lltaskptr,
894-
&hashmap[str, ValueRef] upcalls,
895-
type_names tn, ModuleRef llmod, str name,
896-
bool pass_task, vec[ValueRef] args) -> ValueRef {
912+
fn trans_native(builder b, @glue_fns glues, ValueRef lltaskptr,
913+
&hashmap[str, ValueRef] externs,
914+
type_names tn, ModuleRef llmod, str name,
915+
bool pass_task, vec[ValueRef] args) -> ValueRef {
897916
let int n = (_vec.len[ValueRef](args) as int);
898-
let ValueRef llupcall = get_upcall(upcalls, llmod, name, n);
899-
llupcall = llvm.LLVMConstPointerCast(llupcall, T_int());
917+
let ValueRef llnative = get_extern(externs, llmod, name, n);
918+
llnative = llvm.LLVMConstPointerCast(llnative, T_int());
900919

901920
let ValueRef llglue;
902921
if (pass_task) {
903-
llglue = glues.upcall_glues_rust.(n);
922+
llglue = glues.native_glues_rust.(n);
904923
} else {
905-
llglue = glues.upcall_glues_cdecl.(n);
924+
llglue = glues.native_glues_cdecl.(n);
906925
}
907-
let vec[ValueRef] call_args = vec(llupcall);
926+
let vec[ValueRef] call_args = vec(llnative);
908927

909928
if (!pass_task) {
910929
call_args += vec(lltaskptr);
@@ -5771,8 +5790,8 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
57715790
arg_n += 1u;
57725791
}
57735792

5774-
auto r = trans_upcall2(bcx.build, cx.glues, lltaskptr, cx.upcalls, cx.tn,
5775-
cx.llmod, name, pass_task, call_args);
5793+
auto r = trans_native(bcx.build, cx.glues, lltaskptr, cx.externs, cx.tn,
5794+
cx.llmod, name, pass_task, call_args);
57765795
auto rptr = bcx.build.BitCast(fcx.llretptr, T_ptr(T_i32()));
57775796
bcx.build.Store(r, rptr);
57785797
bcx.build.RetVoid();
@@ -5967,7 +5986,7 @@ fn i2p(ValueRef v, TypeRef t) -> ValueRef {
59675986
}
59685987

59695988
fn trans_exit_task_glue(@glue_fns glues,
5970-
&hashmap[str, ValueRef] upcalls,
5989+
&hashmap[str, ValueRef] externs,
59715990
type_names tn, ModuleRef llmod) {
59725991
let vec[TypeRef] T_args = vec();
59735992
let vec[ValueRef] V_args = vec();
@@ -5979,8 +5998,8 @@ fn trans_exit_task_glue(@glue_fns glues,
59795998
auto build = new_builder(entrybb);
59805999
auto tptr = build.PtrToInt(lltaskptr, T_int());
59816000
auto V_args2 = vec(tptr) + V_args;
5982-
trans_upcall2(build, glues, lltaskptr,
5983-
upcalls, tn, llmod, "upcall_exit", true, V_args2);
6001+
trans_native(build, glues, lltaskptr,
6002+
externs, tn, llmod, "upcall_exit", true, V_args2);
59846003
build.RetVoid();
59856004
}
59866005

@@ -6415,7 +6434,7 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
64156434
yield_glue = decl_glue(llmod, tn, abi.yield_glue_name()),
64166435
/*
64176436
* Note: the signature passed to decl_cdecl_fn here looks unusual
6418-
* because it is. It corresponds neither to an upcall signature
6437+
* because it is. It corresponds neither to a native signature
64196438
* nor a normal rust-ABI signature. In fact it is a fake
64206439
* signature, that exists solely to acquire the task pointer as
64216440
* an argument to the upcall. It so happens that the runtime sets
@@ -6430,14 +6449,14 @@ fn make_glues(ModuleRef llmod, type_names tn) -> @glue_fns {
64306449
T_taskptr(tn)),
64316450
T_void())),
64326451

6433-
upcall_glues_rust =
6434-
_vec.init_fn[ValueRef](bind decl_upcall_glue(llmod, tn, true,
6452+
native_glues_rust =
6453+
_vec.init_fn[ValueRef](bind decl_native_glue(llmod, tn, true,
64356454
_),
6436-
abi.n_upcall_glues + 1 as uint),
6437-
upcall_glues_cdecl =
6438-
_vec.init_fn[ValueRef](bind decl_upcall_glue(llmod, tn, false,
6455+
abi.n_native_glues + 1 as uint),
6456+
native_glues_cdecl =
6457+
_vec.init_fn[ValueRef](bind decl_native_glue(llmod, tn, false,
64396458
_),
6440-
abi.n_upcall_glues + 1 as uint),
6459+
abi.n_native_glues + 1 as uint),
64416460
no_op_type_glue = decl_no_op_type_glue(llmod, tn),
64426461
memcpy_glue = decl_memcpy_glue(llmod),
64436462
bzero_glue = decl_bzero_glue(llmod),
@@ -6503,7 +6522,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
65036522
td = td,
65046523
tn = tn,
65056524
crate_ptr = crate_ptr,
6506-
upcalls = new_str_hash[ValueRef](),
6525+
externs = new_str_hash[ValueRef](),
65076526
intrinsics = intrinsics,
65086527
item_names = new_str_hash[ValueRef](),
65096528
item_ids = new_def_hash[ValueRef](),

0 commit comments

Comments
 (0)