OLD | NEW |
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/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 | 315 |
316 OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { | 316 OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { |
317 DCHECK(info()->IsOptimizing()); | 317 DCHECK(info()->IsOptimizing()); |
318 DCHECK(!info()->IsCompilingForDebugging()); | 318 DCHECK(!info()->IsCompilingForDebugging()); |
319 | 319 |
320 // Do not use Crankshaft/TurboFan if we need to be able to set break points. | 320 // Do not use Crankshaft/TurboFan if we need to be able to set break points. |
321 if (isolate()->debug()->has_break_points()) { | 321 if (isolate()->debug()->has_break_points()) { |
322 return RetryOptimization(kDebuggerHasBreakPoints); | 322 return RetryOptimization(kDebuggerHasBreakPoints); |
323 } | 323 } |
324 | 324 |
325 // Limit the number of times we re-compile a functions with | 325 // Limit the number of times we try to optimize functions. |
326 // the optimizing compiler. | |
327 const int kMaxOptCount = | 326 const int kMaxOptCount = |
328 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; | 327 FLAG_deopt_every_n_times == 0 ? FLAG_max_opt_count : 1000; |
329 if (info()->opt_count() > kMaxOptCount) { | 328 if (info()->opt_count() > kMaxOptCount) { |
330 return AbortOptimization(kOptimizedTooManyTimes); | 329 return AbortOptimization(kOptimizedTooManyTimes); |
331 } | 330 } |
332 | 331 |
333 // Due to an encoding limit on LUnallocated operands in the Lithium | |
334 // language, we cannot optimize functions with too many formal parameters | |
335 // or perform on-stack replacement for function with too many | |
336 // stack-allocated local variables. | |
337 // | |
338 // The encoding is as a signed value, with parameters and receiver using | |
339 // the negative indices and locals the non-negative ones. | |
340 const int parameter_limit = -LUnallocated::kMinFixedSlotIndex; | |
341 Scope* scope = info()->scope(); | |
342 if ((scope->num_parameters() + 1) > parameter_limit) { | |
343 return AbortOptimization(kTooManyParameters); | |
344 } | |
345 | |
346 const int locals_limit = LUnallocated::kMaxFixedSlotIndex; | |
347 if (info()->is_osr() && | |
348 scope->num_parameters() + 1 + scope->num_stack_slots() > locals_limit) { | |
349 return AbortOptimization(kTooManyParametersLocals); | |
350 } | |
351 | |
352 // Check the whitelist for Crankshaft. | 332 // Check the whitelist for Crankshaft. |
353 if (!info()->closure()->PassesFilter(FLAG_hydrogen_filter)) { | 333 if (!info()->closure()->PassesFilter(FLAG_hydrogen_filter)) { |
354 return AbortOptimization(kHydrogenFilter); | 334 return AbortOptimization(kHydrogenFilter); |
355 } | 335 } |
356 | 336 |
357 // Optimization requires a version of fullcode with deoptimization support. | 337 // Optimization requires a version of fullcode with deoptimization support. |
358 // Recompile the unoptimized version of the code if the current version | 338 // Recompile the unoptimized version of the code if the current version |
359 // doesn't have deoptimization support already. | 339 // doesn't have deoptimization support already. |
360 // Otherwise, if we are gathering compilation time and space statistics | 340 // Otherwise, if we are gathering compilation time and space statistics |
361 // for hydrogen, gather baseline statistics for a fullcode compilation. | 341 // for hydrogen, gather baseline statistics for a fullcode compilation. |
(...skipping 10 matching lines...) Expand all Loading... |
372 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed()); | 352 isolate()->GetHStatistics()->IncrementFullCodeGen(timer.Elapsed()); |
373 } | 353 } |
374 } | 354 } |
375 | 355 |
376 DCHECK(info()->shared_info()->has_deoptimization_support()); | 356 DCHECK(info()->shared_info()->has_deoptimization_support()); |
377 | 357 |
378 // Check the enabling conditions for TurboFan. | 358 // Check the enabling conditions for TurboFan. |
379 if (((FLAG_turbo_asm && info()->shared_info()->asm_function()) || | 359 if (((FLAG_turbo_asm && info()->shared_info()->asm_function()) || |
380 info()->closure()->PassesFilter(FLAG_turbo_filter)) && | 360 info()->closure()->PassesFilter(FLAG_turbo_filter)) && |
381 (FLAG_turbo_osr || !info()->is_osr())) { | 361 (FLAG_turbo_osr || !info()->is_osr())) { |
| 362 // Use TurboFan for the compilation. |
382 if (FLAG_trace_opt) { | 363 if (FLAG_trace_opt) { |
383 OFStream os(stdout); | 364 OFStream os(stdout); |
384 os << "[compiling method " << Brief(*info()->closure()) | 365 os << "[compiling method " << Brief(*info()->closure()) |
385 << " using TurboFan"; | 366 << " using TurboFan"; |
386 if (info()->is_osr()) os << " OSR"; | 367 if (info()->is_osr()) os << " OSR"; |
387 os << "]" << std::endl; | 368 os << "]" << std::endl; |
388 } | 369 } |
389 | 370 |
390 if (info()->shared_info()->asm_function()) { | 371 if (info()->shared_info()->asm_function()) { |
391 info()->MarkAsContextSpecializing(); | 372 info()->MarkAsContextSpecializing(); |
392 } else if (FLAG_turbo_type_feedback) { | 373 } else if (FLAG_turbo_type_feedback) { |
393 info()->MarkAsTypeFeedbackEnabled(); | 374 info()->MarkAsTypeFeedbackEnabled(); |
394 info()->EnsureFeedbackVector(); | 375 info()->EnsureFeedbackVector(); |
395 } | 376 } |
396 | 377 |
397 Timer t(this, &time_taken_to_create_graph_); | 378 Timer t(this, &time_taken_to_create_graph_); |
398 compiler::Pipeline pipeline(info()); | 379 compiler::Pipeline pipeline(info()); |
399 pipeline.GenerateCode(); | 380 pipeline.GenerateCode(); |
400 if (!info()->code().is_null()) { | 381 if (!info()->code().is_null()) { |
401 info()->dependencies()->Commit(info()->code()); | 382 info()->dependencies()->Commit(info()->code()); |
402 return SetLastStatus(SUCCEEDED); | 383 return SetLastStatus(SUCCEEDED); |
403 } | 384 } |
404 } | 385 } |
405 | 386 |
406 // Do not use Crankshaft if the code is intended to be serialized. | 387 if (!isolate()->use_crankshaft()) { |
407 if (!isolate()->use_crankshaft()) return SetLastStatus(FAILED); | 388 // Crankshaft is entirely disabled. |
| 389 return SetLastStatus(FAILED); |
| 390 } |
| 391 |
| 392 Scope* scope = info()->scope(); |
| 393 if (LUnallocated::TooManyParameters(scope->num_parameters())) { |
| 394 // Crankshaft would require too many Lithium operands. |
| 395 return AbortOptimization(kTooManyParameters); |
| 396 } |
| 397 |
| 398 if (info()->is_osr() && |
| 399 LUnallocated::TooManyParametersOrStackSlots(scope->num_parameters(), |
| 400 scope->num_stack_slots())) { |
| 401 // Crankshaft would require too many Lithium operands. |
| 402 return AbortOptimization(kTooManyParametersLocals); |
| 403 } |
408 | 404 |
409 if (scope->HasIllegalRedeclaration()) { | 405 if (scope->HasIllegalRedeclaration()) { |
410 // Crankshaft cannot handle illegal redeclarations. | 406 // Crankshaft cannot handle illegal redeclarations. |
411 return AbortOptimization(kFunctionWithIllegalRedeclaration); | 407 return AbortOptimization(kFunctionWithIllegalRedeclaration); |
412 } | 408 } |
413 | 409 |
414 if (FLAG_trace_opt) { | 410 if (FLAG_trace_opt) { |
415 OFStream os(stdout); | 411 OFStream os(stdout); |
416 os << "[compiling method " << Brief(*info()->closure()) | 412 os << "[compiling method " << Brief(*info()->closure()) |
417 << " using Crankshaft"; | 413 << " using Crankshaft"; |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 } | 1541 } |
1546 | 1542 |
1547 | 1543 |
1548 #if DEBUG | 1544 #if DEBUG |
1549 void CompilationInfo::PrintAstForTesting() { | 1545 void CompilationInfo::PrintAstForTesting() { |
1550 PrintF("--- Source from AST ---\n%s\n", | 1546 PrintF("--- Source from AST ---\n%s\n", |
1551 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1547 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1552 } | 1548 } |
1553 #endif | 1549 #endif |
1554 } } // namespace v8::internal | 1550 } } // namespace v8::internal |
OLD | NEW |