Commit 6c701d15 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Don't compute unneeded gray set in AllNodes.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#26773}
parent fade797d
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
#include "src/compiler/all-nodes.h" #include "src/compiler/all-nodes.h"
#include "src/compiler/graph.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
AllNodes::AllNodes(Zone* local_zone, const Graph* graph) AllNodes::AllNodes(Zone* local_zone, const Graph* graph)
: live(local_zone), : live(local_zone), is_live(graph->NodeCount(), false, local_zone) {
gray(local_zone),
state(graph->NodeCount(), AllNodes::kDead, local_zone) {
Node* end = graph->end(); Node* end = graph->end();
state[end->id()] = AllNodes::kLive; is_live[end->id()] = true;
live.push_back(end); live.push_back(end);
// Find all live nodes reachable from end. // Find all live nodes reachable from end.
for (size_t i = 0; i < live.size(); i++) { for (size_t i = 0; i < live.size(); i++) {
...@@ -26,23 +26,14 @@ AllNodes::AllNodes(Zone* local_zone, const Graph* graph) ...@@ -26,23 +26,14 @@ AllNodes::AllNodes(Zone* local_zone, const Graph* graph)
// TODO(titzer): print a warning. // TODO(titzer): print a warning.
continue; continue;
} }
if (state[input->id()] != AllNodes::kLive) { if (!is_live[input->id()]) {
is_live[input->id()] = true;
live.push_back(input); 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 } // namespace compiler
} // namespace internal
} // namespace v8
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef V8_COMPILER_ALL_NODES_H_ #ifndef V8_COMPILER_ALL_NODES_H_
#define V8_COMPILER_ALL_NODES_H_ #define V8_COMPILER_ALL_NODES_H_
#include "src/compiler/graph.h"
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/zone-containers.h" #include "src/zone-containers.h"
...@@ -17,25 +16,23 @@ namespace compiler { ...@@ -17,25 +16,23 @@ namespace compiler {
// from end. // from end.
class AllNodes { class AllNodes {
public: public:
// Constructor. Traverses the graph and builds the {live} and {gray} sets. // Constructor. Traverses the graph and builds the {live} sets.
AllNodes(Zone* local_zone, const Graph* graph); AllNodes(Zone* local_zone, const Graph* graph);
bool IsLive(Node* node) { bool IsLive(Node* node) {
return node != nullptr && node->id() < static_cast<int>(state.size()) && if (!node) return false;
state[node->id()] == kLive; size_t id = node->id();
return id < is_live.size() && is_live[id];
} }
NodeVector live; // Nodes reachable from end. NodeVector live; // Nodes reachable from end.
NodeVector gray; // Nodes themselves not reachable from end, but that
// appear in use lists of live nodes.
private: private:
enum State { kDead, kGray, kLive }; BoolVector is_live;
ZoneVector<State> state;
}; };
}
} } // namespace compiler
} // namespace v8::internal::compiler } // namespace internal
} // namespace v8
#endif // V8_COMPILER_ALL_NODES_H_ #endif // V8_COMPILER_ALL_NODES_H_
...@@ -361,9 +361,17 @@ void GraphVisualizer::Print() { ...@@ -361,9 +361,17 @@ void GraphVisualizer::Print() {
<< " concentrate=\"true\"\n" << " concentrate=\"true\"\n"
<< " \n"; << " \n";
// Find all nodes that are not reachable from end that use live nodes.
std::set<Node*> gray;
for (Node* const node : all_.live) {
for (Node* const use : node->uses()) {
if (!all_.IsLive(use)) gray.insert(use);
}
}
// Make sure all nodes have been output before writing out the edges. // Make sure all nodes have been output before writing out the edges.
for (Node* const node : all_.live) PrintNode(node, false); for (Node* const node : all_.live) PrintNode(node, false);
for (Node* const node : all_.gray) PrintNode(node, true); for (Node* const node : gray) PrintNode(node, true);
// With all the nodes written, add the edges. // With all the nodes written, add the edges.
for (Node* const node : all_.live) { for (Node* const node : all_.live) {
......
...@@ -249,6 +249,7 @@ std::ostream& operator<<(std::ostream& os, const Node& n); ...@@ -249,6 +249,7 @@ std::ostream& operator<<(std::ostream& os, const Node& n);
// Typedefs to shorten commonly used Node containers. // Typedefs to shorten commonly used Node containers.
typedef ZoneDeque<Node*> NodeDeque; typedef ZoneDeque<Node*> NodeDeque;
typedef ZoneSet<Node*> NodeSet;
typedef ZoneVector<Node*> NodeVector; typedef ZoneVector<Node*> NodeVector;
typedef ZoneVector<NodeVector> NodeVectorVector; typedef ZoneVector<NodeVector> NodeVectorVector;
......
...@@ -122,7 +122,12 @@ class OsrDeconstructorTester : public HandleAndZoneScope { ...@@ -122,7 +122,12 @@ class OsrDeconstructorTester : public HandleAndZoneScope {
CHECK(!nodes.IsLive(osr_normal_entry)); CHECK(!nodes.IsLive(osr_normal_entry));
CHECK(!nodes.IsLive(osr_loop_entry)); CHECK(!nodes.IsLive(osr_loop_entry));
// No dangling nodes should be left over. // No dangling nodes should be left over.
CHECK_EQ(0u, nodes.gray.size()); for (Node* const node : nodes.live) {
for (Node* const use : node->uses()) {
CHECK(std::find(nodes.live.begin(), nodes.live.end(), use) !=
nodes.live.end());
}
}
} }
}; };
......
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