Commit c06b1e05 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[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}
parent 66665ae7
...@@ -16,8 +16,10 @@ namespace v8 { ...@@ -16,8 +16,10 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) JSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph)
: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} : AdvancedReducer(editor),
jsgraph_(jsgraph),
simplified_(jsgraph->zone()) {}
Reduction JSIntrinsicLowering::Reduce(Node* node) { Reduction JSIntrinsicLowering::Reduce(Node* node) {
...@@ -95,7 +97,7 @@ Reduction JSIntrinsicLowering::ReduceConstructDouble(Node* node) { ...@@ -95,7 +97,7 @@ Reduction JSIntrinsicLowering::ReduceConstructDouble(Node* node) {
graph()->NewNode(machine()->Float64InsertLowWord32(), graph()->NewNode(machine()->Float64InsertLowWord32(),
jsgraph()->Constant(0), low), jsgraph()->Constant(0), low),
high); high);
NodeProperties::ReplaceWithValue(node, value); ReplaceWithValue(node, value);
return Replace(value); return Replace(value);
} }
...@@ -118,8 +120,7 @@ Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { ...@@ -118,8 +120,7 @@ Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) {
// False branch - the original continuation. // False branch - the original continuation.
Node* if_false = graph()->NewNode(common()->IfFalse(), branch); Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect, ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect, if_false);
if_false);
// True branch: deopt. // True branch: deopt.
Node* if_true = graph()->NewNode(common()->IfTrue(), branch); Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
...@@ -209,7 +210,7 @@ Reduction JSIntrinsicLowering::ReduceIsInstanceType( ...@@ -209,7 +210,7 @@ Reduction JSIntrinsicLowering::ReduceIsInstanceType(
// Replace all effect uses of {node} with the {ephi}. // Replace all effect uses of {node} with the {ephi}.
Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); 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. // Turn the {node} into a Phi.
return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge); return Change(node, common()->Phi(type, 2), vtrue, vfalse, merge);
...@@ -270,7 +271,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringGetChar( ...@@ -270,7 +271,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringGetChar(
node->ReplaceInput(2, effect); node->ReplaceInput(2, effect);
node->ReplaceInput(3, control); node->ReplaceInput(3, control);
node->TrimInputCount(4); node->TrimInputCount(4);
NodeProperties::ReplaceWithValue(node, node, node); RelaxControls(node);
return Changed(node); return Changed(node);
} }
...@@ -292,7 +293,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringSetChar( ...@@ -292,7 +293,7 @@ Reduction JSIntrinsicLowering::ReduceSeqStringSetChar(
node->ReplaceInput(4, control); node->ReplaceInput(4, control);
node->TrimInputCount(5); node->TrimInputCount(5);
NodeProperties::RemoveBounds(node); NodeProperties::RemoveBounds(node);
NodeProperties::ReplaceWithValue(node, string, node); ReplaceWithValue(node, string, node);
return Changed(node); return Changed(node);
} }
...@@ -325,7 +326,7 @@ Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) { ...@@ -325,7 +326,7 @@ Reduction JSIntrinsicLowering::ReduceUnLikely(Node* node, BranchHint hint) {
} }
// Apart from adding hints to branchs nodes, this is the identity function. // Apart from adding hints to branchs nodes, this is the identity function.
Node* value = NodeProperties::GetValueInput(node, 0); Node* value = NodeProperties::GetValueInput(node, 0);
NodeProperties::ReplaceWithValue(node, value); ReplaceWithValue(node, value);
return Changed(value); return Changed(value);
} }
...@@ -386,7 +387,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { ...@@ -386,7 +387,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) {
// Replace all effect uses of {node} with the {ephi0}. // Replace all effect uses of {node} with the {ephi0}.
Node* ephi0 = graph()->NewNode(ephi_op, etrue0, efalse0, merge0); Node* ephi0 = graph()->NewNode(ephi_op, etrue0, efalse0, merge0);
NodeProperties::ReplaceWithValue(node, node, ephi0); ReplaceWithValue(node, node, ephi0);
// Turn the {node} into a Phi. // Turn the {node} into a Phi.
return Change(node, phi_op, vtrue0, vfalse0, merge0); return Change(node, phi_op, vtrue0, vfalse0, merge0);
...@@ -395,7 +396,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) { ...@@ -395,7 +396,7 @@ Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) {
Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) { Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op) {
// Replace all effect uses of {node} with the effect dependency. // 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. // Remove the inputs corresponding to context, effect and control.
NodeProperties::RemoveNonValueInputs(node); NodeProperties::RemoveNonValueInputs(node);
// Finally update the operator to the new one. // Finally update the operator to the new one.
...@@ -419,7 +420,7 @@ Reduction JSIntrinsicLowering::ReduceIsMinusZero(Node* node) { ...@@ -419,7 +420,7 @@ Reduction JSIntrinsicLowering::ReduceIsMinusZero(Node* node) {
machine()->Word32Equal(), double_hi, machine()->Word32Equal(), double_hi,
jsgraph()->Int32Constant(static_cast<int32_t>(0x80000000))); jsgraph()->Int32Constant(static_cast<int32_t>(0x80000000)));
NodeProperties::ReplaceWithValue(node, node, effect); ReplaceWithValue(node, node, effect);
Node* and_result = graph()->NewNode(machine()->Word32And(), check1, check2); Node* and_result = graph()->NewNode(machine()->Word32And(), check1, check2);
...@@ -437,7 +438,7 @@ Reduction JSIntrinsicLowering::ReduceFixedArraySet(Node* node) { ...@@ -437,7 +438,7 @@ Reduction JSIntrinsicLowering::ReduceFixedArraySet(Node* node) {
Node* store = (graph()->NewNode( Node* store = (graph()->NewNode(
simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), base, simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), base,
index, value, effect, control)); index, value, effect, control));
NodeProperties::ReplaceWithValue(node, value, store); ReplaceWithValue(node, value, store);
return Changed(store); return Changed(store);
} }
...@@ -460,7 +461,7 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, ...@@ -460,7 +461,7 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
node->ReplaceInput(0, a); node->ReplaceInput(0, a);
node->ReplaceInput(1, b); node->ReplaceInput(1, b);
node->TrimInputCount(2); node->TrimInputCount(2);
NodeProperties::ReplaceWithValue(node, node, node); RelaxControls(node);
return Changed(node); return Changed(node);
} }
...@@ -472,14 +473,13 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a, ...@@ -472,14 +473,13 @@ Reduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
node->ReplaceInput(1, b); node->ReplaceInput(1, b);
node->ReplaceInput(2, c); node->ReplaceInput(2, c);
node->TrimInputCount(3); node->TrimInputCount(3);
NodeProperties::ReplaceWithValue(node, node, node); RelaxControls(node);
return Changed(node); return Changed(node);
} }
Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) { Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) {
NodeProperties::ReplaceWithValue(node, jsgraph()->UndefinedConstant(), ReplaceWithValue(node, jsgraph()->UndefinedConstant(), effect);
effect);
return Changed(node); return Changed(node);
} }
......
...@@ -20,9 +20,9 @@ class MachineOperatorBuilder; ...@@ -20,9 +20,9 @@ class MachineOperatorBuilder;
// Lowers certain JS-level runtime calls. // Lowers certain JS-level runtime calls.
class JSIntrinsicLowering final : public Reducer { class JSIntrinsicLowering final : public AdvancedReducer {
public: public:
explicit JSIntrinsicLowering(JSGraph* jsgraph); JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph);
~JSIntrinsicLowering() final {} ~JSIntrinsicLowering() final {}
Reduction Reduce(Node* node) final; Reduction Reduce(Node* node) final;
......
...@@ -561,7 +561,7 @@ struct TypedLoweringPhase { ...@@ -561,7 +561,7 @@ struct TypedLoweringPhase {
LoadElimination load_elimination; LoadElimination load_elimination;
JSBuiltinReducer builtin_reducer(data->jsgraph()); JSBuiltinReducer builtin_reducer(data->jsgraph());
JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone); 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()); SimplifiedOperatorReducer simple_reducer(data->jsgraph());
CommonOperatorReducer common_reducer(data->jsgraph()); CommonOperatorReducer common_reducer(data->jsgraph());
AddReducer(data, &graph_reducer, &builtin_reducer); AddReducer(data, &graph_reducer, &builtin_reducer);
......
...@@ -33,7 +33,9 @@ class JSIntrinsicLoweringTest : public GraphTest { ...@@ -33,7 +33,9 @@ class JSIntrinsicLoweringTest : public GraphTest {
MachineOperatorBuilder::kNoFlags) { MachineOperatorBuilder::kNoFlags) {
MachineOperatorBuilder machine(zone(), kMachPtr, flags); MachineOperatorBuilder machine(zone(), kMachPtr, flags);
JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); 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); return reducer.Reduce(node);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment