@@ -57,7 +57,7 @@ use common::CrateContext;
57
57
use common:: { type_is_zero_size, val_ty} ;
58
58
use common;
59
59
use consts;
60
- use context:: { self , LocalCrateContext , SharedCrateContext } ;
60
+ use context:: { self , LocalCrateContext , SharedCrateContext , Stats } ;
61
61
use debuginfo;
62
62
use declare;
63
63
use machine;
@@ -1115,21 +1115,25 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1115
1115
1116
1116
let symbol_map = Rc :: new ( symbol_map) ;
1117
1117
1118
+ let mut all_stats = Stats :: default ( ) ;
1118
1119
let modules: Vec < ModuleTranslation > = codegen_units
1119
1120
. into_iter ( )
1120
1121
. map ( |cgu| {
1121
1122
let dep_node = cgu. work_product_dep_node ( ) ;
1122
- tcx. dep_graph . with_task ( dep_node,
1123
- AssertDepGraphSafe ( & shared_ccx) ,
1124
- AssertDepGraphSafe ( ( cgu, symbol_map. clone ( ) ) ) ,
1125
- module_translation)
1123
+ let ( stats, module) =
1124
+ tcx. dep_graph . with_task ( dep_node,
1125
+ AssertDepGraphSafe ( & shared_ccx) ,
1126
+ AssertDepGraphSafe ( ( cgu, symbol_map. clone ( ) ) ) ,
1127
+ module_translation) ;
1128
+ all_stats. extend ( stats) ;
1129
+ module
1126
1130
} )
1127
1131
. collect ( ) ;
1128
1132
1129
1133
fn module_translation < ' a , ' tcx > (
1130
1134
scx : AssertDepGraphSafe < & SharedCrateContext < ' a , ' tcx > > ,
1131
1135
args : AssertDepGraphSafe < ( CodegenUnit < ' tcx > , Rc < SymbolMap < ' tcx > > ) > )
1132
- -> ModuleTranslation
1136
+ -> ( Stats , ModuleTranslation )
1133
1137
{
1134
1138
// FIXME(#40304): We ought to be using the id as a key and some queries, I think.
1135
1139
let AssertDepGraphSafe ( scx) = scx;
@@ -1161,12 +1165,19 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1161
1165
}
1162
1166
} ) ;
1163
1167
1164
- let source = if let Some ( buf) = previous_work_product {
1168
+ if let Some ( buf) = previous_work_product {
1165
1169
// Don't need to translate this module.
1166
- ModuleSource :: Preexisting ( buf. clone ( ) )
1167
- } else {
1168
- // Instantiate translation items without filling out definitions yet...
1169
- let lcx = LocalCrateContext :: new ( scx, cgu, symbol_map. clone ( ) ) ;
1170
+ let module = ModuleTranslation {
1171
+ name : cgu_name,
1172
+ symbol_name_hash,
1173
+ source : ModuleSource :: Preexisting ( buf. clone ( ) )
1174
+ } ;
1175
+ return ( Stats :: default ( ) , module) ;
1176
+ }
1177
+
1178
+ // Instantiate translation items without filling out definitions yet...
1179
+ let lcx = LocalCrateContext :: new ( scx, cgu, symbol_map. clone ( ) ) ;
1180
+ let module = {
1170
1181
let ccx = CrateContext :: new ( scx, & lcx) ;
1171
1182
let trans_items = ccx. codegen_unit ( )
1172
1183
. items_in_deterministic_order ( ccx. tcx ( ) , & symbol_map) ;
@@ -1214,38 +1225,37 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1214
1225
debuginfo:: finalize ( & ccx) ;
1215
1226
}
1216
1227
1217
- ModuleSource :: Translated ( ModuleLlvm {
1218
- llcx : ccx. llcx ( ) ,
1219
- llmod : ccx. llmod ( ) ,
1220
- } )
1228
+ ModuleTranslation {
1229
+ name : cgu_name,
1230
+ symbol_name_hash,
1231
+ source : ModuleSource :: Translated ( ModuleLlvm {
1232
+ llcx : ccx. llcx ( ) ,
1233
+ llmod : ccx. llmod ( ) ,
1234
+ } )
1235
+ }
1221
1236
} ;
1222
1237
1223
- ModuleTranslation {
1224
- name : cgu_name,
1225
- symbol_name_hash,
1226
- source,
1227
- }
1238
+ ( lcx. into_stats ( ) , module)
1228
1239
}
1229
1240
1230
1241
assert_module_sources:: assert_module_sources ( tcx, & modules) ;
1231
1242
1232
1243
symbol_names_test:: report_symbol_names ( & shared_ccx) ;
1233
1244
1234
1245
if shared_ccx. sess ( ) . trans_stats ( ) {
1235
- let stats = shared_ccx. stats ( ) ;
1236
1246
println ! ( "--- trans stats ---" ) ;
1237
- println ! ( "n_glues_created: {}" , stats . n_glues_created. get( ) ) ;
1238
- println ! ( "n_null_glues: {}" , stats . n_null_glues. get( ) ) ;
1239
- println ! ( "n_real_glues: {}" , stats . n_real_glues. get( ) ) ;
1247
+ println ! ( "n_glues_created: {}" , all_stats . n_glues_created. get( ) ) ;
1248
+ println ! ( "n_null_glues: {}" , all_stats . n_null_glues. get( ) ) ;
1249
+ println ! ( "n_real_glues: {}" , all_stats . n_real_glues. get( ) ) ;
1240
1250
1241
- println ! ( "n_fns: {}" , stats . n_fns. get( ) ) ;
1242
- println ! ( "n_inlines: {}" , stats . n_inlines. get( ) ) ;
1243
- println ! ( "n_closures: {}" , stats . n_closures. get( ) ) ;
1251
+ println ! ( "n_fns: {}" , all_stats . n_fns. get( ) ) ;
1252
+ println ! ( "n_inlines: {}" , all_stats . n_inlines. get( ) ) ;
1253
+ println ! ( "n_closures: {}" , all_stats . n_closures. get( ) ) ;
1244
1254
println ! ( "fn stats:" ) ;
1245
- stats . fn_stats . borrow_mut ( ) . sort_by ( |& ( _, insns_a) , & ( _, insns_b) | {
1255
+ all_stats . fn_stats . borrow_mut ( ) . sort_by ( |& ( _, insns_a) , & ( _, insns_b) | {
1246
1256
insns_b. cmp ( & insns_a)
1247
1257
} ) ;
1248
- for tuple in stats . fn_stats . borrow ( ) . iter ( ) {
1258
+ for tuple in all_stats . fn_stats . borrow ( ) . iter ( ) {
1249
1259
match * tuple {
1250
1260
( ref name, insns) => {
1251
1261
println ! ( "{} insns, {}" , insns, * name) ;
@@ -1255,7 +1265,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1255
1265
}
1256
1266
1257
1267
if shared_ccx. sess ( ) . count_llvm_insns ( ) {
1258
- for ( k, v) in shared_ccx . stats ( ) . llvm_insns . borrow ( ) . iter ( ) {
1268
+ for ( k, v) in all_stats . llvm_insns . borrow ( ) . iter ( ) {
1259
1269
println ! ( "{:7} {}" , * v, * k) ;
1260
1270
}
1261
1271
}
0 commit comments