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