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

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

Issue 10879036: Compute the def-use list on-demand by walking the dominator tree. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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
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/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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // TODO(fschneider): Make sure ic_data are sorted to hit more cases. 66 // TODO(fschneider): Make sure ic_data are sorted to hit more cases.
67 if (ic_data()->GetReceiverClassIdAt(i) != 67 if (ic_data()->GetReceiverClassIdAt(i) !=
68 other->ic_data()->GetReceiverClassIdAt(i)) { 68 other->ic_data()->GetReceiverClassIdAt(i)) {
69 return false; 69 return false;
70 } 70 }
71 } 71 }
72 return true; 72 return true;
73 } 73 }
74 74
75 75
76 UseVal::UseVal(Definition* definition)
77 : definition_(definition), next_use_(NULL), previous_use_(NULL) {
78 AddToUseList();
79 }
80
81
82 void UseVal::SetDefinition(Definition* definition) {
83 ASSERT(definition != NULL);
84 RemoveFromUseList();
85 definition_ = definition;
86 AddToUseList();
87 }
88
89
90 // Returns true if the value represents a constant. 76 // Returns true if the value represents a constant.
91 bool UseVal::BindsToConstant() const { 77 bool UseVal::BindsToConstant() const {
92 BindInstr* bind = definition()->AsBind(); 78 BindInstr* bind = definition()->AsBind();
93 if (bind == NULL) { 79 if (bind == NULL) {
94 return false; 80 return false;
95 } 81 }
96 return bind->computation()->AsMaterialize() != NULL; 82 return bind->computation()->AsMaterialize() != NULL;
97 } 83 }
98 84
99 85
(...skipping 14 matching lines...) Expand all
114 const Object& UseVal::BoundConstant() const { 100 const Object& UseVal::BoundConstant() const {
115 ASSERT(BindsToConstant()); 101 ASSERT(BindsToConstant());
116 BindInstr* bind = definition()->AsBind(); 102 BindInstr* bind = definition()->AsBind();
117 ASSERT(bind != NULL); 103 ASSERT(bind != NULL);
118 MaterializeComp* constant = bind->computation()->AsMaterialize(); 104 MaterializeComp* constant = bind->computation()->AsMaterialize();
119 ASSERT(constant != NULL); 105 ASSERT(constant != NULL);
120 return constant->constant_val()->value(); 106 return constant->constant_val()->value();
121 } 107 }
122 108
123 109
124 void UseVal::RemoveFromUseList() {
125 ASSERT(definition_ != NULL);
126 if (next_use_ != NULL) {
127 next_use_->previous_use_ = previous_use_;
128 }
129 if (previous_use_ != NULL) {
130 previous_use_->next_use_ = next_use_;
131 } else {
132 // This is the head of the list.
133 ASSERT(definition_->use_list() == this);
134 definition_->set_use_list(next_use_);
135 }
136 previous_use_ = next_use_ = NULL;
137 definition_ = NULL;
138 }
139
140
141 void UseVal::AddToUseList() {
142 ASSERT(next_use_ == NULL && previous_use_ == NULL && definition_ != NULL);
143 UseVal* head = definition_->use_list();
144 if (head != NULL) {
145 next_use_ = head;
146 head->previous_use_ = this;
147 }
148 definition_->set_use_list(this);
149 }
150
151
152 MethodRecognizer::Kind MethodRecognizer::RecognizeKind( 110 MethodRecognizer::Kind MethodRecognizer::RecognizeKind(
153 const Function& function) { 111 const Function& function) {
154 // Only core and math library methods can be recognized. 112 // Only core and math library methods can be recognized.
155 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 113 const Library& core_lib = Library::Handle(Library::CoreLibrary());
156 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); 114 const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary());
157 const Library& math_lib = Library::Handle(Library::MathLibrary()); 115 const Library& math_lib = Library::Handle(Library::MathLibrary());
158 const Class& function_class = Class::Handle(function.Owner()); 116 const Class& function_class = Class::Handle(function.Owner());
159 if ((function_class.library() != core_lib.raw()) && 117 if ((function_class.library() != core_lib.raw()) &&
160 (function_class.library() != core_impl_lib.raw()) && 118 (function_class.library() != core_impl_lib.raw()) &&
161 (function_class.library() != math_lib.raw())) { 119 (function_class.library() != math_lib.raw())) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 Instruction* prev_instr = previous(); 177 Instruction* prev_instr = previous();
220 Instruction* next_instr = next(); 178 Instruction* next_instr = next();
221 ASSERT(next_instr != NULL); 179 ASSERT(next_instr != NULL);
222 ASSERT(!next_instr->IsBlockEntry()); 180 ASSERT(!next_instr->IsBlockEntry());
223 prev_instr->set_next(next_instr); 181 prev_instr->set_next(next_instr);
224 next_instr->set_previous(prev_instr); 182 next_instr->set_previous(prev_instr);
225 // Reset successor and previous instruction to indicate 183 // Reset successor and previous instruction to indicate
226 // that the instruction is removed from the graph. 184 // that the instruction is removed from the graph.
227 set_previous(NULL); 185 set_previous(NULL);
228 set_next(NULL); 186 set_next(NULL);
229 ASSERT(!IsDefinition() || AsDefinition()->use_list() == NULL);
230 return return_previous ? prev_instr : next_instr; 187 return return_previous ? prev_instr : next_instr;
231 } 188 }
232 189
233 190
234 void BindInstr::InsertBefore(BindInstr* next) { 191 void BindInstr::InsertBefore(BindInstr* next) {
235 ASSERT(previous_ == NULL); 192 ASSERT(previous_ == NULL);
236 ASSERT(next_ == NULL); 193 ASSERT(next_ == NULL);
237 next_ = next; 194 next_ = next;
238 previous_ = next->previous_; 195 previous_ = next->previous_;
239 next->previous_ = this; 196 next->previous_ = this;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 356 }
400 357
401 358
402 void Instruction::RecordAssignedVars(BitVector* assigned_vars, 359 void Instruction::RecordAssignedVars(BitVector* assigned_vars,
403 intptr_t fixed_parameter_count) { 360 intptr_t fixed_parameter_count) {
404 // Nothing to do for the base class. 361 // Nothing to do for the base class.
405 } 362 }
406 363
407 364
408 void Definition::ReplaceUsesWith(Definition* other) { 365 void Definition::ReplaceUsesWith(Definition* other) {
409 UseVal* head = use_list(); 366 while (instr_use_list_ != NULL) {
410 if (head == NULL) return; 367 UseVal* current = instr_use_list_;
411 368 instr_use_list_ = instr_use_list_->next_use();
412 UseVal* current = head; 369 current->set_definition(other);
413 while (current->next_use() != NULL) { 370 current->set_next_use(other->instr_use_list());
414 current->definition_ = other; 371 other->set_instr_use_list(current);
415 current = current->next_use();
416 } 372 }
417 current->definition_ = other; 373 while (env_use_list_ != NULL) {
418 374 UseVal* current = env_use_list_;
419 if (other->use_list() != NULL) { 375 env_use_list_ = env_use_list_->next_use();
420 current->next_use_ = other->use_list(); 376 current->set_definition(other);
421 other->use_list()->previous_use_ = current; 377 current->set_next_use(other->env_use_list());
378 other->set_env_use_list(current);
422 } 379 }
423 other->set_use_list(head);
424 set_use_list(NULL);
425 } 380 }
426 381
427 382
428 bool Definition::SetPropagatedCid(intptr_t cid) { 383 bool Definition::SetPropagatedCid(intptr_t cid) {
429 ASSERT(cid != kIllegalCid); 384 ASSERT(cid != kIllegalCid);
430 if (propagated_cid_ == kIllegalCid) { 385 if (propagated_cid_ == kIllegalCid) {
431 // First setting, nothing has changed. 386 // First setting, nothing has changed.
432 propagated_cid_ = cid; 387 propagated_cid_ = cid;
433 return false; 388 return false;
434 } 389 }
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 const Object& right_constant = right_use->BoundConstant(); 1033 const Object& right_constant = right_use->BoundConstant();
1079 Definition* left = left_use->definition(); 1034 Definition* left = left_use->definition();
1080 // TODO(fschneider): Handle other cases: e === false and e !== true/false. 1035 // TODO(fschneider): Handle other cases: e === false and e !== true/false.
1081 // Handles e === true. 1036 // Handles e === true.
1082 if ((kind() == Token::kEQ_STRICT) && 1037 if ((kind() == Token::kEQ_STRICT) &&
1083 (right_constant.raw() == Bool::True()) && 1038 (right_constant.raw() == Bool::True()) &&
1084 (left_use->ResultCid() == kBoolCid)) { 1039 (left_use->ResultCid() == kBoolCid)) {
1085 // Remove the constant from the graph. 1040 // Remove the constant from the graph.
1086 BindInstr* right = right_use->definition()->AsBind(); 1041 BindInstr* right = right_use->definition()->AsBind();
1087 if (right != NULL) { 1042 if (right != NULL) {
1088 right->set_use_list(NULL);
1089 right->RemoveFromGraph(); 1043 right->RemoveFromGraph();
1090 } 1044 }
1091 // Return left subexpression as the replacement for this instruction. 1045 // Return left subexpression as the replacement for this instruction.
1092 return left; 1046 return left;
1093 } 1047 }
1094 return instr; 1048 return instr;
1095 } 1049 }
1096 1050
1097 1051
1098 Definition* CheckSmiComp::TryReplace(BindInstr* instr) const { 1052 Definition* CheckSmiComp::TryReplace(BindInstr* instr) const {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 ? UseDefinition(values()[i]->AsUse()->definition()) 1498 ? UseDefinition(values()[i]->AsUse()->definition())
1545 : val); 1499 : val);
1546 } 1500 }
1547 return copy; 1501 return copy;
1548 } 1502 }
1549 1503
1550 1504
1551 #undef __ 1505 #undef __
1552 1506
1553 } // namespace dart 1507 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698