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

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

Issue 838783002: [turbofan] Cleanup Graph and related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Parameter pack causes compile errors. Created 5 years, 11 months 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 | « src/compiler/control-reducer.cc ('k') | src/compiler/graph.cc » ('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 "src/zone.h"
9 #include <set> 9 #include "src/zone-containers.h"
10
11 #include "src/compiler/node.h"
12 #include "src/compiler/node-aux-data.h"
13 #include "src/compiler/source-position.h"
14 10
15 namespace v8 { 11 namespace v8 {
16 namespace internal { 12 namespace internal {
17 namespace compiler { 13 namespace compiler {
18 14
19 // Forward declarations. 15 // Forward declarations.
20 class GraphDecorator; 16 class GraphDecorator;
17 class Node;
18 class Operator;
19
20
21 // Marks are used during traversal of the graph to distinguish states of nodes.
22 // Each node has a mark which is a monotonically increasing integer, and a
23 // {NodeMarker} has a range of values that indicate states of a node.
24 typedef uint32_t Mark;
25
26
27 // NodeIds are identifying numbers for nodes that can be used to index auxiliary
28 // out-of-line data associated with each node.
29 typedef int32_t NodeId;
21 30
22 31
23 class Graph : public ZoneObject { 32 class Graph : public ZoneObject {
24 public: 33 public:
25 explicit Graph(Zone* zone); 34 explicit Graph(Zone* zone);
26 35
27 // Base implementation used by all factory methods. 36 // Base implementation used by all factory methods.
28 Node* NewNode(const Operator* op, int input_count, Node** inputs, 37 Node* NewNode(const Operator* op, int input_count, Node** inputs,
29 bool incomplete = false); 38 bool incomplete = false);
30 39
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 template <class Visitor> 73 template <class Visitor>
65 inline void VisitNodeInputsFromEnd(Visitor* visitor); 74 inline void VisitNodeInputsFromEnd(Visitor* visitor);
66 75
67 Zone* zone() const { return zone_; } 76 Zone* zone() const { return zone_; }
68 Node* start() const { return start_; } 77 Node* start() const { return start_; }
69 Node* end() const { return end_; } 78 Node* end() const { return end_; }
70 79
71 void SetStart(Node* start) { start_ = start; } 80 void SetStart(Node* start) { start_ = start; }
72 void SetEnd(Node* end) { end_ = end; } 81 void SetEnd(Node* end) { end_ = end; }
73 82
74 NodeId NextNodeID() { return next_node_id_++; } 83 int NodeCount() const { return next_node_id_; }
75 NodeId NodeCount() const { return next_node_id_; }
76 84
77 void Decorate(Node* node); 85 void Decorate(Node* node);
78 86 void AddDecorator(GraphDecorator* decorator);
79 void AddDecorator(GraphDecorator* decorator) { 87 void RemoveDecorator(GraphDecorator* decorator);
80 decorators_.push_back(decorator);
81 }
82
83 void RemoveDecorator(GraphDecorator* decorator) {
84 ZoneVector<GraphDecorator*>::iterator it =
85 std::find(decorators_.begin(), decorators_.end(), decorator);
86 DCHECK(it != decorators_.end());
87 decorators_.erase(it, it + 1);
88 }
89 88
90 private: 89 private:
91 template <typename State> 90 friend class NodeMarkerBase;
92 friend class NodeMarker;
93 91
94 Zone* zone_; 92 inline NodeId NextNodeId();
93
94 Zone* const zone_;
95 Node* start_; 95 Node* start_;
96 Node* end_; 96 Node* end_;
97 Mark mark_max_; 97 Mark mark_max_;
98 NodeId next_node_id_; 98 NodeId next_node_id_;
99 ZoneVector<GraphDecorator*> decorators_; 99 ZoneVector<GraphDecorator*> decorators_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(Graph); 101 DISALLOW_COPY_AND_ASSIGN(Graph);
102 }; 102 };
103 103
104 104
105 // A NodeMarker uses monotonically increasing marks to assign local "states"
106 // to nodes. Only one NodeMarker per graph is valid at a given time.
107 template <typename State>
108 class NodeMarker BASE_EMBEDDED {
109 public:
110 NodeMarker(Graph* graph, uint32_t num_states)
111 : mark_min_(graph->mark_max_), mark_max_(graph->mark_max_ += num_states) {
112 DCHECK(num_states > 0); // user error!
113 DCHECK(mark_max_ > mark_min_); // check for wraparound.
114 }
115
116 State Get(Node* node) {
117 Mark mark = node->mark();
118 if (mark < mark_min_) {
119 mark = mark_min_;
120 node->set_mark(mark_min_);
121 }
122 DCHECK_LT(mark, mark_max_);
123 return static_cast<State>(mark - mark_min_);
124 }
125
126 void Set(Node* node, State state) {
127 Mark local = static_cast<Mark>(state);
128 DCHECK(local < (mark_max_ - mark_min_));
129 DCHECK_LT(node->mark(), mark_max_);
130 node->set_mark(local + mark_min_);
131 }
132
133 private:
134 Mark mark_min_;
135 Mark mark_max_;
136 };
137
138
139 // A graph decorator can be used to add behavior to the creation of nodes 105 // A graph decorator can be used to add behavior to the creation of nodes
140 // in a graph. 106 // in a graph.
141 class GraphDecorator : public ZoneObject { 107 class GraphDecorator : public ZoneObject {
142 public: 108 public:
143 virtual ~GraphDecorator() {} 109 virtual ~GraphDecorator() {}
144 virtual void Decorate(Node* node) = 0; 110 virtual void Decorate(Node* node) = 0;
145 }; 111 };
146 112
147 } // namespace compiler 113 } // namespace compiler
148 } // namespace internal 114 } // namespace internal
149 } // namespace v8 115 } // namespace v8
150 116
151 #endif // V8_COMPILER_GRAPH_H_ 117 #endif // V8_COMPILER_GRAPH_H_
OLDNEW
« no previous file with comments | « src/compiler/control-reducer.cc ('k') | src/compiler/graph.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698