Reviewers: titzer,

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

[email protected]

Please review this at https://codereview.chromium.org/940403002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+35, -33 lines):
  M src/compiler/all-nodes.h
  M src/compiler/all-nodes.cc
  M src/compiler/graph-visualizer.cc
  M src/compiler/node.h
  M test/cctest/compiler/test-osr.cc


Index: src/compiler/all-nodes.cc
diff --git a/src/compiler/all-nodes.cc b/src/compiler/all-nodes.cc
index b055a68c08d0ec0a97e9c1719ac19e026aa0cd77..ed4a218c2bc42917aebbe332b72fbaea484ed209 100644
--- a/src/compiler/all-nodes.cc
+++ b/src/compiler/all-nodes.cc
@@ -4,16 +4,16 @@

 #include "src/compiler/all-nodes.h"

+#include "src/compiler/graph.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) {
+    : live(local_zone), is_live(graph->NodeCount(), false, local_zone) {
   Node* end = graph->end();
-  state[end->id()] = AllNodes::kLive;
+  is_live[end->id()] = true;
   live.push_back(end);
   // Find all live nodes reachable from end.
   for (size_t i = 0; i < live.size(); i++) {
@@ -26,23 +26,14 @@ AllNodes::AllNodes(Zone* local_zone, const Graph* graph)
         // TODO(titzer): print a warning.
         continue;
       }
-      if (state[input->id()] != AllNodes::kLive) {
+      if (!is_live[input->id()]) {
+        is_live[input->id()] = true;
         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
Index: src/compiler/all-nodes.h
diff --git a/src/compiler/all-nodes.h b/src/compiler/all-nodes.h
index e6a83ef623761e57da41daa2a7dd65d46a2ad3ac..700f0071b1e531e5514a121554a984cdcba3924d 100644
--- a/src/compiler/all-nodes.h
+++ b/src/compiler/all-nodes.h
@@ -5,7 +5,6 @@
 #ifndef V8_COMPILER_ALL_NODES_H_
 #define V8_COMPILER_ALL_NODES_H_

-#include "src/compiler/graph.h"
 #include "src/compiler/node.h"
 #include "src/zone-containers.h"

@@ -17,25 +16,23 @@ namespace compiler {
 // from end.
 class AllNodes {
  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);

   bool IsLive(Node* node) {
- return node != nullptr && node->id() < static_cast<int>(state.size()) &&
-           state[node->id()] == kLive;
+    if (!node) return false;
+    size_t id = node->id();
+    return id < is_live.size() && is_live[id];
   }

   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;
+  BoolVector is_live;
 };
-}
-}
-}  // namespace v8::internal::compiler
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8

 #endif  // V8_COMPILER_ALL_NODES_H_
Index: src/compiler/graph-visualizer.cc
diff --git a/src/compiler/graph-visualizer.cc b/src/compiler/graph-visualizer.cc index 42d355fb1dba50a18943b4da4621f43039771a45..9947be2999859141e1373c4feea15aaf8e48f0e1 100644
--- a/src/compiler/graph-visualizer.cc
+++ b/src/compiler/graph-visualizer.cc
@@ -361,9 +361,17 @@ void GraphVisualizer::Print() {
       << "  concentrate=\"true\"\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.
   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.
   for (Node* const node : all_.live) {
Index: src/compiler/node.h
diff --git a/src/compiler/node.h b/src/compiler/node.h
index 57a0ebb72e247e23a4c41b9375b3aff53b8eb7c1..ae160335b9ccb2f404b1ed5b4f7cd2765b37ac21 100644
--- a/src/compiler/node.h
+++ b/src/compiler/node.h
@@ -249,6 +249,7 @@ std::ostream& operator<<(std::ostream& os, const Node& n);

 // Typedefs to shorten commonly used Node containers.
 typedef ZoneDeque<Node*> NodeDeque;
+typedef ZoneSet<Node*> NodeSet;
 typedef ZoneVector<Node*> NodeVector;
 typedef ZoneVector<NodeVector> NodeVectorVector;

Index: test/cctest/compiler/test-osr.cc
diff --git a/test/cctest/compiler/test-osr.cc b/test/cctest/compiler/test-osr.cc index e3963901a53584bfa2357609ad7bc9e37b8d2a84..83e0fd0516221ad0bb6976c71d28f8df1a795b5d 100644
--- a/test/cctest/compiler/test-osr.cc
+++ b/test/cctest/compiler/test-osr.cc
@@ -122,7 +122,12 @@ class OsrDeconstructorTester : public HandleAndZoneScope {
     CHECK(!nodes.IsLive(osr_normal_entry));
     CHECK(!nodes.IsLive(osr_loop_entry));
     // 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());
+      }
+    }
   }
 };



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to