Skip to content

Commit 9b824f8

Browse files
committed
---
yaml --- r: 3995 b: refs/heads/master c: 2e6197a h: refs/heads/master i: 3993: f78334a 3991: 593a42c v: v3
1 parent 710f6e8 commit 9b824f8

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b82c9c9e79ffc01dc658f921fbae058572250cf6
2+
refs/heads/master: 2e6197aa959126ac882bc8db2f44d32a4af34f0f

trunk/src/comp/middle/trans.rs

+60-14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import std::option;
2222
import std::option::some;
2323
import std::option::none;
2424
import std::fs;
25+
import std::time;
2526
import syntax::ast;
2627
import syntax::walk;
2728
import driver::session;
@@ -113,7 +114,8 @@ type stats =
113114
mutable uint n_derived_tydescs,
114115
mutable uint n_glues_created,
115116
mutable uint n_null_glues,
116-
mutable uint n_real_glues);
117+
mutable uint n_real_glues,
118+
@mutable (tup(str,int)[]) fn_times);
117119

118120

119121
// Crate context. Every crate we compile has one of these.
@@ -693,6 +695,14 @@ fn sanitize(&str s) -> str {
693695
}
694696

695697

698+
fn log_fn_time(&@crate_ctxt ccx, str name, &time::timeval start,
699+
&time::timeval end) {
700+
auto elapsed = 1000 * ((end.sec - start.sec) as int) +
701+
((end.usec as int) - (start.usec as int)) / 1000;
702+
*ccx.stats.fn_times += ~[tup(name, elapsed)];
703+
}
704+
705+
696706
fn decl_fn(ModuleRef llmod, &str name, uint cc, TypeRef llty) -> ValueRef {
697707
let ValueRef llfn = llvm::LLVMAddFunction(llmod, str::buf(name), llty);
698708
llvm::LLVMSetFunctionCallConv(llfn, cc);
@@ -1475,9 +1485,9 @@ fn declare_generic_glue(&@local_ctxt cx, &ty::t t, TypeRef llfnty, &str name)
14751485
ret llfn;
14761486
}
14771487

1478-
fn make_generic_glue(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
1479-
&make_generic_glue_helper_fn helper,
1480-
&uint[] ty_params) -> ValueRef {
1488+
fn make_generic_glue_inner(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
1489+
&make_generic_glue_helper_fn helper,
1490+
&uint[] ty_params) -> ValueRef {
14811491
auto fcx = new_fn_ctxt(cx, sp, llfn);
14821492
llvm::LLVMSetLinkage(llfn,
14831493
lib::llvm::LLVMInternalLinkage as llvm::Linkage);
@@ -1526,6 +1536,21 @@ fn make_generic_glue(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
15261536
ret llfn;
15271537
}
15281538

1539+
fn make_generic_glue(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
1540+
&make_generic_glue_helper_fn helper,
1541+
&uint[] ty_params, &str name) -> ValueRef {
1542+
if !cx.ccx.sess.get_opts().stats {
1543+
ret make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
1544+
}
1545+
1546+
auto start = time::get_time();
1547+
auto llval = make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params);
1548+
auto end = time::get_time();
1549+
log_fn_time(cx.ccx, "glue " + name + " " + ty_to_short_str(cx.ccx.tcx, t),
1550+
start, end);
1551+
ret llval;
1552+
}
1553+
15291554
fn emit_tydescs(&@crate_ctxt ccx) {
15301555
for each (@tup(ty::t, @tydesc_info) pair in ccx.tydescs.items()) {
15311556
auto glue_fn_ty = T_ptr(T_glue_fn(*ccx));
@@ -2579,7 +2604,8 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
25792604
ti.copy_glue = some[ValueRef](glue_fn);
25802605
auto tg = make_copy_glue;
25812606
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2582-
mgghf_single(tg), ti.ty_params);
2607+
mgghf_single(tg), ti.ty_params,
2608+
"take");
25832609
log #fmt("--- lazily_emit_tydesc_glue TAKE %s",
25842610
ty_to_str(cx.fcx.lcx.ccx.tcx, ti.ty));
25852611
}
@@ -2598,7 +2624,7 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
25982624
ti.drop_glue = some[ValueRef](glue_fn);
25992625
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
26002626
mgghf_single(make_drop_glue),
2601-
ti.ty_params);
2627+
ti.ty_params, "drop");
26022628
log #fmt("--- lazily_emit_tydesc_glue DROP %s",
26032629
ty_to_str(cx.fcx.lcx.ccx.tcx, ti.ty));
26042630
}
@@ -2617,7 +2643,8 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
26172643
ti.free_glue = some[ValueRef](glue_fn);
26182644
auto dg = make_free_glue;
26192645
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2620-
mgghf_single(dg), ti.ty_params);
2646+
mgghf_single(dg), ti.ty_params,
2647+
"free");
26212648
log #fmt("--- lazily_emit_tydesc_glue FREE %s",
26222649
ty_to_str(cx.fcx.lcx.ccx.tcx, ti.ty));
26232650
}
@@ -2635,7 +2662,7 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
26352662
"cmp");
26362663
ti.cmp_glue = some[ValueRef](glue_fn);
26372664
make_generic_glue(lcx, cx.sp, ti.ty, glue_fn,
2638-
mgghf_cmp, ti.ty_params);
2665+
mgghf_cmp, ti.ty_params, "cmp");
26392666
log #fmt("--- lazily_emit_tydesc_glue CMP %s",
26402667
ty_to_str(cx.fcx.lcx.ccx.tcx, ti.ty));
26412668
}
@@ -7060,11 +7087,9 @@ fn finish_fn(&@fn_ctxt fcx, BasicBlockRef lltop) {
70607087
}
70617088

