From c06b1e05ca4ef10a2c9136005bac9b40551d5b93 Mon Sep 17 00:00:00 2001 From: mstarzinger Date: Tue, 19 May 2015 08:10:34 -0700 Subject: [PATCH] [turbofan] Turn JSIntrinsicLowering into an AdvancedReducer. This in turn allows usage of AdvancedReducer::ReplaceWithValue which has access to the underlying graph reducer. It will allow us to deal with exception continuations correctly. R=titzer@chromium.org Review URL: https://codereview.chromium.org/1134663006 Cr-Commit-Position: refs/heads/master@{#28485} --- src/compiler/js-intrinsic-lowering.cc | 34 +++++++++++----------- src/compiler/js-intrinsic-lowering.h | 4 +-- src/compiler/pipeline.cc | 2 +- .../compiler/js-intrinsic-lowering-unittest.cc | 4 ++- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/compiler/js-intrinsic-lowering.cc b/src/compiler/js-intrinsic-lowering.cc index 23b1f80..5e063a7 100644 --- a/src/compiler/js-intrinsic-lowering.cc +++ b/src/compiler/js-intrinsic-lowering.cc @@ -16,8 +16,10 @@ namespace v8 { namespace internal { namespace compiler { -JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) - : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} +JSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph) + : AdvancedReducer(editor), + jsgraph_(jsgraph), + simplified_(jsgraph->zone()) {} Reduction JSIntrinsicLowering::Reduce(Node* node) { @@ -95,7 +97,7 @@ Reduction JSIntrinsicLowering::ReduceConstructDouble(Node* node) { graph()->NewNode(machine()->Float64InsertLowWord32(), jsgraph()->Constant(0), low), high); - NodeProperties::ReplaceWithValue(node, value); + ReplaceWithValue(node, value); return Replace(value); } @@ -118,8 +120,7 @@ Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { // False branch - the original continuation. Node* if_false = graph()->NewNode(common()->IfFalse(), branch); - NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect, - if_false); + ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect, if_false); // True branch: deopt. Node* if_true = graph()->NewNode(common()->IfTrue(), branch); @@ -209,7 +210,7 @@ Reduction JSIntrinsicLowering::ReduceIsInstanceType( // Replace all effect uses of {node} with the {ephi}. Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); - NodeProperties::ReplaceWithValue(node, node, ephi); + ReplaceWithValue(node, node, ephi); // Turn the {node} into a Phi. return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); @@ -270,7 +271,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringGetChar( node->ReplaceInput(2, effect); node->ReplaceInput(3, control); node->TrimInputCount(4); - NodeProperties::ReplaceWithValue(node, node, node); + RelaxControls(node); return Changed(node); } @@ -292,7 +293,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringSetChar( node->ReplaceInput(4, control); node->TrimInputCount(5); NodeProperties::RemoveBounds(node); - NodeProperties::ReplaceWithValue(node, string, node); + ReplaceWithValue(node, string, node); return Changed(node); } @@ -325,7 +326,7 @@ Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { } // Apart from adding hints to branchs nodes, this is the identity function. Node* value = NodeProperties::GetValueInput(node, 0); - NodeProperties::ReplaceWithValue(node, value); + ReplaceWithValue(node, value); return Changed(value); } @@ -386,7 +387,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { // Replace all effect uses of {node} with the {ephi0}. Node* ephi0 = graph()->NewNode(ephi_op, etrue0, efalse0, merge0); - NodeProperties::ReplaceWithValue(node, node, ephi0); + ReplaceWithValue(node, node, ephi0); // Turn the {node} into a Phi. return Change(node, phi_op, vtrue0, vfalse0, merge0); @@ -395,7 +396,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) { // Replace all effect uses of {node} with the effect dependency. - NodeProperties::ReplaceWithValue(node, node); + RelaxEffectsAndControls(node); // Remove the inputs corresponding to context, effect and control. NodeProperties::RemoveNonValueInputs(node); // Finally update the operator to the new one. @@ -419,7 +420,7 @@ Reduction JSIntrinsicLowering::ReduceIsMinusZero(Node* node) { machine()->Word32Equal(), double_hi, jsgraph()->Int32Constant(static_cast(0x80000000))); - NodeProperties::ReplaceWithValue(node, node, effect); + ReplaceWithValue(node, node, effect); Node* and_result = graph()->NewNode(machine()->Word32And(), check1, check2); @@ -437,7 +438,7 @@ Reduction JSIntrinsicLowering::ReduceFixedArraySet(Node* node) { Node* store = (graph()->NewNode( simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), base, index, value, effect, control)); - NodeProperties::ReplaceWithValue(node, value, store); + ReplaceWithValue(node, value, store); return Changed(store); } @@ -460,7 +461,7 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, node->ReplaceInput(0, a); node->ReplaceInput(1, b); node->TrimInputCount(2); - NodeProperties::ReplaceWithValue(node, node, node); + RelaxControls(node); return Changed(node); } @@ -472,14 +473,13 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, node->ReplaceInput(1, b); node->ReplaceInput(2, c); node->TrimInputCount(3); - NodeProperties::ReplaceWithValue(node, node, node); + RelaxControls(node); return Changed(node); } Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { - NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(), - effect); + ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect); return Changed(node); } diff --git a/src/compiler/js-intrinsic-lowering.h b/src/compiler/js-intrinsic-lowering.h index 7bb75ee..339000b 100644 --- a/src/compiler/js-intrinsic-lowering.h +++ b/src/compiler/js-intrinsic-lowering.h @@ -20,9 +20,9 @@ class MachineOperatorBuilder; // Lowers certain JS-level runtime calls. -class JSIntrinsicLowering final : public Reducer { +class JSIntrinsicLowering final : public AdvancedReducer { public: - explicit JSIntrinsicLowering(JSGraph* jsgraph); + JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph); ~JSIntrinsicLowering() final {} Reduction Reduce(Node* node) final; diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index f7c5d43..7387b46 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -561,7 +561,7 @@ struct TypedLoweringPhase { LoadElimination load_elimination; JSBuiltinReducer builtin_reducer(data->jsgraph()); JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone); - JSIntrinsicLowering intrinsic_lowering(data->jsgraph()); + JSIntrinsicLowering intrinsic_lowering(&graph_reducer, data->jsgraph()); SimplifiedOperatorReducer simple_reducer(data->jsgraph()); CommonOperatorReducer common_reducer(data->jsgraph()); AddReducer(data, &graph_reducer, &builtin_reducer); diff --git a/test/unittests/compiler/js-intrinsic-lowering-unittest.cc b/test/unittests/compiler/js-intrinsic-lowering-unittest.cc index bc34306..7c56131 100644 --- a/test/unittests/compiler/js-intrinsic-lowering-unittest.cc +++ b/test/unittests/compiler/js-intrinsic-lowering-unittest.cc @@ -33,7 +33,9 @@ class JSIntrinsicLoweringTest : public GraphTest { MachineOperatorBuilder::kNoFlags) { MachineOperatorBuilder machine(zone(), kMachPtr, flags); JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); - JSIntrinsicLowering reducer(&jsgraph); + // TODO(titzer): mock the GraphReducer here for better unit testing. + GraphReducer graph_reducer(graph(), zone()); + JSIntrinsicLowering reducer(&graph_reducer, &jsgraph); return reducer.Reduce(node); } -- 2.7.4