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

[turbofan] Turn JSBuiltinReducer 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/1158273011

Cr-Commit-Position: refs/heads/master@{#28813}
parent 74f9d8c9
...@@ -14,17 +14,6 @@ namespace internal { ...@@ -14,17 +14,6 @@ namespace internal {
namespace compiler { namespace compiler {
// Helper method that assumes replacement nodes are pure values that don't
// produce an effect. Replaces {node} with {reduction} and relaxes effects.
static Reduction ReplaceWithPureReduction(Node* node, Reduction reduction) {
if (reduction.Changed()) {
NodeProperties::ReplaceWithValue(node, reduction.replacement());
return reduction;
}
return Reducer::NoChange();
}
// Helper class to access JSCallFunction nodes that are potential candidates // Helper class to access JSCallFunction nodes that are potential candidates
// for reduction when they have a BuiltinFunctionId associated with them. // for reduction when they have a BuiltinFunctionId associated with them.
class JSCallReduction { class JSCallReduction {
...@@ -96,8 +85,10 @@ class JSCallReduction { ...@@ -96,8 +85,10 @@ class JSCallReduction {
}; };
JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph) JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph)
: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} : AdvancedReducer(editor),
jsgraph_(jsgraph),
simplified_(jsgraph->zone()) {}
// ECMA-262, section 15.8.2.11. // ECMA-262, section 15.8.2.11.
...@@ -153,21 +144,30 @@ Reduction JSBuiltinReducer::ReduceMathFround(Node* node) { ...@@ -153,21 +144,30 @@ Reduction JSBuiltinReducer::ReduceMathFround(Node* node) {
Reduction JSBuiltinReducer::Reduce(Node* node) { Reduction JSBuiltinReducer::Reduce(Node* node) {
Reduction reduction = NoChange();
JSCallReduction r(node); JSCallReduction r(node);
// Dispatch according to the BuiltinFunctionId if present. // Dispatch according to the BuiltinFunctionId if present.
if (!r.HasBuiltinFunctionId()) return NoChange(); if (!r.HasBuiltinFunctionId()) return NoChange();
switch (r.GetBuiltinFunctionId()) { switch (r.GetBuiltinFunctionId()) {
case kMathMax: case kMathMax:
return ReplaceWithPureReduction(node, ReduceMathMax(node)); reduction = ReduceMathMax(node);
break;
case kMathImul: case kMathImul:
return ReplaceWithPureReduction(node, ReduceMathImul(node)); reduction = ReduceMathImul(node);
break;
case kMathFround: case kMathFround:
return ReplaceWithPureReduction(node, ReduceMathFround(node)); reduction = ReduceMathFround(node);
break;
default: default:
break; break;
} }
return NoChange();
// Replace builtin call assuming replacement nodes are pure values that don't
// produce an effect. Replaces {node} with {reduction} and relaxes effects.
if (reduction.Changed()) ReplaceWithValue(node, reduction.replacement());
return reduction;
} }
......
...@@ -18,9 +18,9 @@ class JSGraph; ...@@ -18,9 +18,9 @@ class JSGraph;
class MachineOperatorBuilder; class MachineOperatorBuilder;
class JSBuiltinReducer final : public Reducer { class JSBuiltinReducer final : public AdvancedReducer {
public: public:
explicit JSBuiltinReducer(JSGraph* jsgraph); explicit JSBuiltinReducer(Editor* editor, JSGraph* jsgraph);
~JSBuiltinReducer() final {} ~JSBuiltinReducer() final {}
Reduction Reduce(Node* node) final; Reduction Reduce(Node* node) final;
......
...@@ -570,7 +570,7 @@ struct TypedLoweringPhase { ...@@ -570,7 +570,7 @@ struct TypedLoweringPhase {
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); JSGraphReducer graph_reducer(data->jsgraph(), temp_zone);
LoadElimination load_elimination; LoadElimination load_elimination;
JSBuiltinReducer builtin_reducer(data->jsgraph()); JSBuiltinReducer builtin_reducer(&graph_reducer, data->jsgraph());
JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone); JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone);
JSIntrinsicLowering intrinsic_lowering( JSIntrinsicLowering intrinsic_lowering(
&graph_reducer, data->jsgraph(), &graph_reducer, data->jsgraph(),
......
...@@ -26,7 +26,9 @@ class JSBuiltinReducerTest : public TypedGraphTest { ...@@ -26,7 +26,9 @@ class JSBuiltinReducerTest : public TypedGraphTest {
MachineOperatorBuilder::Flag::kNoFlags) { MachineOperatorBuilder::Flag::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);
JSBuiltinReducer reducer(&jsgraph); // TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph());
JSBuiltinReducer 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