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

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

Issue 12091091: Move recording of definition used from the value to the definition. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/intermediate_language.h ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_allocator.h" 9 #include "vm/flow_graph_allocator.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 619 }
620 } 620 }
621 621
622 622
623 void Instruction::RecordAssignedVars(BitVector* assigned_vars, 623 void Instruction::RecordAssignedVars(BitVector* assigned_vars,
624 intptr_t fixed_parameter_count) { 624 intptr_t fixed_parameter_count) {
625 // Nothing to do for the base class. 625 // Nothing to do for the base class.
626 } 626 }
627 627
628 628
629 void Value::AddToInputUseList() { 629 void Value::AddToList(Value* value, Value** list) {
630 Value* next = definition()->input_use_list(); 630 Value* next = *list;
631 definition()->set_input_use_list(this); 631 *list = value;
632 set_next_use(next); 632 value->set_next_use(next);
633 set_previous_use(NULL); 633 value->set_previous_use(NULL);
634 if (next != NULL) next->set_previous_use(this); 634 if (next != NULL) next->set_previous_use(value);
635 } 635 }
636 636
637 637
638 void Value::AddToEnvUseList() { 638 void Value::RemoveFromList(Value* value, Value** list) {
639 Value* next = definition()->env_use_list(); 639 Value* previous = value->previous_use();
640 definition()->set_env_use_list(this); 640 Value* next = value->next_use();
641 set_next_use(next);
642 set_previous_use(NULL);
643 if (next != NULL) next->set_previous_use(this);
644 }
645
646
647 void Value::RemoveFromInputUseList() {
648 Value* previous = previous_use();
649 Value* next = next_use();
650 if (previous == NULL) { 641 if (previous == NULL) {
651 definition()->set_input_use_list(next); 642 *list = next;
652 } else { 643 } else {
653 previous->set_next_use(next); 644 previous->set_next_use(next);
654 } 645 }
655 if (next != NULL) next->set_previous_use(previous); 646 if (next != NULL) next->set_previous_use(previous);
656 set_definition(NULL); 647 value->set_previous_use(NULL);
648 value->set_next_use(NULL);
649 value->set_definition(NULL);
657 } 650 }
658 651
659 652
660 void Definition::ReplaceUsesWith(Definition* other) { 653 void Definition::ReplaceUsesWith(Definition* other) {
661 ASSERT(other != NULL); 654 ASSERT(other != NULL);
662 ASSERT(this != other); 655 ASSERT(this != other);
656
657 Value* current = NULL;
663 Value* next = input_use_list(); 658 Value* next = input_use_list();
664 while (next != NULL) { 659 if (next != NULL) {
665 Value* current = next; 660 // Change all the definitions.
666 next = current->next_use(); 661 while (next != NULL) {
667 current->set_definition(other); 662 current = next;
668 current->AddToInputUseList(); 663 current->set_definition(other);
664 next = current->next_use();
665 }
666
667 // Concatenate the lists.
668 next = other->input_use_list();
669 current->set_next_use(next);
670 if (next != NULL) next->set_previous_use(current);
671 other->set_input_use_list(input_use_list());
672 set_input_use_list(NULL);
669 } 673 }
670 674
675 // Repeat for environment uses.
676 current = NULL;
671 next = env_use_list(); 677 next = env_use_list();
672 while (next != NULL) { 678 if (next != NULL) {
673 Value* current = next; 679 while (next != NULL) {
674 next = current->next_use(); 680 current = next;
675 current->set_definition(other); 681 current->set_definition(other);
676 current->AddToEnvUseList(); 682 next = current->next_use();
683 }
684 next = other->env_use_list();
685 current->set_next_use(next);
686 if (next != NULL) next->set_previous_use(current);
687 other->set_env_use_list(env_use_list());
688 set_env_use_list(NULL);
677 } 689 }
678
679 set_input_use_list(NULL);
680 set_env_use_list(NULL);
681 } 690 }
682 691
683 692
684 void Definition::ReplaceWith(Definition* other, 693 void Definition::ReplaceWith(Definition* other,
685 ForwardInstructionIterator* iterator) { 694 ForwardInstructionIterator* iterator) {
686 if ((iterator != NULL) && (this == iterator->Current())) { 695 if ((iterator != NULL) && (this == iterator->Current())) {
687 iterator->ReplaceCurrentWith(other); 696 iterator->ReplaceCurrentWith(other);
688 } else { 697 } else {
689 ReplaceUsesWith(other); 698 ReplaceUsesWith(other);
690 ASSERT(other->env() == NULL); 699 ASSERT(other->env() == NULL);
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 constant_type_args->value().IsTypeArguments()) { 1714 constant_type_args->value().IsTypeArguments()) {
1706 const TypeArguments& instantiator_type_args = 1715 const TypeArguments& instantiator_type_args =
1707 TypeArguments::Cast(constant_type_args->value()); 1716 TypeArguments::Cast(constant_type_args->value());
1708 const AbstractType& new_dst_type = AbstractType::Handle( 1717 const AbstractType& new_dst_type = AbstractType::Handle(
1709 dst_type().InstantiateFrom(instantiator_type_args)); 1718 dst_type().InstantiateFrom(instantiator_type_args));
1710 set_dst_type(AbstractType::ZoneHandle(new_dst_type.Canonicalize())); 1719 set_dst_type(AbstractType::ZoneHandle(new_dst_type.Canonicalize()));
1711 ConstantInstr* null_constant = new ConstantInstr(Object::ZoneHandle()); 1720 ConstantInstr* null_constant = new ConstantInstr(Object::ZoneHandle());
1712 // It is ok to insert instructions before the current during 1721 // It is ok to insert instructions before the current during
1713 // forward iteration. 1722 // forward iteration.
1714 optimizer->InsertBefore(this, null_constant, NULL, Definition::kValue); 1723 optimizer->InsertBefore(this, null_constant, NULL, Definition::kValue);
1715 instantiator_type_arguments()->RemoveFromInputUseList(); 1724 constant_type_args->RemoveInputUse(instantiator_type_arguments());
1716 instantiator_type_arguments()->set_definition(null_constant); 1725 instantiator_type_arguments()->set_definition(null_constant);
1717 instantiator_type_arguments()->AddToInputUseList(); 1726 null_constant->AddInputUse(instantiator_type_arguments());
Kevin Millikin (Google) 2013/01/31 16:37:13 These three lines are going to get combined someho
1718 } 1727 }
1719 return this; 1728 return this;
1720 } 1729 }
1721 1730
1722 1731
1723 Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1732 Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1724 // Only handle strict-compares. 1733 // Only handle strict-compares.
1725 if (comparison()->IsStrictCompare()) { 1734 if (comparison()->IsStrictCompare()) {
1726 Definition* replacement = comparison()->Canonicalize(optimizer); 1735 Definition* replacement = comparison()->Canonicalize(optimizer);
1727 if (replacement == comparison() || replacement == NULL) return this; 1736 if (replacement == comparison() || replacement == NULL) return this;
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 2069
2061 2070
2062 // Copies the environment and updates the environment use lists. 2071 // Copies the environment and updates the environment use lists.
2063 void Environment::DeepCopyTo(Instruction* instr) const { 2072 void Environment::DeepCopyTo(Instruction* instr) const {
2064 Environment* copy = DeepCopy(); 2073 Environment* copy = DeepCopy();
2065 intptr_t use_index = 0; 2074 intptr_t use_index = 0;
2066 for (Environment::DeepIterator it(copy); !it.Done(); it.Advance()) { 2075 for (Environment::DeepIterator it(copy); !it.Done(); it.Advance()) {
2067 Value* value = it.CurrentValue(); 2076 Value* value = it.CurrentValue();
2068 value->set_instruction(instr); 2077 value->set_instruction(instr);
2069 value->set_use_index(use_index++); 2078 value->set_use_index(use_index++);
2070 value->AddToEnvUseList(); 2079 value->definition()->AddEnvUse(value);
2071 } 2080 }
2072 instr->set_env(copy); 2081 instr->set_env(copy);
2073 } 2082 }
2074 2083
2075 2084
2076 // Copies the environment as outer on an inlined instruction and updates the 2085 // Copies the environment as outer on an inlined instruction and updates the
2077 // environment use lists. 2086 // environment use lists.
2078 void Environment::DeepCopyToOuter(Instruction* instr) const { 2087 void Environment::DeepCopyToOuter(Instruction* instr) const {
2079 ASSERT(instr->env()->outer() == NULL); 2088 ASSERT(instr->env()->outer() == NULL);
2080 // Create a deep copy removing caller arguments from the environment. 2089 // Create a deep copy removing caller arguments from the environment.
2081 intptr_t argument_count = instr->env()->fixed_parameter_count(); 2090 intptr_t argument_count = instr->env()->fixed_parameter_count();
2082 Environment* copy = 2091 Environment* copy =
2083 new Environment(values_.length() - argument_count, 2092 new Environment(values_.length() - argument_count,
2084 fixed_parameter_count_, 2093 fixed_parameter_count_,
2085 deopt_id_, 2094 deopt_id_,
2086 function_, 2095 function_,
2087 (outer_ == NULL) ? NULL : outer_->DeepCopy()); 2096 (outer_ == NULL) ? NULL : outer_->DeepCopy());
2088 for (intptr_t i = 0; i < values_.length() - argument_count; ++i) { 2097 for (intptr_t i = 0; i < values_.length() - argument_count; ++i) {
2089 copy->values_.Add(values_[i]->Copy()); 2098 copy->values_.Add(values_[i]->Copy());
2090 } 2099 }
2091 intptr_t use_index = instr->env()->Length(); // Start index after inner. 2100 intptr_t use_index = instr->env()->Length(); // Start index after inner.
2092 for (Environment::DeepIterator it(copy); !it.Done(); it.Advance()) { 2101 for (Environment::DeepIterator it(copy); !it.Done(); it.Advance()) {
2093 Value* value = it.CurrentValue(); 2102 Value* value = it.CurrentValue();
2094 value->set_instruction(instr); 2103 value->set_instruction(instr);
2095 value->set_use_index(use_index++); 2104 value->set_use_index(use_index++);
2096 value->AddToEnvUseList(); 2105 value->definition()->AddEnvUse(value);
2097 } 2106 }
2098 instr->env()->outer_ = copy; 2107 instr->env()->outer_ = copy;
2099 } 2108 }
2100 2109
2101 2110
2102 RangeBoundary RangeBoundary::FromDefinition(Definition* defn, intptr_t offs) { 2111 RangeBoundary RangeBoundary::FromDefinition(Definition* defn, intptr_t offs) {
2103 if (defn->IsConstant() && defn->AsConstant()->value().IsSmi()) { 2112 if (defn->IsConstant() && defn->AsConstant()->value().IsSmi()) {
2104 return FromConstant(Smi::Cast(defn->AsConstant()->value()).Value() + offs); 2113 return FromConstant(Smi::Cast(defn->AsConstant()->value()).Value() + offs);
2105 } 2114 }
2106 return RangeBoundary(kSymbol, reinterpret_cast<intptr_t>(defn), offs); 2115 return RangeBoundary(kSymbol, reinterpret_cast<intptr_t>(defn), offs);
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
2769 default: 2778 default:
2770 UNREACHABLE(); 2779 UNREACHABLE();
2771 } 2780 }
2772 return kPowRuntimeEntry; 2781 return kPowRuntimeEntry;
2773 } 2782 }
2774 2783
2775 2784
2776 #undef __ 2785 #undef __
2777 2786
2778 } // namespace dart 2787 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698