v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
simplify-tf-loops.cc
Go to the documentation of this file.
1// Copyright 2022 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
10
11namespace v8::internal::compiler {
12
14 if (node->opcode() != IrOpcode::kLoop) return NoChange();
15 if (node->InputCount() <= 2) return NoChange();
16
17 Node* new_loop = mcgraph_->graph()->NewNode(mcgraph_->common()->Loop(2),
18 node->InputAt(0), node);
19 node->RemoveInput(0);
20 NodeProperties::ChangeOp(node, mcgraph_->common()->Merge(node->InputCount()));
21
22 base::SmallVector<Edge, 4> control_uses;
23
24 for (Edge edge : node->use_edges()) {
25 Node* use = edge.from();
26 if (!NodeProperties::IsPhi(use)) {
27 control_uses.emplace_back(edge);
28 continue;
29 }
30 Node* dominating_input = use->InputAt(0);
31 use->RemoveInput(0);
33 use, use->opcode() == IrOpcode::kPhi
34 ? mcgraph_->common()->Phi(PhiRepresentationOf(use->op()),
35 use->InputCount() - 1)
36 : mcgraph_->common()->EffectPhi(use->InputCount() - 1));
37
38 Node* new_phi = mcgraph_->graph()->NewNode(
39 use->opcode() == IrOpcode::kPhi
40 ? mcgraph_->common()->Phi(PhiRepresentationOf(use->op()), 2)
41 : mcgraph_->common()->EffectPhi(2),
42 dominating_input, use, new_loop);
43
44 ReplaceWithValue(use, new_phi, new_phi, new_phi);
45 // Restore the use <- new_phi edge we just broke.
46 new_phi->ReplaceInput(1, use);
47 }
48
49 for (Edge edge : control_uses) {
50 if (edge.from() != new_loop) {
51 edge.from()->ReplaceInput(edge.index(), new_loop);
52 }
53 }
54
55 return NoChange();
56}
57
58} // namespace v8::internal::compiler
void emplace_back(Args &&... args)
void ReplaceWithValue(Node *node, Node *value, Node *effect=nullptr, Node *control=nullptr)
const Operator * Phi(MachineRepresentation representation, int value_input_count)
const Operator * Loop(int control_input_count)
const Operator * EffectPhi(int effect_input_count)
const Operator * Merge(int control_input_count)
CommonOperatorBuilder * common() const
static void ChangeOp(Node *node, const Operator *new_op)
void ReplaceInput(int index, Node *new_to)
Definition node.h:76
Node * InputAt(int index) const
Definition node.h:70
Node * RemoveInput(int index)
Definition node.cc:232
Node * NewNode(const Operator *op, int input_count, Node *const *inputs, bool incomplete=false)
MachineRepresentation PhiRepresentationOf(const Operator *const op)