Reviewers: Michael Starzinger,

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

[email protected]
BUG=

Please review this at https://codereview.chromium.org/859053002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+34, -36 lines):
  M src/compiler/common-operator.h
  M src/compiler/common-operator.cc
  M src/compiler/control-reducer.cc
  M src/compiler/loop-peeling.cc


Index: src/compiler/common-operator.cc
diff --git a/src/compiler/common-operator.cc b/src/compiler/common-operator.cc index e7d583f831df475fae0edbd4f6c37f36acea7b8c..74a8cdedfc25105972a6262bcc351ee6a3bb03fb 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<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
Index: src/compiler/common-operator.h
diff --git a/src/compiler/common-operator.h b/src/compiler/common-operator.h
index d61e110a12d6cbd4ec510b74196289e0c283aebd..efbda59ccdef12456f02afa2ab3a1c1317ba5448 100644
--- a/src/compiler/common-operator.h
+++ b/src/compiler/common-operator.h
@@ -200,6 +200,7 @@ class CommonOperatorBuilder FINAL : public ZoneObject {
       MaybeHandle<JSFunction> jsfunction = MaybeHandle<JSFunction>());
   const Operator* Call(const CallDescriptor* descriptor);
   const Operator* Projection(size_t index);
+  const Operator* ResizeMergeOrPhi(const Operator* op, int size);

  private:
   Zone* zone() const { return zone_; }
Index: src/compiler/control-reducer.cc
diff --git a/src/compiler/control-reducer.cc b/src/compiler/control-reducer.cc index ebddfc01e872839bbb8cfac3d8504f619fe721bc..d34b4e8dcec7f207ee9a7f03ef8aff0cda0b9606 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<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.
Index: src/compiler/loop-peeling.cc
diff --git a/src/compiler/loop-peeling.cc b/src/compiler/loop-peeling.cc
index 6a59efc1dce0b00a71f3319b6d06d10e0372e653..f1a5667c534282b9a69a9b0b37ee0c3eac8278c7 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<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;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to