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

Unified Diff: src/compiler/generic-algorithm.h

Issue 760493003: Make generic algorithm a little less generic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-generic-stuff-3
Patch Set: Rebased. Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | src/compiler/generic-algorithm-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/generic-algorithm.h
diff --git a/src/compiler/generic-algorithm.h b/src/compiler/generic-algorithm.h
index 4b695c714d851ca93c52e2d7229351dadb80384f..391757ecb8beefa068b528c57240144879ef8f20 100644
--- a/src/compiler/generic-algorithm.h
+++ b/src/compiler/generic-algorithm.h
@@ -6,7 +6,10 @@
#define V8_COMPILER_GENERIC_ALGORITHM_H_
#include <stack>
+#include <vector>
+#include "src/compiler/graph.h"
+#include "src/compiler/node.h"
#include "src/zone-containers.h"
namespace v8 {
@@ -18,40 +21,37 @@ class Node;
// GenericGraphVisit allows visitation of graphs of nodes and edges in pre- and
// post-order. Visitation uses an explicitly allocated stack rather than the
-// execution stack to avoid stack overflow. Although GenericGraphVisit is
-// primarily intended to traverse networks of nodes through their
-// dependencies and uses, it also can be used to visit any graph-like network
-// by specifying custom traits.
+// execution stack to avoid stack overflow.
class GenericGraphVisit {
public:
// struct Visitor {
- // void Pre(Traits::Node* current);
- // void Post(Traits::Node* current);
- // void PreEdge(Traits::Node* from, int index, Traits::Node* to);
- // void PostEdge(Traits::Node* from, int index, Traits::Node* to);
+ // void Pre(Node* current);
+ // void Post(Node* current);
+ // void PreEdge(Node* from, int index, Node* to);
+ // void PostEdge(Node* from, int index, Node* to);
// }
- template <class Visitor, class Traits, class RootIterator>
- static void Visit(Graph* graph, Zone* zone, RootIterator root_begin,
- RootIterator root_end, Visitor* visitor) {
- typedef typename Traits::Node Node;
- typedef typename Traits::Iterator Iterator;
+ template <class Visitor>
+ static void Visit(Graph* graph, Zone* zone, Node** root_begin,
+ Node** root_end, Visitor* visitor) {
+ typedef typename Node::InputEdges::iterator Iterator;
typedef std::pair<Iterator, Iterator> NodeState;
typedef std::stack<NodeState, ZoneDeque<NodeState> > NodeStateStack;
NodeStateStack stack((ZoneDeque<NodeState>(zone)));
- BoolVector visited(Traits::max_id(graph), false, zone);
+ BoolVector visited(graph->NodeCount(), false, zone);
Node* current = *root_begin;
while (true) {
DCHECK(current != NULL);
const int id = current->id();
DCHECK(id >= 0);
- DCHECK(id < Traits::max_id(graph)); // Must be a valid id.
+ DCHECK(id < graph->NodeCount()); // Must be a valid id.
bool visit = !GetVisited(&visited, id);
if (visit) {
visitor->Pre(current);
SetVisited(&visited, id);
}
- Iterator begin(visit ? Traits::begin(current) : Traits::end(current));
- Iterator end(Traits::end(current));
+ Iterator begin(visit ? current->input_edges().begin()
+ : current->input_edges().end());
+ Iterator end(current->input_edges().end());
stack.push(NodeState(begin, end));
Node* post_order_node = current;
while (true) {
@@ -67,27 +67,26 @@ class GenericGraphVisit {
current = *root_begin;
break;
}
- post_order_node = Traits::from(stack.top().first);
+ post_order_node = (*stack.top().first).from();
visit = true;
} else {
- visitor->PreEdge(Traits::from(top.first), (*top.first).index(),
- Traits::to(top.first));
- current = Traits::to(top.first);
+ visitor->PreEdge((*top.first).from(), (*top.first).index(),
+ (*top.first).to());
+ current = (*top.first).to();
if (!GetVisited(&visited, current->id())) break;
}
top = stack.top();
- visitor->PostEdge(Traits::from(top.first), (*top.first).index(),
- Traits::to(top.first));
+ visitor->PostEdge((*top.first).from(), (*top.first).index(),
+ (*top.first).to());
++stack.top().first;
}
}
}
- template <class Visitor, class Traits>
- static void Visit(Graph* graph, Zone* zone, typename Traits::Node* current,
- Visitor* visitor) {
- typename Traits::Node* array[] = {current};
- Visit<Visitor, Traits>(graph, zone, &array[0], &array[1], visitor);
+ template <class Visitor>
+ static void Visit(Graph* graph, Zone* zone, Node* current, Visitor* visitor) {
+ Node* array[] = {current};
+ Visit<Visitor>(graph, zone, &array[0], &array[1], visitor);
}
struct NullNodeVisitor {
@@ -111,8 +110,11 @@ class GenericGraphVisit {
return visited->at(id);
}
};
-}
-}
-} // namespace v8::internal::compiler
+
+typedef GenericGraphVisit::NullNodeVisitor NullNodeVisitor;
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
#endif // V8_COMPILER_GENERIC_ALGORITHM_H_
« no previous file with comments | « BUILD.gn ('k') | src/compiler/generic-algorithm-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698