Lines Matching refs:node

10 #include "src/compiler/node-properties.h"
30 // True if we can guarantee that {node} will never actually produce a value or
32 bool NoReturn(Node* node) {
33 return node->opcode() == IrOpcode::kDead ||
34 node->opcode() == IrOpcode::kUnreachable ||
35 node->opcode() == IrOpcode::kDeadValue ||
36 NodeProperties::GetTypeOrAny(node).IsNone();
39 Node* FindDeadInput(Node* node) {
40 for (Node* input : node->inputs()) {
48 Reduction DeadCodeElimination::Reduce(Node* node) {
49 switch (node->opcode()) {
51 return ReduceEnd(node);
54 return ReduceLoopOrMerge(node);
56 return ReduceLoopExit(node);
59 return ReduceUnreachableOrIfException(node);
61 return ReducePhi(node);
63 return ReduceEffectPhi(node);
68 return ReduceDeoptimizeOrReturnOrTerminateOrTailCall(node);
70 return PropagateDeadControl(node);
73 return ReduceBranchOrSwitch(node);
75 return ReduceNode(node);
80 Reduction DeadCodeElimination::PropagateDeadControl(Node* node) {
81 DCHECK_EQ(1, node->op()->ControlInputCount());
82 Node* control = NodeProperties::GetControlInput(node);
87 Reduction DeadCodeElimination::ReduceEnd(Node* node) {
88 DCHECK_EQ(IrOpcode::kEnd, node->opcode());
89 Node::Inputs inputs = node->inputs();
97 if (i != live_input_count) node->ReplaceInput(live_input_count, input);
103 node->TrimInputCount(live_input_count);
104 NodeProperties::ChangeOp(node, common()->End(live_input_count));
105 return Changed(node);
111 Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) {
112 DCHECK(IrOpcode::IsMergeOpcode(node->opcode()));
113 Node::Inputs inputs = node->inputs();
115 // Count the number of live inputs to {node} and compact them on the fly, also
120 if (node->opcode() != IrOpcode::kLoop ||
121 node->InputAt(0)->opcode() != IrOpcode::kDead) {
128 node->ReplaceInput(live_input_count, input);
129 for (Node* const use : node->uses()) {
144 for (Node* const use : node->uses()) {
148 use->InputAt(1) == node) {
154 DCHECK_EQ(IrOpcode::kLoop, node->opcode());
162 return Replace(node->InputAt(0));
166 // Trim input count for the {Merge} or {Loop} node.
169 for (Node* const use : node->uses()) {
171 use->ReplaceInput(live_input_count, node);
176 TrimMergeOrPhi(node, live_input_count);
177 return Changed(node);
182 Reduction DeadCodeElimination::RemoveLoopExit(Node* node) {
183 DCHECK_EQ(IrOpcode::kLoopExit, node->opcode());
184 for (Node* const use : node->uses()) {
190 Node* control = NodeProperties::GetControlInput(node, 0);
191 Replace(node, control);
195 Reduction DeadCodeElimination::ReduceNode(Node* node) {
196 DCHECK(!IrOpcode::IsGraphTerminator(node->opcode()));
197 int const effect_input_count = node->op()->EffectInputCount();
198 int const control_input_count = node->op()->ControlInputCount();
201 Reduction reduction = PropagateDeadControl(node);
205 (control_input_count == 0 || node->op()->ControlOutputCount() == 0)) {
206 return ReducePureNode(node);
209 return ReduceEffectNode(node);
214 Reduction DeadCodeElimination::ReducePhi(Node* node) {
215 DCHECK_EQ(IrOpcode::kPhi, node->opcode());
216 Reduction reduction = PropagateDeadControl(node);
218 MachineRepresentation rep = PhiRepresentationOf(node->op());
220 NodeProperties::GetTypeOrAny(node).IsNone()) {
221 return Replace(DeadValue(node, rep));
223 int input_count = node->op()->ValueInputCount();
225 Node* input = NodeProperties::GetValueInput(node, i);
228 NodeProperties::ReplaceValueInput(node, DeadValue(input, rep), i);
234 Reduction DeadCodeElimination::ReduceEffectPhi(Node* node) {
235 DCHECK_EQ(IrOpcode::kEffectPhi, node->opcode());
236 Reduction reduction = PropagateDeadControl(node);
239 Node* merge = NodeProperties::GetControlInput(node);
242 int input_count = node->op()->EffectInputCount();
244 Node* effect = NodeProperties::GetEffectInput(node, i);
252 NodeProperties::ReplaceEffectInput(node, dead_, i);
256 reduction = Changed(node);
262 Reduction DeadCodeElimination::ReducePureNode(Node* node) {
263 DCHECK_EQ(0, node->op()->EffectInputCount());
264 if (node->opcode() == IrOpcode::kDeadValue) return NoChange();
265 if (Node* input = FindDeadInput(node)) {
271 Reduction DeadCodeElimination::ReduceUnreachableOrIfException(Node* node) {
272 DCHECK(node->opcode() == IrOpcode::kUnreachable ||
273 node->opcode() == IrOpcode::kIfException);
274 Reduction reduction = PropagateDeadControl(node);
276 Node* effect = NodeProperties::GetEffectInput(node, 0);
286 Reduction DeadCodeElimination::ReduceEffectNode(Node* node) {
287 DCHECK_EQ(1, node->op()->EffectInputCount());
288 Node* effect = NodeProperties::GetEffectInput(node, 0);
292 if (Node* input = FindDeadInput(node)) {
294 RelaxEffectsAndControls(node);
298 Node* control = node->op()->ControlInputCount() == 1
299 ? NodeProperties::GetControlInput(node, 0)
304 ReplaceWithValue(node, DeadValue(input), node, control);
312 Node* node) {
313 DCHECK(node->opcode() == IrOpcode::kDeoptimize ||
314 node->opcode() == IrOpcode::kReturn ||
315 node->opcode() == IrOpcode::kTerminate ||
316 node->opcode() == IrOpcode::kTailCall);
317 Reduction reduction = PropagateDeadControl(node);
321 if (node->opcode() != IrOpcode::kTerminate &&
322 FindDeadInput(node) != nullptr) {
323 Node* effect = NodeProperties::GetEffectInput(node, 0);
324 Node* control = NodeProperties::GetControlInput(node, 0);
329 node->TrimInputCount(2);
330 node->ReplaceInput(0, effect);
331 node->ReplaceInput(1, control);
332 NodeProperties::ChangeOp(node, common()->Throw());
333 return Changed(node);
338 Reduction DeadCodeElimination::ReduceLoopExit(Node* node) {
339 Node* control = NodeProperties::GetControlInput(node, 0);
340 Node* loop = NodeProperties::GetControlInput(node, 1);
343 return RemoveLoopExit(node);
348 Reduction DeadCodeElimination::ReduceBranchOrSwitch(Node* node) {
349 DCHECK(node->opcode() == IrOpcode::kBranch ||
350 node->opcode() == IrOpcode::kSwitch);
351 Reduction reduction = PropagateDeadControl(node);
353 Node* condition = NodeProperties::GetValueInput(node, 0);
359 size_t const projection_cnt = node->op()->ControlOutputCount();
361 NodeProperties::CollectControlProjections(node, projections,
363 Replace(projections[0], NodeProperties::GetControlInput(node));
369 void DeadCodeElimination::TrimMergeOrPhi(Node* node, int size) {
370 const Operator* const op = common()->ResizeMergeOrPhi(node->op(), size);
371 node->TrimInputCount(OperatorProperties::GetTotalInputCount(op));
372 NodeProperties::ChangeOp(node, op);
375 Node* DeadCodeElimination::DeadValue(Node* node, MachineRepresentation rep) {
376 if (node->opcode() == IrOpcode::kDeadValue) {
377 if (rep == DeadValueRepresentationOf(node->op())) return node;
378 node = NodeProperties::GetValueInput(node, 0);
380 Node* dead_value = graph()->NewNode(common()->DeadValue(rep), node);