Commit 1c50ffb9 authored by Milad Fa's avatar Milad Fa Committed by V8 LUCI CQ

PPC/s390: [masm][ia32][arm] Introduce helper to drop arguments.

Port 6e474ae9

Original Commit Message:

    This CL is a port of https://crrev.com/c/3045349 for ia32 and arm,
    adding helper methods to drop arguments from the stack.

R=pthier@chromium.org, joransiu@ca.ibm.com, junyan@redhat.com, midawson@redhat.com
BUG=
LOG=N

Change-Id: I7099bd98285eb22cc1cbf3abd634b3479fe9e9d9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3072539Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/master@{#76099}
parent 61150c17
......@@ -125,11 +125,8 @@ void Generate_JSBuiltinsConstructStubHelper(MacroAssembler* masm) {
// Leave construct frame.
}
// Remove caller arguments from the stack and return.
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
__ SmiToPtrArrayOffset(scratch, scratch);
__ add(sp, sp, scratch);
__ addi(sp, sp, Operand(kSystemPointerSize));
__ DropArguments(scratch, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ blr();
__ bind(&stack_overflow);
......@@ -286,11 +283,8 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
__ LeaveFrame(StackFrame::CONSTRUCT);
// Remove caller arguments from the stack and return.
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
__ SmiToPtrArrayOffset(r4, r4);
__ add(sp, sp, r4);
__ addi(sp, sp, Operand(kSystemPointerSize));
__ DropArguments(r4, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ blr();
__ bind(&check_receiver);
......@@ -835,7 +829,8 @@ static void LeaveInterpreterFrame(MacroAssembler* masm, Register scratch1,
// Leave the frame (also dropping the register file).
__ LeaveFrame(StackFrame::INTERPRETED);
__ add(sp, sp, params_size);
__ DropArguments(params_size, TurboAssembler::kCountIsBytes,
TurboAssembler::kCountIncludesReceiver);
}
// Tail-call |function_id| if |actual_marker| == |expected_marker|
......@@ -1698,9 +1693,8 @@ void Builtins::Generate_FunctionPrototypeApply(MacroAssembler* masm) {
__ LoadU64(r5, MemOperand(sp, 2 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(ip, r3, Operand(kSystemPointerSizeLog2));
__ add(sp, sp, ip);
__ StoreU64(r8, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r3, r8, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......@@ -1783,9 +1777,8 @@ void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
__ LoadU64(r5, MemOperand(sp, 3 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(ip, r3, Operand(kSystemPointerSizeLog2));
__ add(sp, sp, ip);
__ StoreU64(r8, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r3, r8, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......@@ -1833,9 +1826,8 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
__ blt(&done);
__ LoadU64(r6, MemOperand(sp, 3 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(r0, r3, Operand(kSystemPointerSizeLog2));
__ add(sp, sp, r0);
__ StoreU64(r7, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r3, r7, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......
......@@ -121,11 +121,8 @@ void Generate_JSBuiltinsConstructStubHelper(MacroAssembler* masm) {
// Leave construct frame.
}
// Remove caller arguments from the stack and return.
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
__ SmiToPtrArrayOffset(scratch, scratch);
__ AddS64(sp, sp, scratch);
__ AddS64(sp, sp, Operand(kSystemPointerSize));
__ DropArguments(scratch, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ Ret();
__ bind(&stack_overflow);
......@@ -278,11 +275,8 @@ void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
__ LeaveFrame(StackFrame::CONSTRUCT);
// Remove caller arguments from the stack and return.
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
__ SmiToPtrArrayOffset(r3, r3);
__ AddS64(sp, sp, r3);
__ AddS64(sp, sp, Operand(kSystemPointerSize));
__ DropArguments(r3, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ Ret();
__ bind(&check_receiver);
......@@ -892,7 +886,8 @@ static void LeaveInterpreterFrame(MacroAssembler* masm, Register scratch1,
// Leave the frame (also dropping the register file).
__ LeaveFrame(StackFrame::INTERPRETED);
__ AddS64(sp, sp, params_size);
__ DropArguments(params_size, TurboAssembler::kCountIsBytes,
TurboAssembler::kCountIncludesReceiver);
}
// Tail-call |function_id| if |actual_marker| == |expected_marker|
......@@ -1730,9 +1725,8 @@ void Builtins::Generate_FunctionPrototypeApply(MacroAssembler* masm) {
__ LoadU64(r4, MemOperand(sp, 2 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(r1, r2, Operand(kSystemPointerSizeLog2));
__ lay(sp, MemOperand(sp, r1));
__ StoreU64(r7, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r2, r7, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......@@ -1816,9 +1810,8 @@ void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
__ LoadU64(r4, MemOperand(sp, 3 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(r1, r2, Operand(kSystemPointerSizeLog2));
__ lay(sp, MemOperand(sp, r1));
__ StoreU64(r7, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r2, r7, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......@@ -1867,9 +1860,8 @@ void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
__ blt(&done);
__ LoadU64(r5, MemOperand(sp, 3 * kSystemPointerSize)); // argArray
__ bind(&done);
__ ShiftLeftU64(r1, r2, Operand(kSystemPointerSizeLog2));
__ lay(sp, MemOperand(sp, r1));
__ StoreU64(r6, MemOperand(sp));
__ DropArgumentsAndPushNewReceiver(r2, r6, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
}
// ----------- S t a t e -------------
......
......@@ -1198,6 +1198,47 @@ void TurboAssembler::Prologue() {
}
}
void TurboAssembler::DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode) {
int receiver_bytes =
(mode == kCountExcludesReceiver) ? kSystemPointerSize : 0;
switch (type) {
case kCountIsInteger: {
ShiftLeftU64(ip, count, Operand(kSystemPointerSizeLog2));
add(sp, sp, ip);
break;
}
case kCountIsSmi: {
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
SmiToPtrArrayOffset(count, count);
add(sp, sp, count);
break;
}
case kCountIsBytes: {
add(sp, sp, count);
break;
}
}
if (receiver_bytes != 0) {
addi(sp, sp, Operand(receiver_bytes));
}
}
void TurboAssembler::DropArgumentsAndPushNewReceiver(Register argc,
Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode) {
DCHECK(!AreAliased(argc, receiver));
if (mode == kCountExcludesReceiver) {
// Drop arguments without receiver and override old receiver.
DropArguments(argc, type, kCountIncludesReceiver);
StoreU64(receiver, MemOperand(sp));
} else {
DropArguments(argc, type, mode);
push(receiver);
}
}
void TurboAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
if (FLAG_enable_embedded_constant_pool && load_constant_pool_pointer_reg) {
......
......@@ -112,6 +112,14 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
void StubPrologue(StackFrame::Type type);
void Prologue();
enum ArgumentsCountMode { kCountIncludesReceiver, kCountExcludesReceiver };
enum ArgumentsCountType { kCountIsInteger, kCountIsSmi, kCountIsBytes };
void DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode);
void DropArgumentsAndPushNewReceiver(Register argc, Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode);
// Push a standard frame, consisting of lr, fp, constant pool,
// context and JS function
void PushStandardFrame(Register function_reg);
......@@ -742,6 +750,16 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// ---------------------------------------------------------------------------
// Pointer compression Support
void SmiToPtrArrayOffset(Register dst, Register src) {
#if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH)
STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kSystemPointerSizeLog2);
ShiftLeftU64(dst, src, Operand(kSystemPointerSizeLog2 - kSmiShift));
#else
STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kSystemPointerSizeLog2);
ShiftRightS64(dst, src, Operand(kSmiShift - kSystemPointerSizeLog2));
#endif
}
// Loads a field containing a HeapObject and decompresses it if pointer
// compression is enabled.
void LoadTaggedPointerField(const Register& destination,
......@@ -1074,16 +1092,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
ShiftLeftU64(dst, src, Operand(kSmiShift), rc);
}
void SmiToPtrArrayOffset(Register dst, Register src) {
#if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH)
STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kSystemPointerSizeLog2);
ShiftLeftU64(dst, src, Operand(kSystemPointerSizeLog2 - kSmiShift));
#else
STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kSystemPointerSizeLog2);
ShiftRightS64(dst, src, Operand(kSmiShift - kSystemPointerSizeLog2));
#endif
}
// Jump if either of the registers contain a non-smi.
inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
TestIfSmi(value, r0);
......
......@@ -1400,6 +1400,47 @@ void TurboAssembler::Prologue(Register base, int prologue_offset) {
PushStandardFrame(r3);
}
void TurboAssembler::DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode) {
int receiver_bytes =
(mode == kCountExcludesReceiver) ? kSystemPointerSize : 0;
switch (type) {
case kCountIsInteger: {
ShiftLeftU64(ip, count, Operand(kSystemPointerSizeLog2));
lay(sp, MemOperand(sp, ip));
break;
}
case kCountIsSmi: {
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
SmiToPtrArrayOffset(count, count);
AddS64(sp, sp, count);
break;
}
case kCountIsBytes: {
AddS64(sp, sp, count);
break;
}
}
if (receiver_bytes != 0) {
AddS64(sp, sp, Operand(receiver_bytes));
}
}
void TurboAssembler::DropArgumentsAndPushNewReceiver(Register argc,
Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode) {
DCHECK(!AreAliased(argc, receiver));
if (mode == kCountExcludesReceiver) {
// Drop arguments without receiver and override old receiver.
DropArguments(argc, type, kCountIncludesReceiver);
StoreU64(receiver, MemOperand(sp));
} else {
DropArguments(argc, type, mode);
push(receiver);
}
}
void TurboAssembler::EnterFrame(StackFrame::Type type,
bool load_constant_pool_pointer_reg) {
// We create a stack frame with:
......
......@@ -735,6 +735,14 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
int prologue_offset = 0);
void Prologue(Register base, int prologue_offset = 0);
enum ArgumentsCountMode { kCountIncludesReceiver, kCountExcludesReceiver };
enum ArgumentsCountType { kCountIsInteger, kCountIsSmi, kCountIsBytes };
void DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode);
void DropArgumentsAndPushNewReceiver(Register argc, Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode);
// Get the actual activation frame alignment for target environment.
static int ActivationFrameAlignment();
// ----------------------------------------------------------------
......@@ -1097,6 +1105,16 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// ---------------------------------------------------------------------------
// Pointer compression Support
void SmiToPtrArrayOffset(Register dst, Register src) {
#if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH)
STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kSystemPointerSizeLog2);
ShiftLeftU64(dst, src, Operand(kSystemPointerSizeLog2 - kSmiShift));
#else
STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kSystemPointerSizeLog2);
ShiftRightS64(dst, src, Operand(kSmiShift - kSystemPointerSizeLog2));
#endif
}
// Loads a field containing a HeapObject and decompresses it if pointer
// compression is enabled.
void LoadTaggedPointerField(const Register& destination,
......@@ -1350,16 +1368,6 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
ShiftLeftU64(dst, src, Operand(kSmiShift));
}
void SmiToPtrArrayOffset(Register dst, Register src) {
#if defined(V8_COMPRESS_POINTERS) || defined(V8_31BIT_SMIS_ON_64BIT_ARCH)
STATIC_ASSERT(kSmiTag == 0 && kSmiShift < kSystemPointerSizeLog2);
ShiftLeftU64(dst, src, Operand(kSystemPointerSizeLog2 - kSmiShift));
#else
STATIC_ASSERT(kSmiTag == 0 && kSmiShift > kSystemPointerSizeLog2);
ShiftRightS64(dst, src, Operand(kSmiShift - kSystemPointerSizeLog2));
#endif
}
// Jump if either of the registers contain a non-smi.
inline void JumpIfNotSmi(Register value, Label* not_smi_label) {
TestIfSmi(value);
......
......@@ -4226,17 +4226,20 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) {
// Constant pool is unavailable since the frame has been destructed
ConstantPoolUnavailableScope constant_pool_unavailable(tasm());
if (drop_jsargs) {
// We must pop all arguments from the stack (including the receiver). This
// number of arguments is given by max(1 + argc_reg, parameter_slots).
__ addi(argc_reg, argc_reg, Operand(1)); // Also pop the receiver.
// We must pop all arguments from the stack (including the receiver).
// The number of arguments without the receiver is
// max(argc_reg, parameter_slots-1), and the receiver is added in
// DropArguments().
if (parameter_slots > 1) {
const int parameter_slots_without_receiver = parameter_slots - 1;
Label skip;
__ CmpS64(argc_reg, Operand(parameter_slots), r0);
__ CmpS64(argc_reg, Operand(parameter_slots_without_receiver), r0);
__ bgt(&skip);
__ mov(argc_reg, Operand(parameter_slots));
__ mov(argc_reg, Operand(parameter_slots_without_receiver));
__ bind(&skip);
}
__ Drop(argc_reg);
__ DropArguments(argc_reg, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
} else if (additional_pop_count->IsImmediate()) {
int additional_count = g.ToConstant(additional_pop_count).ToInt32();
__ Drop(parameter_slots + additional_count);
......
......@@ -4146,17 +4146,20 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) {
}
if (drop_jsargs) {
// We must pop all arguments from the stack (including the receiver). This
// number of arguments is given by max(1 + argc_reg, parameter_slots).
__ AddS64(argc_reg, argc_reg, Operand(1)); // Also pop the receiver.
// We must pop all arguments from the stack (including the receiver).
// The number of arguments without the receiver is
// max(argc_reg, parameter_slots-1), and the receiver is added in
// DropArguments().
if (parameter_slots > 1) {
const int parameter_slots_without_receiver = parameter_slots - 1;
Label skip;
__ CmpS64(argc_reg, Operand(parameter_slots));
__ CmpS64(argc_reg, Operand(parameter_slots_without_receiver));
__ bgt(&skip);
__ mov(argc_reg, Operand(parameter_slots));
__ mov(argc_reg, Operand(parameter_slots_without_receiver));
__ bind(&skip);
}
__ Drop(argc_reg);
__ DropArguments(argc_reg, TurboAssembler::kCountIsInteger,
TurboAssembler::kCountExcludesReceiver);
} else if (additional_pop_count->IsImmediate()) {
int additional_count = g.ToConstant(additional_pop_count).ToInt32();
__ Drop(parameter_slots + additional_count);
......
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