[turbofan] Brokerize JSContextSpecialization

Bug: v8:7790
Change-Id: Ief620bc24b59c2a4e0c823a7f7cebf5df114b9a6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1787430
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63714}
This commit is contained in:
Maya Lekova 2019-09-12 13:49:26 +02:00 committed by Commit Bot
parent 23d7e79829
commit 27df753f45
3 changed files with 41 additions and 30 deletions

View File

@ -38,7 +38,7 @@ Reduction JSContextSpecialization::ReduceParameter(Node* node) {
// Constant-fold the function parameter {node}.
Handle<JSFunction> function;
if (closure().ToHandle(&function)) {
Node* value = jsgraph()->HeapConstant(function);
Node* value = jsgraph()->Constant(JSFunctionRef(broker_, function));
return Replace(value);
}
}

View File

@ -107,6 +107,23 @@ static constexpr char kRegisterAllocationZoneName[] =
"register-allocation-zone";
static constexpr char kRegisterAllocatorVerifierZoneName[] =
"register-allocator-verifier-zone";
namespace {
Maybe<OuterContext> GetModuleContext(Handle<JSFunction> closure) {
Context current = closure->context();
size_t distance = 0;
while (!current.IsNativeContext()) {
if (current.IsModuleContext()) {
return Just(
OuterContext(handle(current, current.GetIsolate()), distance));
}
current = current.previous();
distance++;
}
return Nothing<OuterContext>();
}
} // anonymous namespace
class PipelineData {
public:
@ -338,6 +355,20 @@ class PipelineData {
return assembler_options_;
}
void ChooseSpecializationContext() {
if (info()->is_function_context_specializing()) {
DCHECK(info()->has_context());
specialization_context_ =
Just(OuterContext(handle(info()->context(), isolate()), 0));
} else {
specialization_context_ = GetModuleContext(info()->closure());
}
}
Maybe<OuterContext> specialization_context() const {
return specialization_context_;
}
size_t* address_of_max_unoptimized_frame_height() {
return &max_unoptimized_frame_height_;
}
@ -546,6 +577,7 @@ class PipelineData {
JumpOptimizationInfo* jump_optimization_info_ = nullptr;
AssemblerOptions assembler_options_;
Maybe<OuterContext> specialization_context_ = Nothing<OuterContext>();
// The maximal combined height of all inlined frames in their unoptimized
// state. Calculated during instruction selection, applied during code
@ -999,6 +1031,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
if (compilation_info()->closure()->raw_feedback_cell().map() ==
ReadOnlyRoots(isolate).one_closure_cell_map()) {
compilation_info()->MarkAsFunctionContextSpecializing();
data_.ChooseSpecializationContext();
}
if (compilation_info()->is_source_positions_enabled()) {
@ -1032,6 +1065,7 @@ PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() {
TRACE_DISABLED_BY_DEFAULT("v8.compile"), "v8.optimizingCompile.execute",
this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, "function",
compilation_info()->shared_info()->TraceIDRef());
bool success;
if (FLAG_turboprop) {
success = pipeline_.OptimizeGraphForMidTier(linkage_);
@ -1239,38 +1273,10 @@ struct GraphBuilderPhase {
}
};
namespace {
Maybe<OuterContext> GetModuleContext(Handle<JSFunction> closure) {
Context current = closure->context();
size_t distance = 0;
while (!current.IsNativeContext()) {
if (current.IsModuleContext()) {
return Just(
OuterContext(handle(current, current.GetIsolate()), distance));
}
current = current.previous();
distance++;
}
return Nothing<OuterContext>();
}
Maybe<OuterContext> ChooseSpecializationContext(
Isolate* isolate, OptimizedCompilationInfo* info) {
if (info->is_function_context_specializing()) {
DCHECK(info->has_context());
return Just(OuterContext(handle(info->context(), isolate), 0));
}
return GetModuleContext(info->closure());
}
} // anonymous namespace
struct InliningPhase {
static const char* phase_name() { return "V8.TFInlining"; }
void Run(PipelineData* data, Zone* temp_zone) {
Isolate* isolate = data->isolate();
OptimizedCompilationInfo* info = data->info();
GraphReducer graph_reducer(temp_zone, data->graph(), &info->tick_counter(),
data->jsgraph()->Dead());
@ -1287,7 +1293,7 @@ struct InliningPhase {
data->dependencies());
JSContextSpecialization context_specialization(
&graph_reducer, data->jsgraph(), data->broker(),
ChooseSpecializationContext(isolate, data->info()),
data->specialization_context(),
data->info()->is_function_context_specializing()
? data->info()->closure()
: MaybeHandle<JSFunction>());
@ -1419,6 +1425,10 @@ struct SerializationPhase {
RunSerializerForBackgroundCompilation(data->broker(), data->dependencies(),
temp_zone, data->info()->closure(),
flags, data->info()->osr_offset());
if (data->specialization_context().IsJust()) {
ContextRef(data->broker(),
data->specialization_context().FromJust().context);
}
}
};

View File

@ -1969,6 +1969,7 @@ void SerializerForBackgroundCompilation::ProcessBuiltinCall(
case Builtins::kPromiseResolveTrampoline:
// For JSCallReducer::ReducePromiseInternalResolve and
// JSNativeContextSpecialization::ReduceJSResolvePromise.
// TODO(mslekova): Check if this condition is redundant.
if (arguments.size() >= 1) {
Hints const& resolution_hints =
arguments.size() >= 2