Commit 1398078a authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Pull ResizeMergeOrPhi into CommonOperatorBuilder and use in ControlReducer.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/859053002

Cr-Commit-Position: refs/heads/master@{#26175}
parent bd7f546f
......@@ -492,6 +492,24 @@ const Operator* CommonOperatorBuilder::Projection(size_t index) {
index); // parameter
}
const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op,
int size) {
if (op->opcode() == IrOpcode::kPhi) {
return Phi(OpParameter<MachineType>(op), size);
} else if (op->opcode() == IrOpcode::kEffectPhi) {
return EffectPhi(size);
} else if (op->opcode() == IrOpcode::kMerge) {
return Merge(size);
} else if (op->opcode() == IrOpcode::kLoop) {
return Loop(size);
} else {
UNREACHABLE();
return nullptr;
}
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -201,6 +201,10 @@ class CommonOperatorBuilder FINAL : public ZoneObject {
const Operator* Call(const CallDescriptor* descriptor);
const Operator* Projection(size_t index);
// Constructs a new merge or phi operator with the same opcode as {op}, but
// with {size} inputs.
const Operator* ResizeMergeOrPhi(const Operator* op, int size);
private:
Zone* zone() const { return zone_; }
......
......@@ -509,28 +509,24 @@ class ControlReducerImpl {
// Remove inputs to {node} corresponding to the dead inputs to {merge}
// and compact the remaining inputs, updating the operator.
void RemoveDeadInputs(Node* merge, Node* node) {
int pos = 0;
for (int i = 0; i < node->InputCount(); i++) {
int live = 0;
for (int i = 0; i < merge->InputCount(); i++) {
// skip dead inputs.
if (i < merge->InputCount() &&
merge->InputAt(i)->opcode() == IrOpcode::kDead)
continue;
if (merge->InputAt(i)->opcode() == IrOpcode::kDead) continue;
// compact live inputs.
if (pos != i) node->ReplaceInput(pos, node->InputAt(i));
pos++;
if (live != i) node->ReplaceInput(live, node->InputAt(i));
live++;
}
node->TrimInputCount(pos);
if (node->opcode() == IrOpcode::kPhi) {
node->set_op(common_->Phi(OpParameter<MachineType>(node->op()), pos - 1));
} else if (node->opcode() == IrOpcode::kEffectPhi) {
node->set_op(common_->EffectPhi(pos - 1));
} else if (node->opcode() == IrOpcode::kMerge) {
node->set_op(common_->Merge(pos));
} else if (node->opcode() == IrOpcode::kLoop) {
node->set_op(common_->Loop(pos));
} else {
UNREACHABLE();
// compact remaining inputs.
int total = live;
for (int i = merge->InputCount(); i < node->InputCount(); i++) {
if (total != i) node->ReplaceInput(total, node->InputAt(i));
total++;
}
DCHECK_EQ(total, live + node->InputCount() - merge->InputCount());
DCHECK_NE(total, node->InputCount());
node->TrimInputCount(total);
node->set_op(common_->ResizeMergeOrPhi(node->op(), live));
}
// Replace uses of {node} with {replacement} and revisit the uses.
......
......@@ -161,23 +161,6 @@ Node* PeeledIteration::map(Node* node) {
}
static const Operator* ResizeMergeOrPhi(CommonOperatorBuilder* common,
const Operator* op, int size) {
if (op->opcode() == IrOpcode::kPhi) {
return common->Phi(OpParameter<MachineType>(op), size);
} else if (op->opcode() == IrOpcode::kEffectPhi) {
return common->EffectPhi(size);
} else if (op->opcode() == IrOpcode::kMerge) {
return common->Merge(size);
} else if (op->opcode() == IrOpcode::kLoop) {
return common->Loop(size);
} else {
UNREACHABLE();
return nullptr;
}
}
PeeledIteration* LoopPeeler::Peel(Graph* graph, CommonOperatorBuilder* common,
LoopTree* loop_tree, LoopTree::Loop* loop,
Zone* tmp_zone) {
......@@ -225,7 +208,7 @@ PeeledIteration* LoopPeeler::Peel(Graph* graph, CommonOperatorBuilder* common,
for (Node* input : inputs) {
if (input != inputs[0]) { // Non-redundant phi.
inputs.push_back(merge);
const Operator* op = ResizeMergeOrPhi(common, node->op(), backedges);
const Operator* op = common->ResizeMergeOrPhi(node->op(), backedges);
Node* phi = graph->NewNode(op, backedges + 1, &inputs[0]);
node->ReplaceInput(0, phi);
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment