v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
node-observer.cc
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
6
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
14 : id_(node->id()),
15 op_(node->op()),
16 type_(NodeProperties::GetTypeOrAny(node)) {}
17
19 DCHECK_NOT_NULL(node);
20 DCHECK_NOT_NULL(observer);
21 DCHECK(observations_.find(node->id()) == observations_.end());
22
23 observer->set_has_observed_changes();
24 NodeObserver::Observation observation = observer->OnNodeCreated(node);
25 if (observation == NodeObserver::Observation::kContinue) {
26 observations_[node->id()] =
27 zone_->New<NodeObservation>(observer, node, zone_);
28 } else {
30 }
31}
32
33void ObserveNodeManager::OnNodeChanged(const char* reducer_name,
34 const Node* old_node,
35 const Node* new_node) {
36 const auto it = observations_.find(old_node->id());
37 if (it == observations_.end()) return;
38
39 ObservableNodeState new_state{new_node, zone_};
40 NodeObservation* observation = it->second;
41 if (observation->state == new_state) return;
42
43 ObservableNodeState old_state = observation->state;
44 observation->state = new_state;
45
47 observation->observer->OnNodeChanged(reducer_name, new_node, old_state);
49 observations_.erase(old_node->id());
50 } else {
52 if (old_node != new_node) {
53 observations_.erase(old_node->id());
54 observations_[new_node->id()] = observation;
55 }
56 }
57}
58
59} // namespace compiler
60} // namespace internal
61} // namespace v8
T * New(Args &&... args)
Definition zone.h:114
virtual Observation OnNodeChanged(const char *reducer_name, const Node *node, const ObservableNodeState &old_state)
virtual Observation OnNodeCreated(const Node *node)
NodeId id() const
Definition node.h:57
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)
const ObjectRef type_
Node * node
ZoneVector< RpoNumber > & result
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485