OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_MARKER_H_ | 5 #ifndef V8_COMPILER_NODE_MARKER_H_ |
6 #define V8_COMPILER_NODE_MARKER_H_ | 6 #define V8_COMPILER_NODE_MARKER_H_ |
7 | 7 |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 24 matching lines...) Expand all Loading... |
35 node->set_mark(mark + mark_min_); | 35 node->set_mark(mark + mark_min_); |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 Mark const mark_min_; | 39 Mark const mark_min_; |
40 Mark const mark_max_; | 40 Mark const mark_max_; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase); | 42 DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase); |
43 }; | 43 }; |
44 | 44 |
45 | 45 // A NodeMarker assigns a local "state" to every node of a graph in constant |
46 // A NodeMarker uses monotonically increasing marks to assign local "states" | 46 // memory. Only one NodeMarker per graph is valid at a given time, that is, |
47 // to nodes. Only one NodeMarker per graph is valid at a given time. | 47 // after you create a NodeMarker you should no longer use NodeMarkers that |
| 48 // were created earlier. Internally, the local state is stored in the Node |
| 49 // structure. |
| 50 // |
| 51 // When you initialize a NodeMarker, all the local states are conceptually |
| 52 // set to State(0) in constant time. |
| 53 // |
| 54 // In its current implementation, in debug mode NodeMarker will try to |
| 55 // (efficiently) detect invalid use of an older NodeMarker. Namely, if you get |
| 56 // or set a node with a NodeMarker, and then get or set that node |
| 57 // with an older NodeMarker you will get a crash. |
| 58 // |
| 59 // GraphReducer uses a NodeMarker, so individual Reducers cannot use a |
| 60 // NodeMarker. |
48 template <typename State> | 61 template <typename State> |
49 class NodeMarker : public NodeMarkerBase { | 62 class NodeMarker : public NodeMarkerBase { |
50 public: | 63 public: |
51 V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) | 64 V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) |
52 : NodeMarkerBase(graph, num_states) {} | 65 : NodeMarkerBase(graph, num_states) {} |
53 | 66 |
54 V8_INLINE State Get(Node* node) { | 67 V8_INLINE State Get(Node* node) { |
55 return static_cast<State>(NodeMarkerBase::Get(node)); | 68 return static_cast<State>(NodeMarkerBase::Get(node)); |
56 } | 69 } |
57 | 70 |
58 V8_INLINE void Set(Node* node, State state) { | 71 V8_INLINE void Set(Node* node, State state) { |
59 NodeMarkerBase::Set(node, static_cast<Mark>(state)); | 72 NodeMarkerBase::Set(node, static_cast<Mark>(state)); |
60 } | 73 } |
61 }; | 74 }; |
62 | 75 |
63 } // namespace compiler | 76 } // namespace compiler |
64 } // namespace internal | 77 } // namespace internal |
65 } // namespace v8 | 78 } // namespace v8 |
66 | 79 |
67 #endif // V8_COMPILER_NODE_MARKER_H_ | 80 #endif // V8_COMPILER_NODE_MARKER_H_ |
OLD | NEW |