Revision: 23577
Author:   [email protected]
Date:     Tue Sep  2 05:08:54 2014 UTC
Log:      [turbofan] Fix MachineOperatorReducer to use JSGraph as well.

TEST=compiler-unittests,cctest
[email protected]

Review URL: https://codereview.chromium.org/526083002
https://code.google.com/p/v8/source/detail?r=23577

Modified:
 /branches/bleeding_edge/src/compiler/machine-operator-reducer-unittest.cc
 /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc
 /branches/bleeding_edge/src/compiler/machine-operator-reducer.h
 /branches/bleeding_edge/src/compiler/pipeline.cc
/branches/bleeding_edge/test/cctest/compiler/test-machine-operator-reducer.cc

=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer-unittest.cc Mon Sep 1 10:26:12 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator-reducer-unittest.cc Tue Sep 2 05:08:54 2014 UTC
@@ -4,7 +4,9 @@

 #include "src/base/bits.h"
 #include "src/compiler/graph-unittest.h"
+#include "src/compiler/js-graph.h"
 #include "src/compiler/machine-operator-reducer.h"
+#include "src/compiler/typer.h"

 namespace v8 {
 namespace internal {
@@ -18,7 +20,9 @@

  protected:
   Reduction Reduce(Node* node) {
-    MachineOperatorReducer reducer(graph());
+    Typer typer(zone());
+    JSGraph jsgraph(graph(), common(), &typer);
+    MachineOperatorReducer reducer(&jsgraph);
     return reducer.Reduce(node);
   }

=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Fri Aug 22 07:54:09 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Tue Sep 2 05:08:54 2014 UTC
@@ -5,50 +5,34 @@
 #include "src/compiler/machine-operator-reducer.h"

 #include "src/base/bits.h"
-#include "src/compiler/common-node-cache.h"
 #include "src/compiler/generic-node-inl.h"
 #include "src/compiler/graph.h"
+#include "src/compiler/js-graph.h"
 #include "src/compiler/node-matchers.h"

 namespace v8 {
 namespace internal {
 namespace compiler {

-MachineOperatorReducer::MachineOperatorReducer(Graph* graph)
-    : graph_(graph),
-      cache_(new (graph->zone()) CommonNodeCache(graph->zone())),
-      common_(graph->zone()),
-      machine_(graph->zone()) {}
+MachineOperatorReducer::MachineOperatorReducer(JSGraph* jsgraph)
+    : jsgraph_(jsgraph), machine_(jsgraph->zone()) {}


-MachineOperatorReducer::MachineOperatorReducer(Graph* graph,
-                                               CommonNodeCache* cache)
-    : graph_(graph),
-      cache_(cache),
-      common_(graph->zone()),
-      machine_(graph->zone()) {}
+MachineOperatorReducer::~MachineOperatorReducer() {}


 Node* MachineOperatorReducer::Float64Constant(volatile double value) {
-  Node** loc = cache_->FindFloat64Constant(value);
-  if (*loc == NULL) {
-    *loc = graph_->NewNode(common_.Float64Constant(value));
-  }
-  return *loc;
+  return jsgraph()->Float64Constant(value);
 }


 Node* MachineOperatorReducer::Int32Constant(int32_t value) {
-  Node** loc = cache_->FindInt32Constant(value);
-  if (*loc == NULL) {
-    *loc = graph_->NewNode(common_.Int32Constant(value));
-  }
-  return *loc;
+  return jsgraph()->Int32Constant(value);
 }


 Node* MachineOperatorReducer::Int64Constant(int64_t value) {
-  return graph_->NewNode(common_.Int64Constant(value));
+  return graph()->NewNode(common()->Int64Constant(value));
 }


@@ -82,7 +66,7 @@
             Int32BinopMatcher mrightright(mright.right().node());
             if (mrightright.left().Is(32) &&
                 mrightright.right().node() == mleft.right().node()) {
-              graph_->ChangeOperator(node, machine_.Word32Ror());
+              graph()->ChangeOperator(node, machine()->Word32Ror());
               node->ReplaceInput(0, mleft.left().node());
               node->ReplaceInput(1, mleft.right().node());
               return Changed(node);
@@ -91,7 +75,7 @@
           // (x << K) | (x >> (32 - K)) => x ror K
           if (mleft.right().IsInRange(0, 31) &&
               mright.right().Is(32 - mleft.right().Value())) {
-            graph_->ChangeOperator(node, machine_.Word32Ror());
+            graph()->ChangeOperator(node, machine()->Word32Ror());
             node->ReplaceInput(0, mleft.left().node());
             node->ReplaceInput(1, mleft.right().node());
             return Changed(node);
@@ -107,7 +91,7 @@
             Int32BinopMatcher mleftright(mleft.right().node());
             if (mleftright.left().Is(32) &&
                 mleftright.right().node() == mright.right().node()) {
-              graph_->ChangeOperator(node, machine_.Word32Ror());
+              graph()->ChangeOperator(node, machine()->Word32Ror());
               node->ReplaceInput(0, mright.left().node());
               node->ReplaceInput(1, mright.right().node());
               return Changed(node);
@@ -116,7 +100,7 @@
           // (x >> (32 - K)) | (x << K) => x ror K
           if (mright.right().IsInRange(0, 31) &&
               mleft.right().Is(32 - mright.right().Value())) {
-            graph_->ChangeOperator(node, machine_.Word32Ror());
+            graph()->ChangeOperator(node, machine()->Word32Ror());
             node->ReplaceInput(0, mright.left().node());
             node->ReplaceInput(1, mright.right().node());
             return Changed(node);
@@ -209,13 +193,13 @@
         return ReplaceInt32(m.left().Value() * m.right().Value());
       }
       if (m.right().Is(-1)) {  // x * -1 => 0 - x
-        graph_->ChangeOperator(node, machine_.Int32Sub());
+        graph()->ChangeOperator(node, machine()->Int32Sub());
         node->ReplaceInput(0, Int32Constant(0));
         node->ReplaceInput(1, m.left().node());
         return Changed(node);
       }
       if (m.right().IsPowerOf2()) {  // x * 2^n => x << n
-        graph_->ChangeOperator(node, machine_.Word32Shl());
+        graph()->ChangeOperator(node, machine()->Word32Shl());
node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value())));
         return Changed(node);
       }
@@ -233,7 +217,7 @@
         return ReplaceInt32(m.left().Value() / m.right().Value());
       }
       if (m.right().Is(-1)) {  // x / -1 => 0 - x
-        graph_->ChangeOperator(node, machine_.Int32Sub());
+        graph()->ChangeOperator(node, machine()->Int32Sub());
         node->ReplaceInput(0, Int32Constant(0));
         node->ReplaceInput(1, m.left().node());
         return Changed(node);
@@ -250,7 +234,7 @@
         return ReplaceInt32(m.left().Value() / m.right().Value());
       }
       if (m.right().IsPowerOf2()) {  // x / 2^n => x >> n
-        graph_->ChangeOperator(node, machine_.Word32Shr());
+        graph()->ChangeOperator(node, machine()->Word32Shr());
node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value())));
         return Changed(node);
       }
@@ -279,7 +263,7 @@
         return ReplaceInt32(m.left().Value() % m.right().Value());
       }
       if (m.right().IsPowerOf2()) {  // x % 2^n => x & 2^n-1
-        graph_->ChangeOperator(node, machine_.Word32And());
+        graph()->ChangeOperator(node, machine()->Word32And());
         node->ReplaceInput(1, Int32Constant(m.right().Value() - 1));
         return Changed(node);
       }
