blob: 2a24bfb8d31d2d3b82a3dc9c7ebd66768f161018 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2021 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.
#include "src/compiler/wasm-escape-analysis.h"
#include "src/compiler/machine-graph.h"
#include "src/compiler/node-properties.h"
namespace v8 {
namespace internal {
namespace compiler {
Reduction WasmEscapeAnalysis::Reduce(Node* node) {
switch (node->opcode()) {
case IrOpcode::kAllocateRaw:
return ReduceAllocateRaw(node);
default:
return NoChange();
}
}
Reduction WasmEscapeAnalysis::ReduceAllocateRaw(Node* node) {
DCHECK_EQ(node->opcode(), IrOpcode::kAllocateRaw);
// TODO(manoskouk): Account for phis.
// Collect all value edges of {node} in this vector.
std::vector<Edge> value_edges;
for (Edge edge : node->use_edges()) {
if (NodeProperties::IsValueEdge(edge)) {
if (edge.index() != 0 ||
(edge.from()->opcode() != IrOpcode::kStoreToObject &&
edge.from()->opcode() != IrOpcode::kInitializeImmutableInObject)) {
return NoChange();
}
value_edges.push_back(edge);
}
}
// Remove all discovered stores from the effect chain.
for (Edge edge : value_edges) {
DCHECK(NodeProperties::IsValueEdge(edge));
DCHECK_EQ(edge.index(), 0);
Node* use = edge.from();
DCHECK(!use->IsDead());
DCHECK(use->opcode() == IrOpcode::kStoreToObject ||
use->opcode() == IrOpcode::kInitializeImmutableInObject);
// The value stored by this StoreToObject node might be another allocation
// which has no more uses. Therefore we have to revisit it. Note that this
// will not happen automatically: ReplaceWithValue does not trigger revisits
// of former inputs of the replaced node.
Node* stored_value = NodeProperties::GetValueInput(use, 2);
Revisit(stored_value);
ReplaceWithValue(use, mcgraph_->Dead(), NodeProperties::GetEffectInput(use),
mcgraph_->Dead());
use->Kill();
}
// Remove the allocation from the effect and control chains.
ReplaceWithValue(node, mcgraph_->Dead(), NodeProperties::GetEffectInput(node),
NodeProperties::GetControlInput(node));
return Changed(node);
}
} // namespace compiler
} // namespace internal
} // namespace v8
|