[turbofan] Turn JSContextSpecializer into an AdvancedReducer.
authormstarzinger <mstarzinger@chromium.org>
Mon, 8 Jun 2015 12:10:06 +0000 (05:10 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 8 Jun 2015 12:10:10 +0000 (12:10 +0000)
This in turn allows usage of AdvancedReducer::ReplaceWithValue which
has access to the underlying graph reducer.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28838}

src/compiler/js-context-specialization.cc
src/compiler/js-context-specialization.h
src/compiler/js-inlining.cc
src/compiler/pipeline.cc
test/cctest/compiler/test-js-context-specialization.cc
test/mjsunit/mjsunit.status

index 1bf19ac7d6876017ef4cba9f634f85b0251a4738..a39b66fbc85a002665117d75a26ad20cc7ce8114 100644 (file)
@@ -70,7 +70,7 @@ Reduction JSContextSpecializer::ReduceJSLoadContext(Node* node) {
   // TODO(titzer): record the specialization for sharing code across multiple
   // contexts that have the same value in the corresponding context slot.
   Node* constant = jsgraph_->Constant(value);
-  NodeProperties::ReplaceWithValue(node, constant);
+  ReplaceWithValue(node, constant);
   return Replace(constant);
 }
 
index 4a2ce9829ad55c070c6165c6b1c848e72dce74e5..f01ac3f9707e702bb15c1299d5a7d57c7901e7d5 100644 (file)
@@ -15,9 +15,10 @@ namespace compiler {
 
 // Specializes a given JSGraph to a given context, potentially constant folding
 // some {LoadContext} nodes or strength reducing some {StoreContext} nodes.
-class JSContextSpecializer : public Reducer {
+class JSContextSpecializer : public AdvancedReducer {
  public:
-  explicit JSContextSpecializer(JSGraph* jsgraph) : jsgraph_(jsgraph) {}
+  JSContextSpecializer(Editor* editor, JSGraph* jsgraph)
+      : AdvancedReducer(editor), jsgraph_(jsgraph) {}
 
   Reduction Reduce(Node* node) override;
 
index e587f882bcdec0e2f485630f68be241df4fa3f3b..b26b40502de250ee685c736aea4424f0ba221957 100644 (file)
@@ -276,8 +276,8 @@ Reduction JSInliner::Reduce(Node* node) {
   // type feedback in the compiler.
   AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph);
   graph_builder.CreateGraph(true, false);
-  JSContextSpecializer context_specializer(&jsgraph);
   GraphReducer graph_reducer(local_zone_, &graph);
+  JSContextSpecializer context_specializer(&graph_reducer, &jsgraph);
   graph_reducer.AddReducer(&context_specializer);
   graph_reducer.ReduceGraph();
 
index 1d9b329c5be6354eeec9f8dcb3031bc2f6da32b7..e7c76aabc3934d7212c714197bd75ba34470b87a 100644 (file)
@@ -496,8 +496,8 @@ struct ContextSpecializerPhase {
   static const char* phase_name() { return "context specializing"; }
 
   void Run(PipelineData* data, Zone* temp_zone) {
-    JSContextSpecializer spec(data->jsgraph());
     JSGraphReducer graph_reducer(data->jsgraph(), temp_zone);
+    JSContextSpecializer spec(&graph_reducer, data->jsgraph());
     AddReducer(data, &graph_reducer, &spec);
     graph_reducer.ReduceGraph();
   }
index 7eb50085b6fde35515ce22298d109689074e37f4..6148a12a40f558ec00645a6996adfce886ad625c 100644 (file)
@@ -22,8 +22,11 @@ class ContextSpecializationTester : public HandleAndZoneScope {
         javascript_(main_zone()),
         machine_(main_zone()),
         simplified_(main_zone()),
-        jsgraph_(main_isolate(), graph(), common(), &javascript_, &machine_) {}
+        jsgraph_(main_isolate(), graph(), common(), &javascript_, &machine_),
+        reducer_(main_zone(), graph()),
+        spec_(&reducer_, jsgraph()) {}
 
+  JSContextSpecializer* spec() { return &spec_; }
   Factory* factory() { return main_isolate()->factory(); }
   CommonOperatorBuilder* common() { return &common_; }
   JSOperatorBuilder* javascript() { return &javascript_; }
@@ -38,6 +41,8 @@ class ContextSpecializationTester : public HandleAndZoneScope {
   MachineOperatorBuilder machine_;
   SimplifiedOperatorBuilder simplified_;
   JSGraph jsgraph_;
+  GraphReducer reducer_;
+  JSContextSpecializer spec_;
 };
 
 
@@ -60,13 +65,12 @@ TEST(ReduceJSLoadContext) {
   Node* const_context = t.jsgraph()->Constant(native);
   Node* deep_const_context = t.jsgraph()->Constant(subcontext2);
   Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start);
-  JSContextSpecializer spec(t.jsgraph());
 
   {
     // Mutable slot, constant context, depth = 0 => do nothing.
     Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false),
                                     const_context, const_context, start);
-    Reduction r = spec.ReduceJSLoadContext(load);
+    Reduction r = t.spec()->ReduceJSLoadContext(load);
     CHECK(!r.Changed());
   }
 
@@ -74,7 +78,7 @@ TEST(ReduceJSLoadContext) {
     // Mutable slot, non-constant context, depth = 0 => do nothing.
     Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false),
                                     param_context, param_context, start);
-    Reduction r = spec.ReduceJSLoadContext(load);
+    Reduction r = t.spec()->ReduceJSLoadContext(load);
     CHECK(!r.Changed());
   }
 
@@ -83,7 +87,7 @@ TEST(ReduceJSLoadContext) {
     Node* load = t.graph()->NewNode(
         t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false),
         deep_const_context, deep_const_context, start);
-    Reduction r = spec.ReduceJSLoadContext(load);
+    Reduction r = t.spec()->ReduceJSLoadContext(load);
     CHECK(r.Changed());
     Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0);
     CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