@@ -447,6 +431,15 @@
   }
   return NoChange();
 }
-}
+
+
+CommonOperatorBuilder* MachineOperatorReducer::common() const {
+  return jsgraph()->common();
 }
-}  // namespace v8::internal::compiler
+
+
+Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.h Fri Aug 22 07:54:09 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.h Tue Sep 2 05:08:54 2014 UTC
@@ -5,7 +5,6 @@
 #ifndef V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_
 #define V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_

-#include "src/compiler/common-operator.h"
 #include "src/compiler/graph-reducer.h"
 #include "src/compiler/machine-operator.h"

@@ -14,24 +13,20 @@
 namespace compiler {

 // Forward declarations.
-class CommonNodeCache;
+class CommonOperatorBuilder;
+class JSGraph;
+

 // Performs constant folding and strength reduction on nodes that have
 // machine operators.
-class MachineOperatorReducer : public Reducer {
+class MachineOperatorReducer V8_FINAL : public Reducer {
  public:
-  explicit MachineOperatorReducer(Graph* graph);
+  explicit MachineOperatorReducer(JSGraph* jsgraph);
+  ~MachineOperatorReducer();

-  MachineOperatorReducer(Graph* graph, CommonNodeCache* cache);
-
-  virtual Reduction Reduce(Node* node);
+  virtual Reduction Reduce(Node* node) V8_OVERRIDE;

  private:
-  Graph* graph_;
-  CommonNodeCache* cache_;
-  CommonOperatorBuilder common_;
-  MachineOperatorBuilder machine_;
-
   Node* Float64Constant(volatile double value);
   Node* Int32Constant(int32_t value);
   Node* Int64Constant(int64_t value);
@@ -46,9 +41,18 @@
   Reduction ReplaceInt64(int64_t value) {
     return Replace(Int64Constant(value));
   }
+
+  Graph* graph() const;
+  JSGraph* jsgraph() const { return jsgraph_; }
+  CommonOperatorBuilder* common() const;
+  MachineOperatorBuilder* machine() { return &machine_; }
+
+  JSGraph* jsgraph_;
+  MachineOperatorBuilder machine_;
 };
-}
-}
-}  // namespace v8::internal::compiler
+
+}  // namespace compiler
+}  // namespace internal
+}  // namespace v8

 #endif  // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_
=======================================
--- /branches/bleeding_edge/src/compiler/pipeline.cc Thu Aug 28 14:35:11 2014 UTC +++ /branches/bleeding_edge/src/compiler/pipeline.cc Tue Sep 2 05:08:54 2014 UTC
@@ -257,7 +257,7 @@
       MachineOperatorBuilder machine(zone());
       SimplifiedOperatorReducer simple_reducer(&jsgraph, &machine);
       ChangeLowering lowering(&jsgraph, &linkage, &machine);
-      MachineOperatorReducer mach_reducer(&graph);
+      MachineOperatorReducer mach_reducer(&jsgraph);
       GraphReducer graph_reducer(&graph);
// TODO(titzer): Figure out if we should run all reducers at once here.
       graph_reducer.AddReducer(&simple_reducer);
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-machine-operator-reducer.cc Thu Aug 14 09:19:54 2014 UTC +++ /branches/bleeding_edge/test/cctest/compiler/test-machine-operator-reducer.cc Tue Sep 2 05:08:54 2014 UTC
@@ -6,7 +6,9 @@

 #include "src/base/utils/random-number-generator.h"
 #include "src/compiler/graph-inl.h"
+#include "src/compiler/js-graph.h"
 #include "src/compiler/machine-operator-reducer.h"
+#include "src/compiler/typer.h"
 #include "test/cctest/compiler/value-helper.h"

 using namespace v8::internal;
@@ -37,6 +39,8 @@
         machine(main_zone()),
         common(main_zone()),
         graph(main_zone()),
