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