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 <deque> | 8 #include <deque> |
9 #include <stack> | 9 #include <stack> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 DEFER = SKIP | REENTER | 31 DEFER = SKIP | REENTER |
32 }; | 32 }; |
33 | 33 |
34 // struct Visitor { | 34 // struct Visitor { |
35 // Control Pre(Traits::Node* current); | 35 // Control Pre(Traits::Node* current); |
36 // Control Post(Traits::Node* current); | 36 // Control Post(Traits::Node* current); |
37 // void PreEdge(Traits::Node* from, int index, Traits::Node* to); | 37 // void PreEdge(Traits::Node* from, int index, Traits::Node* to); |
38 // void PostEdge(Traits::Node* from, int index, Traits::Node* to); | 38 // void PostEdge(Traits::Node* from, int index, Traits::Node* to); |
39 // } | 39 // } |
40 template <class Visitor, class Traits, class RootIterator> | 40 template <class Visitor, class Traits, class RootIterator> |
41 static void Visit(GenericGraphBase* graph, RootIterator root_begin, | 41 static void Visit(GenericGraphBase* graph, Zone* zone, |
42 RootIterator root_end, Visitor* visitor) { | 42 RootIterator root_begin, RootIterator root_end, |
43 // TODO(bmeurer): Pass "local" zone as parameter. | 43 Visitor* visitor) { |
44 Zone* zone = graph->zone(); | |
45 typedef typename Traits::Node Node; | 44 typedef typename Traits::Node Node; |
46 typedef typename Traits::Iterator Iterator; | 45 typedef typename Traits::Iterator Iterator; |
47 typedef std::pair<Iterator, Iterator> NodeState; | 46 typedef std::pair<Iterator, Iterator> NodeState; |
48 typedef zone_allocator<NodeState> ZoneNodeStateAllocator; | 47 typedef zone_allocator<NodeState> ZoneNodeStateAllocator; |
49 typedef std::deque<NodeState, ZoneNodeStateAllocator> NodeStateDeque; | 48 typedef std::deque<NodeState, ZoneNodeStateAllocator> NodeStateDeque; |
50 typedef std::stack<NodeState, NodeStateDeque> NodeStateStack; | 49 typedef std::stack<NodeState, NodeStateDeque> NodeStateStack; |
51 NodeStateStack stack((NodeStateDeque(ZoneNodeStateAllocator(zone)))); | 50 NodeStateStack stack((NodeStateDeque(ZoneNodeStateAllocator(zone)))); |
52 BoolVector visited(Traits::max_id(graph), false, ZoneBoolAllocator(zone)); | 51 BoolVector visited(Traits::max_id(graph), false, ZoneBoolAllocator(zone)); |
53 Node* current = *root_begin; | 52 Node* current = *root_begin; |
54 while (true) { | 53 while (true) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 89 } |
91 top = stack.top(); | 90 top = stack.top(); |
92 visitor->PostEdge(Traits::from(top.first), top.first.edge().index(), | 91 visitor->PostEdge(Traits::from(top.first), top.first.edge().index(), |
93 Traits::to(top.first)); | 92 Traits::to(top.first)); |
94 ++stack.top().first; | 93 ++stack.top().first; |
95 } | 94 } |
96 } | 95 } |
97 } | 96 } |
98 | 97 |
99 template <class Visitor, class Traits> | 98 template <class Visitor, class Traits> |
100 static void Visit(GenericGraphBase* graph, typename Traits::Node* current, | 99 static void Visit(GenericGraphBase* graph, Zone* zone, |
101 Visitor* visitor) { | 100 typename Traits::Node* current, Visitor* visitor) { |
102 typename Traits::Node* array[] = {current}; | 101 typename Traits::Node* array[] = {current}; |
103 Visit<Visitor, Traits>(graph, &array[0], &array[1], visitor); | 102 Visit<Visitor, Traits>(graph, zone, &array[0], &array[1], visitor); |
104 } | 103 } |
105 | 104 |
106 template <class B, class S> | 105 template <class B, class S> |
107 struct NullNodeVisitor { | 106 struct NullNodeVisitor { |
108 Control Pre(GenericNode<B, S>* node) { return CONTINUE; } | 107 Control Pre(GenericNode<B, S>* node) { return CONTINUE; } |
109 Control Post(GenericNode<B, S>* node) { return CONTINUE; } | 108 Control Post(GenericNode<B, S>* node) { return CONTINUE; } |
110 void PreEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} | 109 void PreEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} |
111 void PostEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} | 110 void PostEdge(GenericNode<B, S>* from, int index, GenericNode<B, S>* to) {} |
112 }; | 111 }; |
113 | 112 |
(...skipping 13 matching lines...) Expand all Loading... |
127 static bool GetVisited(BoolVector* visited, int id) { | 126 static bool GetVisited(BoolVector* visited, int id) { |
128 if (id >= static_cast<int>(visited->size())) return false; | 127 if (id >= static_cast<int>(visited->size())) return false; |
129 return visited->at(id); | 128 return visited->at(id); |
130 } | 129 } |
131 }; | 130 }; |
132 } | 131 } |
133 } | 132 } |
134 } // namespace v8::internal::compiler | 133 } // namespace v8::internal::compiler |
135 | 134 |
136 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ | 135 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ |
OLD | NEW |