@@ -99,7 +103,7 @@ TEST(ReduceJSLoadContext) {
     // Immutable slot, constant context, depth = 0 => specialize.
     Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true),
                                     const_context, const_context, start);
-    Reduction r = spec.ReduceJSLoadContext(load);
+    Reduction r = t.spec()->ReduceJSLoadContext(load);
     CHECK(r.Changed());
     CHECK(r.replacement() != load);
 
@@ -132,13 +136,12 @@ TEST(ReduceJSStoreContext) {
   Node* const_context = t.jsgraph()->Constant(native);
   Node* deep_const_context = t.jsgraph()->Constant(subcontext2);
   Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start);
-  JSContextSpecializer spec(t.jsgraph());
 
   {
     // Mutable slot, constant context, depth = 0 => do nothing.
     Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0),
                                     const_context, const_context, start);
-    Reduction r = spec.ReduceJSStoreContext(load);
+    Reduction r = t.spec()->ReduceJSStoreContext(load);
     CHECK(!r.Changed());
   }
 
@@ -146,7 +149,7 @@ TEST(ReduceJSStoreContext) {
     // Mutable slot, non-constant context, depth = 0 => do nothing.
     Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0),
                                     param_context, param_context, start);
-    Reduction r = spec.ReduceJSStoreContext(load);
+    Reduction r = t.spec()->ReduceJSStoreContext(load);
     CHECK(!r.Changed());
   }
 
@@ -154,7 +157,7 @@ TEST(ReduceJSStoreContext) {
     // Immutable slot, constant context, depth = 0 => do nothing.
     Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, slot),
                                     const_context, const_context, start);
-    Reduction r = spec.ReduceJSStoreContext(load);
+    Reduction r = t.spec()->ReduceJSStoreContext(load);
     CHECK(!r.Changed());
   }
 
@@ -163,7 +166,7 @@ TEST(ReduceJSStoreContext) {
     Node* load = t.graph()->NewNode(
         t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX),
         deep_const_context, deep_const_context, start);
-    Reduction r = spec.ReduceJSStoreContext(load);
+    Reduction r = t.spec()->ReduceJSStoreContext(load);
     CHECK(r.Changed());
     Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0);
     CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
@@ -197,7 +200,6 @@ TEST(SpecializeToContext) {
 
   Node* const_context = t.jsgraph()->Constant(native);
   Node* param_context = t.graph()->NewNode(t.common()->Parameter(0), start);
-  JSContextSpecializer spec(t.jsgraph());
 
   {
     // Check that specialization replaces values and forwards effects
@@ -232,6 +234,7 @@ TEST(SpecializeToContext) {
 
     // Perform the reduction on the entire graph.
     GraphReducer graph_reducer(t.main_zone(), t.graph());
+    JSContextSpecializer spec(&graph_reducer, t.jsgraph());
     graph_reducer.AddReducer(&spec);
     graph_reducer.ReduceGraph();
 
index 3b6bfc5bf7660a1d9cce5c8485b7d2c8d047ee0f..85dce9f0d23e7f5bdbbc6d31b05625072a2d0df3 100644 (file)
   'regress/regress-331444': [PASS, SLOW],
   'regress/regress-490': [PASS, SLOW],
   'regress/regress-crbug-217858': [PASS, SLOW],
+  'regress/regress-crbug-491062': [PASS, SLOW],
   'regress/regress-create-exception': [PASS, SLOW],
   'regress/regress-json-stringify-gc': [PASS, SLOW],
   'string-indexof-2': [PASS, SLOW],