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> | |
9 #include <stack> | 8 #include <stack> |
10 | 9 |
11 #include "src/compiler/generic-graph.h" | 10 #include "src/compiler/generic-graph.h" |
12 #include "src/compiler/generic-node.h" | 11 #include "src/compiler/generic-node.h" |
13 #include "src/zone-containers.h" | 12 #include "src/zone-containers.h" |
14 | 13 |
15 namespace v8 { | 14 namespace v8 { |
16 namespace internal { | 15 namespace internal { |
17 namespace compiler { | 16 namespace compiler { |
18 | 17 |
(...skipping 19 matching lines...) Expand all Loading... |
38 // void PostEdge(Traits::Node* from, int index, Traits::Node* to); | 37 // void PostEdge(Traits::Node* from, int index, Traits::Node* to); |
39 // } | 38 // } |
40 template <class Visitor, class Traits, class RootIterator> | 39 template <class Visitor, class Traits, class RootIterator> |
41 static void Visit(GenericGraphBase* graph, Zone* zone, | 40 static void Visit(GenericGraphBase* graph, Zone* zone, |
42 RootIterator root_begin, RootIterator root_end, | 41 RootIterator root_begin, RootIterator root_end, |
43 Visitor* visitor) { | 42 Visitor* visitor) { |
44 typedef typename Traits::Node Node; | 43 typedef typename Traits::Node Node; |
45 typedef typename Traits::Iterator Iterator; | 44 typedef typename Traits::Iterator Iterator; |
46 typedef std::pair<Iterator, Iterator> NodeState; | 45 typedef std::pair<Iterator, Iterator> NodeState; |
47 typedef zone_allocator<NodeState> ZoneNodeStateAllocator; | 46 typedef zone_allocator<NodeState> ZoneNodeStateAllocator; |
48 typedef std::deque<NodeState, ZoneNodeStateAllocator> NodeStateDeque; | 47 typedef std::stack<NodeState, ZoneDeque<NodeState>> NodeStateStack; |
49 typedef std::stack<NodeState, NodeStateDeque> NodeStateStack; | 48 NodeStateStack stack((ZoneDeque<NodeState>(zone))); |
50 NodeStateStack stack((NodeStateDeque(ZoneNodeStateAllocator(zone)))); | 49 BoolVector visited(Traits::max_id(graph), false, zone); |
51 BoolVector visited(Traits::max_id(graph), false, ZoneBoolAllocator(zone)); | |
52 Node* current = *root_begin; | 50 Node* current = *root_begin; |
53 while (true) { | 51 while (true) { |
54 DCHECK(current != NULL); | 52 DCHECK(current != NULL); |
55 const int id = current->id(); | 53 const int id = current->id(); |
56 DCHECK(id >= 0); | 54 DCHECK(id >= 0); |
57 DCHECK(id < Traits::max_id(graph)); // Must be a valid id. | 55 DCHECK(id < Traits::max_id(graph)); // Must be a valid id. |
58 bool visit = !GetVisited(&visited, id); | 56 bool visit = !GetVisited(&visited, id); |
59 if (visit) { | 57 if (visit) { |
60 Control control = visitor->Pre(current); | 58 Control control = visitor->Pre(current); |
61 visit = !IsSkip(control); | 59 visit = !IsSkip(control); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 static bool GetVisited(BoolVector* visited, int id) { | 124 static bool GetVisited(BoolVector* visited, int id) { |
127 if (id >= static_cast<int>(visited->size())) return false; | 125 if (id >= static_cast<int>(visited->size())) return false; |
128 return visited->at(id); | 126 return visited->at(id); |
129 } | 127 } |
130 }; | 128 }; |
131 } | 129 } |
132 } | 130 } |
133 } // namespace v8::internal::compiler | 131 } // namespace v8::internal::compiler |
134 | 132 |
135 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ | 133 #endif // V8_COMPILER_GENERIC_ALGORITHM_H_ |
OLD | NEW |