| 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/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // volatile because the variable may be clobbered by a longjmp. | 264 // volatile because the variable may be clobbered by a longjmp. |
| 265 volatile bool use_far_branches = false; | 265 volatile bool use_far_branches = false; |
| 266 while (!done) { | 266 while (!done) { |
| 267 const intptr_t prev_deopt_id = isolate->deopt_id(); | 267 const intptr_t prev_deopt_id = isolate->deopt_id(); |
| 268 isolate->set_deopt_id(0); | 268 isolate->set_deopt_id(0); |
| 269 LongJump* old_base = isolate->long_jump_base(); | 269 LongJump* old_base = isolate->long_jump_base(); |
| 270 LongJump bailout_jump; | 270 LongJump bailout_jump; |
| 271 isolate->set_long_jump_base(&bailout_jump); | 271 isolate->set_long_jump_base(&bailout_jump); |
| 272 if (setjmp(*bailout_jump.Set()) == 0) { | 272 if (setjmp(*bailout_jump.Set()) == 0) { |
| 273 FlowGraph* flow_graph = NULL; | 273 FlowGraph* flow_graph = NULL; |
| 274 GrowableArray<const Field*> guarded_fields; |
| 274 // TimerScope needs an isolate to be properly terminated in case of a | 275 // TimerScope needs an isolate to be properly terminated in case of a |
| 275 // LongJump. | 276 // LongJump. |
| 276 { | 277 { |
| 277 TimerScope timer(FLAG_compiler_stats, | 278 TimerScope timer(FLAG_compiler_stats, |
| 278 &CompilerStats::graphbuilder_timer, | 279 &CompilerStats::graphbuilder_timer, |
| 279 isolate); | 280 isolate); |
| 280 Array& ic_data_array = Array::Handle(); | 281 Array& ic_data_array = Array::Handle(); |
| 281 if (optimized) { | 282 if (optimized) { |
| 282 ASSERT(function.HasCode()); | 283 ASSERT(function.HasCode()); |
| 283 // Extract type feedback before the graph is built, as the graph | 284 // Extract type feedback before the graph is built, as the graph |
| 284 // builder uses it to attach it to nodes. | 285 // builder uses it to attach it to nodes. |
| 285 ASSERT(function.deoptimization_counter() < | 286 ASSERT(function.deoptimization_counter() < |
| 286 FLAG_deoptimization_counter_threshold); | 287 FLAG_deoptimization_counter_threshold); |
| 287 const Code& unoptimized_code = | 288 const Code& unoptimized_code = |
| 288 Code::Handle(function.unoptimized_code()); | 289 Code::Handle(function.unoptimized_code()); |
| 289 ic_data_array = unoptimized_code.ExtractTypeFeedbackArray(); | 290 ic_data_array = unoptimized_code.ExtractTypeFeedbackArray(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 // Build the flow graph. | 293 // Build the flow graph. |
| 293 FlowGraphBuilder builder(parsed_function, | 294 FlowGraphBuilder builder(parsed_function, |
| 294 ic_data_array, | 295 ic_data_array, |
| 295 NULL, // NULL = not inlining. | 296 NULL, // NULL = not inlining. |
| 297 &guarded_fields, |
| 296 osr_id); | 298 osr_id); |
| 297 flow_graph = builder.BuildGraph(); | 299 flow_graph = builder.BuildGraph(); |
| 298 } | 300 } |
| 299 | 301 |
| 300 if (FLAG_print_flow_graph || | 302 if (FLAG_print_flow_graph || |
| 301 (optimized && FLAG_print_flow_graph_optimized)) { | 303 (optimized && FLAG_print_flow_graph_optimized)) { |
| 302 if (osr_id == Isolate::kNoDeoptId) { | 304 if (osr_id == Isolate::kNoDeoptId) { |
| 303 FlowGraphPrinter::PrintGraph("Before Optimizations", flow_graph); | 305 FlowGraphPrinter::PrintGraph("Before Optimizations", flow_graph); |
| 304 } else { | 306 } else { |
| 305 FlowGraphPrinter::PrintGraph("For OSR", flow_graph); | 307 FlowGraphPrinter::PrintGraph("For OSR", flow_graph); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 319 flow_graph->ComputeSSA(0, NULL); | 321 flow_graph->ComputeSSA(0, NULL); |
| 320 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 322 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 321 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { | 323 if (FLAG_print_flow_graph || FLAG_print_flow_graph_optimized) { |
| 322 FlowGraphPrinter::PrintGraph("After SSA", flow_graph); | 324 FlowGraphPrinter::PrintGraph("After SSA", flow_graph); |
| 323 } | 325 } |
| 324 } | 326 } |
| 325 | 327 |
| 326 // Collect all instance fields that are loaded in the graph and | 328 // Collect all instance fields that are loaded in the graph and |
| 327 // have non-generic type feedback attached to them that can | 329 // have non-generic type feedback attached to them that can |
| 328 // potentially affect optimizations. | 330 // potentially affect optimizations. |
| 329 GrowableArray<const Field*> guarded_fields(10); | |
| 330 if (optimized) { | 331 if (optimized) { |
| 331 TimerScope timer(FLAG_compiler_stats, | 332 TimerScope timer(FLAG_compiler_stats, |
| 332 &CompilerStats::graphoptimizer_timer, | 333 &CompilerStats::graphoptimizer_timer, |
| 333 isolate); | 334 isolate); |
| 334 | 335 |
| 335 FlowGraphOptimizer optimizer(flow_graph, &guarded_fields); | 336 FlowGraphOptimizer optimizer(flow_graph); |
| 336 optimizer.ApplyICData(); | 337 optimizer.ApplyICData(); |
| 337 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 338 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 338 | 339 |
| 339 // Optimize (a << b) & c patterns. Must occur before | 340 // Optimize (a << b) & c patterns. Must occur before |
| 340 // 'SelectRepresentations' which inserts conversion nodes. | 341 // 'SelectRepresentations' which inserts conversion nodes. |
| 341 // TODO(srdjan): Moved before inlining until environment use list can | 342 // TODO(srdjan): Moved before inlining until environment use list can |
| 342 // be used to detect when shift-left is outside the scope of bit-and. | 343 // be used to detect when shift-left is outside the scope of bit-and. |
| 343 optimizer.TryOptimizeLeftShiftWithBitAndPattern(); | 344 optimizer.TryOptimizeLeftShiftWithBitAndPattern(); |
| 344 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 345 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 345 | 346 |
| 346 // Inlining (mutates the flow graph) | 347 // Inlining (mutates the flow graph) |
| 347 if (FLAG_use_inlining) { | 348 if (FLAG_use_inlining) { |
| 348 TimerScope timer(FLAG_compiler_stats, | 349 TimerScope timer(FLAG_compiler_stats, |
| 349 &CompilerStats::graphinliner_timer); | 350 &CompilerStats::graphinliner_timer); |
| 350 // Propagate types to create more inlining opportunities. | 351 // Propagate types to create more inlining opportunities. |
| 351 if (FLAG_propagate_types) { | 352 if (FLAG_propagate_types) { |
| 352 FlowGraphTypePropagator propagator(flow_graph); | 353 FlowGraphTypePropagator propagator(flow_graph); |
| 353 propagator.Propagate(); | 354 propagator.Propagate(); |
| 354 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 355 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 355 } | 356 } |
| 356 | 357 |
| 357 // Use propagated class-ids to create more inlining opportunities. | 358 // Use propagated class-ids to create more inlining opportunities. |
| 358 optimizer.ApplyClassIds(); | 359 optimizer.ApplyClassIds(); |
| 359 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 360 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 360 | 361 |
| 361 FlowGraphInliner inliner(flow_graph, &guarded_fields); | 362 FlowGraphInliner inliner(flow_graph); |
| 362 inliner.Inline(); | 363 inliner.Inline(); |
| 363 // Use lists are maintained and validated by the inliner. | 364 // Use lists are maintained and validated by the inliner. |
| 364 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 365 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 365 } | 366 } |
| 366 | 367 |
| 367 // Propagate types and eliminate more type tests. | 368 // Propagate types and eliminate more type tests. |
| 368 if (FLAG_propagate_types) { | 369 if (FLAG_propagate_types) { |
| 369 FlowGraphTypePropagator propagator(flow_graph); | 370 FlowGraphTypePropagator propagator(flow_graph); |
| 370 propagator.Propagate(); | 371 propagator.Propagate(); |
| 371 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 372 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 Object::Handle(isolate->object_store()->sticky_error()); | 924 Object::Handle(isolate->object_store()->sticky_error()); |
| 924 isolate->object_store()->clear_sticky_error(); | 925 isolate->object_store()->clear_sticky_error(); |
| 925 isolate->set_long_jump_base(base); | 926 isolate->set_long_jump_base(base); |
| 926 return result.raw(); | 927 return result.raw(); |
| 927 } | 928 } |
| 928 UNREACHABLE(); | 929 UNREACHABLE(); |
| 929 return Object::null(); | 930 return Object::null(); |
| 930 } | 931 } |
| 931 | 932 |
| 932 } // namespace dart | 933 } // namespace dart |
| OLD | NEW |