v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
node-marker.h
Go to the documentation of this file.
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
10namespace v8 {
11namespace internal {
12namespace compiler {
13
14// Forward declarations.
15class TFGraph;
16
17// Base class for templatized NodeMarkers.
19 public:
20 NodeMarkerBase(TFGraph* graph, uint32_t num_states);
23
24 V8_INLINE Mark Get(const Node* node) {
25 Mark mark = node->mark();
26 if (mark < mark_min_) {
27 return 0;
28 }
29 DCHECK_LT(mark, mark_max_);
30 return mark - mark_min_;
31 }
32 V8_INLINE void Set(Node* node, Mark mark) {
34 DCHECK_LT(node->mark(), mark_max_);
35 node->set_mark(mark + mark_min_);
36 }
37
38 private:
41};
42
43// A NodeMarker assigns a local "state" to every node of a graph in constant
44// memory. Only one NodeMarker per graph is valid at a given time, that is,
45// after you create a NodeMarker you should no longer use NodeMarkers that
46// were created earlier. Internally, the local state is stored in the Node
47// structure.
48//
49// When you initialize a NodeMarker, all the local states are conceptually
50// set to State(0) in constant time.
51//
52// In its current implementation, in debug mode NodeMarker will try to
53// (efficiently) detect invalid use of an older NodeMarker. Namely, if you set a
54// node with a NodeMarker, and then get or set that node with an older
55// NodeMarker you will get a crash.
56//
57// GraphReducer uses a NodeMarker, so individual Reducers cannot use a
58// NodeMarker.
59template <typename State>
60class NodeMarker : public NodeMarkerBase {
61 public:
62 V8_INLINE NodeMarker(TFGraph* graph, uint32_t num_states)
63 : NodeMarkerBase(graph, num_states) {}
64
65 V8_INLINE State Get(const Node* node) {
66 return static_cast<State>(NodeMarkerBase::Get(node));
67 }
68
69 V8_INLINE void Set(Node* node, State state) {
70 NodeMarkerBase::Set(node, static_cast<Mark>(state));
71 }
72};
73
74} // namespace compiler
75} // namespace internal
76} // namespace v8
77
78#endif // V8_COMPILER_NODE_MARKER_H_
NodeMarkerBase(TFGraph *graph, uint32_t num_states)
V8_INLINE Mark Get(const Node *node)
Definition node-marker.h:24
NodeMarkerBase(const NodeMarkerBase &)=delete
V8_INLINE void Set(Node *node, Mark mark)
Definition node-marker.h:32
NodeMarkerBase & operator=(const NodeMarkerBase &)=delete
V8_INLINE NodeMarker(TFGraph *graph, uint32_t num_states)
Definition node-marker.h:62
V8_INLINE void Set(Node *node, State state)
Definition node-marker.h:69
V8_INLINE State Get(const Node *node)
Definition node-marker.h:65
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define V8_INLINE
Definition v8config.h:500