OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_GRAPH_REDUCER_H_ | 5 #ifndef V8_COMPILER_GRAPH_REDUCER_H_ |
6 #define V8_COMPILER_GRAPH_REDUCER_H_ | 6 #define V8_COMPILER_GRAPH_REDUCER_H_ |
7 | 7 |
8 #include "src/compiler/node-marker.h" | 8 #include "src/compiler/node-marker.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 public: | 70 public: |
71 virtual ~Editor() {} | 71 virtual ~Editor() {} |
72 | 72 |
73 // Replace {node} with {replacement}. | 73 // Replace {node} with {replacement}. |
74 virtual void Replace(Node* node, Node* replacement) = 0; | 74 virtual void Replace(Node* node, Node* replacement) = 0; |
75 // Revisit the {node} again later. | 75 // Revisit the {node} again later. |
76 virtual void Revisit(Node* node) = 0; | 76 virtual void Revisit(Node* node) = 0; |
77 // Replace value uses of {node} with {value} and effect uses of {node} with | 77 // Replace value uses of {node} with {value} and effect uses of {node} with |
78 // {effect}. If {effect == NULL}, then use the effect input to {node}. All | 78 // {effect}. If {effect == NULL}, then use the effect input to {node}. All |
79 // control uses will be relaxed assuming {node} cannot throw. | 79 // control uses will be relaxed assuming {node} cannot throw. |
80 virtual void ReplaceWithValue(Node* node, Node* value, | 80 virtual void ReplaceWithValue(Node* node, Node* value, Node* effect, |
81 Node* effect = nullptr, | 81 Node* control) = 0; |
82 Node* control = nullptr) = 0; | |
83 }; | 82 }; |
84 | 83 |
85 explicit AdvancedReducer(Editor* editor) : editor_(editor) {} | 84 explicit AdvancedReducer(Editor* editor) : editor_(editor) {} |
86 | 85 |
87 protected: | 86 protected: |
88 // Helper functions for subclasses to produce reductions for a node. | 87 // Helper functions for subclasses to produce reductions for a node. |
89 static Reduction Replace(Node* node) { return Reducer::Replace(node); } | 88 static Reduction Replace(Node* node) { return Reducer::Replace(node); } |
90 | 89 |
91 // Helper functions for subclasses to edit the graph. | 90 // Helper functions for subclasses to edit the graph. |
92 void Replace(Node* node, Node* replacement) { | 91 void Replace(Node* node, Node* replacement) { |
93 DCHECK_NOT_NULL(editor_); | 92 DCHECK_NOT_NULL(editor_); |
94 editor_->Replace(node, replacement); | 93 editor_->Replace(node, replacement); |
95 } | 94 } |
96 void Revisit(Node* node) { | 95 void Revisit(Node* node) { |
97 DCHECK_NOT_NULL(editor_); | 96 DCHECK_NOT_NULL(editor_); |
98 editor_->Revisit(node); | 97 editor_->Revisit(node); |
99 } | 98 } |
100 void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr, | 99 void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr, |
101 Node* control = nullptr) { | 100 Node* control = nullptr) { |
102 DCHECK_NOT_NULL(editor_); | 101 DCHECK_NOT_NULL(editor_); |
103 editor_->ReplaceWithValue(node, value, effect, control); | 102 editor_->ReplaceWithValue(node, value, effect, control); |
104 } | 103 } |
105 | 104 |
106 // Relax the effects of {node} by immediately replacing effect and control | 105 // Relax the effects of {node} by immediately replacing effect and control |
107 // uses of {node} with the effect and control input to {node}. | 106 // uses of {node} with the effect and control input to {node}. |
108 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. | 107 // TODO(turbofan): replace the effect input to {node} with {graph->start()}. |
109 void RelaxEffectsAndControls(Node* node) { | 108 void RelaxEffectsAndControls(Node* node) { |
110 DCHECK_NOT_NULL(editor_); | 109 ReplaceWithValue(node, node, nullptr, nullptr); |
111 editor_->ReplaceWithValue(node, node, nullptr, nullptr); | |
112 } | 110 } |
113 | 111 |
114 // Relax the control uses of {node} by immediately replacing them with the | 112 // Relax the control uses of {node} by immediately replacing them with the |
115 // control input to {node}. | 113 // control input to {node}. |
116 void RelaxControls(Node* node) { | 114 void RelaxControls(Node* node) { |
117 DCHECK_NOT_NULL(editor_); | 115 ReplaceWithValue(node, node, node, nullptr); |
118 editor_->ReplaceWithValue(node, node, node, nullptr); | |
119 } | 116 } |
120 | 117 |
121 private: | 118 private: |
122 Editor* const editor_; | 119 Editor* const editor_; |
123 }; | 120 }; |
124 | 121 |
125 | 122 |
126 // Performs an iterative reduction of a node graph. | 123 // Performs an iterative reduction of a node graph. |
127 class GraphReducer final : public AdvancedReducer::Editor { | 124 class GraphReducer : public AdvancedReducer::Editor { |
128 public: | 125 public: |
129 GraphReducer(Graph* graph, Zone* zone); | 126 GraphReducer(Graph* graph, Node* dead_value, Node* dead_control, Zone* zone); |
titzer
2015/06/05 09:42:26
Can we move the zone first and then have default v
Michael Starzinger
2015/06/05 11:06:54
Done.
| |
130 ~GraphReducer() final; | 127 ~GraphReducer(); |
131 | 128 |
132 Graph* graph() const { return graph_; } | 129 Graph* graph() const { return graph_; } |
133 | 130 |
134 void AddReducer(Reducer* reducer); | 131 void AddReducer(Reducer* reducer); |
135 | 132 |
136 // Reduce a single node. | 133 // Reduce a single node. |
137 void ReduceNode(Node* const); | 134 void ReduceNode(Node* const); |
138 // Reduce the whole graph. | 135 // Reduce the whole graph. |
139 void ReduceGraph(); | 136 void ReduceGraph(); |
140 | 137 |
141 private: | 138 private: |
142 enum class State : uint8_t; | 139 enum class State : uint8_t; |
143 struct NodeState { | 140 struct NodeState { |
144 Node* node; | 141 Node* node; |
145 int input_index; | 142 int input_index; |
146 }; | 143 }; |
147 | 144 |
148 // Reduce a single node. | 145 // Reduce a single node. |
149 Reduction Reduce(Node* const); | 146 Reduction Reduce(Node* const); |
150 // Reduce the node on top of the stack. | 147 // Reduce the node on top of the stack. |
151 void ReduceTop(); | 148 void ReduceTop(); |
152 | 149 |
153 // Replace {node} with {replacement}. | 150 // Replace {node} with {replacement}. |
154 void Replace(Node* node, Node* replacement) final; | 151 void Replace(Node* node, Node* replacement) final; |
155 | 152 |
156 // Replace value uses of {node} with {value} and effect uses of {node} with | 153 // Replace value uses of {node} with {value} and effect uses of {node} with |
157 // {effect}. If {effect == NULL}, then use the effect input to {node}. All | 154 // {effect}. If {effect == NULL}, then use the effect input to {node}. All |
158 // control uses will be relaxed assuming {node} cannot throw. | 155 // control uses will be relaxed assuming {node} cannot throw. |
159 void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr, | 156 void ReplaceWithValue(Node* node, Node* value, Node* effect, |
160 Node* control = nullptr) final; | 157 Node* control) final; |
161 | 158 |
162 // Replace all uses of {node} with {replacement} if the id of {replacement} is | 159 // Replace all uses of {node} with {replacement} if the id of {replacement} is |
163 // less than or equal to {max_id}. Otherwise, replace all uses of {node} whose | 160 // less than or equal to {max_id}. Otherwise, replace all uses of {node} whose |
164 // id is less than or equal to {max_id} with the {replacement}. | 161 // id is less than or equal to {max_id} with the {replacement}. |
165 void Replace(Node* node, Node* replacement, NodeId max_id); | 162 void Replace(Node* node, Node* replacement, NodeId max_id); |
166 | 163 |
167 // Node stack operations. | 164 // Node stack operations. |
168 void Pop(); | 165 void Pop(); |
169 void Push(Node* node); | 166 void Push(Node* node); |
170 | 167 |
171 // Revisit queue operations. | 168 // Revisit queue operations. |
172 bool Recurse(Node* node); | 169 bool Recurse(Node* node); |
173 void Revisit(Node* node) final; | 170 void Revisit(Node* node) final; |
174 | 171 |
175 Graph* const graph_; | 172 Graph* const graph_; |
173 Node* const dead_value_; | |
174 Node* const dead_control_; | |
176 NodeMarker<State> state_; | 175 NodeMarker<State> state_; |
177 ZoneVector<Reducer*> reducers_; | 176 ZoneVector<Reducer*> reducers_; |
178 ZoneStack<Node*> revisit_; | 177 ZoneStack<Node*> revisit_; |
179 ZoneStack<NodeState> stack_; | 178 ZoneStack<NodeState> stack_; |
180 | 179 |
181 DISALLOW_COPY_AND_ASSIGN(GraphReducer); | 180 DISALLOW_COPY_AND_ASSIGN(GraphReducer); |
182 }; | 181 }; |
183 | 182 |
184 } // namespace compiler | 183 } // namespace compiler |
185 } // namespace internal | 184 } // namespace internal |
186 } // namespace v8 | 185 } // namespace v8 |
187 | 186 |
188 #endif // V8_COMPILER_GRAPH_REDUCER_H_ | 187 #endif // V8_COMPILER_GRAPH_REDUCER_H_ |
OLD | NEW |