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

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

Issue 12335063: Add functions for setting an environment and rebinding a use. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased and incorportated review comments. Created 7 years, 10 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
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/flow_graph_allocator.cc » ('j') | 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.h" 5 #include "vm/flow_graph.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/flow_graph_builder.h" 8 #include "vm/flow_graph_builder.h"
9 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 Environment* env, 65 Environment* env,
66 Definition::UseKind use_kind) { 66 Definition::UseKind use_kind) {
67 InsertAfter(next->previous(), instr, env, use_kind); 67 InsertAfter(next->previous(), instr, env, use_kind);
68 } 68 }
69 69
70 70
71 void FlowGraph::InsertAfter(Instruction* prev, 71 void FlowGraph::InsertAfter(Instruction* prev,
72 Instruction* instr, 72 Instruction* instr,
73 Environment* env, 73 Environment* env,
74 Definition::UseKind use_kind) { 74 Definition::UseKind use_kind) {
75 for (intptr_t i = instr->InputCount() - 1; i >= 0; --i) {
76 Value* input = instr->InputAt(i);
77 input->definition()->AddInputUse(input);
78 }
79 ASSERT(instr->env() == NULL);
80 if (env != NULL) env->DeepCopyTo(instr);
81 if (use_kind == Definition::kValue) { 75 if (use_kind == Definition::kValue) {
82 ASSERT(instr->IsDefinition()); 76 ASSERT(instr->IsDefinition());
83 instr->AsDefinition()->set_ssa_temp_index(alloc_ssa_temp_index()); 77 instr->AsDefinition()->set_ssa_temp_index(alloc_ssa_temp_index());
84 } 78 }
85 instr->InsertAfter(prev); 79 instr->InsertAfter(prev);
80 ASSERT(instr->env() == NULL);
81 if (env != NULL) env->DeepCopyTo(instr);
86 } 82 }
87 83
88 84
89 void FlowGraph::DiscoverBlocks() { 85 void FlowGraph::DiscoverBlocks() {
90 // Initialize state. 86 // Initialize state.
91 preorder_.Clear(); 87 preorder_.Clear();
92 postorder_.Clear(); 88 postorder_.Clear();
93 reverse_postorder_.Clear(); 89 reverse_postorder_.Clear();
94 parent_.Clear(); 90 parent_.Clear();
95 assigned_vars_.Clear(); 91 assigned_vars_.Clear();
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) { 461 for (ForwardInstructionIterator it(block_entry); !it.Done(); it.Advance()) {
466 Instruction* current = it.Current(); 462 Instruction* current = it.Current();
467 // Attach current environment to the instructions that can deoptimize and 463 // Attach current environment to the instructions that can deoptimize and
468 // at goto instructions. Optimizations like LICM expect an environment at 464 // at goto instructions. Optimizations like LICM expect an environment at
469 // gotos. 465 // gotos.
470 if (current->CanDeoptimize() || current->IsGoto()) { 466 if (current->CanDeoptimize() || current->IsGoto()) {
471 Environment* deopt_env = 467 Environment* deopt_env =
472 Environment::From(*env, 468 Environment::From(*env,
473 num_non_copied_params_, 469 num_non_copied_params_,
474 parsed_function_.function()); 470 parsed_function_.function());
475 current->set_env(deopt_env); 471 current->SetEnvironment(deopt_env);
476 intptr_t use_index = 0;
477 for (Environment::DeepIterator it(deopt_env); !it.Done(); it.Advance()) { 472 for (Environment::DeepIterator it(deopt_env); !it.Done(); it.Advance()) {
478 Value* use = it.CurrentValue(); 473 Value* use = it.CurrentValue();
479 use->set_instruction(current);
480 use->set_use_index(use_index++);
481 use->definition()->AddEnvUse(use); 474 use->definition()->AddEnvUse(use);
482 } 475 }
483 } 476 }
484 if (current->CanDeoptimize()) { 477 if (current->CanDeoptimize()) {
485 current->env()->set_deopt_id(current->deopt_id()); 478 current->env()->set_deopt_id(current->deopt_id());
486 } 479 }
487 480
488 // 2a. Handle uses: 481 // 2a. Handle uses:
489 // Update expression stack environment for each use. 482 // Update expression stack environment for each use.
490 // For each use of a LoadLocal or StoreLocal: Replace it with the value 483 // For each use of a LoadLocal or StoreLocal: Replace it with the value
491 // from the environment. 484 // from the environment.
492 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) { 485 for (intptr_t i = current->InputCount() - 1; i >= 0; --i) {
493 Value* v = current->InputAt(i); 486 Value* v = current->InputAt(i);
494 // Update expression stack. 487 // Update expression stack.
495 ASSERT(env->length() > variable_count()); 488 ASSERT(env->length() > variable_count());
496 489
497 Definition* reaching_defn = env->RemoveLast(); 490 Definition* reaching_defn = env->RemoveLast();
498 491
499 Definition* input_defn = v->definition(); 492 Definition* input_defn = v->definition();
500 if (input_defn->IsLoadLocal() || input_defn->IsStoreLocal()) { 493 if (input_defn->IsLoadLocal() || input_defn->IsStoreLocal()) {
501 // Remove the load/store from the graph. 494 // Remove the load/store from the graph.
502 input_defn->UnuseAllInputs();
503 input_defn->RemoveFromGraph(); 495 input_defn->RemoveFromGraph();
504 // Assert we are not referencing nulls in the initial environment. 496 // Assert we are not referencing nulls in the initial environment.
505 ASSERT(reaching_defn->ssa_temp_index() != -1); 497 ASSERT(reaching_defn->ssa_temp_index() != -1);
506 v->set_definition(reaching_defn); 498 v->set_definition(reaching_defn);
507 input_defn = reaching_defn; 499 input_defn = reaching_defn;
508 } 500 }
509 input_defn->AddInputUse(v); 501 input_defn->AddInputUse(v);
510 } 502 }
511 503
512 // Drop pushed arguments for calls. 504 // Drop pushed arguments for calls.
(...skipping 24 matching lines...) Expand all
537 if ((phi != NULL) && !phi->is_alive()) { 529 if ((phi != NULL) && !phi->is_alive()) {
538 phi->mark_alive(); 530 phi->mark_alive();
539 live_phis->Add(phi); 531 live_phis->Add(phi);
540 } 532 }
541 } 533 }
542 // Update expression stack or remove from graph. 534 // Update expression stack or remove from graph.
543 if (definition->is_used()) { 535 if (definition->is_used()) {
544 env->Add((*env)[index]); 536 env->Add((*env)[index]);
545 // We remove load/store instructions when we find their use in 2a. 537 // We remove load/store instructions when we find their use in 2a.
546 } else { 538 } else {
547 definition->UnuseAllInputs();
548 it.RemoveCurrentFromGraph(); 539 it.RemoveCurrentFromGraph();
549 } 540 }
550 } else { 541 } else {
551 // Not a load or store. 542 // Not a load or store.
552 if (definition->is_used()) { 543 if (definition->is_used()) {
553 // Assign fresh SSA temporary and update expression stack. 544 // Assign fresh SSA temporary and update expression stack.
554 definition->set_ssa_temp_index(alloc_ssa_temp_index()); 545 definition->set_ssa_temp_index(alloc_ssa_temp_index());
555 env->Add(definition); 546 env->Add(definition);
556 } 547 }
557 } 548 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 !it.Done(); 685 !it.Done();
695 it.Advance()) { 686 it.Advance()) {
696 ++size; 687 ++size;
697 } 688 }
698 } 689 }
699 return size; 690 return size;
700 } 691 }
701 692
702 693
703 } // namespace dart 694 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/compiler.cc ('k') | runtime/vm/flow_graph_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698