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

Side by Side Diff: src/compiler/graph.h

Issue 768763002: [turbofan] Add TraversalState and GraphTraversal and use them in GraphReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/graph-reducer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_GRAPH_H_ 5 #ifndef V8_COMPILER_GRAPH_H_
6 #define V8_COMPILER_GRAPH_H_ 6 #define V8_COMPILER_GRAPH_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "src/compiler/generic-algorithm.h" 11 #include "src/compiler/generic-algorithm.h"
12 #include "src/compiler/node.h" 12 #include "src/compiler/node.h"
13 #include "src/compiler/node-aux-data.h" 13 #include "src/compiler/node-aux-data.h"
14 #include "src/compiler/source-position.h" 14 #include "src/compiler/source-position.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 namespace compiler { 18 namespace compiler {
19 19
20 class GraphDecorator; 20 class GraphDecorator;
21 21
22 template <typename LocalState>
Michael Starzinger 2014/11/28 11:27:27 nit: Can we use s/LocalState/State/ here for reada
23 class GraphTraversal : public ZoneObject {
Michael Starzinger 2014/11/28 11:27:27 As discussed offline: Since this is not really a "
24 public:
25 LocalState GetState(Node* node) {
26 TraversalState state = node->traversal_state();
27 if (state < traversal_state_min_) {
28 state = traversal_state_min_;
29 node->set_traversal_state(traversal_state_min_);
30 }
31 DCHECK_LT(state, traversal_state_max_);
32 return static_cast<LocalState>(state - traversal_state_min_);
33 }
34
35 void SetState(Node* node, LocalState state) {
36 TraversalState local = static_cast<TraversalState>(state);
37 DCHECK(local >= 0 && local < (traversal_state_max_ - traversal_state_min_));
38 DCHECK_LT(node->traversal_state(), traversal_state_max_);
39 node->set_traversal_state(local + traversal_state_min_);
40 }
41
42 private:
43 GraphTraversal(TraversalState min, TraversalState max)
44 : traversal_state_min_(min), traversal_state_max_(max) {}
45
46 TraversalState traversal_state_min_;
47 TraversalState traversal_state_max_;
48
49 friend class Graph;
50 };
22 51
23 class Graph : public GenericGraph<Node> { 52 class Graph : public GenericGraph<Node> {
24 public: 53 public:
25 explicit Graph(Zone* zone); 54 explicit Graph(Zone* zone);
26 55
27 // Base implementation used by all factory methods. 56 // Base implementation used by all factory methods.
28 Node* NewNode(const Operator* op, int input_count, Node** inputs, 57 Node* NewNode(const Operator* op, int input_count, Node** inputs,
29 bool incomplete = false); 58 bool incomplete = false);
30 59
31 // Factories for nodes with static input counts. 60 // Factories for nodes with static input counts.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 decorators_.push_back(decorator); 105 decorators_.push_back(decorator);
77 } 106 }
78 107
79 void RemoveDecorator(GraphDecorator* decorator) { 108 void RemoveDecorator(GraphDecorator* decorator) {
80 ZoneVector<GraphDecorator*>::iterator it = 109 ZoneVector<GraphDecorator*>::iterator it =
81 std::find(decorators_.begin(), decorators_.end(), decorator); 110 std::find(decorators_.begin(), decorators_.end(), decorator);
82 DCHECK(it != decorators_.end()); 111 DCHECK(it != decorators_.end());
83 decorators_.erase(it, it + 1); 112 decorators_.erase(it, it + 1);
84 } 113 }
85 114
115 template <typename LocalState>
Michael Starzinger 2014/11/28 11:27:27 nit: Can we use s/LocalState/State/ here for reada
116 GraphTraversal<LocalState>* NewTraversal(Zone* local_zone,
117 uint32_t num_states) {
118 TraversalState min = traversal_state_max_;
119 TraversalState max = (traversal_state_max_ += num_states);
120 return new (local_zone) GraphTraversal<LocalState>(min, max);
121 }
122
86 private: 123 private:
124 TraversalState traversal_state_max_;
87 ZoneVector<GraphDecorator*> decorators_; 125 ZoneVector<GraphDecorator*> decorators_;
88 }; 126 };
89 127
90 128
91 class GraphDecorator : public ZoneObject { 129 class GraphDecorator : public ZoneObject {
92 public: 130 public:
93 virtual ~GraphDecorator() {} 131 virtual ~GraphDecorator() {}
94 virtual void Decorate(Node* node) = 0; 132 virtual void Decorate(Node* node) = 0;
95 }; 133 };
96 134
97 } // namespace compiler 135 } // namespace compiler
98 } // namespace internal 136 } // namespace internal
99 } // namespace v8 137 } // namespace v8
100 138
101 #endif // V8_COMPILER_GRAPH_H_ 139 #endif // V8_COMPILER_GRAPH_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/graph-reducer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698