v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
node-observer.h
Go to the documentation of this file.
1// Copyright 2021 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_OBSERVER_H_
6#define V8_COMPILER_NODE_OBSERVER_H_
7
8// This file declares the implementation of a new intrinsic %ObserveNode(expr),
9// which has noop semantics but triggers the invocation of callbacks on a
10// NodeObserver object. The NodeObserver is set on the OptimizedCompilationInfo
11// and callbacks are called when the node generated for 'expr' is created or
12// changed in any phase, until EffectControlLinearization.
13//
14// The modifications currently observed are changes to the observed Node
15// operator and type and its replacement with another Node.
16//
17// This provides the infrastructure to write unit tests that check for the
18// construction of or the lowering to specific nodes in the TurboFan graphs.
19
20#include "src/compiler/node.h"
22#include "src/zone/zone.h"
23
24namespace v8 {
25namespace internal {
26namespace compiler {
27
28class Node;
29class Operator;
30
32 public:
33 ObservableNodeState(const Node* node, Zone* zone);
34
35 uint32_t id() const { return id_; }
36 const Operator* op() const { return op_; }
37 int16_t opcode() const { return op_->opcode(); }
38 Type type() const { return type_; }
39
40 private:
41 uint32_t id_;
42 const Operator* op_;
44};
45
46inline bool operator==(const ObservableNodeState& lhs,
47 const ObservableNodeState& rhs) {
48 return lhs.id() == rhs.id() && lhs.op() == rhs.op() &&
49 lhs.type() == rhs.type();
50}
51
52inline bool operator!=(const ObservableNodeState& lhs,
53 const ObservableNodeState& rhs) {
54 return !operator==(lhs, rhs);
55}
56
57class NodeObserver : public ZoneObject {
58 public:
59 enum class Observation {
61 kStop,
62 };
63
64 NodeObserver() = default;
65 virtual ~NodeObserver() = 0;
66
67 NodeObserver(const NodeObserver&) = delete;
69
70 virtual Observation OnNodeCreated(const Node* node) {
72 }
73
74 virtual Observation OnNodeChanged(const char* reducer_name, const Node* node,
75 const ObservableNodeState& old_state) {
77 }
78
81
82 private:
83 std::atomic<bool> has_observed_changes_{false};
84};
85inline NodeObserver::~NodeObserver() = default;
86
87struct NodeObservation : public ZoneObject {
88 NodeObservation(NodeObserver* node_observer, const Node* node, Zone* zone)
89 : observer(node_observer), state(node, zone) {
90 DCHECK_NOT_NULL(node_observer);
91 }
92
95};
96
98 public:
99 explicit ObserveNodeManager(Zone* zone) : zone_(zone), observations_(zone) {}
100
101 void StartObserving(Node* node, NodeObserver* observer);
102 void OnNodeChanged(const char* reducer_name, const Node* old_node,
103 const Node* new_node);
104
105 private:
108};
109
125
126} // namespace compiler
127} // namespace internal
128} // namespace v8
129
130#endif // V8_COMPILER_NODE_OBSERVER_H_
NodeObserver & operator=(const NodeObserver &)=delete
std::atomic< bool > has_observed_changes_
virtual Observation OnNodeChanged(const char *reducer_name, const Node *node, const ObservableNodeState &old_state)
virtual Observation OnNodeCreated(const Node *node)
NodeObserver(const NodeObserver &)=delete
ObservableNodeState(const Node *node, Zone *zone)
void OnNodeChanged(const char *reducer_name, const Node *old_node, const Node *new_node)
ZoneMap< NodeId, NodeObservation * > observations_
void StartObserving(Node *node, NodeObserver *observer)
bool operator!=(DeoptimizeParameters lhs, DeoptimizeParameters rhs)
bool operator==(const BranchParameters &lhs, const BranchParameters &rhs)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
NodeObservation(NodeObserver *node_observer, const Node *node, Zone *zone)
ObserveNodeInfo(ObserveNodeManager *manager, NodeObserver *observer)