Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 DEFINE_FLAG(bool, disassemble_optimized, false, "Disassemble optimized code."); | 38 DEFINE_FLAG(bool, disassemble_optimized, false, "Disassemble optimized code."); |
| 39 DEFINE_FLAG(bool, trace_bailout, false, "Print bailout from ssa compiler."); | 39 DEFINE_FLAG(bool, trace_bailout, false, "Print bailout from ssa compiler."); |
| 40 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); | 40 DEFINE_FLAG(bool, trace_compiler, false, "Trace compiler operations."); |
| 41 DEFINE_FLAG(bool, constant_propagation, true, | 41 DEFINE_FLAG(bool, constant_propagation, true, |
| 42 "Do conditional constant propagation/unreachable code elimination."); | 42 "Do conditional constant propagation/unreachable code elimination."); |
| 43 DEFINE_FLAG(bool, common_subexpression_elimination, true, | 43 DEFINE_FLAG(bool, common_subexpression_elimination, true, |
| 44 "Do common subexpression elimination."); | 44 "Do common subexpression elimination."); |
| 45 DEFINE_FLAG(bool, loop_invariant_code_motion, true, | 45 DEFINE_FLAG(bool, loop_invariant_code_motion, true, |
| 46 "Do loop invariant code motion."); | 46 "Do loop invariant code motion."); |
| 47 DEFINE_FLAG(bool, propagate_types, true, "Do static type propagation."); | 47 DEFINE_FLAG(bool, propagate_types, true, "Do static type propagation."); |
| 48 DEFINE_FLAG(bool, allocation_sinking, true, | |
| 49 "attempt to sink temporary allocations to side exits"); | |
| 48 DEFINE_FLAG(int, deoptimization_counter_threshold, 16, | 50 DEFINE_FLAG(int, deoptimization_counter_threshold, 16, |
| 49 "How many times we allow deoptimization before we disallow optimization."); | 51 "How many times we allow deoptimization before we disallow optimization."); |
| 50 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); | 52 DEFINE_FLAG(bool, use_inlining, true, "Enable call-site inlining"); |
| 51 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); | 53 DEFINE_FLAG(bool, range_analysis, true, "Enable range analysis"); |
| 52 DEFINE_FLAG(bool, verify_compiler, false, | 54 DEFINE_FLAG(bool, verify_compiler, false, |
| 53 "Enable compiler verification assertions"); | 55 "Enable compiler verification assertions"); |
| 54 DECLARE_FLAG(bool, print_flow_graph); | 56 DECLARE_FLAG(bool, print_flow_graph); |
| 55 DECLARE_FLAG(bool, print_flow_graph_optimized); | 57 DECLARE_FLAG(bool, print_flow_graph_optimized); |
| 56 DECLARE_FLAG(bool, trace_failed_optimization_attempts); | 58 DECLARE_FLAG(bool, trace_failed_optimization_attempts); |
| 57 | 59 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 287 } |
| 286 | 288 |
| 287 // The final canonicalization pass before the code generation. | 289 // The final canonicalization pass before the code generation. |
| 288 if (FLAG_propagate_types) { | 290 if (FLAG_propagate_types) { |
| 289 // Recompute types after code movement was done to ensure correct | 291 // Recompute types after code movement was done to ensure correct |
| 290 // reaching types for hoisted values. | 292 // reaching types for hoisted values. |
| 291 FlowGraphTypePropagator propagator(flow_graph); | 293 FlowGraphTypePropagator propagator(flow_graph); |
| 292 propagator.Propagate(); | 294 propagator.Propagate(); |
| 293 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 295 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 294 } | 296 } |
| 297 | |
| 298 // Detach environments from the instructions that can't deoptimized. | |
|
srdjan
2013/05/07 23:11:45
s/deoptimized/deoptimize/
Vyacheslav Egorov (Google)
2013/05/07 23:28:21
Done.
| |
| 299 // Do it before we attempt to perform allocation sinking to minimize | |
| 300 // amount of materializations it has to perform. | |
| 301 optimizer.EliminateEnvironments(); | |
| 302 | |
| 303 // Attempt to sink allocations of temporary non-escaping objects to | |
| 304 // the deoptimization path. | |
| 305 AllocationSinking* sinking = NULL; | |
| 306 if (FLAG_allocation_sinking) { | |
| 307 sinking = new AllocationSinking(flow_graph); | |
| 308 sinking->Optimize(); | |
| 309 } | |
| 310 | |
| 295 if (optimizer.Canonicalize()) { | 311 if (optimizer.Canonicalize()) { |
| 296 // To fully remove redundant boxing (e.g. BoxDouble used only in | 312 // To fully remove redundant boxing (e.g. BoxDouble used only in |
| 297 // environments and UnboxDouble instructions) instruction we | 313 // environments and UnboxDouble instructions) instruction we |
| 298 // first need to replace all their uses and then fold them away. | 314 // first need to replace all their uses and then fold them away. |
| 299 // For now we just repeat Canonicalize twice to do that. | 315 // For now we just repeat Canonicalize twice to do that. |
| 300 // TODO(vegorov): implement a separate representation folding pass. | 316 // TODO(vegorov): implement a separate representation folding pass. |
| 301 optimizer.Canonicalize(); | 317 optimizer.Canonicalize(); |
| 302 } | 318 } |
| 303 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 319 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 304 | 320 |
| 321 if (sinking != NULL) { | |
| 322 // Remove all MaterializeObject instructions inserted by allocation | |
| 323 // sinking from the flow graph and let them float on the side referenced | |
| 324 // only from environments. Register allocator will consider them | |
| 325 // as part of a deoptimization environment. | |
| 326 sinking->DetachMaterializations(); | |
| 327 } | |
| 328 | |
| 305 // Perform register allocation on the SSA graph. | 329 // Perform register allocation on the SSA graph. |
| 306 FlowGraphAllocator allocator(*flow_graph); | 330 FlowGraphAllocator allocator(*flow_graph); |
| 307 allocator.AllocateRegisters(); | 331 allocator.AllocateRegisters(); |
| 308 | 332 |
| 309 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { | 333 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { |
| 310 FlowGraphPrinter::PrintGraph("After Optimizations", flow_graph); | 334 FlowGraphPrinter::PrintGraph("After Optimizations", flow_graph); |
| 311 } | 335 } |
| 312 } | 336 } |
| 313 | 337 |
| 314 Assembler assembler; | 338 Assembler assembler; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 Object::Handle(isolate->object_store()->sticky_error()); | 733 Object::Handle(isolate->object_store()->sticky_error()); |
| 710 isolate->object_store()->clear_sticky_error(); | 734 isolate->object_store()->clear_sticky_error(); |
| 711 isolate->set_long_jump_base(base); | 735 isolate->set_long_jump_base(base); |
| 712 return result.raw(); | 736 return result.raw(); |
| 713 } | 737 } |
| 714 UNREACHABLE(); | 738 UNREACHABLE(); |
| 715 return Object::null(); | 739 return Object::null(); |
| 716 } | 740 } |
| 717 | 741 |
| 718 } // namespace dart | 742 } // namespace dart |
| OLD | NEW |