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) {
void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) {
IncrementNodeCount();
node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids()));
if (eager_literals_ && node->ShouldEagerCompile()) {
eager_literals_->Add(new (zone())
ThreadedListZoneEntry<FunctionLiteral*>(node));
if (node->ShouldEagerCompile()) {
// If the function literal is being eagerly compiled, recurse into the
// 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);
}
......
......@@ -434,6 +434,17 @@ CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
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,
Compiler::EagerInnerFunctionLiterals* eager_literals) {
RuntimeCallTimerScope runtimeTimer(parse_info->isolate(),
......@@ -443,16 +454,9 @@ bool Renumber(ParseInfo* parse_info,
parse_info->zone(), parse_info->literal(), eager_literals)) {
return false;
}
Handle<SharedFunctionInfo> shared_info = parse_info->shared_info();
if (!shared_info.is_null()) {
FunctionLiteral* lit = parse_info->literal();
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);
}
if (!parse_info->shared_info().is_null()) {
SetSharedFunctionFlagsFromLiteral(parse_info->literal(),
parse_info->shared_info());
}
return true;
}
......@@ -481,7 +485,7 @@ bool GenerateUnoptimizedCode(CompilationInfo* info) {
return true;
}
bool CompileUnoptimizedInnerFunctionsRecursively(
bool CompileUnoptimizedInnerFunctions(
ThreadedList<ThreadedListZoneEntry<FunctionLiteral*>>* literals,
CompilationInfo* outer_info) {
Isolate* isolate = outer_info->isolate();
......@@ -491,21 +495,13 @@ bool CompileUnoptimizedInnerFunctionsRecursively(
for (auto it : *literals) {
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.
Handle<SharedFunctionInfo> shared;
MaybeHandle<SharedFunctionInfo> maybe_existing =
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);
}
// The {literal} has already been numbered because AstNumbering decends into
// eagerly compiled function literals.
SetSharedFunctionFlagsFromLiteral(literal, shared);
ParseInfo parse_info(script);
parse_info.set_literal(literal);
......@@ -520,11 +516,7 @@ bool CompileUnoptimizedInnerFunctionsRecursively(
if (outer_info->will_serialize()) info.PrepareForSerializing();
if (outer_info->is_debug()) info.MarkAsDebug();
Compiler::EagerInnerFunctionLiterals inner_literals;
if (!Renumber(&parse_info, &inner_literals) ||
!CompileUnoptimizedInnerFunctionsRecursively(&inner_literals,
outer_info) ||
!GenerateUnoptimizedCode(&info)) {
if (!GenerateUnoptimizedCode(&info)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
}
......@@ -544,7 +536,7 @@ bool CompileUnoptimizedCode(CompilationInfo* info) {
Compiler::EagerInnerFunctionLiterals inner_literals;
if (!Compiler::Analyze(info->parse_info(), &inner_literals) ||
!CompileUnoptimizedInnerFunctionsRecursively(&inner_literals, info) ||
!CompileUnoptimizedInnerFunctions(&inner_literals, info) ||
!GenerateUnoptimizedCode(info)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
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