node-marker.h 1.61 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_NODE_MARKER_H_
#define V8_COMPILER_NODE_MARKER_H_

8
#include "src/compiler/node.h"
9 10 11 12 13 14 15 16 17 18 19 20 21 22

namespace v8 {
namespace internal {
namespace compiler {

// Forward declarations.
class Graph;


// Base class for templatized NodeMarkers.
class NodeMarkerBase {
 public:
  NodeMarkerBase(Graph* graph, uint32_t num_states);

23 24 25 26 27 28 29 30 31 32 33 34 35 36
  V8_INLINE Mark Get(Node* node) {
    Mark mark = node->mark();
    if (mark < mark_min_) {
      mark = mark_min_;
      node->set_mark(mark_min_);
    }
    DCHECK_LT(mark, mark_max_);
    return mark - mark_min_;
  }
  V8_INLINE void Set(Node* node, Mark mark) {
    DCHECK_LT(mark, mark_max_ - mark_min_);
    DCHECK_LT(node->mark(), mark_max_);
    node->set_mark(mark + mark_min_);
  }
37 38

 private:
39 40
  Mark const mark_min_;
  Mark const mark_max_;
41 42 43 44 45 46 47 48 49 50

  DISALLOW_COPY_AND_ASSIGN(NodeMarkerBase);
};


// A NodeMarker uses monotonically increasing marks to assign local "states"
// to nodes. Only one NodeMarker per graph is valid at a given time.
template <typename State>
class NodeMarker : public NodeMarkerBase {
 public:
51
  V8_INLINE NodeMarker(Graph* graph, uint32_t num_states)
52 53
      : NodeMarkerBase(graph, num_states) {}

54
  V8_INLINE State Get(Node* node) {
55 56 57
    return static_cast<State>(NodeMarkerBase::Get(node));
  }

58
  V8_INLINE void Set(Node* node, State state) {
59 60 61 62 63 64 65 66 67
    NodeMarkerBase::Set(node, static_cast<Mark>(state));
  }
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_NODE_MARKER_H_