Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: src/compiler/graph-reducer.cc

Issue 1367423002: [turbofan] Move node verification methods to the Verifier class. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tweaks Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/graph.cc ('k') | src/compiler/node-properties.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <functional> 5 #include <functional>
6 #include <limits> 6 #include <limits>
7 7
8 #include "src/compiler/graph.h" 8 #include "src/compiler/graph.h"
9 #include "src/compiler/graph-reducer.h" 9 #include "src/compiler/graph-reducer.h"
10 #include "src/compiler/node.h" 10 #include "src/compiler/node.h"
11 #include "src/compiler/node-properties.h" 11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/verifier.h"
12 13
13 namespace v8 { 14 namespace v8 {
14 namespace internal { 15 namespace internal {
15 namespace compiler { 16 namespace compiler {
16 17
17 enum class GraphReducer::State : uint8_t { 18 enum class GraphReducer::State : uint8_t {
18 kUnvisited, 19 kUnvisited,
19 kRevisit, 20 kRevisit,
20 kOnStack, 21 kOnStack,
21 kVisited 22 kVisited
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 153 }
153 } 154 }
154 } 155 }
155 156
156 157
157 void GraphReducer::Replace(Node* node, Node* replacement) { 158 void GraphReducer::Replace(Node* node, Node* replacement) {
158 Replace(node, replacement, std::numeric_limits<NodeId>::max()); 159 Replace(node, replacement, std::numeric_limits<NodeId>::max());
159 } 160 }
160 161
161 162
162 namespace {
163
164
165 void VerifyUseReplacement(const Edge& edge, const Node* replacement) {
166 // Check that the user does not misuse the replacement.
167 DCHECK(!NodeProperties::IsControlEdge(edge) ||
168 replacement->op()->ControlOutputCount() > 0);
169 DCHECK(!NodeProperties::IsEffectEdge(edge) ||
170 replacement->op()->EffectOutputCount() > 0);
171 DCHECK(!NodeProperties::IsFrameStateEdge(edge) ||
172 replacement->opcode() == IrOpcode::kFrameState);
173 }
174
175 } // namespace
176
177
178 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) { 163 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) {
179 if (node == graph()->start()) graph()->SetStart(replacement); 164 if (node == graph()->start()) graph()->SetStart(replacement);
180 if (node == graph()->end()) graph()->SetEnd(replacement); 165 if (node == graph()->end()) graph()->SetEnd(replacement);
181 if (replacement->id() <= max_id) { 166 if (replacement->id() <= max_id) {
182 // {replacement} is an old node, so unlink {node} and assume that 167 // {replacement} is an old node, so unlink {node} and assume that
183 // {replacement} was already reduced and finish. 168 // {replacement} was already reduced and finish.
184 for (Edge edge : node->use_edges()) { 169 for (Edge edge : node->use_edges()) {
185 Node* const user = edge.from(); 170 Node* const user = edge.from();
186 VerifyUseReplacement(edge, replacement); 171 Verifier::VerifyEdgeInputReplacement(edge, replacement);
187 edge.UpdateTo(replacement); 172 edge.UpdateTo(replacement);
188 // Don't revisit this node if it refers to itself. 173 // Don't revisit this node if it refers to itself.
189 if (user != node) Revisit(user); 174 if (user != node) Revisit(user);
190 } 175 }
191 node->Kill(); 176 node->Kill();
192 } else { 177 } else {
193 // Replace all old uses of {node} with {replacement}, but allow new nodes 178 // Replace all old uses of {node} with {replacement}, but allow new nodes
194 // created by this reduction to use {node}. 179 // created by this reduction to use {node}.
195 for (Edge edge : node->use_edges()) { 180 for (Edge edge : node->use_edges()) {
196 Node* const user = edge.from(); 181 Node* const user = edge.from();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void GraphReducer::Revisit(Node* node) { 254 void GraphReducer::Revisit(Node* node) {
270 if (state_.Get(node) == State::kVisited) { 255 if (state_.Get(node) == State::kVisited) {
271 state_.Set(node, State::kRevisit); 256 state_.Set(node, State::kRevisit);
272 revisit_.push(node); 257 revisit_.push(node);
273 } 258 }
274 } 259 }
275 260
276 } // namespace compiler 261 } // namespace compiler
277 } // namespace internal 262 } // namespace internal
278 } // namespace v8 263 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/graph.cc ('k') | src/compiler/node-properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698