Commit 3937dd67 authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Remove GenericAlgorithm from verifier and graph replay.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/879583002

Cr-Commit-Position: refs/heads/master@{#26280}
parent 0e7379e0
......@@ -507,6 +507,8 @@ source_set("v8_base") {
"src/compilation-statistics.h",
"src/compiler/access-builder.cc",
"src/compiler/access-builder.h",
"src/compiler/all-nodes.cc",
"src/compiler/all-nodes.h",
"src/compiler/ast-graph-builder.cc",
"src/compiler/ast-graph-builder.h",
"src/compiler/ast-loop-assignment-analyzer.cc",
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/all-nodes.h"
namespace v8 {
namespace internal {
namespace compiler {
AllNodes::AllNodes(Zone* local_zone, const Graph* graph)
: live(local_zone),
gray(local_zone),
state(graph->NodeCount(), AllNodes::kDead, local_zone) {
Node* end = graph->end();
state[end->id()] = AllNodes::kLive;
live.push_back(end);
// Find all live nodes reachable from end.
for (size_t i = 0; i < live.size(); i++) {
for (Node* const input : live[i]->inputs()) {
if (input == nullptr) {
// TODO(titzer): print a warning.
continue;
}
if (input->id() >= graph->NodeCount()) {
// TODO(titzer): print a warning.
continue;
}
if (state[input->id()] != AllNodes::kLive) {
live.push_back(input);
state[input->id()] = AllNodes::kLive;
}
}
}
// Find all nodes that are not reachable from end that use live nodes.
for (size_t i = 0; i < live.size(); i++) {
for (Node* const use : live[i]->uses()) {
if (state[use->id()] == AllNodes::kDead) {
gray.push_back(use);
state[use->id()] = AllNodes::kGray;
}
}
}
}
}
}
} // namespace v8::internal::compiler
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_ALL_NODES_H_
#define V8_COMPILER_ALL_NODES_H_
#include "src/compiler/graph.h"
#include "src/compiler/node.h"
#include "src/v8.h"
#include "src/zone-containers.h"
namespace v8 {
namespace internal {
namespace compiler {
// A helper utility that traverses the graph and gathers all nodes reachable
// from end.
class AllNodes {
public:
// Constructor. Traverses the graph and builds the {live} and {gray} sets.
AllNodes(Zone* local_zone, const Graph* graph);
bool IsLive(Node* node) {
return node != nullptr && node->id() < static_cast<int>(state.size()) &&
state[node->id()] == kLive;
}
NodeVector live; // Nodes reachable from end.
NodeVector gray; // Nodes themselves not reachable from end, but that
// appear in use lists of live nodes.
private:
enum State { kDead, kGray, kLive };
ZoneVector<State> state;
};
}
}
} // namespace v8::internal::compiler
#endif // V8_COMPILER_ALL_NODES_H_
......@@ -8,7 +8,7 @@
#include "src/v8.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/graph.h"
#include "src/compiler/node.h"
namespace v8 {
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/graph-reducer.h"
#include <functional>
#include "src/compiler/graph-inl.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-reducer.h"
#include "src/compiler/node.h"
namespace v8 {
namespace internal {
......
......@@ -4,9 +4,9 @@
#include "src/compiler/graph-replay.h"
#include "src/compiler/all-nodes.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/node.h"
#include "src/compiler/operator.h"
#include "src/compiler/operator-properties.h"
......@@ -20,22 +20,26 @@ namespace compiler {
void GraphReplayPrinter::PrintReplay(Graph* graph) {
GraphReplayPrinter replay;
PrintF(" Node* nil = graph.NewNode(common_builder.Dead());\n");
graph->VisitNodeInputsFromEnd(&replay);
}
Zone zone;
AllNodes nodes(&zone, graph);
void GraphReplayPrinter::Pre(Node* node) {
PrintReplayOpCreator(node->op());
PrintF(" Node* n%d = graph.NewNode(op", node->id());
for (int i = 0; i < node->InputCount(); ++i) {
PrintF(", nil");
// Allocate the nodes first.
for (Node* node : nodes.live) {
PrintReplayOpCreator(node->op());
PrintF(" Node* n%d = graph.NewNode(op", node->id());
for (int i = 0; i < node->InputCount(); ++i) {
PrintF(", nil");
}
PrintF("); USE(n%d);\n", node->id());
}
PrintF("); USE(n%d);\n", node->id());
}
void GraphReplayPrinter::PostEdge(Node* from, int index, Node* to) {
PrintF(" n%d->ReplaceInput(%d, n%d);\n", from->id(), index, to->id());
// Connect the nodes to their inputs.
for (Node* node : nodes.live) {
for (int i = 0; i < node->InputCount(); i++) {
PrintF(" n%d->ReplaceInput(%d, n%d);\n", node->id(), i,
node->InputAt(i)->id());
}
}
}
......
......@@ -5,7 +5,6 @@
#ifndef V8_COMPILER_GRAPH_REPLAY_H_
#define V8_COMPILER_GRAPH_REPLAY_H_
#include "src/compiler/generic-algorithm.h"
#include "src/compiler/node.h"
namespace v8 {
......@@ -18,7 +17,7 @@ class Graph;
// Helper class to print a full replay of a graph. This replay can be used to
// materialize the same graph within a C++ unit test and hence test subsequent
// optimization passes on a graph without going through the construction steps.
class GraphReplayPrinter FINAL : public NullNodeVisitor {
class GraphReplayPrinter {
public:
#ifdef DEBUG
static void PrintReplay(Graph* graph);
......@@ -26,9 +25,6 @@ class GraphReplayPrinter FINAL : public NullNodeVisitor {
static void PrintReplay(Graph* graph) {}
#endif
void Pre(Node* node);
void PostEdge(Node* from, int index, Node* to);
private:
GraphReplayPrinter() {}
......
......@@ -8,8 +8,8 @@
#include <string>
#include "src/code-stubs.h"
#include "src/compiler/all-nodes.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/node.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/node-properties-inl.h"
......@@ -31,57 +31,6 @@ static const char* SafeMnemonic(Node* node) {
#define DEAD_COLOR "#999999"
class AllNodes {
public:
enum State { kDead, kGray, kLive };
AllNodes(Zone* local_zone, const Graph* graph)
: state(graph->NodeCount(), kDead, local_zone),
live(local_zone),
gray(local_zone) {
Node* end = graph->end();
state[end->id()] = kLive;
live.push_back(end);
// Find all live nodes reachable from end.
for (size_t i = 0; i < live.size(); i++) {
for (Node* const input : live[i]->inputs()) {
if (input == NULL) {
// TODO(titzer): print a warning.
continue;
}
if (input->id() >= graph->NodeCount()) {
// TODO(titzer): print a warning.
continue;
}
if (state[input->id()] != kLive) {
live.push_back(input);
state[input->id()] = kLive;
}
}
}
// Find all nodes that are not reachable from end that use live nodes.
for (size_t i = 0; i < live.size(); i++) {
for (Node* const use : live[i]->uses()) {
if (state[use->id()] == kDead) {
gray.push_back(use);
state[use->id()] = kGray;
}
}
}
}
bool IsLive(Node* node) {
return node != NULL && node->id() < static_cast<int>(state.size()) &&
state[node->id()] == kLive;
}
ZoneVector<State> state;
NodeVector live;
NodeVector gray;
};
class Escaped {
public:
explicit Escaped(const std::ostringstream& os,
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "src/compiler/diamond.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-builtin-reducer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/node-matchers.h"
......
......@@ -6,7 +6,6 @@
#include "src/compiler.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
......
......@@ -5,7 +5,6 @@
#include "src/code-factory.h"
#include "src/code-stubs.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-generic-lowering.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-aux-data-inl.h"
......
......@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "src/compiler/access-builder.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/js-typed-lowering.h"
#include "src/compiler/node-aux-data-inl.h"
......
......@@ -10,7 +10,6 @@
#include "src/code-factory.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/diamond.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/linkage.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
......
......@@ -11,8 +11,7 @@
#include <string>
#include "src/bit-vector.h"
#include "src/compiler/generic-algorithm.h"
#include "src/compiler/graph-inl.h"
#include "src/compiler/all-nodes.h"
#include "src/compiler/graph.h"
#include "src/compiler/node.h"
#include "src/compiler/node-properties-inl.h"
......@@ -40,12 +39,11 @@ static bool IsUseDefChainLinkPresent(Node* def, Node* use) {
}
class Verifier::Visitor : public NullNodeVisitor {
class Verifier::Visitor {
public:
Visitor(Zone* z, Typing typed) : zone(z), typing(typed) {}
// Fulfills the PreNodeCallback interface.
void Pre(Node* node);
void Check(Node* node);
Zone* zone;
Typing typing;
......@@ -113,7 +111,7 @@ class Verifier::Visitor : public NullNodeVisitor {
};
void Verifier::Visitor::Pre(Node* node) {
void Verifier::Visitor::Check(Node* node) {
int value_count = node->op()->ValueInputCount();
int context_count = OperatorProperties::GetContextInputCount(node->op());
int frame_state_count =
......@@ -754,10 +752,11 @@ void Verifier::Visitor::Pre(Node* node) {
void Verifier::Run(Graph* graph, Typing typing) {
Visitor visitor(graph->zone(), typing);
CHECK_NE(NULL, graph->start());
CHECK_NE(NULL, graph->end());
graph->VisitNodeInputsFromEnd(&visitor);
Zone zone;
Visitor visitor(&zone, typing);
for (Node* node : AllNodes(&zone, graph).live) visitor.Check(node);
}
......
......@@ -412,6 +412,8 @@
'../../src/compilation-statistics.h',
'../../src/compiler/access-builder.cc',
'../../src/compiler/access-builder.h',
'../../src/compiler/all-nodes.cc',
'../../src/compiler/all-nodes.h',
'../../src/compiler/ast-graph-builder.cc',
'../../src/compiler/ast-graph-builder.h',
'../../src/compiler/ast-loop-assignment-analyzer.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment