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 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace compiler { | 12 namespace compiler { |
13 | 13 |
14 // Foward declarations. | 14 // Foward declarations. |
15 struct FieldAccess; | 15 struct FieldAccess; |
16 class JSGraph; | 16 class JSGraph; |
17 | 17 |
18 class LoadElimination final : public AdvancedReducer { | 18 class LoadElimination final : public AdvancedReducer { |
19 public: | 19 public: |
20 LoadElimination(Editor* editor, JSGraph* jsgraph, Zone* zone) | 20 LoadElimination(Editor* editor, JSGraph* jsgraph, Zone* zone) |
21 : AdvancedReducer(editor), node_states_(zone), jsgraph_(jsgraph) {} | 21 : AdvancedReducer(editor), node_states_(zone), jsgraph_(jsgraph) {} |
22 ~LoadElimination() final {} | 22 ~LoadElimination() final {} |
23 | 23 |
24 Reduction Reduce(Node* node) final; | 24 Reduction Reduce(Node* node) final; |
25 | 25 |
26 private: | 26 private: |
| 27 static const size_t kMaxTrackedChecks = 8; |
| 28 |
| 29 // Abstract state to approximate the current state of checks that are |
| 30 // only invalidated by calls, i.e. array buffer neutering checks, along |
| 31 // the effect paths through the graph. |
| 32 class AbstractChecks final : public ZoneObject { |
| 33 public: |
| 34 explicit AbstractChecks(Zone* zone) { |
| 35 for (size_t i = 0; i < arraysize(nodes_); ++i) { |
| 36 nodes_[i] = nullptr; |
| 37 } |
| 38 } |
| 39 AbstractChecks(Node* node, Zone* zone) : AbstractChecks(zone) { |
| 40 nodes_[next_index_++] = node; |
| 41 } |
| 42 |
| 43 AbstractChecks const* Extend(Node* node, Zone* zone) const { |
| 44 AbstractChecks* that = new (zone) AbstractChecks(*this); |
| 45 that->nodes_[that->next_index_] = node; |
| 46 that->next_index_ = (that->next_index_ + 1) % arraysize(nodes_); |
| 47 return that; |
| 48 } |
| 49 Node* Lookup(Node* node) const; |
| 50 bool Equals(AbstractChecks const* that) const; |
| 51 AbstractChecks const* Merge(AbstractChecks const* that, Zone* zone) const; |
| 52 |
| 53 private: |
| 54 Node* nodes_[kMaxTrackedChecks]; |
| 55 size_t next_index_ = 0; |
| 56 }; |
| 57 |
27 static const size_t kMaxTrackedElements = 8; | 58 static const size_t kMaxTrackedElements = 8; |
28 | 59 |
29 // Abstract state to approximate the current state of an element along the | 60 // Abstract state to approximate the current state of an element along the |
30 // effect paths through the graph. | 61 // effect paths through the graph. |
31 class AbstractElements final : public ZoneObject { | 62 class AbstractElements final : public ZoneObject { |
32 public: | 63 public: |
33 explicit AbstractElements(Zone* zone) { | 64 explicit AbstractElements(Zone* zone) { |
34 for (size_t i = 0; i < arraysize(elements_); ++i) { | 65 for (size_t i = 0; i < arraysize(elements_); ++i) { |
35 elements_[i] = Element(); | 66 elements_[i] = Element(); |
36 } | 67 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 AbstractState const* KillField(Node* object, size_t index, | 157 AbstractState const* KillField(Node* object, size_t index, |
127 Zone* zone) const; | 158 Zone* zone) const; |
128 Node* LookupField(Node* object, size_t index) const; | 159 Node* LookupField(Node* object, size_t index) const; |
129 | 160 |
130 AbstractState const* AddElement(Node* object, Node* index, Node* value, | 161 AbstractState const* AddElement(Node* object, Node* index, Node* value, |
131 Zone* zone) const; | 162 Zone* zone) const; |
132 AbstractState const* KillElement(Node* object, Node* index, | 163 AbstractState const* KillElement(Node* object, Node* index, |
133 Zone* zone) const; | 164 Zone* zone) const; |
134 Node* LookupElement(Node* object, Node* index) const; | 165 Node* LookupElement(Node* object, Node* index) const; |
135 | 166 |
| 167 AbstractState const* AddCheck(Node* node, Zone* zone) const; |
| 168 Node* LookupCheck(Node* node) const; |
| 169 |
136 private: | 170 private: |
| 171 AbstractChecks const* checks_ = nullptr; |
137 AbstractElements const* elements_ = nullptr; | 172 AbstractElements const* elements_ = nullptr; |
138 AbstractField const* fields_[kMaxTrackedFields]; | 173 AbstractField const* fields_[kMaxTrackedFields]; |
139 }; | 174 }; |
140 | 175 |
141 class AbstractStateForEffectNodes final : public ZoneObject { | 176 class AbstractStateForEffectNodes final : public ZoneObject { |
142 public: | 177 public: |
143 explicit AbstractStateForEffectNodes(Zone* zone) : info_for_node_(zone) {} | 178 explicit AbstractStateForEffectNodes(Zone* zone) : info_for_node_(zone) {} |
144 AbstractState const* Get(Node* node) const; | 179 AbstractState const* Get(Node* node) const; |
145 void Set(Node* node, AbstractState const* state); | 180 void Set(Node* node, AbstractState const* state); |
146 | 181 |
147 Zone* zone() const { return info_for_node_.get_allocator().zone(); } | 182 Zone* zone() const { return info_for_node_.get_allocator().zone(); } |
148 | 183 |
149 private: | 184 private: |
150 ZoneVector<AbstractState const*> info_for_node_; | 185 ZoneVector<AbstractState const*> info_for_node_; |
151 }; | 186 }; |
152 | 187 |
| 188 Reduction ReduceArrayBufferWasNeutered(Node* node); |
153 Reduction ReduceCheckMaps(Node* node); | 189 Reduction ReduceCheckMaps(Node* node); |
154 Reduction ReduceEnsureWritableFastElements(Node* node); | 190 Reduction ReduceEnsureWritableFastElements(Node* node); |
155 Reduction ReduceMaybeGrowFastElements(Node* node); | 191 Reduction ReduceMaybeGrowFastElements(Node* node); |
156 Reduction ReduceTransitionElementsKind(Node* node); | 192 Reduction ReduceTransitionElementsKind(Node* node); |
157 Reduction ReduceLoadField(Node* node); | 193 Reduction ReduceLoadField(Node* node); |
158 Reduction ReduceStoreField(Node* node); | 194 Reduction ReduceStoreField(Node* node); |
159 Reduction ReduceLoadElement(Node* node); | 195 Reduction ReduceLoadElement(Node* node); |
160 Reduction ReduceStoreElement(Node* node); | 196 Reduction ReduceStoreElement(Node* node); |
161 Reduction ReduceStoreTypedElement(Node* node); | 197 Reduction ReduceStoreTypedElement(Node* node); |
162 Reduction ReduceEffectPhi(Node* node); | 198 Reduction ReduceEffectPhi(Node* node); |
(...skipping 16 matching lines...) Expand all Loading... |
179 JSGraph* const jsgraph_; | 215 JSGraph* const jsgraph_; |
180 | 216 |
181 DISALLOW_COPY_AND_ASSIGN(LoadElimination); | 217 DISALLOW_COPY_AND_ASSIGN(LoadElimination); |
182 }; | 218 }; |
183 | 219 |
184 } // namespace compiler | 220 } // namespace compiler |
185 } // namespace internal | 221 } // namespace internal |
186 } // namespace v8 | 222 } // namespace v8 |
187 | 223 |
188 #endif // V8_COMPILER_LOAD_ELIMINATION_H_ | 224 #endif // V8_COMPILER_LOAD_ELIMINATION_H_ |
OLD | NEW |