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 {
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
// for reduction when they have a BuiltinFunctionId associated with them.
class JSCallReduction {
......@@ -96,8 +85,10 @@ class JSCallReduction {
};
JSBuiltinReducer::JSBuiltinReducer(JSGraph* jsgraph)
: jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph)
: AdvancedReducer(editor),
jsgraph_(jsgraph),
simplified_(jsgraph->zone()) {}
// ECMA-262, section 15.8.2.11.
......@@ -153,21 +144,30 @@ Reduction JSBuiltinReducer::ReduceMathFround(Node* node) {
Reduction JSBuiltinReducer::Reduce(Node* node) {
Reduction reduction = NoChange();
JSCallReduction r(node);
// Dispatch according to the BuiltinFunctionId if present.
if (!r.HasBuiltinFunctionId()) return NoChange();
switch (r.GetBuiltinFunctionId()) {
case kMathMax:
return ReplaceWithPureReduction(node, ReduceMathMax(node));
reduction = ReduceMathMax(node);
break;
case kMathImul:
return ReplaceWithPureReduction(node, ReduceMathImul(node));
reduction = ReduceMathImul(node);
break;
case kMathFround:
return ReplaceWithPureReduction(node, ReduceMathFround(node));
reduction = ReduceMathFround(node);
break;
default:
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;
class MachineOperatorBuilder;
class JSBuiltinReducer final : public Reducer {
class JSBuiltinReducer final : public AdvancedReducer {
public:
explicit JSBuiltinReducer(JSGraph* jsgraph);
explicit JSBuiltinReducer(Editor* editor, JSGraph* jsgraph);
~JSBuiltinReducer() final {}
Reduction Reduce(Node* node) final;
......
......@@ -570,7 +570,7 @@ struct TypedLoweringPhase {
void Run(PipelineData* data, Zone* temp_zone) {
JSGraphReducer graph_reducer(data->jsgraph(), temp_zone);
LoadElimination load_elimination;
JSBuiltinReducer builtin_reducer(data->jsgraph());
JSBuiltinReducer builtin_reducer(&graph_reducer, data->jsgraph());
JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone);
JSIntrinsicLowering intrinsic_lowering(
&graph_reducer, data->jsgraph(),
......
......@@ -26,7 +26,9 @@ class JSBuiltinReducerTest : public TypedGraphTest {
MachineOperatorBuilder::Flag::kNoFlags) {
MachineOperatorBuilder machine(zone(), kMachPtr, flags);
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);
}
......
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