Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: src/compiler.cc

Issue 2611313002: [complier] Enable parallel eager inner function compilation with compiler dispatcher. (Closed)
Patch Set: Move flag Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 77c0199a40f2b2d48e0dc3ba58856d8caeab05b3..102bff6a0002aa5402cde1674706b90f642f8db3 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -15,6 +15,7 @@
#include "src/bootstrapper.h"
#include "src/codegen.h"
#include "src/compilation-cache.h"
+#include "src/compiler-dispatcher/compiler-dispatcher.h"
#include "src/compiler-dispatcher/optimizing-compile-dispatcher.h"
#include "src/compiler/pipeline.h"
#include "src/crankshaft/hydrogen.h"
@@ -375,6 +376,20 @@ bool ShouldUseIgnition(CompilationInfo* info) {
return shared->PassesFilter(FLAG_ignition_filter);
}
+bool UseAsmWasm(DeclarationScope* scope, Handle<SharedFunctionInfo> shared_info,
+ bool is_debug) {
+ return FLAG_validate_asm && scope->asm_module() &&
+ !shared_info->is_asm_wasm_broken() && !is_debug;
+}
+
+bool UseCompilerDispatcher(CompilerDispatcher* dispatcher,
+ DeclarationScope* scope,
+ Handle<SharedFunctionInfo> shared_info,
+ bool is_debug, bool will_serialize) {
+ return dispatcher->IsEnabled() && !is_debug && !will_serialize &&
+ !UseAsmWasm(scope, shared_info, is_debug);
+}
+
CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) {
// Function should have been parsed and analyzed before creating a compilation
// job.
@@ -428,28 +443,31 @@ void InstallUnoptimizedCode(CompilationInfo* info) {
CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
CompilationJob::Status status = job->FinalizeJob();
if (status == CompilationJob::SUCCEEDED) {
- InstallUnoptimizedCode(job->info());
+ CompilationInfo* info = job->info();
+ DCHECK(!info->code().is_null());
+ if (info->parse_info()->literal()->should_be_used_once_hint()) {
+ info->code()->MarkToBeExecutedOnce(info->isolate());
+ }
+ InstallUnoptimizedCode(info);
job->RecordUnoptimizedCompilationStats();
}
return status;
}
-bool Renumber(ParseInfo* parse_info,
+bool Renumber(Isolate* isolate, Zone* zone, FunctionLiteral* literal,
+ Handle<SharedFunctionInfo> shared_info,
Compiler::EagerInnerFunctionLiterals* eager_literals) {
- RuntimeCallTimerScope runtimeTimer(parse_info->isolate(),
+ RuntimeCallTimerScope runtimeTimer(isolate,
&RuntimeCallStats::CompileRenumber);
- if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(),
- parse_info->literal(), eager_literals)) {
+ if (!AstNumbering::Renumber(isolate, zone, 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());
+ shared_info->set_ast_node_count(literal->ast_node_count());
+ if (literal->dont_optimize_reason() != kNoReason) {
+ shared_info->DisableOptimization(literal->dont_optimize_reason());
}
- if (lit->flags() & AstProperties::kMustUseIgnitionTurbo) {
+ if (literal->flags() & AstProperties::kMustUseIgnitionTurbo) {
shared_info->set_must_use_ignition_turbo(true);
}
}
@@ -457,8 +475,7 @@ bool Renumber(ParseInfo* parse_info,
}
bool GenerateUnoptimizedCode(CompilationInfo* info) {
- if (FLAG_validate_asm && info->scope()->asm_module() &&
- !info->shared_info()->is_asm_wasm_broken() && !info->is_debug()) {
+ if (UseAsmWasm(info->scope(), info->shared_info(), info->is_debug())) {
EnsureFeedbackMetadata(info);
MaybeHandle<FixedArray> wasm_data;
wasm_data = AsmJs::CompileAsmViaWasm(info);
@@ -485,54 +502,54 @@ bool CompileUnoptimizedInnerFunctionsRecursively(
CompilationInfo* outer_info) {
Isolate* isolate = outer_info->isolate();
Handle<Script> script = outer_info->script();
+ bool is_debug = outer_info->is_debug();
+ bool will_serialize = outer_info->will_serialize();
RuntimeCallTimerScope runtimeTimer(isolate,
&RuntimeCallStats::CompileInnerFunction);
for (auto it : *literals) {
FunctionLiteral* literal = it->value();
-
- // 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);
- }
-
- Zone zone(isolate->allocator(), ZONE_NAME);
- ParseInfo parse_info(&zone, script);
- parse_info.set_literal(literal);
- parse_info.set_shared_info(shared);
- parse_info.set_function_literal_id(shared->function_literal_id());
- parse_info.set_language_mode(literal->scope()->language_mode());
- parse_info.set_ast_value_factory(
- outer_info->parse_info()->ast_value_factory());
- parse_info.set_ast_value_factory_owned(false);
-
- CompilationInfo info(&parse_info, Handle<JSFunction>::null());
- if (outer_info->will_serialize()) info.PrepareForSerializing();
- if (outer_info->is_debug()) info.MarkAsDebug();
-
+ Handle<SharedFunctionInfo> shared =
+ Compiler::GetSharedFunctionInfo(literal, script, outer_info);
Compiler::EagerInnerFunctionLiterals inner_literals;
- if (!Renumber(&parse_info, &inner_literals) ||
+ if (!Renumber(isolate, outer_info->zone(), literal, shared,
+ &inner_literals) ||
!CompileUnoptimizedInnerFunctionsRecursively(&inner_literals,
- outer_info) ||
- !GenerateUnoptimizedCode(&info)) {
+ outer_info)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
}
- DCHECK(!info.code().is_null());
- RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, &info);
- if (literal->should_be_used_once_hint()) {
- info.code()->MarkToBeExecutedOnce(isolate);
+ // Try to enqueue the eager function on the compiler dispatcher.
+ CompilerDispatcher* dispatcher = isolate->compiler_dispatcher();
+ if (UseCompilerDispatcher(dispatcher, literal->scope(), shared, is_debug,
+ will_serialize) &&
+ dispatcher->EnqueueAndStep(
+ shared, literal, outer_info->parse_info()->ast_value_factory())) {
+ // If we have successfully queued up the function for compilation on the
+ // compiler dispatcher then we are done.
+ continue;
+ } else {
+ // Otherwise generate unoptimized code now.
+ Zone zone(isolate->allocator(), ZONE_NAME);
+ ParseInfo parse_info(&zone, script);
+ CompilationInfo info(&parse_info, Handle<JSFunction>::null());
+
+ parse_info.set_literal(literal);
+ parse_info.set_shared_info(shared);
+ parse_info.set_function_literal_id(shared->function_literal_id());
+ parse_info.set_language_mode(literal->scope()->language_mode());
+ parse_info.set_ast_value_factory(
+ outer_info->parse_info()->ast_value_factory());
+ parse_info.set_ast_value_factory_owned(false);
+
+ if (will_serialize) info.PrepareForSerializing();
+ if (is_debug) info.MarkAsDebug();
+
+ if (!GenerateUnoptimizedCode(&info)) {
+ if (!isolate->has_pending_exception()) isolate->StackOverflow();
+ return false;
+ }
}
}
return true;
@@ -550,6 +567,15 @@ bool CompileUnoptimizedCode(CompilationInfo* info) {
return false;
}
+ // TODO(rmcilroy): Remove this once the enqueued tasks can keep the parsed
+ // zone and handles alive and replace with a check in CompileLazy to finish
+ // the task itself.
+ if (isolate->compiler_dispatcher()->IsEnabled() &&
+ !isolate->compiler_dispatcher()->FinishAllNow()) {
+ if (!isolate->has_pending_exception()) isolate->StackOverflow();
+ return false;
+ }
+
return true;
}
@@ -1125,7 +1151,10 @@ bool Compiler::Analyze(ParseInfo* info,
&RuntimeCallStats::CompileAnalyse);
if (!Rewriter::Rewrite(info)) return false;
DeclarationScope::Analyze(info, AnalyzeMode::kRegular);
- if (!Renumber(info, eager_literals)) return false;
+ if (!Renumber(info->isolate(), info->zone(), info->literal(),
+ info->shared_info(), eager_literals)) {
+ return false;
+ }
DCHECK_NOT_NULL(info->scope());
return true;
}

Powered by Google App Engine
This is Rietveld 408576698