v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-escape-analysis.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
9
10namespace v8 {
11namespace internal {
12namespace compiler {
13
15 switch (node->opcode()) {
16 case IrOpcode::kAllocateRaw:
17 return ReduceAllocateRaw(node);
18 default:
19 return NoChange();
20 }
21}
22
24 DCHECK_EQ(node->opcode(), IrOpcode::kAllocateRaw);
25 // TODO(manoskouk): Account for phis that still have uses.
26
27 // Collect all value edges of {node} in this vector.
28 std::vector<Edge> value_edges;
29 for (Edge edge : node->use_edges()) {
31 if ((edge.from()->opcode() == IrOpcode::kPhi &&
32 edge.from()->use_edges().empty()) ||
33 (edge.index() == 0 &&
34 (edge.from()->opcode() == IrOpcode::kStoreToObject ||
35 edge.from()->opcode() == IrOpcode::kInitializeImmutableInObject))) {
36 // StoreToObject, InitializeImmutableInObject and phis without uses can
37 // be replaced and do not require the allocation.
38 value_edges.push_back(edge);
39 } else {
40 // Allocation not reducible.
41 return NoChange();
42 }
43 }
44 }
45
46 // Remove all discovered stores from the effect chain.
47 for (Edge edge : value_edges) {
49 Node* use = edge.from();
50
51 if (use->opcode() == IrOpcode::kPhi) {
52 DCHECK(use->use_edges().empty());
53 // Useless phi. Kill it.
54 use->Kill();
55
56 } else {
57 DCHECK_EQ(edge.index(), 0);
58 DCHECK(!use->IsDead());
59 DCHECK(use->opcode() == IrOpcode::kStoreToObject ||
60 use->opcode() == IrOpcode::kInitializeImmutableInObject);
61 // The value stored by this StoreToObject node might be another allocation
62 // which has no more uses. Therefore we have to revisit it. Note that this
63 // will not happen automatically: ReplaceWithValue does not trigger
64 // revisits of former inputs of the replaced node.
65 Node* stored_value = NodeProperties::GetValueInput(use, 2);
66 Revisit(stored_value);
69 use->Kill();
70 }
71 }
72
73 // Remove the allocation from the effect and control chains.
76
77 return Changed(node);
78}
79
80} // namespace compiler
81} // namespace internal
82} // namespace v8
void ReplaceWithValue(Node *node, Node *value, Node *effect=nullptr, Node *control=nullptr)
static Node * GetEffectInput(Node *node, int index=0)
static Node * GetValueInput(Node *node, int index)
static Node * GetControlInput(Node *node, int index=0)
static Reduction Changed(Node *node)
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485