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

Side by Side Diff: src/compiler.cc

Issue 2156753002: [Intepreter] Always use BytecodeGraphBuilder when --turbo-from-bytecode (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler.h" 5 #include "src/compiler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "src/asmjs/asm-js.h" 9 #include "src/asmjs/asm-js.h"
10 #include "src/asmjs/asm-typer.h" 10 #include "src/asmjs/asm-typer.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 info->isolate(), info->literal()->feedback_vector_spec()); 434 info->isolate(), info->literal()->feedback_vector_spec());
435 info->shared_info()->set_feedback_metadata(*feedback_metadata); 435 info->shared_info()->set_feedback_metadata(*feedback_metadata);
436 } 436 }
437 437
438 // It's very important that recompiles do not alter the structure of the type 438 // It's very important that recompiles do not alter the structure of the type
439 // feedback vector. Verify that the structure fits the function literal. 439 // feedback vector. Verify that the structure fits the function literal.
440 CHECK(!info->shared_info()->feedback_metadata()->SpecDiffersFrom( 440 CHECK(!info->shared_info()->feedback_metadata()->SpecDiffersFrom(
441 info->literal()->feedback_vector_spec())); 441 info->literal()->feedback_vector_spec()));
442 } 442 }
443 443
444 bool UseIgnition(CompilationInfo* info) {
445 DCHECK(info->has_shared_info());
446
447 // When requesting debug code as a replacement for existing code, we provide
448 // the same kind as the existing code (to prevent implicit tier-change).
449 if (info->is_debug() && info->shared_info()->is_compiled()) {
450 return info->shared_info()->HasBytecodeArray();
451 }
452
453 // For generator or async functions we might avoid Ignition wholesale.
454 if (info->shared_info()->is_resumable() && !FLAG_ignition_generators) {
455 return false;
456 }
457
458 // Since we can't OSR from Ignition, skip Ignition for asm.js functions.
459 if (info->shared_info()->asm_function()) {
460 return false;
461 }
462
463 // Checks whether top level functions should be passed by the filter.
464 if (info->shared_info()->is_toplevel()) {
465 Vector<const char> filter = CStrVector(FLAG_ignition_filter);
466 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*');
467 }
468
469 // Finally respect the filter.
470 return info->shared_info()->PassesFilter(FLAG_ignition_filter);
471 }
472
473 int CodeAndMetadataSize(CompilationInfo* info) { 444 int CodeAndMetadataSize(CompilationInfo* info) {
474 if (info->has_bytecode_array()) { 445 if (info->has_bytecode_array()) {
475 return info->bytecode_array()->SizeIncludingMetadata(); 446 return info->bytecode_array()->SizeIncludingMetadata();
476 } 447 }
477 return info->code()->SizeIncludingMetadata(); 448 return info->code()->SizeIncludingMetadata();
478 } 449 }
479 450
480 bool GenerateUnoptimizedCode(CompilationInfo* info) { 451 bool GenerateUnoptimizedCode(CompilationInfo* info) {
481 bool success; 452 bool success;
482 EnsureFeedbackMetadata(info); 453 EnsureFeedbackMetadata(info);
483 if (FLAG_validate_asm && info->scope()->asm_module()) { 454 if (FLAG_validate_asm && info->scope()->asm_module()) {
484 MaybeHandle<FixedArray> wasm_data; 455 MaybeHandle<FixedArray> wasm_data;
485 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); 456 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info());
486 if (!wasm_data.is_null()) { 457 if (!wasm_data.is_null()) {
487 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); 458 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked());
488 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); 459 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs());
489 return true; 460 return true;
490 } 461 }
491 } 462 }
492 if (FLAG_ignition && UseIgnition(info)) { 463 if (FLAG_ignition && Compiler::ShouldUseIgnition(info)) {
493 success = interpreter::Interpreter::MakeBytecode(info); 464 success = interpreter::Interpreter::MakeBytecode(info);
494 } else { 465 } else {
495 success = FullCodeGenerator::MakeCode(info); 466 success = FullCodeGenerator::MakeCode(info);
496 } 467 }
497 if (success) { 468 if (success) {
498 Isolate* isolate = info->isolate(); 469 Isolate* isolate = info->isolate();
499 Counters* counters = isolate->counters(); 470 Counters* counters = isolate->counters();
500 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually. 471 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually.
501 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); 472 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info));
502 counters->total_baseline_compile_count()->Increment(1); 473 counters->total_baseline_compile_count()->Increment(1);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 return MaybeHandle<Code>(); 766 return MaybeHandle<Code>();
796 } 767 }
797 768
798 CanonicalHandleScope canonical(isolate); 769 CanonicalHandleScope canonical(isolate);
799 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); 770 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate);
800 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::OptimizeCode); 771 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::OptimizeCode);
801 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.OptimizeCode"); 772 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.OptimizeCode");
802 773
803 // TurboFan can optimize directly from existing bytecode. 774 // TurboFan can optimize directly from existing bytecode.
804 if (FLAG_turbo_from_bytecode && use_turbofan && 775 if (FLAG_turbo_from_bytecode && use_turbofan &&
805 info->shared_info()->HasBytecodeArray()) { 776 Compiler::ShouldUseIgnition(info)) {
777 if (!Compiler::EnsureBytecode(info)) return MaybeHandle<Code>();
806 info->MarkAsOptimizeFromBytecode(); 778 info->MarkAsOptimizeFromBytecode();
807 } 779 }
808 780
809 if (IsEvalToplevel(shared)) { 781 if (IsEvalToplevel(shared)) {
810 parse_info->set_eval(); 782 parse_info->set_eval();
811 if (function->context()->IsNativeContext()) parse_info->set_global(); 783 if (function->context()->IsNativeContext()) parse_info->set_global();
812 parse_info->set_toplevel(); 784 parse_info->set_toplevel();
813 parse_info->set_allow_lazy_parsing(false); 785 parse_info->set_allow_lazy_parsing(false);
814 parse_info->set_lazy(false); 786 parse_info->set_lazy(false);
815 } 787 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 } 1309 }
1338 1310
1339 // Restore the original function info list in order to remain side-effect 1311 // Restore the original function info list in order to remain side-effect
1340 // free as much as possible, since some code expects the old shared function 1312 // free as much as possible, since some code expects the old shared function
1341 // infos to stick around. 1313 // infos to stick around.
1342 script->set_shared_function_infos(*old_function_infos); 1314 script->set_shared_function_infos(*old_function_infos);
1343 1315
1344 return infos; 1316 return infos;
1345 } 1317 }
1346 1318
1319 bool Compiler::EnsureBytecode(CompilationInfo* info) {
1320 DCHECK(Compiler::ShouldUseIgnition(info));
1321 if (!info->shared_info()->HasBytecodeArray()) {
1322 DCHECK(!info->shared_info()->is_compiled());
1323 if (GetUnoptimizedCode(info).is_null()) return false;
1324 }
1325 DCHECK(info->shared_info()->HasBytecodeArray());
1326 return true;
1327 }
1328
1347 // TODO(turbofan): In the future, unoptimized code with deopt support could 1329 // TODO(turbofan): In the future, unoptimized code with deopt support could
1348 // be generated lazily once deopt is triggered. 1330 // be generated lazily once deopt is triggered.
1349 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { 1331 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) {
1350 DCHECK_NOT_NULL(info->literal()); 1332 DCHECK_NOT_NULL(info->literal());
1351 DCHECK_NOT_NULL(info->scope()); 1333 DCHECK_NOT_NULL(info->scope());
1352 Handle<SharedFunctionInfo> shared = info->shared_info(); 1334 Handle<SharedFunctionInfo> shared = info->shared_info();
1353 if (!shared->has_deoptimization_support()) { 1335 if (!shared->has_deoptimization_support()) {
1354 Zone zone(info->isolate()->allocator()); 1336 Zone zone(info->isolate()->allocator());
1355 CompilationInfo unoptimized(info->parse_info(), info->closure()); 1337 CompilationInfo unoptimized(info->parse_info(), info->closure());
1356 unoptimized.EnableDeoptimizationSupport(); 1338 unoptimized.EnableDeoptimizationSupport();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 // Install compilation result on the shared function info 1380 // Install compilation result on the shared function info
1399 shared->EnableDeoptimizationSupport(*unoptimized.code()); 1381 shared->EnableDeoptimizationSupport(*unoptimized.code());
1400 1382
1401 // The existing unoptimized code was replaced with the new one. 1383 // The existing unoptimized code was replaced with the new one.
1402 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, 1384 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG,
1403 &unoptimized); 1385 &unoptimized);
1404 } 1386 }
1405 return true; 1387 return true;
1406 } 1388 }
1407 1389
1390 // static
1391 Compiler::CompilationTier Compiler::NextCompilationTier(JSFunction* function) {
1392 Handle<SharedFunctionInfo> shared(function->shared(), function->GetIsolate());
1393 if (shared->code()->is_interpreter_trampoline_builtin()) {
1394 if (FLAG_turbo_from_bytecode && UseTurboFan(shared)) {
1395 return OPTIMIZED;
1396 } else {
1397 return BASELINE;
1398 }
1399 } else {
1400 return OPTIMIZED;
1401 }
1402 }
1403
1404 // static
1405 bool Compiler::ShouldUseIgnition(CompilationInfo* info) {
1406 DCHECK(info->has_shared_info());
1407
1408 // When requesting debug code as a replacement for existing code, we provide
1409 // the same kind as the existing code (to prevent implicit tier-change).
1410 if (info->is_debug() && info->shared_info()->is_compiled()) {
1411 return info->shared_info()->HasBytecodeArray();
1412 }
1413
1414 // For generator or async functions we might avoid Ignition wholesale.
1415 if (info->shared_info()->is_resumable() && !FLAG_ignition_generators) {
1416 return false;
1417 }
1418
1419 // Since we can't OSR from Ignition, skip Ignition for asm.js functions.
1420 if (info->shared_info()->asm_function()) {
1421 return false;
1422 }
1423
1424 // Checks whether top level functions should be passed by the filter.
1425 if (info->shared_info()->is_toplevel()) {
1426 Vector<const char> filter = CStrVector(FLAG_ignition_filter);
1427 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*');
1428 }
1429
1430 // Finally respect the filter.
1431 return info->shared_info()->PassesFilter(FLAG_ignition_filter);
1432 }
1433
1408 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( 1434 MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
1409 Handle<String> source, Handle<SharedFunctionInfo> outer_info, 1435 Handle<String> source, Handle<SharedFunctionInfo> outer_info,
1410 Handle<Context> context, LanguageMode language_mode, 1436 Handle<Context> context, LanguageMode language_mode,
1411 ParseRestriction restriction, int eval_scope_position, int eval_position, 1437 ParseRestriction restriction, int eval_scope_position, int eval_position,
1412 int line_offset, int column_offset, Handle<Object> script_name, 1438 int line_offset, int column_offset, Handle<Object> script_name,
1413 ScriptOriginOptions options) { 1439 ScriptOriginOptions options) {
1414 Isolate* isolate = source->GetIsolate(); 1440 Isolate* isolate = source->GetIsolate();
1415 int source_length = source->length(); 1441 int source_length = source->length();
1416 isolate->counters()->total_eval_size()->Increment(source_length); 1442 isolate->counters()->total_eval_size()->Increment(source_length);
1417 isolate->counters()->total_compile_size()->Increment(source_length); 1443 isolate->counters()->total_compile_size()->Increment(source_length);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 DCHECK(shared->is_compiled()); 1869 DCHECK(shared->is_compiled());
1844 function->set_literals(cached.literals); 1870 function->set_literals(cached.literals);
1845 } else if (shared->is_compiled()) { 1871 } else if (shared->is_compiled()) {
1846 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1872 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1847 JSFunction::EnsureLiterals(function); 1873 JSFunction::EnsureLiterals(function);
1848 } 1874 }
1849 } 1875 }
1850 1876
1851 } // namespace internal 1877 } // namespace internal
1852 } // namespace v8 1878 } // namespace v8
OLDNEW
« src/compiler.h ('K') | « src/compiler.h ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698