Commit eafcdc96 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

PPC/s390: [wasm] Introduce jump table

Port 733b7c82

Original Commit Message:

    This introduces the concept of a jump table for WebAssembly, which is
    used for every direct and indirect call to any WebAssembly function.
    For lazy compilation, it will initially contain code to call the
    WasmCompileLazy builtin, where it passes the function index to be
    called.
    For non-lazy-compilation, it will contain a jump to the actual code.
    The jump table allows to easily redirect functions for lazy
    compilation, tier-up, debugging and (in the future) code aging. After
    this CL, we will not need to patch existing code any more for any of
    these operations.

R=clemensh@chromium.org, joransiu@ca.ibm.com, michael_dawson@ca.ibm.com
BUG= v8:7758

Change-Id: I1a370910ffa56dbdd609be6922067842a6adf1df
Reviewed-on: https://chromium-review.googlesource.com/1105060
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53852}
parent 996a6c10
......@@ -2368,6 +2368,9 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
}
void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// The function index was put in r15 by the jump table trampoline.
// Convert to Smi for the runtime call.
__ SmiTag(r15, r15);
{
TrapOnAbortScope trap_on_abort_scope(masm); // Avoid calls to Abort.
FrameAndConstantPoolScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
......@@ -2382,8 +2385,9 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ MultiPush(gp_regs);
__ MultiPushDoubles(fp_regs);
// Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister);
// Pass instance and function index as explicit arguments to the runtime
// function.
__ Push(kWasmInstanceRegister, r15);
// Load the correct CEntry builtin from the instance object.
__ LoadP(r5, FieldMemOperand(kWasmInstanceRegister,
WasmInstanceObject::kCEntryStubOffset));
......
......@@ -2373,6 +2373,9 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
}
void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
// The function index was put in r7 by the jump table trampoline.
// Convert to Smi for the runtime call.
__ SmiTag(r7, r7);
{
TrapOnAbortScope trap_on_abort_scope(masm); // Avoid calls to Abort.
FrameAndConstantPoolScope scope(masm, StackFrame::WASM_COMPILE_LAZY);
......@@ -2389,8 +2392,9 @@ void Builtins::Generate_WasmCompileLazy(MacroAssembler* masm) {
__ MultiPush(gp_regs);
__ MultiPushDoubles(fp_regs);
// Pass the WASM instance as an explicit argument to WasmCompileLazy.
__ Push(kWasmInstanceRegister);
// Pass instance and function index as explicit arguments to the runtime
// function.
__ Push(kWasmInstanceRegister, r7);
// Load the correct CEntry builtin from the instance object.
__ LoadP(r4, FieldMemOperand(kWasmInstanceRegister,
WasmInstanceObject::kCEntryStubOffset));
......
......@@ -138,6 +138,54 @@ void JumpTableAssembler::NopBytes(int bytes) {
}
}
#elif V8_TARGET_ARCH_S390
void JumpTableAssembler::EmitLazyCompileJumpSlot(uint32_t func_index,
Address lazy_compile_target) {
// Load function index to r7. 6 bytes
lgfi(r7, Operand(func_index));
// Jump to {lazy_compile_target}. 6 bytes or 12 bytes
mov(r1, Operand(lazy_compile_target));
b(r1); // 2 bytes
}
void JumpTableAssembler::EmitJumpSlot(Address target) {
mov(r1, Operand(target));
b(r1);
}
void JumpTableAssembler::NopBytes(int bytes) {
DCHECK_LE(0, bytes);
DCHECK_EQ(0, bytes % 2);
for (; bytes > 0; bytes -= 2) {
nop(0);
}
}
#elif V8_TARGET_ARCH_PPC
void JumpTableAssembler::EmitLazyCompileJumpSlot(uint32_t func_index,
Address lazy_compile_target) {
// Load function index to r8. max 5 instrs
mov(r15, Operand(func_index));
// Jump to {lazy_compile_target}. max 5 instrs
mov(r0, Operand(lazy_compile_target));
mtctr(r0);
bctr();
}
void JumpTableAssembler::EmitJumpSlot(Address target) {
mov(r0, Operand(target));
mtctr(r0);
bctr();
}
void JumpTableAssembler::NopBytes(int bytes) {
DCHECK_LE(0, bytes);
DCHECK_EQ(0, bytes % 4);
for (; bytes > 0; bytes -= 4) {
nop(0);
}
}
#else
void JumpTableAssembler::EmitLazyCompileJumpSlot(uint32_t func_index,
Address lazy_compile_target) {
......
......@@ -43,6 +43,14 @@ class JumpTableAssembler : public TurboAssembler {
static constexpr int kJumpTableSlotSize = 5 * kInstrSize;
#elif V8_TARGET_ARCH_ARM64
static constexpr int kJumpTableSlotSize = 3 * kInstructionSize;
#elif V8_TARGET_ARCH_S390X
static constexpr int kJumpTableSlotSize = 20;
#elif V8_TARGET_ARCH_S390
static constexpr int kJumpTableSlotSize = 14;
#elif V8_TARGET_ARCH_PPC64
static constexpr int kJumpTableSlotSize = 48;
#elif V8_TARGET_ARCH_PPC
static constexpr int kJumpTableSlotSize = 24;
#else
static constexpr int kJumpTableSlotSize = 1;
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment