@@ -22,6 +22,7 @@ import std::option;
22
22
import std:: option:: some;
23
23
import std:: option:: none;
24
24
import std:: fs;
25
+ import std:: time;
25
26
import syntax:: ast;
26
27
import syntax:: walk;
27
28
import driver:: session;
@@ -113,7 +114,8 @@ type stats =
113
114
mutable uint n_derived_tydescs,
114
115
mutable uint n_glues_created,
115
116
mutable uint n_null_glues,
116
- mutable uint n_real_glues) ;
117
+ mutable uint n_real_glues,
118
+ @mutable ( tup( str, int) [ ] ) fn_times) ;
117
119
118
120
119
121
// Crate context. Every crate we compile has one of these.
@@ -693,6 +695,14 @@ fn sanitize(&str s) -> str {
693
695
}
694
696
695
697
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
+
696
706
fn decl_fn ( ModuleRef llmod, & str name , uint cc, TypeRef llty) -> ValueRef {
697
707
let ValueRef llfn = llvm:: LLVMAddFunction ( llmod, str:: buf ( name) , llty) ;
698
708
llvm:: LLVMSetFunctionCallConv ( llfn, cc) ;
@@ -1475,9 +1485,9 @@ fn declare_generic_glue(&@local_ctxt cx, &ty::t t, TypeRef llfnty, &str name)
1475
1485
ret llfn;
1476
1486
}
1477
1487
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 {
1481
1491
auto fcx = new_fn_ctxt( cx, sp, llfn) ;
1482
1492
llvm:: LLVMSetLinkage ( llfn,
1483
1493
lib:: llvm:: LLVMInternalLinkage as llvm:: Linkage ) ;
@@ -1526,6 +1536,21 @@ fn make_generic_glue(&@local_ctxt cx, &span sp, &ty::t t, ValueRef llfn,
1526
1536
ret llfn;
1527
1537
}
1528
1538
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
+
1529
1554
fn emit_tydescs( & @crate_ctxt ccx) {
1530
1555
for each ( @tup( ty:: t, @tydesc_info) pair in ccx. tydescs. items( ) ) {
1531
1556
auto glue_fn_ty = T_ptr ( T_glue_fn ( * ccx) ) ;
@@ -2579,7 +2604,8 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
2579
2604
ti. copy_glue = some[ ValueRef ] ( glue_fn) ;
2580
2605
auto tg = make_copy_glue;
2581
2606
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") ;
2583
2609
log #fmt( "--- lazily_emit_tydesc_glue TAKE %s",
2584
2610
ty_to_str( cx. fcx. lcx. ccx. tcx, ti. ty) ) ;
2585
2611
}
@@ -2598,7 +2624,7 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
2598
2624
ti. drop_glue = some[ ValueRef ] ( glue_fn) ;
2599
2625
make_generic_glue( lcx, cx. sp, ti. ty, glue_fn,
2600
2626
mgghf_single( make_drop_glue) ,
2601
- ti. ty_params) ;
2627
+ ti. ty_params, "drop" ) ;
2602
2628
log #fmt( "--- lazily_emit_tydesc_glue DROP %s",
2603
2629
ty_to_str( cx. fcx. lcx. ccx. tcx, ti. ty) ) ;
2604
2630
}
@@ -2617,7 +2643,8 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
2617
2643
ti. free_glue = some[ ValueRef ] ( glue_fn) ;
2618
2644
auto dg = make_free_glue;
2619
2645
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") ;
2621
2648
log #fmt( "--- lazily_emit_tydesc_glue FREE %s",
2622
2649
ty_to_str( cx. fcx. lcx. ccx. tcx, ti. ty) ) ;
2623
2650
}
@@ -2635,7 +2662,7 @@ fn lazily_emit_tydesc_glue(&@block_ctxt cx, int field,
2635
2662
"cmp") ;
2636
2663
ti. cmp_glue = some[ ValueRef ] ( glue_fn) ;
2637
2664
make_generic_glue( lcx, cx. sp, ti. ty, glue_fn,
2638
- mgghf_cmp, ti. ty_params) ;
2665
+ mgghf_cmp, ti. ty_params, "cmp" ) ;
2639
2666
log #fmt( "--- lazily_emit_tydesc_glue CMP %s",
2640
2667
ty_to_str( cx. fcx. lcx. ccx. tcx, ti. ty) ) ;
2641
2668
}
@@ -7060,11 +7087,9 @@ fn finish_fn(&@fn_ctxt fcx, BasicBlockRef lltop) {
7060
7087
}
7061
7088
7062
7089
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) {
7068
7093
set_uwtable( llfndecl) ;
7069
7094
7070
7095
// Set up arguments to the function.
@@ -7114,6 +7139,22 @@ fn trans_fn(@local_ctxt cx, &span sp, &ast::_fn f, ValueRef llfndecl,
7114
7139
finish_fn( fcx, lltop) ;
7115
7140
}
7116
7141
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
+
7117
7158
// process_fwding_mthd: Create the forwarding function that appears in a
7118
7159
// vtable slot for method calls that "fall through" to an inner object. A
7119
7160
// helper function for create_vtbl.
@@ -8649,7 +8690,8 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
8649
8690
mutable n_derived_tydescs=0 u,
8650
8691
mutable n_glues_created=0 u,
8651
8692
mutable n_null_glues=0 u,
8652
- mutable n_real_glues=0 u) ,
8693
+ mutable n_real_glues=0 u,
8694
+ fn_times=@mutable ~[ ] ) ,
8653
8695
upcalls=upcall:: declare_upcalls( tn, tydesc_type, taskptr_type,
8654
8696
llmod) ,
8655
8697
rust_object_type=T_rust_object ( ) ,
@@ -8672,6 +8714,10 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
8672
8714
log_err #fmt( "n_glues_created: %u", ccx. stats. n_glues_created) ;
8673
8715
log_err #fmt( "n_null_glues: %u", ccx. stats. n_null_glues) ;
8674
8716
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
+ }
8675
8721
}
8676
8722
ret llmod;
8677
8723
}
0 commit comments