| 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/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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 | 29 |
| 30 void UseVal::SetDefinition(Definition* definition) { | 30 void UseVal::SetDefinition(Definition* definition) { |
| 31 ASSERT(definition != NULL); | 31 ASSERT(definition != NULL); |
| 32 RemoveFromUseList(); | 32 RemoveFromUseList(); |
| 33 definition_ = definition; | 33 definition_ = definition; |
| 34 AddToUseList(); | 34 AddToUseList(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 // Returns true if the value represents a constant. |
| 39 bool UseVal::BindsToConstant() const { |
| 40 BindInstr* bind = definition()->AsBind(); |
| 41 if (bind == NULL) { |
| 42 return false; |
| 43 } |
| 44 return bind->computation()->AsConstant() != NULL; |
| 45 } |
| 46 |
| 47 |
| 48 // Returns true if the value represents constant null. |
| 49 bool UseVal::BindsToConstantNull() const { |
| 50 BindInstr* bind = definition()->AsBind(); |
| 51 if (bind == NULL) { |
| 52 return false; |
| 53 } |
| 54 ConstantVal* constant = bind->computation()->AsConstant(); |
| 55 if (constant != NULL) { |
| 56 return constant->value().IsNull(); |
| 57 } |
| 58 return false; |
| 59 } |
| 60 |
| 61 |
| 38 void UseVal::RemoveFromUseList() { | 62 void UseVal::RemoveFromUseList() { |
| 39 ASSERT(definition_ != NULL); | 63 ASSERT(definition_ != NULL); |
| 40 if (next_use_ != NULL) { | 64 if (next_use_ != NULL) { |
| 41 next_use_->previous_use_ = previous_use_; | 65 next_use_->previous_use_ = previous_use_; |
| 42 } | 66 } |
| 43 if (previous_use_ != NULL) { | 67 if (previous_use_ != NULL) { |
| 44 previous_use_->next_use_ = next_use_; | 68 previous_use_->next_use_ = next_use_; |
| 45 } else { | 69 } else { |
| 46 // This is the head of the list. | 70 // This is the head of the list. |
| 47 ASSERT(definition_->use_list() == this); | 71 ASSERT(definition_->use_list() == this); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 166 } |
| 143 | 167 |
| 144 | 168 |
| 145 void ForwardInstructionIterator::RemoveCurrentFromGraph() { | 169 void ForwardInstructionIterator::RemoveCurrentFromGraph() { |
| 146 current_ = current_->RemoveFromGraph(true); // Set current_ to previous. | 170 current_ = current_->RemoveFromGraph(true); // Set current_ to previous. |
| 147 } | 171 } |
| 148 | 172 |
| 149 | 173 |
| 150 // Default implementation of visiting basic blocks. Can be overridden. | 174 // Default implementation of visiting basic blocks. Can be overridden. |
| 151 void FlowGraphVisitor::VisitBlocks() { | 175 void FlowGraphVisitor::VisitBlocks() { |
| 176 ASSERT(current_iterator_ == NULL); |
| 152 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 177 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 153 BlockEntryInstr* entry = block_order_[i]; | 178 BlockEntryInstr* entry = block_order_[i]; |
| 154 entry->Accept(this); | 179 entry->Accept(this); |
| 155 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 180 ForwardInstructionIterator it(entry); |
| 181 current_iterator_ = ⁢ |
| 182 for (; !it.Done(); it.Advance()) { |
| 156 it.Current()->Accept(this); | 183 it.Current()->Accept(this); |
| 157 } | 184 } |
| 185 current_iterator_ = NULL; |
| 158 } | 186 } |
| 159 } | 187 } |
| 160 | 188 |
| 161 | 189 |
| 162 // Returns true if the compile type of this value is more specific than the | 190 // Returns true if the compile type of this value is more specific than the |
| 163 // given dst_type. | 191 // given dst_type. |
| 164 // TODO(regis): Support a set of compile types for the given value. | 192 // TODO(regis): Support a set of compile types for the given value. |
| 165 bool Value::CompileTypeIsMoreSpecificThan(const AbstractType& dst_type) const { | 193 bool Value::CompileTypeIsMoreSpecificThan(const AbstractType& dst_type) const { |
| 166 ASSERT(!dst_type.IsMalformed()); // Should be tested by caller. | 194 // No type is more specific than a malformed type. |
| 167 ASSERT(!dst_type.IsDynamicType()); // Should be tested by caller. | 195 if (dst_type.IsMalformed()) { |
| 168 ASSERT(!dst_type.IsObjectType()); // Should be tested by caller. | 196 return false; |
| 197 } |
| 169 | 198 |
| 170 // If the value is the null constant, its type (NullType) is more specific | 199 // If the value is the null constant, its type (NullType) is more specific |
| 171 // than the destination type, even if the destination type is the void type, | 200 // than the destination type, even if the destination type is the void type, |
| 172 // since a void function is allowed to return null. | 201 // since a void function is allowed to return null. |
| 173 if (IsConstant() && AsConstant()->value().IsNull()) { | 202 if (BindsToConstantNull()) { |
| 174 return true; | 203 return true; |
| 175 } | 204 } |
| 176 | 205 |
| 177 // Functions that do not explicitly return a value, implicitly return null, | 206 // Functions that do not explicitly return a value, implicitly return null, |
| 178 // except generative constructors, which return the object being constructed. | 207 // except generative constructors, which return the object being constructed. |
| 179 // It is therefore acceptable for void functions to return null. | 208 // It is therefore acceptable for void functions to return null. |
| 180 // In case of a null constant, we have already returned true above, else we | 209 // In case of a null constant, we have already returned true above, else we |
| 181 // return false here. | 210 // return false here. |
| 182 if (dst_type.IsVoidType()) { | 211 if (dst_type.IsVoidType()) { |
| 183 return false; | 212 return false; |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 return Type::DynamicType(); | 651 return Type::DynamicType(); |
| 623 } | 652 } |
| 624 | 653 |
| 625 | 654 |
| 626 RawAbstractType* PolymorphicInstanceCallComp::CompileType() const { | 655 RawAbstractType* PolymorphicInstanceCallComp::CompileType() const { |
| 627 return Type::DynamicType(); | 656 return Type::DynamicType(); |
| 628 } | 657 } |
| 629 | 658 |
| 630 | 659 |
| 631 RawAbstractType* StaticCallComp::CompileType() const { | 660 RawAbstractType* StaticCallComp::CompileType() const { |
| 632 return function().result_type(); | 661 if (FLAG_enable_type_checks) { |
| 662 return function().result_type(); |
| 663 } |
| 664 return Type::DynamicType(); |
| 633 } | 665 } |
| 634 | 666 |
| 635 | 667 |
| 636 RawAbstractType* LoadLocalComp::CompileType() const { | 668 RawAbstractType* LoadLocalComp::CompileType() const { |
| 637 if (FLAG_enable_type_checks) { | 669 if (FLAG_enable_type_checks) { |
| 638 return local().type().raw(); | 670 return local().type().raw(); |
| 639 } | 671 } |
| 640 return Type::DynamicType(); | 672 return Type::DynamicType(); |
| 641 } | 673 } |
| 642 | 674 |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 if (compiler->is_ssa()) { | 1346 if (compiler->is_ssa()) { |
| 1315 ASSERT(locs()->in(0).IsRegister()); | 1347 ASSERT(locs()->in(0).IsRegister()); |
| 1316 __ PushRegister(locs()->in(0).reg()); | 1348 __ PushRegister(locs()->in(0).reg()); |
| 1317 } | 1349 } |
| 1318 } | 1350 } |
| 1319 | 1351 |
| 1320 | 1352 |
| 1321 #undef __ | 1353 #undef __ |
| 1322 | 1354 |
| 1323 } // namespace dart | 1355 } // namespace dart |
| OLD | NEW |