| 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_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 | |
| 23 class Graph : public GenericGraph<Node> { | 22 class Graph : public GenericGraph<Node> { |
| 24 public: | 23 public: |
| 25 explicit Graph(Zone* zone); | 24 explicit Graph(Zone* zone); |
| 26 | 25 |
| 27 // Base implementation used by all factory methods. | 26 // Base implementation used by all factory methods. |
| 28 Node* NewNode(const Operator* op, int input_count, Node** inputs, | 27 Node* NewNode(const Operator* op, int input_count, Node** inputs, |
| 29 bool incomplete = false); | 28 bool incomplete = false); |
| 30 | 29 |
| 31 // Factories for nodes with static input counts. | 30 // Factories for nodes with static input counts. |
| 32 Node* NewNode(const Operator* op) { | 31 Node* NewNode(const Operator* op) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 70 } |
| 72 | 71 |
| 73 void RemoveDecorator(GraphDecorator* decorator) { | 72 void RemoveDecorator(GraphDecorator* decorator) { |
| 74 ZoneVector<GraphDecorator*>::iterator it = | 73 ZoneVector<GraphDecorator*>::iterator it = |
| 75 std::find(decorators_.begin(), decorators_.end(), decorator); | 74 std::find(decorators_.begin(), decorators_.end(), decorator); |
| 76 DCHECK(it != decorators_.end()); | 75 DCHECK(it != decorators_.end()); |
| 77 decorators_.erase(it, it + 1); | 76 decorators_.erase(it, it + 1); |
| 78 } | 77 } |
| 79 | 78 |
| 80 private: | 79 private: |
| 80 template <typename State> |
| 81 friend class NodeMarker; |
| 82 |
| 83 Mark mark_max_; |
| 81 ZoneVector<GraphDecorator*> decorators_; | 84 ZoneVector<GraphDecorator*> decorators_; |
| 82 }; | 85 }; |
| 83 | 86 |
| 84 | 87 |
| 88 // A NodeMarker uses monotonically increasing marks to assign local "states" |
| 89 // to nodes. Only one NodeMarker per graph is valid at a given time. |
| 90 template <typename State> |
| 91 class NodeMarker BASE_EMBEDDED { |
| 92 public: |
| 93 NodeMarker(Graph* graph, uint32_t num_states) |
| 94 : mark_min_(graph->mark_max_), mark_max_(graph->mark_max_ += num_states) { |
| 95 DCHECK(num_states > 0); // user error! |
| 96 DCHECK(mark_max_ > mark_min_); // check for wraparound. |
| 97 } |
| 98 |
| 99 State Get(Node* node) { |
| 100 Mark mark = node->mark(); |
| 101 if (mark < mark_min_) { |
| 102 mark = mark_min_; |
| 103 node->set_mark(mark_min_); |
| 104 } |
| 105 DCHECK_LT(mark, mark_max_); |
| 106 return static_cast<State>(mark - mark_min_); |
| 107 } |
| 108 |
| 109 void Set(Node* node, State state) { |
| 110 Mark local = static_cast<Mark>(state); |
| 111 DCHECK(local < (mark_max_ - mark_min_)); |
| 112 DCHECK_LT(node->mark(), mark_max_); |
| 113 node->set_mark(local + mark_min_); |
| 114 } |
| 115 |
| 116 private: |
| 117 Mark mark_min_; |
| 118 Mark mark_max_; |
| 119 }; |
| 120 |
| 121 |
| 122 // A graph decorator can be used to add behavior to the creation of nodes |
| 123 // in a graph. |
| 85 class GraphDecorator : public ZoneObject { | 124 class GraphDecorator : public ZoneObject { |
| 86 public: | 125 public: |
| 87 virtual ~GraphDecorator() {} | 126 virtual ~GraphDecorator() {} |
| 88 virtual void Decorate(Node* node) = 0; | 127 virtual void Decorate(Node* node) = 0; |
| 89 }; | 128 }; |
| 90 | 129 |
| 91 } // namespace compiler | 130 } // namespace compiler |
| 92 } // namespace internal | 131 } // namespace internal |
| 93 } // namespace v8 | 132 } // namespace v8 |
| 94 | 133 |
| 95 #endif // V8_COMPILER_GRAPH_H_ | 134 #endif // V8_COMPILER_GRAPH_H_ |
| OLD | NEW |