Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_COMPILER_NODE_MARKER_H_ |
| 6 | #define V8_COMPILER_NODE_MARKER_H_ |
| 7 | |
| 8 | #include "src/compiler/node.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | namespace compiler { |
| 13 | |
| 14 | // Forward declarations. |
| 15 | class Graph; |
| 16 | |
| 17 | |
| 18 | // Base class for templatized NodeMarkers. |
| 19 | class NodeMarkerBase { |
| 20 | public: |
| 21 | NodeMarkerBase(Graph* graph, uint32_t num_states); |
| 22 | |
| 23 | V8_INLINE Mark Get(Node* node) { |
| 24 | Mark mark = node->mark(); |
| 25 | if (mark < mark_min_) { |
| 26 | mark = mark_min_; |
| 27 | node->set_mark(mark_min_); |
| 28 | } |
| 29 | DCHECK_LT(mark, mark_max_); |
| 30 | return mark - mark_min_; |
| 31 | } |
| 32 | V8_INLINE void Set(Node* node, Mark mark) { |
| 33 | DCHECK_LT(mark, mark_max_ - mark_min_); |
| 34 | DCHECK_LT(node->mark(), mark_max_); |
| 35 | node->set_mark(mark + mark_min_); |
| 36 | } |
| 37 | |
| 38 | private: |
| 39 | Mark const mark_min_; |
| 40 | Mark const mark_max_; |
| 41 | |
| 42 | DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase); |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | // A NodeMarker uses monotonically increasing marks to assign local "states" |
| 47 | // to nodes. Only one NodeMarker per graph is valid at a given time. |
| 48 | template <typename State> |
| 49 | class NodeMarker : public NodeMarkerBase { |
| 50 | public: |
| 51 | V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) |
| 52 | : NodeMarkerBase(graph, num_states) {} |
| 53 | |
| 54 | V8_INLINE State Get(Node* node) { |
| 55 | return static_cast<State>(NodeMarkerBase::Get(node)); |
| 56 | } |
| 57 | |
| 58 | V8_INLINE void Set(Node* node, State state) { |
| 59 | NodeMarkerBase::Set(node, static_cast<Mark>(state)); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | } // namespace compiler |
| 64 | } // namespace internal |
| 65 | } // namespace v8 |
| 66 | |
| 67 | #endif // V8_COMPILER_NODE_MARKER_H_ |