[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Copyright 2015 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/dead-code-elimination.h"
|
|
|
|
|
|
|
|
#include "src/compiler/common-operator.h"
|
|
|
|
#include "src/compiler/graph.h"
|
2017-11-15 18:39:07 +00:00
|
|
|
#include "src/compiler/js-operator.h"
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
|
|
|
#include "src/compiler/operator-properties.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
DeadCodeElimination::DeadCodeElimination(Editor* editor, Graph* graph,
|
2017-11-15 18:39:07 +00:00
|
|
|
CommonOperatorBuilder* common,
|
|
|
|
Zone* temp_zone)
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
: AdvancedReducer(editor),
|
|
|
|
graph_(graph),
|
|
|
|
common_(common),
|
2017-11-15 18:39:07 +00:00
|
|
|
dead_(graph->NewNode(common->Dead())),
|
|
|
|
zone_(temp_zone) {
|
2017-01-03 15:25:09 +00:00
|
|
|
NodeProperties::SetType(dead_, Type::None());
|
|
|
|
}
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
|
2017-11-15 18:39:07 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// True if we can guarantee that {node} will never actually produce a value or
|
|
|
|
// effect.
|
|
|
|
bool NoReturn(Node* node) {
|
|
|
|
return node->opcode() == IrOpcode::kDead ||
|
|
|
|
node->opcode() == IrOpcode::kUnreachable ||
|
|
|
|
node->opcode() == IrOpcode::kDeadValue ||
|
|
|
|
NodeProperties::GetTypeOrAny(node)->IsNone();
|
|
|
|
}
|
|
|
|
|
2018-01-04 12:45:56 +00:00
|
|
|
Node* FindDeadInput(Node* node) {
|
2017-11-15 18:39:07 +00:00
|
|
|
for (Node* input : node->inputs()) {
|
2018-01-04 12:45:56 +00:00
|
|
|
if (NoReturn(input)) return input;
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
2018-01-04 12:45:56 +00:00
|
|
|
return nullptr;
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
Reduction DeadCodeElimination::Reduce(Node* node) {
|
|
|
|
switch (node->opcode()) {
|
|
|
|
case IrOpcode::kEnd:
|
|
|
|
return ReduceEnd(node);
|
|
|
|
case IrOpcode::kLoop:
|
|
|
|
case IrOpcode::kMerge:
|
|
|
|
return ReduceLoopOrMerge(node);
|
2016-07-14 14:59:44 +00:00
|
|
|
case IrOpcode::kLoopExit:
|
|
|
|
return ReduceLoopExit(node);
|
2017-11-15 18:39:07 +00:00
|
|
|
case IrOpcode::kUnreachable:
|
|
|
|
case IrOpcode::kIfException:
|
|
|
|
return ReduceUnreachableOrIfException(node);
|
|
|
|
case IrOpcode::kPhi:
|
|
|
|
return ReducePhi(node);
|
|
|
|
case IrOpcode::kEffectPhi:
|
|
|
|
return PropagateDeadControl(node);
|
|
|
|
case IrOpcode::kDeoptimize:
|
|
|
|
case IrOpcode::kReturn:
|
|
|
|
case IrOpcode::kTerminate:
|
|
|
|
return ReduceDeoptimizeOrReturnOrTerminate(node);
|
|
|
|
case IrOpcode::kThrow:
|
|
|
|
return PropagateDeadControl(node);
|
|
|
|
case IrOpcode::kBranch:
|
|
|
|
case IrOpcode::kSwitch:
|
|
|
|
return ReduceBranchOrSwitch(node);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
default:
|
|
|
|
return ReduceNode(node);
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2017-11-15 18:39:07 +00:00
|
|
|
Reduction DeadCodeElimination::PropagateDeadControl(Node* node) {
|
|
|
|
DCHECK_EQ(1, node->op()->ControlInputCount());
|
|
|
|
Node* control = NodeProperties::GetControlInput(node);
|
|
|
|
if (control->opcode() == IrOpcode::kDead) return Replace(control);
|
|
|
|
return NoChange();
|
|
|
|
}
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceEnd(Node* node) {
|
|
|
|
DCHECK_EQ(IrOpcode::kEnd, node->opcode());
|
2017-01-10 13:55:03 +00:00
|
|
|
Node::Inputs inputs = node->inputs();
|
|
|
|
DCHECK_LE(1, inputs.count());
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
int live_input_count = 0;
|
2017-01-10 13:55:03 +00:00
|
|
|
for (int i = 0; i < inputs.count(); ++i) {
|
|
|
|
Node* const input = inputs[i];
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Skip dead inputs.
|
|
|
|
if (input->opcode() == IrOpcode::kDead) continue;
|
|
|
|
// Compact live inputs.
|
|
|
|
if (i != live_input_count) node->ReplaceInput(live_input_count, input);
|
|
|
|
++live_input_count;
|
|
|
|
}
|
|
|
|
if (live_input_count == 0) {
|
|
|
|
return Replace(dead());
|
2017-01-10 13:55:03 +00:00
|
|
|
} else if (live_input_count < inputs.count()) {
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
node->TrimInputCount(live_input_count);
|
2015-09-24 14:46:29 +00:00
|
|
|
NodeProperties::ChangeOp(node, common()->End(live_input_count));
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
return Changed(node);
|
|
|
|
}
|
2017-01-10 13:55:03 +00:00
|
|
|
DCHECK_EQ(inputs.count(), live_input_count);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceLoopOrMerge(Node* node) {
|
|
|
|
DCHECK(IrOpcode::IsMergeOpcode(node->opcode()));
|
2017-01-10 13:55:03 +00:00
|
|
|
Node::Inputs inputs = node->inputs();
|
|
|
|
DCHECK_LE(1, inputs.count());
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Count the number of live inputs to {node} and compact them on the fly, also
|
|
|
|
// compacting the inputs of the associated {Phi} and {EffectPhi} uses at the
|
|
|
|
// same time. We consider {Loop}s dead even if only the first control input
|
|
|
|
// is dead.
|
|
|
|
int live_input_count = 0;
|
|
|
|
if (node->opcode() != IrOpcode::kLoop ||
|
|
|
|
node->InputAt(0)->opcode() != IrOpcode::kDead) {
|
2017-01-10 13:55:03 +00:00
|
|
|
for (int i = 0; i < inputs.count(); ++i) {
|
|
|
|
Node* const input = inputs[i];
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Skip dead inputs.
|
|
|
|
if (input->opcode() == IrOpcode::kDead) continue;
|
|
|
|
// Compact live inputs.
|
|
|
|
if (live_input_count != i) {
|
|
|
|
node->ReplaceInput(live_input_count, input);
|
|
|
|
for (Node* const use : node->uses()) {
|
|
|
|
if (NodeProperties::IsPhi(use)) {
|
2017-01-10 13:55:03 +00:00
|
|
|
DCHECK_EQ(inputs.count() + 1, use->InputCount());
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
use->ReplaceInput(live_input_count, use->InputAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++live_input_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (live_input_count == 0) {
|
|
|
|
return Replace(dead());
|
|
|
|
} else if (live_input_count == 1) {
|
|
|
|
// Due to compaction above, the live input is at offset 0.
|
|
|
|
for (Node* const use : node->uses()) {
|
|
|
|
if (NodeProperties::IsPhi(use)) {
|
|
|
|
Replace(use, use->InputAt(0));
|
2016-07-14 14:59:44 +00:00
|
|
|
} else if (use->opcode() == IrOpcode::kLoopExit &&
|
|
|
|
use->InputAt(1) == node) {
|
|
|
|
RemoveLoopExit(use);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
} else if (use->opcode() == IrOpcode::kTerminate) {
|
|
|
|
DCHECK_EQ(IrOpcode::kLoop, node->opcode());
|
|
|
|
Replace(use, dead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Replace(node->InputAt(0));
|
|
|
|
}
|
|
|
|
DCHECK_LE(2, live_input_count);
|
2017-01-10 13:55:03 +00:00
|
|
|
DCHECK_LE(live_input_count, inputs.count());
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Trim input count for the {Merge} or {Loop} node.
|
2017-01-10 13:55:03 +00:00
|
|
|
if (live_input_count < inputs.count()) {
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// Trim input counts for all phi uses and revisit them.
|
|
|
|
for (Node* const use : node->uses()) {
|
|
|
|
if (NodeProperties::IsPhi(use)) {
|
|
|
|
use->ReplaceInput(live_input_count, node);
|
|
|
|
TrimMergeOrPhi(use, live_input_count);
|
|
|
|
Revisit(use);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TrimMergeOrPhi(node, live_input_count);
|
|
|
|
return Changed(node);
|
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
2016-07-14 14:59:44 +00:00
|
|
|
Reduction DeadCodeElimination::RemoveLoopExit(Node* node) {
|
|
|
|
DCHECK_EQ(IrOpcode::kLoopExit, node->opcode());
|
|
|
|
for (Node* const use : node->uses()) {
|
|
|
|
if (use->opcode() == IrOpcode::kLoopExitValue ||
|
|
|
|
use->opcode() == IrOpcode::kLoopExitEffect) {
|
|
|
|
Replace(use, use->InputAt(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Node* control = NodeProperties::GetControlInput(node, 0);
|
|
|
|
Replace(node, control);
|
|
|
|
return Replace(control);
|
|
|
|
}
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceNode(Node* node) {
|
2017-11-15 18:39:07 +00:00
|
|
|
DCHECK(!IrOpcode::IsGraphTerminator(node->opcode()));
|
|
|
|
int const effect_input_count = node->op()->EffectInputCount();
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
int const control_input_count = node->op()->ControlInputCount();
|
2017-11-15 18:39:07 +00:00
|
|
|
DCHECK_LE(control_input_count, 1);
|
|
|
|
if (control_input_count == 1) {
|
|
|
|
Reduction reduction = PropagateDeadControl(node);
|
|
|
|
if (reduction.Changed()) return reduction;
|
|
|
|
}
|
|
|
|
if (effect_input_count == 0 &&
|
|
|
|
(control_input_count == 0 || node->op()->ControlOutputCount() == 0)) {
|
|
|
|
return ReducePureNode(node);
|
|
|
|
}
|
|
|
|
if (effect_input_count > 0) {
|
|
|
|
return ReduceEffectNode(node);
|
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReducePhi(Node* node) {
|
|
|
|
DCHECK_EQ(IrOpcode::kPhi, node->opcode());
|
|
|
|
Reduction reduction = PropagateDeadControl(node);
|
|
|
|
if (reduction.Changed()) return reduction;
|
2018-01-04 12:45:56 +00:00
|
|
|
MachineRepresentation rep = PhiRepresentationOf(node->op());
|
|
|
|
if (rep == MachineRepresentation::kNone ||
|
2017-11-15 18:39:07 +00:00
|
|
|
NodeProperties::GetTypeOrAny(node)->IsNone()) {
|
2018-01-04 12:45:56 +00:00
|
|
|
return Replace(DeadValue(node, rep));
|
|
|
|
}
|
|
|
|
int input_count = node->op()->ValueInputCount();
|
|
|
|
for (int i = 0; i < input_count; ++i) {
|
|
|
|
Node* input = NodeProperties::GetValueInput(node, i);
|
|
|
|
if (input->opcode() == IrOpcode::kDeadValue &&
|
|
|
|
DeadValueRepresentationOf(input->op()) != rep) {
|
|
|
|
NodeProperties::ReplaceValueInput(node, DeadValue(input, rep), i);
|
|
|
|
}
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReducePureNode(Node* node) {
|
|
|
|
DCHECK_EQ(0, node->op()->EffectInputCount());
|
2018-01-04 12:45:56 +00:00
|
|
|
if (node->opcode() == IrOpcode::kDeadValue) return NoChange();
|
|
|
|
if (Node* input = FindDeadInput(node)) {
|
|
|
|
return Replace(DeadValue(input));
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceUnreachableOrIfException(Node* node) {
|
|
|
|
DCHECK(node->opcode() == IrOpcode::kUnreachable ||
|
|
|
|
node->opcode() == IrOpcode::kIfException);
|
|
|
|
Reduction reduction = PropagateDeadControl(node);
|
|
|
|
if (reduction.Changed()) return reduction;
|
|
|
|
Node* effect = NodeProperties::GetEffectInput(node, 0);
|
|
|
|
if (effect->opcode() == IrOpcode::kDead) {
|
|
|
|
return Replace(effect);
|
|
|
|
}
|
|
|
|
if (effect->opcode() == IrOpcode::kUnreachable) {
|
2018-01-04 12:45:56 +00:00
|
|
|
return Replace(effect);
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceEffectNode(Node* node) {
|
|
|
|
DCHECK_EQ(1, node->op()->EffectInputCount());
|
|
|
|
Node* effect = NodeProperties::GetEffectInput(node, 0);
|
|
|
|
if (effect->opcode() == IrOpcode::kDead) {
|
|
|
|
return Replace(effect);
|
|
|
|
}
|
2018-01-04 12:45:56 +00:00
|
|
|
if (Node* input = FindDeadInput(node)) {
|
2017-11-15 18:39:07 +00:00
|
|
|
if (effect->opcode() == IrOpcode::kUnreachable) {
|
|
|
|
RelaxEffectsAndControls(node);
|
2018-01-04 12:45:56 +00:00
|
|
|
return Replace(DeadValue(input));
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Node* control = node->op()->ControlInputCount() == 1
|
|
|
|
? NodeProperties::GetControlInput(node, 0)
|
|
|
|
: graph()->start();
|
|
|
|
Node* unreachable =
|
|
|
|
graph()->NewNode(common()->Unreachable(), effect, control);
|
2018-01-04 12:45:56 +00:00
|
|
|
NodeProperties::SetType(unreachable, Type::None());
|
|
|
|
ReplaceWithValue(node, DeadValue(input), node, control);
|
2017-11-15 18:39:07 +00:00
|
|
|
return Replace(unreachable);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
Reduction DeadCodeElimination::ReduceDeoptimizeOrReturnOrTerminate(Node* node) {
|
|
|
|
DCHECK(node->opcode() == IrOpcode::kDeoptimize ||
|
|
|
|
node->opcode() == IrOpcode::kReturn ||
|
|
|
|
node->opcode() == IrOpcode::kTerminate);
|
|
|
|
Reduction reduction = PropagateDeadControl(node);
|
|
|
|
if (reduction.Changed()) return reduction;
|
2018-01-04 12:45:56 +00:00
|
|
|
if (FindDeadInput(node) != nullptr) {
|
2017-11-15 18:39:07 +00:00
|
|
|
Node* effect = NodeProperties::GetEffectInput(node, 0);
|
|
|
|
Node* control = NodeProperties::GetControlInput(node, 0);
|
|
|
|
if (effect->opcode() != IrOpcode::kUnreachable) {
|
|
|
|
effect = graph()->NewNode(common()->Unreachable(), effect, control);
|
2018-01-04 12:45:56 +00:00
|
|
|
NodeProperties::SetType(effect, Type::None());
|
2017-11-15 18:39:07 +00:00
|
|
|
}
|
|
|
|
node->TrimInputCount(2);
|
|
|
|
node->ReplaceInput(0, effect);
|
|
|
|
node->ReplaceInput(1, control);
|
|
|
|
NodeProperties::ChangeOp(node, common()->Throw());
|
|
|
|
return Changed(node);
|
|
|
|
}
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
2016-07-14 14:59:44 +00:00
|
|
|
Reduction DeadCodeElimination::ReduceLoopExit(Node* node) {
|
|
|
|
Node* control = NodeProperties::GetControlInput(node, 0);
|
|
|
|
Node* loop = NodeProperties::GetControlInput(node, 1);
|
|
|
|
if (control->opcode() == IrOpcode::kDead ||
|
|
|
|
loop->opcode() == IrOpcode::kDead) {
|
|
|
|
return RemoveLoopExit(node);
|
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
|
2017-11-15 18:39:07 +00:00
|
|
|
Reduction DeadCodeElimination::ReduceBranchOrSwitch(Node* node) {
|
|
|
|
DCHECK(node->opcode() == IrOpcode::kBranch ||
|
|
|
|
node->opcode() == IrOpcode::kSwitch);
|
|
|
|
Reduction reduction = PropagateDeadControl(node);
|
|
|
|
if (reduction.Changed()) return reduction;
|
|
|
|
Node* condition = NodeProperties::GetValueInput(node, 0);
|
|
|
|
if (condition->opcode() == IrOpcode::kDeadValue) {
|
|
|
|
// Branches or switches on {DeadValue} must originate from unreachable code
|
|
|
|
// and cannot matter. Due to schedule freedom between the effect and the
|
|
|
|
// control chain, they might still appear in reachable code. Remove them by
|
|
|
|
// always choosing the first projection.
|
|
|
|
size_t const projection_cnt = node->op()->ControlOutputCount();
|
|
|
|
Node** projections = zone_->NewArray<Node*>(projection_cnt);
|
|
|
|
NodeProperties::CollectControlProjections(node, projections,
|
|
|
|
projection_cnt);
|
|
|
|
Replace(projections[0], NodeProperties::GetControlInput(node));
|
|
|
|
return Replace(dead());
|
|
|
|
}
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
void DeadCodeElimination::TrimMergeOrPhi(Node* node, int size) {
|
|
|
|
const Operator* const op = common()->ResizeMergeOrPhi(node->op(), size);
|
|
|
|
node->TrimInputCount(OperatorProperties::GetTotalInputCount(op));
|
2015-09-24 14:46:29 +00:00
|
|
|
NodeProperties::ChangeOp(node, op);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 12:45:56 +00:00
|
|
|
Node* DeadCodeElimination::DeadValue(Node* node, MachineRepresentation rep) {
|
|
|
|
if (node->opcode() == IrOpcode::kDeadValue) {
|
|
|
|
if (rep == DeadValueRepresentationOf(node->op())) return node;
|
|
|
|
node = NodeProperties::GetValueInput(node, 0);
|
|
|
|
}
|
|
|
|
Node* dead_value = graph()->NewNode(common()->DeadValue(rep), node);
|
|
|
|
NodeProperties::SetType(dead_value, Type::None());
|
|
|
|
return dead_value;
|
|
|
|
}
|
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|