OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef V8_COMPILER_GENERIC_ALGORITHM_H_ | 5 #ifndef V8_COMPILER_GENERIC_ALGORITHM_H_ |
6 #define V8_COMPILER_GENERIC_ALGORITHM_H_ | 6 #define V8_COMPILER_GENERIC_ALGORITHM_H_ |
7 | 7 |
8 #include <stack> | 8 #include <stack> |
9 | 9 |
10 #include "src/compiler/generic-graph.h" | 10 #include "src/compiler/generic-graph.h" |
| 11 #include "src/compiler/generic-node.h" |
11 #include "src/zone-containers.h" | 12 #include "src/zone-containers.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 namespace compiler { | 16 namespace compiler { |
16 | 17 |
17 // GenericGraphVisit allows visitation of graphs of nodes and edges in pre- and | 18 // GenericGraphVisit allows visitation of graphs of nodes and edges in pre- and |
18 // post-order. Visitation uses an explicitly allocated stack rather than the | 19 // post-order. Visitation uses an explicitly allocated stack rather than the |
19 // execution stack to avoid stack overflow. Although GenericGraphVisit is | 20 // execution stack to avoid stack overflow. Although GenericGraphVisit is |
20 // primarily intended to traverse networks of nodes through their | 21 // primarily intended to traverse networks of nodes through their |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 template <class Visitor, class Traits> | 95 template <class Visitor, class Traits> |
95 static void Visit(GenericGraphBase* graph, Zone* zone, | 96 static void Visit(GenericGraphBase* graph, Zone* zone, |
96 typename Traits::Node* current, Visitor* visitor) { | 97 typename Traits::Node* current, Visitor* visitor) { |
97 typename Traits::Node* array[] = {current}; | 98 typename Traits::Node* array[] = {current}; |
98 Visit<Visitor, Traits>(graph, zone, &array[0], &array[1], visitor); | 99 Visit<Visitor, Traits>(graph, zone, &array[0], &array[1], visitor); |
99 } | 100 } |
100 | 101 |
101 template <class Node> | 102 template <class B, class S> |
102 struct NullNodeVisitor { | 103 struct NullNodeVisitor { |
103 Control Pre(Node* node) { return CONTINUE; } | 104 Control Pre(GenericNode<B, S>* node) { return CONTINUE; } |
104 Control Post(Node* node) { return CONTINUE; } | 105 Control Post(GenericNode<B, S>* node) { return CONTINUE; } |
105 void PreEdge(Node* from, int index, Node* to) {} | 106 void PreEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} |
106 void PostEdge(Node* from, int index, Node* to) {} | 107 void PostEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} |
107 }; | 108 }; |
108 | 109 |
109 private: | 110 private: |
110 static bool IsSkip(Control c) { return c & SKIP; } | 111 static bool IsSkip(Control c) { return c & SKIP; } |
111 static bool IsReenter(Control c) { return c & REENTER; } | 112 static bool IsReenter(Control c) { return c & REENTER; } |
112 | 113 |
113 // TODO(turbofan): resizing could be optionally templatized away. | 114 // TODO(turbofan): resizing could be optionally templatized away. |
114 static void SetVisited(BoolVector* visited, int id, bool value) { | 115 static void SetVisited(BoolVector* visited, int id, bool value) { |
115 if (id >= static_cast<int>(visited->size())) { | 116 if (id >= static_cast<int>(visited->size())) { |
116 // Resize and set all values to unvisited. | 117 // Resize and set all values to unvisited. |
117 visited->resize((3 * id) / 2, false); | 118 visited->resize((3 * id) / 2, false); |
118 } | 119 } |
119 visited->at(id) = value; | 120 visited->at(id) = value; |
120 } | 121 } |
121 | 122 |
122 static bool GetVisited(BoolVector* visited, int id) { | 123 static bool GetVisited(BoolVector* visited, int id) { |
123 if (id >= static_cast<int>(visited->size())) return false; | 124 if (id >= static_cast<int>(visited->size())) return false; |
124 return visited->at(id); | 125 return visited->at(id); |
125 } | 126 } |
126 }; | 127 }; |
127 } | 128 } |
128 } | 129 } |
129 } // namespace v8::internal::compiler | 130 } // namespace v8::internal::compiler |
130 | 131 |
131 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ | 132 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ |
OLD | NEW |