OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_LOAD_ELIMINATION_H_ | 5 #ifndef V8_COMPILER_LOAD_ELIMINATION_H_ |
6 #define V8_COMPILER_LOAD_ELIMINATION_H_ | 6 #define V8_COMPILER_LOAD_ELIMINATION_H_ |
7 | 7 |
8 #include "src/base/compiler-specific.h" | 8 #include "src/base/compiler-specific.h" |
9 #include "src/compiler/graph-reducer.h" | 9 #include "src/compiler/graph-reducer.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
| 11 #include "src/zone/zone-handle-set.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
| 15 |
| 16 // Forward declarations. |
| 17 class Factory; |
| 18 |
14 namespace compiler { | 19 namespace compiler { |
15 | 20 |
16 // Foward declarations. | 21 // Foward declarations. |
17 class CommonOperatorBuilder; | 22 class CommonOperatorBuilder; |
18 struct FieldAccess; | 23 struct FieldAccess; |
19 class Graph; | 24 class Graph; |
20 class JSGraph; | 25 class JSGraph; |
21 | 26 |
22 class V8_EXPORT_PRIVATE LoadElimination final | 27 class V8_EXPORT_PRIVATE LoadElimination final |
23 : public NON_EXPORTED_BASE(AdvancedReducer) { | 28 : public NON_EXPORTED_BASE(AdvancedReducer) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 150 } |
146 | 151 |
147 void Print() const; | 152 void Print() const; |
148 | 153 |
149 private: | 154 private: |
150 ZoneMap<Node*, Node*> info_for_node_; | 155 ZoneMap<Node*, Node*> info_for_node_; |
151 }; | 156 }; |
152 | 157 |
153 static size_t const kMaxTrackedFields = 32; | 158 static size_t const kMaxTrackedFields = 32; |
154 | 159 |
| 160 // Abstract state to approximate the current map of an object along the |
| 161 // effect paths through the graph. |
| 162 class AbstractMaps final : public ZoneObject { |
| 163 public: |
| 164 explicit AbstractMaps(Zone* zone) : info_for_node_(zone) {} |
| 165 AbstractMaps(Node* object, ZoneHandleSet<Map> maps, Zone* zone) |
| 166 : info_for_node_(zone) { |
| 167 info_for_node_.insert(std::make_pair(object, maps)); |
| 168 } |
| 169 |
| 170 AbstractMaps const* Extend(Node* object, ZoneHandleSet<Map> maps, |
| 171 Zone* zone) const { |
| 172 AbstractMaps* that = new (zone) AbstractMaps(zone); |
| 173 that->info_for_node_ = this->info_for_node_; |
| 174 that->info_for_node_.insert(std::make_pair(object, maps)); |
| 175 return that; |
| 176 } |
| 177 bool Lookup(Node* object, ZoneHandleSet<Map>* object_maps) const; |
| 178 AbstractMaps const* Kill(Node* object, Zone* zone) const; |
| 179 bool Equals(AbstractMaps const* that) const { |
| 180 return this == that || this->info_for_node_ == that->info_for_node_; |
| 181 } |
| 182 AbstractMaps const* Merge(AbstractMaps const* that, Zone* zone) const { |
| 183 if (this->Equals(that)) return this; |
| 184 AbstractMaps* copy = new (zone) AbstractMaps(zone); |
| 185 for (auto this_it : this->info_for_node_) { |
| 186 Node* this_object = this_it.first; |
| 187 ZoneHandleSet<Map> this_maps = this_it.second; |
| 188 auto that_it = that->info_for_node_.find(this_object); |
| 189 if (that_it != that->info_for_node_.end() && |
| 190 that_it->second == this_maps) { |
| 191 copy->info_for_node_.insert(this_it); |
| 192 } |
| 193 } |
| 194 return copy; |
| 195 } |
| 196 |
| 197 void Print() const; |
| 198 |
| 199 private: |
| 200 ZoneMap<Node*, ZoneHandleSet<Map>> info_for_node_; |
| 201 }; |
| 202 |
155 class AbstractState final : public ZoneObject { | 203 class AbstractState final : public ZoneObject { |
156 public: | 204 public: |
157 AbstractState() { | 205 AbstractState() { |
158 for (size_t i = 0; i < arraysize(fields_); ++i) { | 206 for (size_t i = 0; i < arraysize(fields_); ++i) { |
159 fields_[i] = nullptr; | 207 fields_[i] = nullptr; |
160 } | 208 } |
161 } | 209 } |
162 | 210 |
163 bool Equals(AbstractState const* that) const; | 211 bool Equals(AbstractState const* that) const; |
164 void Merge(AbstractState const* that, Zone* zone); | 212 void Merge(AbstractState const* that, Zone* zone); |
165 | 213 |
| 214 AbstractState const* AddMaps(Node* object, ZoneHandleSet<Map> maps, |
| 215 Zone* zone) const; |
| 216 AbstractState const* KillMaps(Node* object, Zone* zone) const; |
| 217 bool LookupMaps(Node* object, ZoneHandleSet<Map>* object_maps) const; |
| 218 |
166 AbstractState const* AddField(Node* object, size_t index, Node* value, | 219 AbstractState const* AddField(Node* object, size_t index, Node* value, |
167 Zone* zone) const; | 220 Zone* zone) const; |
168 AbstractState const* KillField(Node* object, size_t index, | 221 AbstractState const* KillField(Node* object, size_t index, |
169 Zone* zone) const; | 222 Zone* zone) const; |
170 AbstractState const* KillFields(Node* object, Zone* zone) const; | 223 AbstractState const* KillFields(Node* object, Zone* zone) const; |
171 Node* LookupField(Node* object, size_t index) const; | 224 Node* LookupField(Node* object, size_t index) const; |
172 | 225 |
173 AbstractState const* AddElement(Node* object, Node* index, Node* value, | 226 AbstractState const* AddElement(Node* object, Node* index, Node* value, |
174 Zone* zone) const; | 227 Zone* zone) const; |
175 AbstractState const* KillElement(Node* object, Node* index, | 228 AbstractState const* KillElement(Node* object, Node* index, |
176 Zone* zone) const; | 229 Zone* zone) const; |
177 Node* LookupElement(Node* object, Node* index) const; | 230 Node* LookupElement(Node* object, Node* index) const; |
178 | 231 |
179 AbstractState const* AddCheck(Node* node, Zone* zone) const; | 232 AbstractState const* AddCheck(Node* node, Zone* zone) const; |
180 Node* LookupCheck(Node* node) const; | 233 Node* LookupCheck(Node* node) const; |
181 | 234 |
182 void Print() const; | 235 void Print() const; |
183 | 236 |
184 private: | 237 private: |
185 AbstractChecks const* checks_ = nullptr; | 238 AbstractChecks const* checks_ = nullptr; |
186 AbstractElements const* elements_ = nullptr; | 239 AbstractElements const* elements_ = nullptr; |
187 AbstractField const* fields_[kMaxTrackedFields]; | 240 AbstractField const* fields_[kMaxTrackedFields]; |
| 241 AbstractMaps const* maps_ = nullptr; |
188 }; | 242 }; |
189 | 243 |
190 class AbstractStateForEffectNodes final : public ZoneObject { | 244 class AbstractStateForEffectNodes final : public ZoneObject { |
191 public: | 245 public: |
192 explicit AbstractStateForEffectNodes(Zone* zone) : info_for_node_(zone) {} | 246 explicit AbstractStateForEffectNodes(Zone* zone) : info_for_node_(zone) {} |
193 AbstractState const* Get(Node* node) const; | 247 AbstractState const* Get(Node* node) const; |
194 void Set(Node* node, AbstractState const* state); | 248 void Set(Node* node, AbstractState const* state); |
195 | 249 |
196 Zone* zone() const { return info_for_node_.get_allocator().zone(); } | 250 Zone* zone() const { return info_for_node_.get_allocator().zone(); } |
197 | 251 |
(...skipping 18 matching lines...) Expand all Loading... |
216 Reduction UpdateState(Node* node, AbstractState const* state); | 270 Reduction UpdateState(Node* node, AbstractState const* state); |
217 | 271 |
218 AbstractState const* ComputeLoopState(Node* node, | 272 AbstractState const* ComputeLoopState(Node* node, |
219 AbstractState const* state) const; | 273 AbstractState const* state) const; |
220 | 274 |
221 static int FieldIndexOf(int offset); | 275 static int FieldIndexOf(int offset); |
222 static int FieldIndexOf(FieldAccess const& access); | 276 static int FieldIndexOf(FieldAccess const& access); |
223 | 277 |
224 CommonOperatorBuilder* common() const; | 278 CommonOperatorBuilder* common() const; |
225 AbstractState const* empty_state() const { return &empty_state_; } | 279 AbstractState const* empty_state() const { return &empty_state_; } |
| 280 Factory* factory() const; |
226 Graph* graph() const; | 281 Graph* graph() const; |
227 JSGraph* jsgraph() const { return jsgraph_; } | 282 JSGraph* jsgraph() const { return jsgraph_; } |
228 Zone* zone() const { return node_states_.zone(); } | 283 Zone* zone() const { return node_states_.zone(); } |
229 | 284 |
230 AbstractState const empty_state_; | 285 AbstractState const empty_state_; |
231 AbstractStateForEffectNodes node_states_; | 286 AbstractStateForEffectNodes node_states_; |
232 JSGraph* const jsgraph_; | 287 JSGraph* const jsgraph_; |
233 | 288 |
234 DISALLOW_COPY_AND_ASSIGN(LoadElimination); | 289 DISALLOW_COPY_AND_ASSIGN(LoadElimination); |
235 }; | 290 }; |
236 | 291 |
237 } // namespace compiler | 292 } // namespace compiler |
238 } // namespace internal | 293 } // namespace internal |
239 } // namespace v8 | 294 } // namespace v8 |
240 | 295 |
241 #endif // V8_COMPILER_LOAD_ELIMINATION_H_ | 296 #endif // V8_COMPILER_LOAD_ELIMINATION_H_ |
OLD | NEW |