+        typer(main_zone()),
+        jsgraph(&graph, &common, &typer),
         maxuint32(Constant<int32_t>(kMaxUInt32)) {
     Node* s = graph.NewNode(common.Start(num_parameters));
     graph.SetStart(s);
@@ -48,6 +52,8 @@
   MachineOperatorBuilder machine;
   CommonOperatorBuilder common;
   Graph graph;
+  Typer typer;
+  JSGraph jsgraph;
   Node* maxuint32;

   template <typename T>
@@ -68,7 +74,7 @@
   void CheckFoldBinop(volatile T expect, Node* a, Node* b) {
     CHECK_NE(NULL, binop);
     Node* n = graph.NewNode(binop, a, b);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction reduction = reducer.Reduce(n);
     CHECK(reduction.Changed());
     CHECK_NE(n, reduction.replacement());
@@ -80,7 +86,7 @@
   void CheckBinop(Node* expect, Node* a, Node* b) {
     CHECK_NE(NULL, binop);
     Node* n = graph.NewNode(binop, a, b);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction reduction = reducer.Reduce(n);
     CHECK(reduction.Changed());
     CHECK_EQ(expect, reduction.replacement());
@@ -92,7 +98,7 @@
                       Node* right) {
     CHECK_NE(NULL, binop);
     Node* n = graph.NewNode(binop, left, right);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction reduction = reducer.Reduce(n);
     CHECK(reduction.Changed());
     CHECK_EQ(binop, reduction.replacement()->op());
@@ -107,7 +113,7 @@
                       Node* right_expect, Node* left, Node* right) {
     CHECK_NE(NULL, binop);
     Node* n = graph.NewNode(binop, left, right);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction r = reducer.Reduce(n);
     CHECK(r.Changed());
     CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
@@ -122,7 +128,7 @@
                       volatile T right_expect, Node* left, Node* right) {
     CHECK_NE(NULL, binop);
     Node* n = graph.NewNode(binop, left, right);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction r = reducer.Reduce(n);
     CHECK(r.Changed());
     CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
@@ -139,7 +145,7 @@
     Node* k = Constant<T>(constant);
     {
       Node* n = graph.NewNode(binop, k, p);
-      MachineOperatorReducer reducer(&graph);
+      MachineOperatorReducer reducer(&jsgraph);
       Reduction reduction = reducer.Reduce(n);
       CHECK(!reduction.Changed() || reduction.replacement() == n);
       CHECK_EQ(p, n->InputAt(0));
@@ -147,7 +153,7 @@
     }
     {
       Node* n = graph.NewNode(binop, p, k);
-      MachineOperatorReducer reducer(&graph);
+      MachineOperatorReducer reducer(&jsgraph);
       Reduction reduction = reducer.Reduce(n);
       CHECK(!reduction.Changed());
       CHECK_EQ(p, n->InputAt(0));
@@ -163,7 +169,7 @@
     Node* p = Parameter();
     Node* k = Constant<T>(constant);
     Node* n = graph.NewNode(binop, k, p);
-    MachineOperatorReducer reducer(&graph);
+    MachineOperatorReducer reducer(&jsgraph);
     Reduction reduction = reducer.Reduce(n);
     CHECK(!reduction.Changed());
     CHECK_EQ(k, n->InputAt(0));
@@ -633,7 +639,7 @@
   Node* load = R.graph.NewNode(R.machine.Load(kMachInt32), base, index);

   {
-    MachineOperatorReducer reducer(&R.graph);
+    MachineOperatorReducer reducer(&R.jsgraph);
     Reduction reduction = reducer.Reduce(load);
     CHECK(!reduction.Changed());  // loads should not be reduced.
   }
@@ -641,7 +647,7 @@
   {
Node* store = R.graph.NewNode(R.machine.Store(kMachInt32, kNoWriteBarrier),
                                   base, index, load);
-    MachineOperatorReducer reducer(&R.graph);
+    MachineOperatorReducer reducer(&R.jsgraph);
     Reduction reduction = reducer.Reduce(store);
     CHECK(!reduction.Changed());  // stores should not be reduced.
   }

--
--
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