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_NODE_H_ | 5 #ifndef V8_COMPILER_NODE_H_ |
6 #define V8_COMPILER_NODE_H_ | 6 #define V8_COMPILER_NODE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "src/compiler/generic-algorithm.h" | 12 #include "src/compiler/generic-algorithm.h" |
13 #include "src/compiler/generic-node.h" | 13 #include "src/compiler/generic-node.h" |
14 #include "src/compiler/opcodes.h" | 14 #include "src/compiler/opcodes.h" |
15 #include "src/compiler/operator.h" | 15 #include "src/compiler/operator.h" |
16 #include "src/types.h" | 16 #include "src/types.h" |
17 #include "src/zone.h" | 17 #include "src/zone.h" |
18 #include "src/zone-allocator.h" | 18 #include "src/zone-allocator.h" |
19 | 19 |
20 namespace v8 { | 20 namespace v8 { |
21 namespace internal { | 21 namespace internal { |
22 namespace compiler { | 22 namespace compiler { |
23 | 23 |
| 24 // Marks are used during traversal of the graph to distinguish states of nodes. |
| 25 // Each node has a mark which is a monotonically increasing integer, and a |
| 26 // {NodeMarker} has a range of values that indicate states of a node. |
| 27 typedef uint32_t Mark; |
| 28 |
24 class NodeData { | 29 class NodeData { |
25 public: | 30 public: |
26 const Operator* op() const { return op_; } | 31 const Operator* op() const { return op_; } |
27 void set_op(const Operator* op) { op_ = op; } | 32 void set_op(const Operator* op) { op_ = op; } |
28 | 33 |
29 IrOpcode::Value opcode() const { | 34 IrOpcode::Value opcode() const { |
30 DCHECK(op_->opcode() <= IrOpcode::kLast); | 35 DCHECK(op_->opcode() <= IrOpcode::kLast); |
31 return static_cast<IrOpcode::Value>(op_->opcode()); | 36 return static_cast<IrOpcode::Value>(op_->opcode()); |
32 } | 37 } |
33 | 38 |
34 protected: | 39 protected: |
35 const Operator* op_; | 40 const Operator* op_; |
36 Bounds bounds_; | 41 Bounds bounds_; |
| 42 Mark mark_; |
37 explicit NodeData(Zone* zone) {} | 43 explicit NodeData(Zone* zone) {} |
38 | 44 |
39 friend class NodeProperties; | 45 friend class NodeProperties; |
| 46 template <typename State> |
| 47 friend class NodeMarker; |
| 48 |
40 Bounds bounds() { return bounds_; } | 49 Bounds bounds() { return bounds_; } |
41 void set_bounds(Bounds b) { bounds_ = b; } | 50 void set_bounds(Bounds b) { bounds_ = b; } |
| 51 |
| 52 // Only NodeMarkers should manipulate the marks on nodes. |
| 53 Mark mark() { return mark_; } |
| 54 void set_mark(Mark mark) { mark_ = mark; } |
42 }; | 55 }; |
43 | 56 |
44 // A Node is the basic primitive of an IR graph. In addition to the members | 57 // A Node is the basic primitive of an IR graph. In addition to the members |
45 // inherited from Vector, Nodes only contain a mutable Operator that may change | 58 // inherited from Vector, Nodes only contain a mutable Operator that may change |
46 // during compilation, e.g. during lowering passes. Other information that | 59 // during compilation, e.g. during lowering passes. Other information that |
47 // needs to be associated with Nodes during compilation must be stored | 60 // needs to be associated with Nodes during compilation must be stored |
48 // out-of-line indexed by the Node's id. | 61 // out-of-line indexed by the Node's id. |
49 class Node FINAL : public GenericNode<NodeData, Node> { | 62 class Node FINAL : public GenericNode<NodeData, Node> { |
50 public: | 63 public: |
51 Node(GenericGraphBase* graph, int input_count, int reserve_input_count) | 64 Node(GenericGraphBase* graph, int input_count, int reserve_input_count) |
52 : GenericNode<NodeData, Node>(graph, input_count, reserve_input_count) {} | 65 : GenericNode<NodeData, Node>(graph, input_count, reserve_input_count) {} |
53 | 66 |
54 void Initialize(const Operator* op) { set_op(op); } | 67 void Initialize(const Operator* op) { |
| 68 set_op(op); |
| 69 set_mark(0); |
| 70 } |
55 | 71 |
56 bool IsDead() const { return InputCount() > 0 && InputAt(0) == NULL; } | 72 bool IsDead() const { return InputCount() > 0 && InputAt(0) == NULL; } |
57 void Kill(); | 73 void Kill(); |
58 | 74 |
59 void CollectProjections(ZoneVector<Node*>* projections); | 75 void CollectProjections(ZoneVector<Node*>* projections); |
60 Node* FindProjection(size_t projection_index); | 76 Node* FindProjection(size_t projection_index); |
61 }; | 77 }; |
62 | 78 |
63 std::ostream& operator<<(std::ostream& os, const Node& n); | 79 std::ostream& operator<<(std::ostream& os, const Node& n); |
64 | 80 |
(...skipping 21 matching lines...) Expand all Loading... |
86 template <typename T> | 102 template <typename T> |
87 static inline const T& OpParameter(const Node* node) { | 103 static inline const T& OpParameter(const Node* node) { |
88 return OpParameter<T>(node->op()); | 104 return OpParameter<T>(node->op()); |
89 } | 105 } |
90 | 106 |
91 } // namespace compiler | 107 } // namespace compiler |
92 } // namespace internal | 108 } // namespace internal |
93 } // namespace v8 | 109 } // namespace v8 |
94 | 110 |
95 #endif // V8_COMPILER_NODE_H_ | 111 #endif // V8_COMPILER_NODE_H_ |
OLD | NEW |