Closed Bug 1889091 Opened 2 months ago Closed 2 months ago

Specialize calls to native functions with variadic parameters

Categories

(Core :: JavaScript Engine: JIT, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(6 files)

The existing LApplyArgsGeneric and friends instructions push the arguments in preparation for a JIT to JIT call, which means when calling a native function, we first have reorder the arguments in jit::InvokeFunction before calling the native function. This is slow when the number of arguments exceeds in inline stack space of GenericArgsBase::v_, i.e. there are more than six arguments, because we first have to heap allocate enough space to hold the arguments.

Part 3 will also call this new method.

Move arguments length checks into separate methods for reusability. See part 3.

Depends on D206351

The existing LApplyArgsGeneric and friends instructions push the arguments in
preparation for a JIT to JIT call, which means when calling a native function,
we first have reorder the arguments in jit::InvokeFunction before calling the
native function. This is slow when the number of arguments exceeds in inline
stack space of GenericArgsBase::v_, i.e. there are more than six arguments,
because we first have to heap allocate enough space to hold the arguments.

This commit adds specializations for LApplyArgsGeneric and other instructions
when the target function is known to be a native function. These new instructions
push the arguments in the correct order for JIT to C++ calls, so we no longer
have to reorder the arguments.

Depends on D206352

This extra move was necessary when we still computed the "extra stack space" and
CodeGenerator::emitCallInvokeFunction contained this code:

// Push the space used by the arguments.
masm.moveStackPtrTo(objreg);
masm.Push(extraStackSize);

This code has been removed in bug 1773971.

Depends on D206353

CodeGenerator.cpp:

  • Improve comment why we check for odd/even number of arguments.
  • Reformat comments which predate the change to two-space indent.
  • Improve comment for extraFormals.
  • Remove comments about "extra stack space". (Extra stack space was removed in bug 1774390.)
  • Remove "Initially the number of args to the caller." comment, because it's not
    true for scalar replaced rest-parameters. And "Initially" makes it sound like that
    the register value is changed at some point, but that's actually not the case.

LIR-shared.h:

  • Align case for tmpObjReg and tmpCopy.

Lowering.cpp

  • Rename "stack counter register" to "copy register" to match LIR instruction use.

Depends on D206354

It was useful to use an explicit parameter when scratch was used to hold the
extra stack space. But now that we no longer have to compute the extra stack
space, it's no longer necessary to have an out-param and we can instead use a
local variable similar to how ToRegister(apply->getTempObject()) is used.

Depends on D206355

Blocks: sm-jits
Severity: -- → N/A
Priority: -- → P2
Pushed by andre.bargull@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/d3e12936814d
Part 1: Add infallible MacroAssembler::loadArgumentsObjectLength. r=jandem
https://hg.mozilla.org/integration/autoland/rev/39575eed5f8a
Part 2: Add CodeGenerator::emitApply{Args,ArgsObject,Array}Guard. r=jandem
https://hg.mozilla.org/integration/autoland/rev/3ef1b0ae5ce0
Part 3: Specialize calls to native functions with variadic parameters. r=jandem
https://hg.mozilla.org/integration/autoland/rev/2ea52b74deea
Part 4: Remove extra stack pointer move. r=jandem
https://hg.mozilla.org/integration/autoland/rev/7351cc1e72dd
Part 5: Update comments and variable names. r=jandem
https://hg.mozilla.org/integration/autoland/rev/7a8990de860d
Part 6: Remove "scratch" register parameter from emitPushArguments. r=jandem
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: