Commit 380b720d authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Compiler] Have renumber recurse into eagerly compiled function literals.

This enables us to produce the list of eager inner functions for compilation
in one go during the outer function's renumbering step, and avoid having
to do renumbering explicitly on the inner functions, simplifying the zone
ownership.

BUG=v8:5203, v8:5215

Review-Url: https://codereview.chromium.org/2648503002
Cr-Original-Commit-Position: refs/heads/master@{#42540}
Committed: https://chromium.googlesource.com/v8/v8/+/3541a074e241421b64ba41d81d8a99bb6ac62c5e
Review-Url: https://codereview.chromium.org/2648503002
Cr-Commit-Position: refs/heads/master@{#42580}
parent 87851fda
...@@ -592,12 +592,18 @@ void AstNumberingVisitor::VisitArguments(ZoneList<Expression*>* arguments) { ...@@ -592,12 +592,18 @@ void AstNumberingVisitor::VisitArguments(ZoneList<Expression*>* arguments) {
void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) { void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
IncrementNodeCount(); IncrementNodeCount();
node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids())); node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids()));
if (eager_literals_ && node->ShouldEagerCompile()) { if (node->ShouldEagerCompile()) {
eager_literals_->Add(new (zone()) // If the function literal is being eagerly compiled, recurse into the
ThreadedListZoneEntry<FunctionLiteral*>(node)); // declarations and body of the function literal.
if (!AstNumbering::Renumber(stack_limit_, zone_, node, eager_literals_)) {
SetStackOverflow();
return;
}
if (eager_literals_) {
eager_literals_->Add(new (zone())
ThreadedListZoneEntry<FunctionLiteral*>(node));
}
} }
// We don't recurse into the declarations or body of the function literal:
// you have to separately Renumber() each FunctionLiteral that you compile.
ReserveFeedbackSlots(node); ReserveFeedbackSlots(node);
} }
......
...@@ -434,6 +434,17 @@ CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) { ...@@ -434,6 +434,17 @@ CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
return status; return status;
} }
void SetSharedFunctionFlagsFromLiteral(FunctionLiteral* literal,
Handle<SharedFunctionInfo> shared_info) {
shared_info->set_ast_node_count(literal->ast_node_count());
if (literal->dont_optimize_reason() != kNoReason) {
shared_info->DisableOptimization(literal->dont_optimize_reason());
}
if (literal->flags() & AstProperties::kMustUseIgnitionTurbo) {
shared_info->set_must_use_ignition_turbo(true);
}
}
bool Renumber(ParseInfo* parse_info, bool Renumber(ParseInfo* parse_info,
Compiler::EagerInnerFunctionLiterals* eager_literals) { Compiler::EagerInnerFunctionLiterals* eager_literals) {
RuntimeCallTimerScope runtimeTimer(parse_info->isolate(), RuntimeCallTimerScope runtimeTimer(parse_info->isolate(),
...@@ -443,16 +454,9 @@ bool Renumber(ParseInfo* parse_info, ...@@ -443,16 +454,9 @@ bool Renumber(ParseInfo* parse_info,
parse_info->zone(), parse_info->literal(), eager_literals)) { parse_info->zone(), parse_info->literal(), eager_literals)) {
return false; return false;
} }
Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); if (!parse_info->shared_info().is_null()) {
if (!shared_info.is_null()) { SetSharedFunctionFlagsFromLiteral(parse_info->literal(),
FunctionLiteral* lit = parse_info->literal(); parse_info->shared_info());
shared_info->set_ast_node_count(lit->ast_node_count());
if (lit->dont_optimize_reason() != kNoReason) {
shared_info->DisableOptimization(lit->dont_optimize_reason());
}
if (lit->flags() & AstProperties::kMustUseIgnitionTurbo) {
shared_info->set_must_use_ignition_turbo(true);
}
} }
return true; return true;
} }
...@@ -481,7 +485,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) { ...@@ -481,7 +485,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) {
return true; return true;
} }
bool CompileUnoptimizedInnerFunctionsRecursively( bool CompileUnoptimizedInnerFunctions(
ThreadedList<ThreadedListZoneEntry<FunctionLiteral*>>* literals, ThreadedList<ThreadedListZoneEntry<FunctionLiteral*>>* literals,
CompilationInfo* outer_info) { CompilationInfo* outer_info) {
Isolate* isolate = outer_info->isolate(); Isolate* isolate = outer_info->isolate();
...@@ -491,21 +495,13 @@ bool CompileUnoptimizedInnerFunctionsRecursively( ...@@ -491,21 +495,13 @@ bool CompileUnoptimizedInnerFunctionsRecursively(
for (auto it : *literals) { for (auto it : *literals) {
FunctionLiteral* literal = it->value(); FunctionLiteral* literal = it->value();
Handle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfo(literal, script, outer_info);
if (shared->is_compiled()) continue;
// Find any previously allocated shared function info for the given literal. // The {literal} has already been numbered because AstNumbering decends into
Handle<SharedFunctionInfo> shared; // eagerly compiled function literals.
MaybeHandle<SharedFunctionInfo> maybe_existing = SetSharedFunctionFlagsFromLiteral(literal, shared);
script->FindSharedFunctionInfo(isolate, literal);
if (maybe_existing.ToHandle(&shared)) {
DCHECK(!shared->is_toplevel());
// If we found an existing shared function info with compiled code,
// we are done.
if (shared->is_compiled()) continue;
} else {
shared =
isolate->factory()->NewSharedFunctionInfoForLiteral(literal, script);
shared->set_is_toplevel(false);
}
ParseInfo parse_info(script); ParseInfo parse_info(script);
parse_info.set_literal(literal); parse_info.set_literal(literal);
...@@ -520,11 +516,7 @@ bool CompileUnoptimizedInnerFunctionsRecursively( ...@@ -520,11 +516,7 @@ bool CompileUnoptimizedInnerFunctionsRecursively(
if (outer_info->will_serialize()) info.PrepareForSerializing(); if (outer_info->will_serialize()) info.PrepareForSerializing();
if (outer_info->is_debug()) info.MarkAsDebug(); if (outer_info->is_debug()) info.MarkAsDebug();
Compiler::EagerInnerFunctionLiterals inner_literals; if (!GenerateUnoptimizedCode(&info)) {
if (!Renumber(&parse_info, &inner_literals) ||
!CompileUnoptimizedInnerFunctionsRecursively(&inner_literals,
outer_info) ||
!GenerateUnoptimizedCode(&info)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false; return false;
} }
...@@ -544,7 +536,7 @@ bool CompileUnoptimizedCode(CompilationInfo* info) { ...@@ -544,7 +536,7 @@ bool CompileUnoptimizedCode(CompilationInfo* info) {
Compiler::EagerInnerFunctionLiterals inner_literals; Compiler::EagerInnerFunctionLiterals inner_literals;
if (!Compiler::Analyze(info->parse_info(), &inner_literals) || if (!Compiler::Analyze(info->parse_info(), &inner_literals) ||
!CompileUnoptimizedInnerFunctionsRecursively(&inner_literals, info) || !CompileUnoptimizedInnerFunctions(&inner_literals, info) ||
!GenerateUnoptimizedCode(info)) { !GenerateUnoptimizedCode(info)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false; return false;
......
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