From 1398078ab37a67b7c2871bc6eea926a540572ff8 Mon Sep 17 00:00:00 2001 From: titzer Date: Tue, 20 Jan 2015 10:23:27 -0800 Subject: [PATCH] [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} --- src/compiler/common-operator.cc | 18 ++++++++++++++++++ src/compiler/common-operator.h | 4 ++++ src/compiler/control-reducer.cc | 32 ++++++++++++++------------------ src/compiler/loop-peeling.cc | 19 +------------------ 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/compiler/common-operator.cc b/src/compiler/common-operator.cc index e7d583f..74a8cde 100644 --- a/src/compiler/common-operator.cc +++ b/src/compiler/common-operator.cc @@ -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(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 diff --git a/src/compiler/common-operator.h b/src/compiler/common-operator.h index d61e110..1531b23 100644 --- a/src/compiler/common-operator.h +++ b/src/compiler/common-operator.h @@ -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_; } diff --git a/src/compiler/control-reducer.cc b/src/compiler/control-reducer.cc index ebddfc0..d34b4e8 100644 --- a/src/compiler/control-reducer.cc +++ b/src/compiler/control-reducer.cc @@ -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(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. diff --git a/src/compiler/loop-peeling.cc b/src/compiler/loop-peeling.cc index 6a59efc..f1a5667 100644 --- a/src/compiler/loop-peeling.cc +++ b/src/compiler/loop-peeling.cc @@ -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(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; -- 2.7.4