70627089

7063-
// trans_fn: creates an LLVM function corresponding to a source language
7064-
// function.
7065-
fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
7066-
option::t[ty::t] ty_self, &ast::ty_param[] ty_params,
7067-
ast::node_id id) {
7090+
fn trans_fn_inner(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
7091+
option::t[ty::t] ty_self, &ast::ty_param[] ty_params,
7092+
ast::node_id id) {
70687093
set_uwtable(llfndecl);
70697094

70707095
// Set up arguments to the function.
@@ -7114,6 +7139,22 @@ fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
71147139
finish_fn(fcx, lltop);
71157140
}
71167141

7142+
7143+
// trans_fn: creates an LLVM function corresponding to a source language
7144+
// function.
7145+
fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
7146+
option::t[ty::t] ty_self, &ast::ty_param[] ty_params,
7147+
ast::node_id id) {
7148+
if !cx.ccx.sess.get_opts().stats {
7149+
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
7150+
}
7151+
7152+
auto start = time::get_time();
7153+
trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id);
7154+
auto end = time::get_time();
7155+
log_fn_time(cx.ccx, str::connect_ivec(cx.path, "::"), start, end);
7156+
}
7157+
71177158
// process_fwding_mthd: Create the forwarding function that appears in a
71187159
// vtable slot for method calls that "fall through" to an inner object. A
71197160
// helper function for create_vtbl.
@@ -8649,7 +8690,8 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
86498690
mutable n_derived_tydescs=0u,
86508691
mutable n_glues_created=0u,
86518692
mutable n_null_glues=0u,
8652-
mutable n_real_glues=0u),
8693+
mutable n_real_glues=0u,
8694+
fn_times=@mutable ~[]),
86538695
upcalls=upcall::declare_upcalls(tn, tydesc_type, taskptr_type,
86548696
llmod),
86558697
rust_object_type=T_rust_object(),
@@ -8672,6 +8714,10 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
86728714
log_err #fmt("n_glues_created: %u", ccx.stats.n_glues_created);
86738715
log_err #fmt("n_null_glues: %u", ccx.stats.n_null_glues);
86748716
log_err #fmt("n_real_glues: %u", ccx.stats.n_real_glues);
8717+
8718+
for (tup(str,int) timing in *ccx.stats.fn_times) {
8719+
log_err #fmt("time: %s took %d ms", timing._0, timing._1);
8720+
}
86758721
}
86768722
ret llmod;
86778723
}

0 commit comments

Comments
 (0)