OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/js-inlining.h" | 5 #include "src/compiler/js-inlining.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/compiler/all-nodes.h" | 10 #include "src/compiler/all-nodes.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 if (!Compiler::ParseAndAnalyze(info.parse_info())) { | 335 if (!Compiler::ParseAndAnalyze(info.parse_info())) { |
336 TRACE("Not inlining %s into %s because parsing failed\n", | 336 TRACE("Not inlining %s into %s because parsing failed\n", |
337 function->shared()->DebugName()->ToCString().get(), | 337 function->shared()->DebugName()->ToCString().get(), |
338 info_->shared_info()->DebugName()->ToCString().get()); | 338 info_->shared_info()->DebugName()->ToCString().get()); |
339 if (info_->isolate()->has_pending_exception()) { | 339 if (info_->isolate()->has_pending_exception()) { |
340 info_->isolate()->clear_pending_exception(); | 340 info_->isolate()->clear_pending_exception(); |
341 } | 341 } |
342 return NoChange(); | 342 return NoChange(); |
343 } | 343 } |
344 | 344 |
| 345 // In strong mode, in case of too few arguments we need to throw a TypeError |
| 346 // so we must not inline this call. |
| 347 size_t parameter_count = info.literal()->parameter_count(); |
| 348 if (is_strong(info.language_mode()) && |
| 349 call.formal_arguments() < parameter_count) { |
| 350 TRACE("Not inlining %s into %s because too few arguments for strong mode\n", |
| 351 function->shared()->DebugName()->ToCString().get(), |
| 352 info_->shared_info()->DebugName()->ToCString().get()); |
| 353 return NoChange(); |
| 354 } |
| 355 |
345 if (!Compiler::EnsureDeoptimizationSupport(&info)) { | 356 if (!Compiler::EnsureDeoptimizationSupport(&info)) { |
346 TRACE("Not inlining %s into %s because deoptimization support failed\n", | 357 TRACE("Not inlining %s into %s because deoptimization support failed\n", |
347 function->shared()->DebugName()->ToCString().get(), | 358 function->shared()->DebugName()->ToCString().get(), |
348 info_->shared_info()->DebugName()->ToCString().get()); | 359 info_->shared_info()->DebugName()->ToCString().get()); |
349 return NoChange(); | 360 return NoChange(); |
350 } | 361 } |
351 // Remember that we inlined this function. This needs to be called right | 362 // Remember that we inlined this function. This needs to be called right |
352 // after we ensure deoptimization support so that the code flusher | 363 // after we ensure deoptimization support so that the code flusher |
353 // does not remove the code with the deoptimization support. | 364 // does not remove the code with the deoptimization support. |
354 info_->AddInlinedFunction(info.shared_info()); | 365 info_->AddInlinedFunction(info.shared_info()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // TODO(turbofan): We might want to load the context from the JSFunction at | 404 // TODO(turbofan): We might want to load the context from the JSFunction at |
394 // runtime in case we only know the SharedFunctionInfo once we have dynamic | 405 // runtime in case we only know the SharedFunctionInfo once we have dynamic |
395 // type feedback in the compiler. | 406 // type feedback in the compiler. |
396 Node* context = jsgraph_->Constant(handle(function->context())); | 407 Node* context = jsgraph_->Constant(handle(function->context())); |
397 | 408 |
398 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); | 409 CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone()); |
399 visitor.CopyGraph(); | 410 visitor.CopyGraph(); |
400 | 411 |
401 Node* start = visitor.GetCopy(graph.start()); | 412 Node* start = visitor.GetCopy(graph.start()); |
402 Node* end = visitor.GetCopy(graph.end()); | 413 Node* end = visitor.GetCopy(graph.end()); |
| 414 Node* frame_state = call.frame_state(); |
403 | 415 |
404 Node* frame_state = call.frame_state(); | 416 // Insert argument adaptor frame if required. The callees formal parameter |
405 size_t const inlinee_formal_parameters = start->op()->ValueOutputCount() - 3; | 417 // count (i.e. value outputs of start node minus target, receiver & context) |
406 // Insert argument adaptor frame if required. | 418 // have to match the number of arguments passed to the call. |
407 if (call.formal_arguments() != inlinee_formal_parameters) { | 419 DCHECK_EQ(parameter_count, start->op()->ValueOutputCount() - 3); |
408 // In strong mode, in case of too few arguments we need to throw a | 420 if (call.formal_arguments() != parameter_count) { |
409 // TypeError so we must not inline this call. | |
410 // TODO(jarin) This check should be moved before the decision point | |
411 // above so that we do not compile the function uselessly. | |
412 if (is_strong(info.language_mode()) && | |
413 call.formal_arguments() < inlinee_formal_parameters) { | |
414 return NoChange(); | |
415 } | |
416 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info(), | 421 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info(), |
417 info.zone()); | 422 info.zone()); |
418 } | 423 } |
419 | 424 |
420 return InlineCall(node, context, frame_state, start, end); | 425 return InlineCall(node, context, frame_state, start, end); |
421 } | 426 } |
422 | 427 |
423 } // namespace compiler | 428 } // namespace compiler |
424 } // namespace internal | 429 } // namespace internal |
425 } // namespace v8 | 430 } // namespace v8 |
OLD | NEW |