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) { ...@@ -492,6 +492,24 @@ const Operator* CommonOperatorBuilder::Projection(size_t index) {
index); // parameter 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 compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -201,6 +201,10 @@ class CommonOperatorBuilder FINAL : public ZoneObject { ...@@ -201,6 +201,10 @@ class CommonOperatorBuilder FINAL : public ZoneObject {
const Operator* Call(const CallDescriptor* descriptor); const Operator* Call(const CallDescriptor* descriptor);
const Operator* Projection(size_t index); 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: private:
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
......
...@@ -509,28 +509,24 @@ class ControlReducerImpl { ...@@ -509,28 +509,24 @@ class ControlReducerImpl {
// Remove inputs to {node} corresponding to the dead inputs to {merge} // Remove inputs to {node} corresponding to the dead inputs to {merge}
// and compact the remaining inputs, updating the operator. // and compact the remaining inputs, updating the operator.
void RemoveDeadInputs(Node* merge, Node* node) { void RemoveDeadInputs(Node* merge, Node* node) {
int pos = 0; int live = 0;
for (int i = 0; i < node->InputCount(); i++) { for (int i = 0; i < merge->InputCount(); i++) {
// skip dead inputs. // skip dead inputs.
if (i < merge->InputCount() && if (merge->InputAt(i)->opcode() == IrOpcode::kDead) continue;
merge->InputAt(i)->opcode() == IrOpcode::kDead)
continue;
// compact live inputs. // compact live inputs.
if (pos != i) node->ReplaceInput(pos, node->InputAt(i)); if (live != i) node->ReplaceInput(live, node->InputAt(i));
pos++; live++;
} }
node->TrimInputCount(pos); // compact remaining inputs.
if (node->opcode() == IrOpcode::kPhi) { int total = live;
node->set_op(common_->Phi(OpParameter<MachineType>(node->op()), pos - 1)); for (int i = merge->InputCount(); i < node->InputCount(); i++) {
} else if (node->opcode() == IrOpcode::kEffectPhi) { if (total != i) node->ReplaceInput(total, node->InputAt(i));
node->set_op(common_->EffectPhi(pos - 1)); total++;
} 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();
} }
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. // Replace uses of {node} with {replacement} and revisit the uses.
......
...@@ -161,23 +161,6 @@ Node* PeeledIteration::map(Node* node) { ...@@ -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, PeeledIteration* LoopPeeler::Peel(Graph* graph, CommonOperatorBuilder* common,
LoopTree* loop_tree, LoopTree::Loop* loop, LoopTree* loop_tree, LoopTree::Loop* loop,
Zone* tmp_zone) { Zone* tmp_zone) {
...@@ -225,7 +208,7 @@ PeeledIteration* LoopPeeler::Peel(Graph* graph, CommonOperatorBuilder* common, ...@@ -225,7 +208,7 @@ PeeledIteration* LoopPeeler::Peel(Graph* graph, CommonOperatorBuilder* common,
for (Node* input : inputs) { for (Node* input : inputs) {
if (input != inputs[0]) { // Non-redundant phi. if (input != inputs[0]) { // Non-redundant phi.
inputs.push_back(merge); 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* phi = graph->NewNode(op, backedges + 1, &inputs[0]);
node->ReplaceInput(0, phi); node->ReplaceInput(0, phi);
break; 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