| 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 { | 
|  11 namespace internal { |  11 namespace internal { | 
|  12 namespace compiler { |  12 namespace compiler { | 
|  13  |  13  | 
|  14 // Forward declarations. |  14 // Forward declarations. | 
|  15 class Graph; |  15 class Graph; | 
|  16  |  16  | 
|  17  |  17  | 
|  18 // Base class for templatized NodeMarkers. |  18 // Base class for templatized NodeMarkers. | 
|  19 class NodeMarkerBase { |  19 class NodeMarkerBase { | 
|  20  public: |  20  public: | 
|  21   NodeMarkerBase(Graph* graph, uint32_t num_states); |  21   NodeMarkerBase(Graph* graph, uint32_t num_states); | 
|  22  |  22  | 
|  23   V8_INLINE Mark Get(Node* node) { |  23   V8_INLINE Mark Get(const Node* node) { | 
|  24     Mark mark = node->mark(); |  24     Mark mark = node->mark(); | 
|  25     if (mark < mark_min_) { |  25     if (mark < mark_min_) { | 
|  26       mark = mark_min_; |  26       return 0; | 
|  27       node->set_mark(mark_min_); |  | 
|  28     } |  27     } | 
|  29     DCHECK_LT(mark, mark_max_); |  28     DCHECK_LT(mark, mark_max_); | 
|  30     return mark - mark_min_; |  29     return mark - mark_min_; | 
|  31   } |  30   } | 
|  32   V8_INLINE void Set(Node* node, Mark mark) { |  31   V8_INLINE void Set(Node* node, Mark mark) { | 
|  33     DCHECK_LT(mark, mark_max_ - mark_min_); |  32     DCHECK_LT(mark, mark_max_ - mark_min_); | 
|  34     DCHECK_LT(node->mark(), mark_max_); |  33     DCHECK_LT(node->mark(), mark_max_); | 
|  35     node->set_mark(mark + mark_min_); |  34     node->set_mark(mark + mark_min_); | 
|  36   } |  35   } | 
|  37  |  36  | 
|  38  private: |  37  private: | 
|  39   Mark const mark_min_; |  38   Mark const mark_min_; | 
|  40   Mark const mark_max_; |  39   Mark const mark_max_; | 
|  41  |  40  | 
|  42   DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase); |  41   DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase); | 
|  43 }; |  42 }; | 
|  44  |  43  | 
|  45 // A NodeMarker assigns a local "state" to every node of a graph in constant |  44 // A NodeMarker assigns a local "state" to every node of a graph in constant | 
|  46 // memory. Only one NodeMarker per graph is valid at a given time, that is, |  45 // memory. Only one NodeMarker per graph is valid at a given time, that is, | 
|  47 // after you create a NodeMarker you should no longer use NodeMarkers that |  46 // 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 |  47 // were created earlier. Internally, the local state is stored in the Node | 
|  49 // structure. |  48 // structure. | 
|  50 // |  49 // | 
|  51 // When you initialize a NodeMarker, all the local states are conceptually |  50 // When you initialize a NodeMarker, all the local states are conceptually | 
|  52 // set to State(0) in constant time. |  51 // set to State(0) in constant time. | 
|  53 // |  52 // | 
|  54 // In its current implementation, in debug mode NodeMarker will try to |  53 // In its current implementation, in debug mode NodeMarker will try to | 
|  55 // (efficiently) detect invalid use of an older NodeMarker. Namely, if you get |  54 // (efficiently) detect invalid use of an older NodeMarker. Namely, if you set a | 
|  56 // or set a node with a NodeMarker, and then get or set that node |  55 // node with a NodeMarker, and then get or set that node with an older | 
|  57 // with an older NodeMarker you will get a crash. |  56 // NodeMarker you will get a crash. | 
|  58 // |  57 // | 
|  59 // GraphReducer uses a NodeMarker, so individual Reducers cannot use a |  58 // GraphReducer uses a NodeMarker, so individual Reducers cannot use a | 
|  60 // NodeMarker. |  59 // NodeMarker. | 
|  61 template <typename State> |  60 template <typename State> | 
|  62 class NodeMarker : public NodeMarkerBase { |  61 class NodeMarker : public NodeMarkerBase { | 
|  63  public: |  62  public: | 
|  64   V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) |  63   V8_INLINE NodeMarker(Graph* graph, uint32_t num_states) | 
|  65       : NodeMarkerBase(graph, num_states) {} |  64       : NodeMarkerBase(graph, num_states) {} | 
|  66  |  65  | 
|  67   V8_INLINE State Get(Node* node) { |  66   V8_INLINE State Get(const Node* node) { | 
|  68     return static_cast<State>(NodeMarkerBase::Get(node)); |  67     return static_cast<State>(NodeMarkerBase::Get(node)); | 
|  69   } |  68   } | 
|  70  |  69  | 
|  71   V8_INLINE void Set(Node* node, State state) { |  70   V8_INLINE void Set(Node* node, State state) { | 
|  72     NodeMarkerBase::Set(node, static_cast<Mark>(state)); |  71     NodeMarkerBase::Set(node, static_cast<Mark>(state)); | 
|  73   } |  72   } | 
|  74 }; |  73 }; | 
|  75  |  74  | 
|  76 }  // namespace compiler |  75 }  // namespace compiler | 
|  77 }  // namespace internal |  76 }  // namespace internal | 
|  78 }  // namespace v8 |  77 }  // namespace v8 | 
|  79  |  78  | 
|  80 #endif  // V8_COMPILER_NODE_MARKER_H_ |  79 #endif  // V8_COMPILER_NODE_MARKER_H_ | 
| OLD | NEW |