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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 "Eliminate type checks when allowed by static type analysis."); | 25 "Eliminate type checks when allowed by static type analysis."); |
| 26 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); | 26 DEFINE_FLAG(bool, print_ast, false, "Print abstract syntax tree."); |
| 27 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); | 27 DEFINE_FLAG(bool, print_flow_graph, false, "Print the IR flow graph."); |
| 28 DEFINE_FLAG(bool, trace_type_check_elimination, false, | 28 DEFINE_FLAG(bool, trace_type_check_elimination, false, |
| 29 "Trace type check elimination at compile time."); | 29 "Trace type check elimination at compile time."); |
| 30 DECLARE_FLAG(bool, enable_type_checks); | 30 DECLARE_FLAG(bool, enable_type_checks); |
| 31 | 31 |
| 32 | 32 |
| 33 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) | 33 FlowGraphBuilder::FlowGraphBuilder(const ParsedFunction& parsed_function) |
| 34 : parsed_function_(parsed_function), | 34 : parsed_function_(parsed_function), |
| 35 copied_parameter_count_(parsed_function.copied_parameter_count()), | |
| 36 // All parameters are copied if any parameter is. | |
| 37 non_copied_parameter_count_((copied_parameter_count_ == 0) | |
| 38 ? parsed_function.function().num_fixed_parameters() | |
| 39 : 0), | |
| 40 stack_local_count_(parsed_function.stack_local_count()), | |
| 35 preorder_block_entries_(), | 41 preorder_block_entries_(), |
| 36 postorder_block_entries_(), | 42 postorder_block_entries_(), |
| 37 context_level_(0), | 43 context_level_(0), |
| 38 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), | 44 last_used_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 39 try_index_(CatchClauseNode::kInvalidTryIndex), | 45 try_index_(CatchClauseNode::kInvalidTryIndex), |
| 40 graph_entry_(NULL), | 46 graph_entry_(NULL), |
| 41 current_ssa_temp_index_(0) { } | 47 current_ssa_temp_index_(0) { } |
| 42 | 48 |
| 43 | 49 |
| 44 void FlowGraphBuilder::AddCatchEntry(TargetEntryInstr* entry) { | 50 void FlowGraphBuilder::AddCatchEntry(TargetEntryInstr* entry) { |
| (...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2292 TargetEntryInstr* normal_entry = new TargetEntryInstr(); | 2298 TargetEntryInstr* normal_entry = new TargetEntryInstr(); |
| 2293 graph_entry_ = new GraphEntryInstr(normal_entry); | 2299 graph_entry_ = new GraphEntryInstr(normal_entry); |
| 2294 EffectGraphVisitor for_effect(this, 0); | 2300 EffectGraphVisitor for_effect(this, 0); |
| 2295 parsed_function().node_sequence()->Visit(&for_effect); | 2301 parsed_function().node_sequence()->Visit(&for_effect); |
| 2296 AppendFragment(normal_entry, for_effect); | 2302 AppendFragment(normal_entry, for_effect); |
| 2297 // Check that the graph is properly terminated. | 2303 // Check that the graph is properly terminated. |
| 2298 ASSERT(!for_effect.is_open()); | 2304 ASSERT(!for_effect.is_open()); |
| 2299 GrowableArray<intptr_t> parent; | 2305 GrowableArray<intptr_t> parent; |
| 2300 GrowableArray<BitVector*> assigned_vars; | 2306 GrowableArray<BitVector*> assigned_vars; |
| 2301 | 2307 |
| 2302 // Either all parameters are fixed (none are named) or they are all copied. | |
| 2303 // This could change, so we keep fixed/copied counts separate. | |
| 2304 intptr_t fixed_parameter_count; // This is really the "non-copied" count. | |
| 2305 intptr_t copied_parameter_count; | |
| 2306 if (parsed_function_.copied_parameter_count() > 0) { | |
| 2307 fixed_parameter_count = 0; | |
| 2308 copied_parameter_count = parsed_function_.copied_parameter_count(); | |
| 2309 } else { | |
| 2310 fixed_parameter_count = parsed_function_.function().num_fixed_parameters(); | |
| 2311 copied_parameter_count = 0; | |
| 2312 } | |
| 2313 const intptr_t stack_local_count = parsed_function_.stack_local_count(); | |
| 2314 const intptr_t variable_count = | |
| 2315 stack_local_count + fixed_parameter_count + copied_parameter_count; | |
| 2316 | |
| 2317 // Perform a depth-first traversal of the graph to build preorder and | 2308 // Perform a depth-first traversal of the graph to build preorder and |
| 2318 // postorder block orders. | 2309 // postorder block orders. |
| 2319 graph_entry_->DiscoverBlocks(NULL, // Entry block predecessor. | 2310 graph_entry_->DiscoverBlocks(NULL, // Entry block predecessor. |
| 2320 &preorder_block_entries_, | 2311 &preorder_block_entries_, |
| 2321 &postorder_block_entries_, | 2312 &postorder_block_entries_, |
| 2322 &parent, | 2313 &parent, |
| 2323 &assigned_vars, | 2314 &assigned_vars, |
| 2324 variable_count, | 2315 variable_count(), |
| 2325 fixed_parameter_count); | 2316 non_copied_parameter_count_); |
| 2326 // Number blocks in reverse postorder. | 2317 // Number blocks in reverse postorder. |
| 2327 intptr_t block_count = postorder_block_entries_.length(); | 2318 intptr_t block_count = postorder_block_entries_.length(); |
| 2328 for (intptr_t i = 0; i < block_count; ++i) { | 2319 for (intptr_t i = 0; i < block_count; ++i) { |
| 2329 postorder_block_entries_[i]->set_block_id(block_count - i - 1); | 2320 postorder_block_entries_[i]->set_block_id(block_count - i - 1); |
| 2330 } | 2321 } |
| 2331 | 2322 |
| 2332 if (for_optimized) { | 2323 if (for_optimized) { |
| 2333 // Link instructions backwards for optimized compilation. | 2324 // Link instructions backwards for optimized compilation. |
| 2334 for (intptr_t i = 0; i < block_count; ++i) { | 2325 for (intptr_t i = 0; i < block_count; ++i) { |
| 2335 BlockEntryInstr* entry = postorder_block_entries_[i]; | 2326 BlockEntryInstr* entry = postorder_block_entries_[i]; |
| 2336 Instruction* previous = entry; | 2327 Instruction* previous = entry; |
| 2337 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 2328 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 2338 Instruction* current = it.Current(); | 2329 Instruction* current = it.Current(); |
| 2339 current->set_previous(previous); | 2330 current->set_previous(previous); |
| 2340 previous = current; | 2331 previous = current; |
| 2341 } | 2332 } |
| 2342 } | 2333 } |
| 2343 } | 2334 } |
| 2344 | 2335 |
| 2345 if (for_optimized && use_ssa) { | 2336 if (for_optimized && use_ssa) { |
| 2346 GrowableArray<BitVector*> dominance_frontier; | 2337 GrowableArray<BitVector*> dominance_frontier; |
| 2347 ComputeDominators(&preorder_block_entries_, &parent, &dominance_frontier); | 2338 ComputeDominators(&preorder_block_entries_, &parent, &dominance_frontier); |
| 2348 InsertPhis(preorder_block_entries_, | 2339 InsertPhis(preorder_block_entries_, |
| 2349 assigned_vars, | 2340 assigned_vars, |
| 2350 variable_count, | |
| 2351 dominance_frontier); | 2341 dominance_frontier); |
| 2352 Rename(stack_local_count, fixed_parameter_count, copied_parameter_count); | 2342 Rename(); |
| 2353 } | 2343 } |
| 2354 if (FLAG_print_flow_graph || (Dart::flow_graph_writer() != NULL)) { | 2344 if (FLAG_print_flow_graph || (Dart::flow_graph_writer() != NULL)) { |
| 2355 intptr_t length = postorder_block_entries_.length(); | 2345 intptr_t length = postorder_block_entries_.length(); |
| 2356 GrowableArray<BlockEntryInstr*> reverse_postorder(length); | 2346 GrowableArray<BlockEntryInstr*> reverse_postorder(length); |
| 2357 for (intptr_t i = length - 1; i >= 0; --i) { | 2347 for (intptr_t i = length - 1; i >= 0; --i) { |
| 2358 reverse_postorder.Add(postorder_block_entries_[i]); | 2348 reverse_postorder.Add(postorder_block_entries_[i]); |
| 2359 } | 2349 } |
| 2360 if (FLAG_print_flow_graph) { | 2350 if (FLAG_print_flow_graph) { |
| 2361 // Print flow graph to stdout. | 2351 // Print flow graph to stdout. |
| 2362 FlowGraphPrinter printer(function, reverse_postorder); | 2352 FlowGraphPrinter printer(function, reverse_postorder); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2491 (*label)[current_index] = | 2481 (*label)[current_index] = |
| 2492 Utils::Minimum((*label)[current_index], (*label)[next_index]); | 2482 Utils::Minimum((*label)[current_index], (*label)[next_index]); |
| 2493 (*parent)[current_index] = (*parent)[next_index]; | 2483 (*parent)[current_index] = (*parent)[next_index]; |
| 2494 } | 2484 } |
| 2495 } | 2485 } |
| 2496 | 2486 |
| 2497 | 2487 |
| 2498 void FlowGraphBuilder::InsertPhis( | 2488 void FlowGraphBuilder::InsertPhis( |
| 2499 const GrowableArray<BlockEntryInstr*>& preorder, | 2489 const GrowableArray<BlockEntryInstr*>& preorder, |
| 2500 const GrowableArray<BitVector*>& assigned_vars, | 2490 const GrowableArray<BitVector*>& assigned_vars, |
| 2501 const intptr_t var_count, | |
| 2502 const GrowableArray<BitVector*>& dom_frontier) { | 2491 const GrowableArray<BitVector*>& dom_frontier) { |
| 2503 const intptr_t block_count = preorder.length(); | 2492 const intptr_t block_count = preorder.length(); |
| 2504 // Map preorder block number to the highest variable index that has a phi | 2493 // Map preorder block number to the highest variable index that has a phi |
| 2505 // in that block. Use it to avoid inserting multiple phis for the same | 2494 // in that block. Use it to avoid inserting multiple phis for the same |
| 2506 // variable. | 2495 // variable. |
| 2507 GrowableArray<intptr_t> has_already(block_count); | 2496 GrowableArray<intptr_t> has_already(block_count); |
| 2508 // Map preorder block number to the highest variable index for which the | 2497 // Map preorder block number to the highest variable index for which the |
| 2509 // block went on the worklist. Use it to avoid adding the same block to | 2498 // block went on the worklist. Use it to avoid adding the same block to |
| 2510 // the worklist more than once for the same variable. | 2499 // the worklist more than once for the same variable. |
| 2511 GrowableArray<intptr_t> work(block_count); | 2500 GrowableArray<intptr_t> work(block_count); |
| 2512 | 2501 |
| 2513 // Initialize has_already and work. | 2502 // Initialize has_already and work. |
| 2514 for (intptr_t block_index = 0; block_index < block_count; ++block_index) { | 2503 for (intptr_t block_index = 0; block_index < block_count; ++block_index) { |
| 2515 has_already.Add(-1); | 2504 has_already.Add(-1); |
| 2516 work.Add(-1); | 2505 work.Add(-1); |
| 2517 } | 2506 } |
| 2518 | 2507 |
| 2519 // Insert phis for each variable in turn. | 2508 // Insert phis for each variable in turn. |
| 2520 GrowableArray<BlockEntryInstr*> worklist; | 2509 GrowableArray<BlockEntryInstr*> worklist; |
| 2521 for (intptr_t var_index = 0; var_index < var_count; ++var_index) { | 2510 for (intptr_t var_index = 0; var_index < variable_count(); ++var_index) { |
| 2522 // Add to the worklist each block containing an assignment. | 2511 // Add to the worklist each block containing an assignment. |
| 2523 for (intptr_t block_index = 0; block_index < block_count; ++block_index) { | 2512 for (intptr_t block_index = 0; block_index < block_count; ++block_index) { |
| 2524 if (assigned_vars[block_index]->Contains(var_index)) { | 2513 if (assigned_vars[block_index]->Contains(var_index)) { |
| 2525 work[block_index] = var_index; | 2514 work[block_index] = var_index; |
| 2526 worklist.Add(preorder[block_index]); | 2515 worklist.Add(preorder[block_index]); |
| 2527 } | 2516 } |
| 2528 } | 2517 } |
| 2529 | 2518 |
| 2530 while (!worklist.is_empty()) { | 2519 while (!worklist.is_empty()) { |
| 2531 BlockEntryInstr* current = worklist.Last(); | 2520 BlockEntryInstr* current = worklist.Last(); |
| 2532 worklist.RemoveLast(); | 2521 worklist.RemoveLast(); |
| 2533 // Ensure a phi for each block in the dominance frontier of current. | 2522 // Ensure a phi for each block in the dominance frontier of current. |
| 2534 for (BitVector::Iterator it(dom_frontier[current->preorder_number()]); | 2523 for (BitVector::Iterator it(dom_frontier[current->preorder_number()]); |
| 2535 !it.Done(); | 2524 !it.Done(); |
| 2536 it.Advance()) { | 2525 it.Advance()) { |
| 2537 int index = it.Current(); | 2526 int index = it.Current(); |
| 2538 if (has_already[index] < var_index) { | 2527 if (has_already[index] < var_index) { |
| 2539 BlockEntryInstr* block = preorder[index]; | 2528 BlockEntryInstr* block = preorder[index]; |
| 2540 ASSERT(block->IsJoinEntry()); | 2529 ASSERT(block->IsJoinEntry()); |
| 2541 block->AsJoinEntry()->InsertPhi(var_index, var_count); | 2530 block->AsJoinEntry()->InsertPhi(var_index, variable_count()); |
| 2542 has_already[index] = var_index; | 2531 has_already[index] = var_index; |
| 2543 if (work[index] < var_index) { | 2532 if (work[index] < var_index) { |
| 2544 work[index] = var_index; | 2533 work[index] = var_index; |
| 2545 worklist.Add(block); | 2534 worklist.Add(block); |
| 2546 } | 2535 } |
| 2547 } | 2536 } |
| 2548 } | 2537 } |
| 2549 } | 2538 } |
| 2550 } | 2539 } |
| 2551 } | 2540 } |
| 2552 | 2541 |
| 2553 | 2542 |
| 2554 void FlowGraphBuilder::Rename(intptr_t stack_local_count, | 2543 void FlowGraphBuilder::Rename() { |
| 2555 intptr_t fixed_parameter_count, | |
| 2556 intptr_t copied_parameter_count) { | |
| 2557 // TODO(fschneider): Store counts in the FlowGraphBuilder instead of | 2544 // TODO(fschneider): Store counts in the FlowGraphBuilder instead of |
|
Kevin Millikin (Google)
2012/08/06 14:01:14
I'll remove the TODO :)
| |
| 2558 // passing it around. | 2545 // passing it around. |
| 2559 // TODO(fschneider): Support catch-entry. | 2546 // TODO(fschneider): Support catch-entry. |
| 2560 if (graph_entry_->SuccessorCount() > 1) { | 2547 if (graph_entry_->SuccessorCount() > 1) { |
| 2561 Bailout("Catch-entry support in SSA."); | 2548 Bailout("Catch-entry support in SSA."); |
| 2562 } | 2549 } |
| 2563 | 2550 |
| 2564 const intptr_t parameter_count = | |
| 2565 fixed_parameter_count + copied_parameter_count; | |
| 2566 const intptr_t variable_count = parameter_count + stack_local_count; | |
| 2567 | |
| 2568 // Initialize start environment. | 2551 // Initialize start environment. |
| 2569 GrowableArray<Value*> start_env(variable_count); | 2552 GrowableArray<Value*> start_env(variable_count()); |
| 2570 intptr_t i = 0; | 2553 for (intptr_t i = 0; i < parameter_count(); ++i) { |
| 2571 for (; i < parameter_count; ++i) { | |
| 2572 ParameterInstr* param = new ParameterInstr(i); | 2554 ParameterInstr* param = new ParameterInstr(i); |
| 2573 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. | 2555 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. |
| 2574 start_env.Add(new UseVal(param)); | 2556 start_env.Add(new UseVal(param)); |
| 2575 } | 2557 } |
| 2576 | 2558 |
| 2577 // All locals are initialized with #null. | 2559 // All locals are initialized with #null. |
| 2578 Value* null_value = new ConstantVal(Object::ZoneHandle()); | 2560 Value* null_value = new ConstantVal(Object::ZoneHandle()); |
| 2579 for (; i < variable_count; i++) { | 2561 while (start_env.length() < variable_count()) { |
| 2580 start_env.Add(null_value); | 2562 start_env.Add(null_value); |
| 2581 } | 2563 } |
| 2582 graph_entry_->set_start_env( | 2564 graph_entry_->set_start_env( |
| 2583 new Environment(start_env, fixed_parameter_count)); | 2565 new Environment(start_env, non_copied_parameter_count_)); |
| 2584 | 2566 |
| 2585 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); | 2567 BlockEntryInstr* normal_entry = graph_entry_->SuccessorAt(0); |
| 2586 ASSERT(normal_entry != NULL); // Must have entry. | 2568 ASSERT(normal_entry != NULL); // Must have entry. |
| 2587 GrowableArray<Value*> env(variable_count); | 2569 GrowableArray<Value*> env(variable_count()); |
| 2588 env.AddArray(start_env); | 2570 env.AddArray(start_env); |
| 2589 RenameRecursive(normal_entry, &env, variable_count, fixed_parameter_count); | 2571 RenameRecursive(normal_entry, &env); |
| 2590 } | 2572 } |
| 2591 | 2573 |
| 2592 | 2574 |
| 2593 // Helper to a copy a value iff it is a UseVal. | 2575 // Helper to a copy a value iff it is a UseVal. |
| 2594 static Value* CopyValue(Value* value) { | 2576 static Value* CopyValue(Value* value) { |
| 2595 return value->IsUse() | 2577 return value->IsUse() |
| 2596 ? new UseVal(value->AsUse()->definition()) | 2578 ? new UseVal(value->AsUse()->definition()) |
| 2597 : value; | 2579 : value; |
| 2598 } | 2580 } |
| 2599 | 2581 |
| 2600 | 2582 |
| 2601 void FlowGraphBuilder::RenameRecursive(BlockEntryInstr* block_entry, | 2583 void FlowGraphBuilder::RenameRecursive(BlockEntryInstr* block_entry, |
| 2602 GrowableArray<Value*>* env, | 2584 GrowableArray<Value*>* env) { |
| 2603 intptr_t var_count, | |
| 2604 intptr_t fixed_parameter_count) { | |
| 2605 // 1. Process phis first. | 2585 // 1. Process phis first. |
| 2606 if (block_entry->IsJoinEntry()) { | 2586 if (block_entry->IsJoinEntry()) { |
| 2607 JoinEntryInstr* join = block_entry->AsJoinEntry(); | 2587 JoinEntryInstr* join = block_entry->AsJoinEntry(); |
| 2608 if (join->phis() != NULL) { | 2588 if (join->phis() != NULL) { |
| 2609 for (intptr_t i = 0; i < join->phis()->length(); ++i) { | 2589 for (intptr_t i = 0; i < join->phis()->length(); ++i) { |
| 2610 PhiInstr* phi = (*join->phis())[i]; | 2590 PhiInstr* phi = (*join->phis())[i]; |
| 2611 if (phi != NULL) { | 2591 if (phi != NULL) { |
| 2612 (*env)[i] = new UseVal(phi); | 2592 (*env)[i] = new UseVal(phi); |
| 2613 phi->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. | 2593 phi->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. |
| 2614 } | 2594 } |
| 2615 } | 2595 } |
| 2616 } | 2596 } |
| 2617 } | 2597 } |
| 2618 | 2598 |
| 2619 // 2. Process normal instructions. | 2599 // 2. Process normal instructions. |
| 2620 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) { | 2600 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) { |
| 2621 Instruction* current = it.Current(); | 2601 Instruction* current = it.Current(); |
| 2622 // Attach current environment to the instruction. First, each instruction | 2602 // Attach current environment to the instruction. First, each instruction |
| 2623 // gets a full copy of the environment. Later we optimize this by | 2603 // gets a full copy of the environment. Later we optimize this by |
| 2624 // eliminating unnecessary environments. | 2604 // eliminating unnecessary environments. |
| 2625 current->set_env(new Environment(*env, fixed_parameter_count)); | 2605 current->set_env(new Environment(*env, non_copied_parameter_count_)); |
| 2626 | 2606 |
| 2627 // 2a. Handle uses: | 2607 // 2a. Handle uses: |
| 2628 // Update expression stack environment for each use. | 2608 // Update expression stack environment for each use. |
| 2629 // For each use of a LoadLocal or StoreLocal: Replace it with the value | 2609 // For each use of a LoadLocal or StoreLocal: Replace it with the value |
| 2630 // from the environment. | 2610 // from the environment. |
| 2631 for (intptr_t i = 0; i < current->InputCount(); ++i) { | 2611 for (intptr_t i = 0; i < current->InputCount(); ++i) { |
| 2632 Value* v = current->InputAt(i); | 2612 Value* v = current->InputAt(i); |
| 2633 if (!v->IsUse()) continue; | 2613 if (!v->IsUse()) continue; |
| 2634 // Update expression stack. | 2614 // Update expression stack. |
| 2635 ASSERT(env->length() > var_count); | 2615 ASSERT(env->length() > variable_count()); |
| 2636 env->RemoveLast(); | 2616 env->RemoveLast(); |
| 2637 BindInstr* as_bind = v->AsUse()->definition()->AsBind(); | 2617 BindInstr* as_bind = v->AsUse()->definition()->AsBind(); |
| 2638 if ((as_bind != NULL) && as_bind->computation()->IsLoadLocal()) { | 2618 if ((as_bind != NULL) && as_bind->computation()->IsLoadLocal()) { |
| 2639 Computation* comp = as_bind->computation(); | 2619 Computation* comp = as_bind->computation(); |
| 2640 intptr_t index = | 2620 intptr_t index = comp->AsLoadLocal()->local().BitIndexIn( |
|
Florian Schneider
2012/08/06 14:13:16
Not sure if it's possible, but I'd break line afte
| |
| 2641 comp->AsLoadLocal()->local().BitIndexIn(fixed_parameter_count); | 2621 non_copied_parameter_count_); |
| 2642 current->SetInputAt(i, CopyValue((*env)[index])); | 2622 current->SetInputAt(i, CopyValue((*env)[index])); |
| 2643 } | 2623 } |
| 2644 if ((as_bind != NULL) && as_bind->computation()->IsStoreLocal()) { | 2624 if ((as_bind != NULL) && as_bind->computation()->IsStoreLocal()) { |
| 2645 // For each use of a StoreLocal: Replace it with the value from the | 2625 // For each use of a StoreLocal: Replace it with the value from the |
| 2646 // environment. | 2626 // environment. |
| 2647 Computation* comp = as_bind->computation(); | 2627 Computation* comp = as_bind->computation(); |
| 2648 intptr_t index = | 2628 intptr_t index = comp->AsStoreLocal()->local().BitIndexIn( |
|
Florian Schneider
2012/08/06 14:13:16
Not sure if it's possible, but I'd break line afte
| |
| 2649 comp->AsStoreLocal()->local().BitIndexIn(fixed_parameter_count); | 2629 non_copied_parameter_count_); |
| 2650 current->SetInputAt(i, CopyValue((*env)[index])); | 2630 current->SetInputAt(i, CopyValue((*env)[index])); |
| 2651 } | 2631 } |
| 2652 } | 2632 } |
| 2653 | 2633 |
| 2654 // Drop pushed arguments for calls. | 2634 // Drop pushed arguments for calls. |
| 2655 for (intptr_t j = 0; j < current->ArgumentCount(); j++) { | 2635 for (intptr_t j = 0; j < current->ArgumentCount(); j++) { |
| 2656 env->RemoveLast(); | 2636 env->RemoveLast(); |
| 2657 } | 2637 } |
| 2658 | 2638 |
| 2659 // 2b. Handle LoadLocal and StoreLocal. | 2639 // 2b. Handle LoadLocal and StoreLocal. |
| 2660 // For each LoadLocal: Remove it from the graph. | 2640 // For each LoadLocal: Remove it from the graph. |
| 2661 // For each StoreLocal: Remove it from the graph and update the environment. | 2641 // For each StoreLocal: Remove it from the graph and update the environment. |
| 2662 BindInstr* bind = current->AsBind(); | 2642 BindInstr* bind = current->AsBind(); |
| 2663 if (bind != NULL) { | 2643 if (bind != NULL) { |
| 2664 LoadLocalComp* load = bind->computation()->AsLoadLocal(); | 2644 LoadLocalComp* load = bind->computation()->AsLoadLocal(); |
| 2665 StoreLocalComp* store = bind->computation()->AsStoreLocal(); | 2645 StoreLocalComp* store = bind->computation()->AsStoreLocal(); |
| 2666 if ((load != NULL) || (store != NULL)) { | 2646 if ((load != NULL) || (store != NULL)) { |
| 2667 intptr_t index; | 2647 intptr_t index; |
| 2668 if (store != NULL) { | 2648 if (store != NULL) { |
| 2669 index = store->local().BitIndexIn(fixed_parameter_count); | 2649 index = store->local().BitIndexIn(non_copied_parameter_count_); |
| 2670 // Update renaming environment. | 2650 // Update renaming environment. |
| 2671 (*env)[index] = store->value(); | 2651 (*env)[index] = store->value(); |
| 2672 } else { | 2652 } else { |
| 2673 // The graph construction ensures we do not have an unused LoadLocal | 2653 // The graph construction ensures we do not have an unused LoadLocal |
| 2674 // computation. | 2654 // computation. |
| 2675 ASSERT(bind->is_used()); | 2655 ASSERT(bind->is_used()); |
| 2676 index = load->local().BitIndexIn(fixed_parameter_count); | 2656 index = load->local().BitIndexIn(non_copied_parameter_count_); |
| 2677 } | 2657 } |
| 2678 // Update expression stack and remove from graph. | 2658 // Update expression stack and remove from graph. |
| 2679 if (bind->is_used()) { | 2659 if (bind->is_used()) { |
| 2680 env->Add(CopyValue((*env)[index])); | 2660 env->Add(CopyValue((*env)[index])); |
| 2681 } | 2661 } |
| 2682 it.RemoveCurrentFromGraph(); | 2662 it.RemoveCurrentFromGraph(); |
| 2683 } else { | 2663 } else { |
| 2684 // Not a load or store. | 2664 // Not a load or store. |
| 2685 if (bind->is_used()) { | 2665 if (bind->is_used()) { |
| 2686 // Assign fresh SSA temporary and update expression stack. | 2666 // Assign fresh SSA temporary and update expression stack. |
| 2687 bind->set_ssa_temp_index(alloc_ssa_temp_index()); | 2667 bind->set_ssa_temp_index(alloc_ssa_temp_index()); |
| 2688 env->Add(new UseVal(bind)); | 2668 env->Add(new UseVal(bind)); |
| 2689 } | 2669 } |
| 2690 } | 2670 } |
| 2691 } | 2671 } |
| 2692 | 2672 |
| 2693 // 2c. Handle pushed argument. | 2673 // 2c. Handle pushed argument. |
| 2694 PushArgumentInstr* push = current->AsPushArgument(); | 2674 PushArgumentInstr* push = current->AsPushArgument(); |
| 2695 if (push != NULL) { | 2675 if (push != NULL) { |
| 2696 env->Add(push->value()); | 2676 env->Add(push->value()); |
| 2697 } | 2677 } |
| 2698 } | 2678 } |
| 2699 | 2679 |
| 2700 // 3. Process dominated blocks. | 2680 // 3. Process dominated blocks. |
| 2701 for (intptr_t i = 0; i < block_entry->dominated_blocks().length(); ++i) { | 2681 for (intptr_t i = 0; i < block_entry->dominated_blocks().length(); ++i) { |
| 2702 BlockEntryInstr* block = block_entry->dominated_blocks()[i]; | 2682 BlockEntryInstr* block = block_entry->dominated_blocks()[i]; |
| 2703 GrowableArray<Value*> new_env(env->length()); | 2683 GrowableArray<Value*> new_env(env->length()); |
| 2704 new_env.AddArray(*env); | 2684 new_env.AddArray(*env); |
| 2705 RenameRecursive(block, &new_env, var_count, fixed_parameter_count); | 2685 RenameRecursive(block, &new_env); |
| 2706 } | 2686 } |
| 2707 | 2687 |
| 2708 // 4. Process successor block. We have edge-split form, so that only blocks | 2688 // 4. Process successor block. We have edge-split form, so that only blocks |
| 2709 // with one successor can have a join block as successor. | 2689 // with one successor can have a join block as successor. |
| 2710 if ((block_entry->last_instruction()->SuccessorCount() == 1) && | 2690 if ((block_entry->last_instruction()->SuccessorCount() == 1) && |
| 2711 block_entry->last_instruction()->SuccessorAt(0)->IsJoinEntry()) { | 2691 block_entry->last_instruction()->SuccessorAt(0)->IsJoinEntry()) { |
| 2712 JoinEntryInstr* successor = | 2692 JoinEntryInstr* successor = |
| 2713 block_entry->last_instruction()->SuccessorAt(0)->AsJoinEntry(); | 2693 block_entry->last_instruction()->SuccessorAt(0)->AsJoinEntry(); |
| 2714 intptr_t pred_index = successor->IndexOfPredecessor(block_entry); | 2694 intptr_t pred_index = successor->IndexOfPredecessor(block_entry); |
| 2715 ASSERT(pred_index >= 0); | 2695 ASSERT(pred_index >= 0); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2735 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 2715 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 2736 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 2716 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 2737 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2717 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2738 const Error& error = Error::Handle( | 2718 const Error& error = Error::Handle( |
| 2739 LanguageError::New(String::Handle(String::New(chars)))); | 2719 LanguageError::New(String::Handle(String::New(chars)))); |
| 2740 Isolate::Current()->long_jump_base()->Jump(1, error); | 2720 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2741 } | 2721 } |
| 2742 | 2722 |
| 2743 | 2723 |
| 2744 } // namespace dart | 2724 } // namespace dart |
| OLD | NEW |