Commit 62cb792c authored by Zhao Jiazhong's avatar Zhao Jiazhong Committed by Commit Bot

[mips][wasm][liftoff] Add direct and indirect tail-calls

Port b64cede5
https://crrev.com/c/2289970

Port 5de28709
https://crrev.com/c/2316304

Change-Id: Ia4e24558b10adef196ab167137a9a5b6db98754b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2321950Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Cr-Commit-Position: refs/heads/master@{#69089}
parent dfd86b05
......@@ -275,6 +275,29 @@ int LiftoffAssembler::PrepareStackFrame() {
return offset;
}
void LiftoffAssembler::PrepareTailCall(int num_callee_stack_params,
int stack_param_delta) {
UseScratchRegisterScope temps(this);
Register scratch = temps.Acquire();
// Push the return address and frame pointer to complete the stack frame.
Lw(scratch, MemOperand(fp, 4));
Push(scratch);
Lw(scratch, MemOperand(fp, 0));
Push(scratch);
// Shift the whole frame upwards.
int slot_count = num_callee_stack_params + 2;
for (int i = slot_count - 1; i >= 0; --i) {
Lw(scratch, MemOperand(sp, i * 4));
Sw(scratch, MemOperand(fp, (i - stack_param_delta) * 4));
}
// Set the new stack and frame pointer.
addiu(sp, fp, -stack_param_delta * 4);
Pop(ra, fp);
}
void LiftoffAssembler::PatchPrepareStackFrame(int offset, int frame_size) {
// We can't run out of space, just pass anything big enough to not cause the
// assembler to try to grow the buffer.
......@@ -2575,6 +2598,10 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
Call(addr, RelocInfo::WASM_CALL);
}
void LiftoffAssembler::TailCallNativeWasmCode(Address addr) {
Jump(addr, RelocInfo::WASM_CALL);
}
void LiftoffAssembler::CallIndirect(const wasm::FunctionSig* sig,
compiler::CallDescriptor* call_descriptor,
Register target) {
......@@ -2586,6 +2613,15 @@ void LiftoffAssembler::CallIndirect(const wasm::FunctionSig* sig,
}
}
void LiftoffAssembler::TailCallIndirect(Register target) {
if (target == no_reg) {
Pop(kScratchReg);
Jump(kScratchReg);
} else {
Jump(target);
}
}
void LiftoffAssembler::CallRuntimeStub(WasmCode::RuntimeStubId sid) {
// A direct call to a wasm runtime stub defined in this module.
// Just encode the stub index. This will be patched at relocation.
......
......@@ -240,6 +240,29 @@ int LiftoffAssembler::PrepareStackFrame() {
return offset;
}
void LiftoffAssembler::PrepareTailCall(int num_callee_stack_params,
int stack_param_delta) {
UseScratchRegisterScope temps(this);
Register scratch = temps.Acquire();
// Push the return address and frame pointer to complete the stack frame.
Ld(scratch, MemOperand(fp, 8));
Push(scratch);
Ld(scratch, MemOperand(fp, 0));
Push(scratch);
// Shift the whole frame upwards.
int slot_count = num_callee_stack_params + 2;
for (int i = slot_count - 1; i >= 0; --i) {
Ld(scratch, MemOperand(sp, i * 8));
Sd(scratch, MemOperand(fp, (i - stack_param_delta) * 8));
}
// Set the new stack and frame pointer.
daddiu(sp, fp, -stack_param_delta * 8);
Pop(ra, fp);
}
void LiftoffAssembler::PatchPrepareStackFrame(int offset, int frame_size) {
// We can't run out of space, just pass anything big enough to not cause the
// assembler to try to grow the buffer.
......@@ -2678,6 +2701,10 @@ void LiftoffAssembler::CallNativeWasmCode(Address addr) {
Call(addr, RelocInfo::WASM_CALL);
}
void LiftoffAssembler::TailCallNativeWasmCode(Address addr) {
Jump(addr, RelocInfo::WASM_CALL);
}
void LiftoffAssembler::CallIndirect(const wasm::FunctionSig* sig,
compiler::CallDescriptor* call_descriptor,
Register target) {
......@@ -2689,6 +2716,15 @@ void LiftoffAssembler::CallIndirect(const wasm::FunctionSig* sig,
}
}
void LiftoffAssembler::TailCallIndirect(Register target) {
if (target == no_reg) {
Pop(kScratchReg);
Jump(kScratchReg);
} else {
Jump(target);
}
}
void LiftoffAssembler::CallRuntimeStub(WasmCode::RuntimeStubId sid) {
// A direct call to a wasm runtime stub defined in this module.
// Just encode the stub index. This will be patched at relocation.
......
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