From 99f0130782a57a9abcaea7da5f2a495fe3cb2071 Mon Sep 17 00:00:00 2001 From: "chunyang.dai" Date: Wed, 9 Sep 2015 22:42:39 -0700 Subject: [PATCH] X87: [calls] Consistent call protocol for calls. port b37907ff7f866873ddfbfc97670b43c19a5fc7f9 (r30648). original commit message: The number of actual arguments should always be available, there's no point in trying to optimize away a simple assignment of an immediate to a register before some calls. The main motivation is to have a consistent state at the beginning of every function. Currently the arguments register (i.e. rax or eax) either contains the number of arguments or some random garbage depending on whether the callsite decided that the callee might need the information or not. This causes trouble with runtime implementations of functions that do not set internal_formal_parameter_count to the DontAdaptArguments sentinel (we don't have any of those yet), but also makes it impossible to sanity check the arguments in the callee, because the callee doesn't know whether the caller decided to pass the number of arguments or random garbage. BUG= Review URL: https://codereview.chromium.org/1335453002 Cr-Commit-Position: refs/heads/master@{#30669} --- src/x87/lithium-codegen-x87.cc | 11 +++-------- src/x87/macro-assembler-x87.cc | 6 ++++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/x87/lithium-codegen-x87.cc b/src/x87/lithium-codegen-x87.cc index 1b5b176..b3dc919 100644 --- a/src/x87/lithium-codegen-x87.cc +++ b/src/x87/lithium-codegen-x87.cc @@ -3611,11 +3611,8 @@ void LCodeGen::CallKnownFunction(Handle function, // Change context. __ mov(esi, FieldOperand(function_reg, JSFunction::kContextOffset)); - // Set eax to arguments count if adaption is not needed. Assumes that eax - // is available to write to at this point. - if (dont_adapt_arguments) { - __ mov(eax, arity); - } + // Always initialize eax to the number of actual arguments. + __ mov(eax, arity); // Invoke function directly. if (function.is_identical_to(info()->closure())) { @@ -3677,9 +3674,7 @@ void LCodeGen::DoCallJSFunction(LCallJSFunction* instr) { DCHECK(ToRegister(instr->function()).is(edi)); DCHECK(ToRegister(instr->result()).is(eax)); - if (instr->hydrogen()->pass_argument_count()) { - __ mov(eax, instr->arity()); - } + __ mov(eax, instr->arity()); // Change context. __ mov(esi, FieldOperand(edi, JSFunction::kContextOffset)); diff --git a/src/x87/macro-assembler-x87.cc b/src/x87/macro-assembler-x87.cc index 090fc6e..265d061 100644 --- a/src/x87/macro-assembler-x87.cc +++ b/src/x87/macro-assembler-x87.cc @@ -1888,10 +1888,10 @@ void MacroAssembler::InvokePrologue(const ParameterCount& expected, Label invoke; if (expected.is_immediate()) { DCHECK(actual.is_immediate()); + mov(eax, actual.immediate()); if (expected.immediate() == actual.immediate()) { definitely_matches = true; } else { - mov(eax, actual.immediate()); const int sentinel = SharedFunctionInfo::kDontAdaptArgumentsSentinel; if (expected.immediate() == sentinel) { // Don't worry about adapting arguments for builtins that @@ -1909,10 +1909,10 @@ void MacroAssembler::InvokePrologue(const ParameterCount& expected, // Expected is in register, actual is immediate. This is the // case when we invoke function values without going through the // IC mechanism. + mov(eax, actual.immediate()); cmp(expected.reg(), actual.immediate()); j(equal, &invoke); DCHECK(expected.reg().is(ebx)); - mov(eax, actual.immediate()); } else if (!expected.reg().is(actual.reg())) { // Both expected and actual are in (different) registers. This // is the case when we invoke functions using call and apply. @@ -1920,6 +1920,8 @@ void MacroAssembler::InvokePrologue(const ParameterCount& expected, j(equal, &invoke); DCHECK(actual.reg().is(eax)); DCHECK(expected.reg().is(ebx)); + } else { + Move(eax, actual.reg()); } } -- 2.7.4