| 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 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 | 1112 |
| 1113 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); | 1113 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); |
| 1114 }; | 1114 }; |
| 1115 | 1115 |
| 1116 | 1116 |
| 1117 class JoinEntryInstr : public BlockEntryInstr { | 1117 class JoinEntryInstr : public BlockEntryInstr { |
| 1118 public: | 1118 public: |
| 1119 JoinEntryInstr(intptr_t block_id, intptr_t try_index) | 1119 JoinEntryInstr(intptr_t block_id, intptr_t try_index) |
| 1120 : BlockEntryInstr(block_id, try_index), | 1120 : BlockEntryInstr(block_id, try_index), |
| 1121 predecessors_(2), // Two is the assumed to be the common case. | 1121 predecessors_(2), // Two is the assumed to be the common case. |
| 1122 phis_(NULL), | 1122 phis_(NULL) { } |
| 1123 phi_count_(0) { } | |
| 1124 | 1123 |
| 1125 DECLARE_INSTRUCTION(JoinEntry) | 1124 DECLARE_INSTRUCTION(JoinEntry) |
| 1126 | 1125 |
| 1127 virtual intptr_t PredecessorCount() const { return predecessors_.length(); } | 1126 virtual intptr_t PredecessorCount() const { return predecessors_.length(); } |
| 1128 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { | 1127 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { |
| 1129 return predecessors_[index]; | 1128 return predecessors_[index]; |
| 1130 } | 1129 } |
| 1131 | 1130 |
| 1132 // Returns -1 if pred is not in the list. | 1131 // Returns -1 if pred is not in the list. |
| 1133 intptr_t IndexOfPredecessor(BlockEntryInstr* pred) const; | 1132 intptr_t IndexOfPredecessor(BlockEntryInstr* pred) const; |
| 1134 | 1133 |
| 1135 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } | 1134 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } |
| 1136 | 1135 |
| 1137 virtual void PrepareEntry(FlowGraphCompiler* compiler); | 1136 virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| 1138 | 1137 |
| 1139 void InsertPhi(intptr_t var_index, intptr_t var_count); | 1138 void InsertPhi(intptr_t var_index, intptr_t var_count); |
| 1140 void RemoveDeadPhis(); | 1139 void RemoveDeadPhis(Definition* replacement); |
| 1141 | 1140 |
| 1142 void InsertPhi(PhiInstr* phi); | 1141 void InsertPhi(PhiInstr* phi); |
| 1143 | 1142 |
| 1144 intptr_t phi_count() const { return phi_count_; } | |
| 1145 | |
| 1146 virtual void PrintTo(BufferFormatter* f) const; | 1143 virtual void PrintTo(BufferFormatter* f) const; |
| 1147 | 1144 |
| 1148 private: | 1145 private: |
| 1149 // Classes that have access to predecessors_ when inlining. | 1146 // Classes that have access to predecessors_ when inlining. |
| 1150 friend class BlockEntryInstr; | 1147 friend class BlockEntryInstr; |
| 1151 friend class ValueInliningContext; | 1148 friend class ValueInliningContext; |
| 1152 | 1149 |
| 1150 // Direct access to phis_ in order to resize it due to phi elimination. |
| 1151 friend class ConstantPropagator; |
| 1152 |
| 1153 virtual void ClearPredecessors() { predecessors_.Clear(); } | 1153 virtual void ClearPredecessors() { predecessors_.Clear(); } |
| 1154 virtual void AddPredecessor(BlockEntryInstr* predecessor); | 1154 virtual void AddPredecessor(BlockEntryInstr* predecessor); |
| 1155 | 1155 |
| 1156 GrowableArray<BlockEntryInstr*> predecessors_; | 1156 GrowableArray<BlockEntryInstr*> predecessors_; |
| 1157 ZoneGrowableArray<PhiInstr*>* phis_; | 1157 ZoneGrowableArray<PhiInstr*>* phis_; |
| 1158 intptr_t phi_count_; | |
| 1159 | 1158 |
| 1160 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr); | 1159 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr); |
| 1161 }; | 1160 }; |
| 1162 | 1161 |
| 1163 | 1162 |
| 1164 class PhiIterator : public ValueObject { | 1163 class PhiIterator : public ValueObject { |
| 1165 public: | 1164 public: |
| 1166 explicit PhiIterator(JoinEntryInstr* join) | 1165 explicit PhiIterator(JoinEntryInstr* join) |
| 1167 : phis_(join->phis()), index_(-1) { | 1166 : phis_(join->phis()), index_(0) { } |
| 1168 if (!Done()) Advance(); // Advance to the first phi. | |
| 1169 } | |
| 1170 | 1167 |
| 1171 void Advance() { | 1168 void Advance() { |
| 1172 ASSERT(!Done()); | 1169 ASSERT(!Done()); |
| 1173 do { | 1170 index_++; |
| 1174 index_++; | |
| 1175 } while (!Done() && (Current() == NULL)); | |
| 1176 } | 1171 } |
| 1177 | 1172 |
| 1178 bool Done() const { | 1173 bool Done() const { |
| 1179 return (phis_ == NULL) || (index_ >= phis_->length()); | 1174 return (phis_ == NULL) || (index_ >= phis_->length()); |
| 1180 } | 1175 } |
| 1181 | 1176 |
| 1182 PhiInstr* Current() const { | 1177 PhiInstr* Current() const { |
| 1183 return (*phis_)[index_]; | 1178 return (*phis_)[index_]; |
| 1184 } | 1179 } |
| 1185 | 1180 |
| (...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4494 ForwardInstructionIterator* current_iterator_; | 4489 ForwardInstructionIterator* current_iterator_; |
| 4495 | 4490 |
| 4496 private: | 4491 private: |
| 4497 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 4492 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 4498 }; | 4493 }; |
| 4499 | 4494 |
| 4500 | 4495 |
| 4501 } // namespace dart | 4496 } // namespace dart |
| 4502 | 4497 |
| 4503 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 4498 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |