| OLD | NEW |
| 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 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
| 6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // is guaranteed to be sub type of this type. | 111 // is guaranteed to be sub type of this type. |
| 112 // | 112 // |
| 113 // Values of CompileType form a lattice with a None type as a bottom and a | 113 // Values of CompileType form a lattice with a None type as a bottom and a |
| 114 // nullable Dynamic type as a top element. Method Union provides a join | 114 // nullable Dynamic type as a top element. Method Union provides a join |
| 115 // operation for the lattice. | 115 // operation for the lattice. |
| 116 class CompileType : public ValueObject { | 116 class CompileType : public ValueObject { |
| 117 public: | 117 public: |
| 118 static const bool kNullable = true; | 118 static const bool kNullable = true; |
| 119 static const bool kNonNullable = false; | 119 static const bool kNonNullable = false; |
| 120 | 120 |
| 121 CompileType(const CompileType& other) | |
| 122 : ValueObject(), | |
| 123 is_nullable_(other.is_nullable_), | |
| 124 cid_(other.cid_), | |
| 125 type_(other.type_) { } | |
| 126 | |
| 127 CompileType& operator=(const CompileType& other) { | |
| 128 is_nullable_ = other.is_nullable_; | |
| 129 cid_ = other.cid_; | |
| 130 type_ = other.type_; | |
| 131 return *this; | |
| 132 } | |
| 133 | |
| 134 // Return type such that concrete value's type in runtime is guaranteed to | 121 // Return type such that concrete value's type in runtime is guaranteed to |
| 135 // be subtype of it. | 122 // be subtype of it. |
| 136 const AbstractType* ToAbstractType(); | 123 const AbstractType* ToAbstractType(); |
| 137 | 124 |
| 138 // Return class id such that it is either kDynamicCid or in runtime | 125 // Return class id such that it is either kDynamicCid or in runtime |
| 139 // value is guaranteed to have an equal class id. | 126 // value is guaranteed to have an equal class id. |
| 140 intptr_t ToCid(); | 127 intptr_t ToCid(); |
| 141 | 128 |
| 142 // Return class id such that it is either kDynamicCid or in runtime | 129 // Return class id such that it is either kDynamicCid or in runtime |
| 143 // value is guaranteed to be either null or have an equal class id. | 130 // value is guaranteed to be either null or have an equal class id. |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 bool Done() const { return current_ == NULL; } | 1003 bool Done() const { return current_ == NULL; } |
| 1017 | 1004 |
| 1018 // Removes 'current_' from graph and sets 'current_' to previous instruction. | 1005 // Removes 'current_' from graph and sets 'current_' to previous instruction. |
| 1019 void RemoveCurrentFromGraph(); | 1006 void RemoveCurrentFromGraph(); |
| 1020 | 1007 |
| 1021 Instruction* Current() const { return current_; } | 1008 Instruction* Current() const { return current_; } |
| 1022 | 1009 |
| 1023 private: | 1010 private: |
| 1024 BlockEntryInstr* block_entry_; | 1011 BlockEntryInstr* block_entry_; |
| 1025 Instruction* current_; | 1012 Instruction* current_; |
| 1013 |
| 1014 DISALLOW_COPY_AND_ASSIGN(ForwardInstructionIterator); |
| 1026 }; | 1015 }; |
| 1027 | 1016 |
| 1028 | 1017 |
| 1029 class BackwardInstructionIterator : public ValueObject { | 1018 class BackwardInstructionIterator : public ValueObject { |
| 1030 public: | 1019 public: |
| 1031 explicit BackwardInstructionIterator(BlockEntryInstr* block_entry) | 1020 explicit BackwardInstructionIterator(BlockEntryInstr* block_entry) |
| 1032 : block_entry_(block_entry), current_(block_entry->last_instruction()) { | 1021 : block_entry_(block_entry), current_(block_entry->last_instruction()) { |
| 1033 ASSERT(block_entry_->previous() == NULL); | 1022 ASSERT(block_entry_->previous() == NULL); |
| 1034 } | 1023 } |
| 1035 | 1024 |
| 1036 void Advance() { | 1025 void Advance() { |
| 1037 ASSERT(!Done()); | 1026 ASSERT(!Done()); |
| 1038 current_ = current_->previous(); | 1027 current_ = current_->previous(); |
| 1039 } | 1028 } |
| 1040 | 1029 |
| 1041 bool Done() const { return current_ == block_entry_; } | 1030 bool Done() const { return current_ == block_entry_; } |
| 1042 | 1031 |
| 1043 Instruction* Current() const { return current_; } | 1032 Instruction* Current() const { return current_; } |
| 1044 | 1033 |
| 1045 private: | 1034 private: |
| 1046 BlockEntryInstr* block_entry_; | 1035 BlockEntryInstr* block_entry_; |
| 1047 Instruction* current_; | 1036 Instruction* current_; |
| 1037 |
| 1038 DISALLOW_COPY_AND_ASSIGN(BackwardInstructionIterator); |
| 1048 }; | 1039 }; |
| 1049 | 1040 |
| 1050 | 1041 |
| 1051 class GraphEntryInstr : public BlockEntryInstr { | 1042 class GraphEntryInstr : public BlockEntryInstr { |
| 1052 public: | 1043 public: |
| 1053 GraphEntryInstr(const ParsedFunction& parsed_function, | 1044 GraphEntryInstr(const ParsedFunction& parsed_function, |
| 1054 TargetEntryInstr* normal_entry); | 1045 TargetEntryInstr* normal_entry); |
| 1055 | 1046 |
| 1056 DECLARE_INSTRUCTION(GraphEntry) | 1047 DECLARE_INSTRUCTION(GraphEntry) |
| 1057 | 1048 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 return (phis_ == NULL) || (index_ >= phis_->length()); | 1156 return (phis_ == NULL) || (index_ >= phis_->length()); |
| 1166 } | 1157 } |
| 1167 | 1158 |
| 1168 PhiInstr* Current() const { | 1159 PhiInstr* Current() const { |
| 1169 return (*phis_)[index_]; | 1160 return (*phis_)[index_]; |
| 1170 } | 1161 } |
| 1171 | 1162 |
| 1172 private: | 1163 private: |
| 1173 ZoneGrowableArray<PhiInstr*>* phis_; | 1164 ZoneGrowableArray<PhiInstr*>* phis_; |
| 1174 intptr_t index_; | 1165 intptr_t index_; |
| 1166 |
| 1167 DISALLOW_COPY_AND_ASSIGN(PhiIterator); |
| 1175 }; | 1168 }; |
| 1176 | 1169 |
| 1177 | 1170 |
| 1178 class TargetEntryInstr : public BlockEntryInstr { | 1171 class TargetEntryInstr : public BlockEntryInstr { |
| 1179 public: | 1172 public: |
| 1180 TargetEntryInstr(intptr_t block_id, intptr_t try_index) | 1173 TargetEntryInstr(intptr_t block_id, intptr_t try_index) |
| 1181 : BlockEntryInstr(block_id, try_index), | 1174 : BlockEntryInstr(block_id, try_index), |
| 1182 predecessor_(NULL), | 1175 predecessor_(NULL), |
| 1183 catch_try_index_(CatchClauseNode::kInvalidTryIndex), | 1176 catch_try_index_(CatchClauseNode::kInvalidTryIndex), |
| 1184 catch_handler_types_(Array::ZoneHandle()) { } | 1177 catch_handler_types_(Array::ZoneHandle()) { } |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 LocationSummary* locs_; | 1791 LocationSummary* locs_; |
| 1799 }; | 1792 }; |
| 1800 | 1793 |
| 1801 | 1794 |
| 1802 class RangeBoundary : public ValueObject { | 1795 class RangeBoundary : public ValueObject { |
| 1803 public: | 1796 public: |
| 1804 enum Kind { kUnknown, kSymbol, kConstant }; | 1797 enum Kind { kUnknown, kSymbol, kConstant }; |
| 1805 | 1798 |
| 1806 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { } | 1799 RangeBoundary() : kind_(kUnknown), value_(0), offset_(0) { } |
| 1807 | 1800 |
| 1808 RangeBoundary(const RangeBoundary& other) | |
| 1809 : ValueObject(), | |
| 1810 kind_(other.kind_), | |
| 1811 value_(other.value_), | |
| 1812 offset_(other.offset_) { } | |
| 1813 | |
| 1814 RangeBoundary& operator=(const RangeBoundary& other) { | |
| 1815 kind_ = other.kind_; | |
| 1816 value_ = other.value_; | |
| 1817 offset_ = other.offset_; | |
| 1818 return *this; | |
| 1819 } | |
| 1820 | |
| 1821 static RangeBoundary FromConstant(intptr_t val) { | 1801 static RangeBoundary FromConstant(intptr_t val) { |
| 1822 return RangeBoundary(kConstant, val, 0); | 1802 return RangeBoundary(kConstant, val, 0); |
| 1823 } | 1803 } |
| 1824 | 1804 |
| 1825 static RangeBoundary FromDefinition(Definition* defn, intptr_t offs = 0); | 1805 static RangeBoundary FromDefinition(Definition* defn, intptr_t offs = 0); |
| 1826 | 1806 |
| 1827 static RangeBoundary MinSmi() { | 1807 static RangeBoundary MinSmi() { |
| 1828 return FromConstant(Smi::kMinValue); | 1808 return FromConstant(Smi::kMinValue); |
| 1829 } | 1809 } |
| 1830 | 1810 |
| (...skipping 2494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4325 #undef DECLARE_INSTRUCTION | 4305 #undef DECLARE_INSTRUCTION |
| 4326 | 4306 |
| 4327 class Environment : public ZoneAllocated { | 4307 class Environment : public ZoneAllocated { |
| 4328 public: | 4308 public: |
| 4329 // Iterate the non-NULL values in the innermost level of an environment. | 4309 // Iterate the non-NULL values in the innermost level of an environment. |
| 4330 class ShallowIterator : public ValueObject { | 4310 class ShallowIterator : public ValueObject { |
| 4331 public: | 4311 public: |
| 4332 explicit ShallowIterator(Environment* environment) | 4312 explicit ShallowIterator(Environment* environment) |
| 4333 : environment_(environment), index_(0) { } | 4313 : environment_(environment), index_(0) { } |
| 4334 | 4314 |
| 4335 ShallowIterator(const ShallowIterator& other) | |
| 4336 : ValueObject(), | |
| 4337 environment_(other.environment_), | |
| 4338 index_(other.index_) { } | |
| 4339 | |
| 4340 ShallowIterator& operator=(const ShallowIterator& other) { | |
| 4341 environment_ = other.environment_; | |
| 4342 index_ = other.index_; | |
| 4343 return *this; | |
| 4344 } | |
| 4345 | |
| 4346 Environment* environment() const { return environment_; } | 4315 Environment* environment() const { return environment_; } |
| 4347 | 4316 |
| 4348 void Advance() { | 4317 void Advance() { |
| 4349 ASSERT(!Done()); | 4318 ASSERT(!Done()); |
| 4350 ++index_; | 4319 ++index_; |
| 4351 } | 4320 } |
| 4352 | 4321 |
| 4353 bool Done() const { | 4322 bool Done() const { |
| 4354 return (environment_ == NULL) || (index_ >= environment_->Length()); | 4323 return (environment_ == NULL) || (index_ >= environment_->Length()); |
| 4355 } | 4324 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4418 } | 4387 } |
| 4419 | 4388 |
| 4420 private: | 4389 private: |
| 4421 void SkipDone() { | 4390 void SkipDone() { |
| 4422 while (!Done() && iterator_.Done()) { | 4391 while (!Done() && iterator_.Done()) { |
| 4423 iterator_ = ShallowIterator(iterator_.environment()->outer()); | 4392 iterator_ = ShallowIterator(iterator_.environment()->outer()); |
| 4424 } | 4393 } |
| 4425 } | 4394 } |
| 4426 | 4395 |
| 4427 ShallowIterator iterator_; | 4396 ShallowIterator iterator_; |
| 4397 |
| 4398 DISALLOW_COPY_AND_ASSIGN(DeepIterator); |
| 4428 }; | 4399 }; |
| 4429 | 4400 |
| 4430 // Construct an environment by constructing uses from an array of definitions. | 4401 // Construct an environment by constructing uses from an array of definitions. |
| 4431 static Environment* From(const GrowableArray<Definition*>& definitions, | 4402 static Environment* From(const GrowableArray<Definition*>& definitions, |
| 4432 intptr_t fixed_parameter_count, | 4403 intptr_t fixed_parameter_count, |
| 4433 const Function& function); | 4404 const Function& function); |
| 4434 | 4405 |
| 4435 void set_locations(Location* locations) { | 4406 void set_locations(Location* locations) { |
| 4436 ASSERT(locations_ == NULL); | 4407 ASSERT(locations_ == NULL); |
| 4437 locations_ = locations; | 4408 locations_ = locations; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4544 ForwardInstructionIterator* current_iterator_; | 4515 ForwardInstructionIterator* current_iterator_; |
| 4545 | 4516 |
| 4546 private: | 4517 private: |
| 4547 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 4518 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 4548 }; | 4519 }; |
| 4549 | 4520 |
| 4550 | 4521 |
| 4551 } // namespace dart | 4522 } // namespace dart |
| 4552 | 4523 |
| 4553 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 4524 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |