Commit d702f707 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Move native context specialization before inlining.

Perform native context specialization immediately after graph
construction (also after inlinee graph construction). This way
we can do unified inlining before we go to typing and typed
lowering. And we will get better typing due to constants and
(checked) type feedback.

R=mstarzinger@chromium.org
BUG=v8:4470
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#31255}
parent a2a45a16
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "src/compiler/all-nodes.h" #include "src/compiler/all-nodes.h"
#include "src/compiler/ast-graph-builder.h" #include "src/compiler/ast-graph-builder.h"
#include "src/compiler/common-operator.h" #include "src/compiler/common-operator.h"
#include "src/compiler/common-operator-reducer.h"
#include "src/compiler/dead-code-elimination.h"
#include "src/compiler/graph-reducer.h"
#include "src/compiler/js-global-specialization.h"
#include "src/compiler/js-operator.h" #include "src/compiler/js-operator.h"
#include "src/compiler/node-matchers.h" #include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
...@@ -310,7 +314,15 @@ Reduction JSInliner::ReduceJSCallFunction(Node* node, ...@@ -310,7 +314,15 @@ Reduction JSInliner::ReduceJSCallFunction(Node* node,
Zone zone; Zone zone;
ParseInfo parse_info(&zone, function); ParseInfo parse_info(&zone, function);
CompilationInfo info(&parse_info); CompilationInfo info(&parse_info);
if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled(); if (info_->is_deoptimization_enabled()) {
info.MarkAsDeoptimizationEnabled();
}
if (info_->is_native_context_specializing()) {
info.MarkAsNativeContextSpecializing();
}
if (info_->is_typing_enabled()) {
info.MarkAsTypingEnabled();
}
if (!Compiler::ParseAndAnalyze(info.parse_info())) { if (!Compiler::ParseAndAnalyze(info.parse_info())) {
TRACE("Not inlining %s into %s because parsing failed\n", TRACE("Not inlining %s into %s because parsing failed\n",
...@@ -339,6 +351,30 @@ Reduction JSInliner::ReduceJSCallFunction(Node* node, ...@@ -339,6 +351,30 @@ Reduction JSInliner::ReduceJSCallFunction(Node* node,
AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph); AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph);
graph_builder.CreateGraph(false); graph_builder.CreateGraph(false);
// TODO(mstarzinger): Unify this with the Pipeline once JSInliner refactoring
// starts.
if (info.is_native_context_specializing()) {
GraphReducer graph_reducer(local_zone_, &graph, jsgraph.Dead());
DeadCodeElimination dead_code_elimination(&graph_reducer, &graph,
jsgraph.common());
CommonOperatorReducer common_reducer(&graph_reducer, &graph,
jsgraph.common(), jsgraph.machine());
JSGlobalSpecialization::Flags flags = JSGlobalSpecialization::kNoFlags;
if (info.is_deoptimization_enabled()) {
flags |= JSGlobalSpecialization::kDeoptimizationEnabled;
}
if (info.is_typing_enabled()) {
flags |= JSGlobalSpecialization::kTypingEnabled;
}
JSGlobalSpecialization global_specialization(
&graph_reducer, &jsgraph, flags,
handle(info.global_object(), info.isolate()), info_->dependencies());
graph_reducer.AddReducer(&dead_code_elimination);
graph_reducer.AddReducer(&common_reducer);
graph_reducer.AddReducer(&global_specialization);
graph_reducer.ReduceGraph();
}
// The inlinee specializes to the context from the JSFunction object. // The inlinee specializes to the context from the JSFunction object.
// TODO(turbofan): We might want to load the context from the JSFunction at // TODO(turbofan): We might want to load the context from the JSFunction at
// runtime in case we only know the SharedFunctionInfo once we have dynamic // runtime in case we only know the SharedFunctionInfo once we have dynamic
......
...@@ -496,6 +496,34 @@ struct GraphBuilderPhase { ...@@ -496,6 +496,34 @@ struct GraphBuilderPhase {
}; };
struct NativeContextSpecializationPhase {
static const char* phase_name() { return "native context specialization"; }
void Run(PipelineData* data, Zone* temp_zone) {
JSGraphReducer graph_reducer(data->jsgraph(), temp_zone);
DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(),
data->common());
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->common(), data->machine());
JSGlobalSpecialization::Flags flags = JSGlobalSpecialization::kNoFlags;
if (data->info()->is_deoptimization_enabled()) {
flags |= JSGlobalSpecialization::kDeoptimizationEnabled;
}
if (data->info()->is_typing_enabled()) {
flags |= JSGlobalSpecialization::kTypingEnabled;
}
JSGlobalSpecialization global_specialization(
&graph_reducer, data->jsgraph(), flags,
handle(data->info()->global_object(), data->isolate()),
data->info()->dependencies());
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &common_reducer);
AddReducer(data, &graph_reducer, &global_specialization);
graph_reducer.ReduceGraph();
}
};
struct InliningPhase { struct InliningPhase {
static const char* phase_name() { return "inlining"; } static const char* phase_name() { return "inlining"; }
...@@ -512,20 +540,6 @@ struct InliningPhase { ...@@ -512,20 +540,6 @@ struct InliningPhase {
: MaybeHandle<Context>()); : MaybeHandle<Context>());
JSFrameSpecialization frame_specialization(data->info()->osr_frame(), JSFrameSpecialization frame_specialization(data->info()->osr_frame(),
data->jsgraph()); data->jsgraph());
JSGlobalSpecialization::Flags global_flags =
JSGlobalSpecialization::kNoFlags;
if (data->info()->is_deoptimization_enabled()) {
global_flags |= JSGlobalSpecialization::kDeoptimizationEnabled;
}
if (data->info()->is_typing_enabled()) {
global_flags |= JSGlobalSpecialization::kTypingEnabled;
}
JSGlobalSpecialization global_specialization(
&graph_reducer, data->jsgraph(), global_flags,
data->info()->has_global_object()
? handle(data->info()->global_object())
: Handle<GlobalObject>(),
data->info()->dependencies());
JSInliningHeuristic inlining(&graph_reducer, JSInliningHeuristic inlining(&graph_reducer,
data->info()->is_inlining_enabled() data->info()->is_inlining_enabled()
? JSInliningHeuristic::kGeneralInlining ? JSInliningHeuristic::kGeneralInlining
...@@ -536,9 +550,6 @@ struct InliningPhase { ...@@ -536,9 +550,6 @@ struct InliningPhase {
if (data->info()->is_frame_specializing()) { if (data->info()->is_frame_specializing()) {
AddReducer(data, &graph_reducer, &frame_specialization); AddReducer(data, &graph_reducer, &frame_specialization);
} }
if (data->info()->is_native_context_specializing()) {
AddReducer(data, &graph_reducer, &global_specialization);
}
AddReducer(data, &graph_reducer, &context_specialization); AddReducer(data, &graph_reducer, &context_specialization);
AddReducer(data, &graph_reducer, &inlining); AddReducer(data, &graph_reducer, &inlining);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
...@@ -1096,7 +1107,13 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -1096,7 +1107,13 @@ Handle<Code> Pipeline::GenerateCode() {
RunPrintAndVerify("OSR deconstruction", true); RunPrintAndVerify("OSR deconstruction", true);
} }
// Perform context specialization and inlining (if enabled). // Perform native context specialization (if enabled).
if (info()->is_native_context_specializing()) {
Run<NativeContextSpecializationPhase>();
RunPrintAndVerify("Native context specialized", true);
}
// Perform function context specialization and inlining (if enabled).
Run<InliningPhase>(); Run<InliningPhase>();
RunPrintAndVerify("Inlined", true); RunPrintAndVerify("Inlined", true);
......
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