Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: runtime/vm/flow_graph_inliner.cc

Issue 11236063: Restructure code generation timers and add sub-timers for inlining phases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/vm/compiler_stats.h ('K') | « runtime/vm/compiler_stats.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph_inliner.h" 5 #include "vm/flow_graph_inliner.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/flow_graph.h" 9 #include "vm/flow_graph.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Save and clear deopt id. 262 // Save and clear deopt id.
263 const intptr_t prev_deopt_id = isolate->deopt_id(); 263 const intptr_t prev_deopt_id = isolate->deopt_id();
264 isolate->set_deopt_id(0); 264 isolate->set_deopt_id(0);
265 // Install bailout jump. 265 // Install bailout jump.
266 LongJump* base = isolate->long_jump_base(); 266 LongJump* base = isolate->long_jump_base();
267 LongJump jump; 267 LongJump jump;
268 isolate->set_long_jump_base(&jump); 268 isolate->set_long_jump_base(&jump);
269 if (setjmp(*jump.Set()) == 0) { 269 if (setjmp(*jump.Set()) == 0) {
270 // Parse the callee function. 270 // Parse the callee function.
271 bool in_cache; 271 bool in_cache;
272 ParsedFunction* parsed_function = ParseFunction(function, &in_cache); 272 ParsedFunction* parsed_function;
273 {
274 TimerScope timer(FLAG_compiler_stats,
275 &CompilerStats::graphinliner_parse_timer,
276 isolate);
277 parsed_function = ParseFunction(function, &in_cache);
278 }
273 279
274 // Load IC data for the callee. 280 // Load IC data for the callee.
275 if (function.HasCode()) { 281 if (function.HasCode()) {
276 const Code& unoptimized_code = 282 const Code& unoptimized_code =
277 Code::Handle(function.unoptimized_code()); 283 Code::Handle(function.unoptimized_code());
278 isolate->set_ic_data_array(unoptimized_code.ExtractTypeFeedbackArray()); 284 isolate->set_ic_data_array(unoptimized_code.ExtractTypeFeedbackArray());
279 } 285 }
280 286
281 // Build the callee graph. 287 // Build the callee graph.
282 FlowGraphBuilder builder(*parsed_function); 288 FlowGraphBuilder builder(*parsed_function);
283 builder.SetInitialBlockId(caller_graph_->max_block_id()); 289 builder.SetInitialBlockId(caller_graph_->max_block_id());
284 FlowGraph* callee_graph = 290 FlowGraph* callee_graph;
285 builder.BuildGraph(FlowGraphBuilder::kValueContext); 291 {
292 TimerScope timer(FLAG_compiler_stats,
293 &CompilerStats::graphinliner_build_timer,
294 isolate);
295 callee_graph = builder.BuildGraph(FlowGraphBuilder::kValueContext);
296 }
286 297
287 // Abort if the callee graph contains control flow. 298 // Abort if the callee graph contains control flow.
288 if (!FLAG_inline_control_flow && 299 if (!FLAG_inline_control_flow &&
289 (callee_graph->preorder().length() != 2)) { 300 (callee_graph->preorder().length() != 2)) {
290 function.set_is_inlinable(false); 301 function.set_is_inlinable(false);
291 isolate->set_long_jump_base(base); 302 isolate->set_long_jump_base(base);
292 isolate->set_ic_data_array(prev_ic_data.raw()); 303 isolate->set_ic_data_array(prev_ic_data.raw());
293 TRACE_INLINING(OS::Print(" Bailout: control flow\n")); 304 TRACE_INLINING(OS::Print(" Bailout: control flow\n"));
294 return false; 305 return false;
295 } 306 }
296 307
297 // Compute SSA on the callee graph, catching bailouts. 308 {
298 callee_graph->ComputeSSA(next_ssa_temp_index_); 309 TimerScope timer(FLAG_compiler_stats,
299 callee_graph->ComputeUseLists(); 310 &CompilerStats::graphinliner_ssa_timer,
311 isolate);
312 // Compute SSA on the callee graph, catching bailouts.
313 callee_graph->ComputeSSA(next_ssa_temp_index_);
314 callee_graph->ComputeUseLists();
315 }
300 316
301 // TODO(zerny): Do more optimization passes on the callee graph. 317 {
302 FlowGraphOptimizer optimizer(callee_graph); 318 TimerScope timer(FLAG_compiler_stats,
303 optimizer.ApplyICData(); 319 &CompilerStats::graphinliner_opt_timer,
304 callee_graph->ComputeUseLists(); 320 isolate);
321 // TODO(zerny): Do more optimization passes on the callee graph.
322 FlowGraphOptimizer optimizer(callee_graph);
323 optimizer.ApplyICData();
324 callee_graph->ComputeUseLists();
325 }
305 326
306 if (FLAG_trace_inlining && FLAG_print_flow_graph) { 327 if (FLAG_trace_inlining && FLAG_print_flow_graph) {
307 OS::Print("Callee graph for inlining %s\n", 328 OS::Print("Callee graph for inlining %s\n",
308 function.ToFullyQualifiedCString()); 329 function.ToFullyQualifiedCString());
309 FlowGraphPrinter printer(*callee_graph); 330 FlowGraphPrinter printer(*callee_graph);
310 printer.PrintBlocks(); 331 printer.PrintBlocks();
311 } 332 }
312 333
313 // If result is more than size threshold then abort. 334 // If result is more than size threshold then abort.
314 // TODO(zerny): Do this after CP and dead code elimination. 335 // TODO(zerny): Do this after CP and dead code elimination.
315 intptr_t size = callee_graph->InstructionCount(); 336 intptr_t size = callee_graph->InstructionCount();
316 if (size > FLAG_inlining_size_threshold) { 337 if (size > FLAG_inlining_size_threshold) {
317 function.set_is_inlinable(false); 338 function.set_is_inlinable(false);
318 isolate->set_long_jump_base(base); 339 isolate->set_long_jump_base(base);
319 isolate->set_deopt_id(prev_deopt_id); 340 isolate->set_deopt_id(prev_deopt_id);
320 isolate->set_ic_data_array(prev_ic_data.raw()); 341 isolate->set_ic_data_array(prev_ic_data.raw());
321 TRACE_INLINING(OS::Print(" Bailout: graph size %"Pd"\n", size)); 342 TRACE_INLINING(OS::Print(" Bailout: graph size %"Pd"\n", size));
322 return false; 343 return false;
323 } 344 }
324 345
325 // If depth is less or equal to threshold recursively add call sites. 346 // If depth is less or equal to threshold recursively add call sites.
326 if (inlining_depth_ < FLAG_inlining_depth_threshold) { 347 if (inlining_depth_ < FLAG_inlining_depth_threshold) {
327 collected_call_sites_->FindCallSites(callee_graph); 348 collected_call_sites_->FindCallSites(callee_graph);
328 } 349 }
329 350
330 // Plug result in the caller graph. 351 {
331 caller_graph_->InlineCall(call, callee_graph); 352 TimerScope timer(FLAG_compiler_stats,
332 next_ssa_temp_index_ = caller_graph_->max_virtual_register_number(); 353 &CompilerStats::graphinliner_subst_timer,
354 isolate);
333 355
334 // Remove push arguments of the call. 356 // Plug result in the caller graph.
335 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) { 357 caller_graph_->InlineCall(call, callee_graph);
336 PushArgumentInstr* push = call->ArgumentAt(i); 358 next_ssa_temp_index_ = caller_graph_->max_virtual_register_number();
337 push->ReplaceUsesWith(push->value()->definition()); 359
338 push->RemoveFromGraph(); 360 // Remove push arguments of the call.
361 for (intptr_t i = 0; i < call->ArgumentCount(); ++i) {
362 PushArgumentInstr* push = call->ArgumentAt(i);
363 push->ReplaceUsesWith(push->value()->definition());
364 push->RemoveFromGraph();
365 }
366
367 // Replace formal parameters with actuals.
368 intptr_t arg_index = 0;
369 GrowableArray<Definition*>* defns =
370 callee_graph->graph_entry()->initial_definitions();
371 for (intptr_t i = 0; i < defns->length(); ++i) {
372 ParameterInstr* param = (*defns)[i]->AsParameter();
373 if (param != NULL) {
374 param->ReplaceUsesWith((*arguments)[arg_index++]->definition());
375 }
376 }
377 ASSERT(arg_index == arguments->length());
378
379 // Replace callee's null constant with caller's null constant.
380 callee_graph->graph_entry()->constant_null()->ReplaceUsesWith(
381 caller_graph_->graph_entry()->constant_null());
339 } 382 }
340 383
341 // Replace formal parameters with actuals.
342 intptr_t arg_index = 0;
343 GrowableArray<Definition*>* defns =
344 callee_graph->graph_entry()->initial_definitions();
345 for (intptr_t i = 0; i < defns->length(); ++i) {
346 ParameterInstr* param = (*defns)[i]->AsParameter();
347 if (param != NULL) {
348 param->ReplaceUsesWith((*arguments)[arg_index++]->definition());
349 }
350 }
351 ASSERT(arg_index == arguments->length());
352
353 // Replace callee's null constant with caller's null constant.
354 callee_graph->graph_entry()->constant_null()->ReplaceUsesWith(
355 caller_graph_->graph_entry()->constant_null());
356
357 TRACE_INLINING(OS::Print(" Success\n")); 384 TRACE_INLINING(OS::Print(" Success\n"));
358 385
359 // Add the function to the cache. 386 // Add the function to the cache.
360 if (!in_cache) function_cache.Add(parsed_function); 387 if (!in_cache) function_cache.Add(parsed_function);
361 388
362 // Check that inlining maintains use lists. 389 // Check that inlining maintains use lists.
363 DEBUG_ASSERT(!FLAG_verify_compiler || caller_graph_->ValidateUseLists()); 390 DEBUG_ASSERT(!FLAG_verify_compiler || caller_graph_->ValidateUseLists());
364 391
365 // Build succeeded so we restore the bailout jump. 392 // Build succeeded so we restore the bailout jump.
366 inlined_ = true; 393 inlined_ = true;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 OS::Print("After Inlining of %s\n", flow_graph_-> 532 OS::Print("After Inlining of %s\n", flow_graph_->
506 parsed_function().function().ToFullyQualifiedCString()); 533 parsed_function().function().ToFullyQualifiedCString());
507 FlowGraphPrinter printer(*flow_graph_); 534 FlowGraphPrinter printer(*flow_graph_);
508 printer.PrintBlocks(); 535 printer.PrintBlocks();
509 } 536 }
510 } 537 }
511 } 538 }
512 } 539 }
513 540
514 } // namespace dart 541 } // namespace dart
OLDNEW
« runtime/vm/compiler_stats.h ('K') | « runtime/vm/compiler_stats.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698