Commit 0bceaf1e authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[ia32] Use one scratch register in StackOverflowCheck

This CL removed the 2nd scratch register from StackOverflowCheck
on ia32 and lower register pressure at use sites. This will make
it easier to preserve the kRootRegister (ebx) in future CLs.

Bug: v8:6666
Change-Id: I225ffdf155a4547fcec02a033638da094995f181
Reviewed-on: https://chromium-review.googlesource.com/1194122
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55477}
parent bb1a232c
...@@ -321,29 +321,27 @@ void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) { ...@@ -321,29 +321,27 @@ void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) {
} }
static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args, static void Generate_StackOverflowCheck(MacroAssembler* masm, Register num_args,
Register scratch1, Register scratch2, Register scratch, Label* stack_overflow,
Label* stack_overflow,
bool include_receiver = false) { bool include_receiver = false) {
// Check the stack for overflow. We are not trying to catch // Check the stack for overflow. We are not trying to catch
// interruptions (e.g. debug break and preemption) here, so the "real stack // interruptions (e.g. debug break and preemption) here, so the "real stack
// limit" is checked. // limit" is checked.
ExternalReference real_stack_limit = ExternalReference real_stack_limit =
ExternalReference::address_of_real_stack_limit(masm->isolate()); ExternalReference::address_of_real_stack_limit(masm->isolate());
__ mov(scratch1, __ StaticVariable(real_stack_limit)); // Compute the space that is left as a negative number in scratch. If
// Make scratch2 the space we have left. The stack might already be overflowed // we already overflowed, this will be a positive number.
// here which will cause scratch2 to become negative. __ mov(scratch, __ StaticVariable(real_stack_limit));
__ mov(scratch2, esp); __ sub(scratch, esp);
__ sub(scratch2, scratch1); // Add the size of the arguments.
// Make scratch1 the space we need for the array when it is unrolled onto the static_assert(kPointerSize == 4,
// stack. "The next instruction assumes kPointerSize == 4");
__ mov(scratch1, num_args); __ lea(scratch, Operand(scratch, num_args, times_4, 0));
if (include_receiver) { if (include_receiver) {
__ add(scratch1, Immediate(1)); __ add(scratch, Immediate(kPointerSize));
} }
__ shl(scratch1, kPointerSizeLog2); // See if we overflowed, i.e. scratch is positive.
// Check if the arguments will overflow the stack. __ cmp(scratch, Immediate(0));
__ cmp(scratch2, scratch1); __ j(greater, stack_overflow); // Signed comparison.
__ j(less_equal, stack_overflow); // Signed comparison.
} }
static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
...@@ -370,9 +368,9 @@ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, ...@@ -370,9 +368,9 @@ static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
__ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset)); __ mov(ebx, Operand(ebx, EntryFrameConstants::kArgvOffset));
// Check if we have enough stack space to push all arguments. // Check if we have enough stack space to push all arguments.
// Argument count in eax. Clobbers ecx and edx. // Argument count in eax. Clobbers ecx.
Label enough_stack_space, stack_overflow; Label enough_stack_space, stack_overflow;
Generate_StackOverflowCheck(masm, eax, ecx, edx, &stack_overflow); Generate_StackOverflowCheck(masm, eax, ecx, &stack_overflow);
__ jmp(&enough_stack_space); __ jmp(&enough_stack_space);
__ bind(&stack_overflow); __ bind(&stack_overflow);
...@@ -960,7 +958,7 @@ void Builtins::Generate_InterpreterPushArgsThenCallImpl( ...@@ -960,7 +958,7 @@ void Builtins::Generate_InterpreterPushArgsThenCallImpl(
// to perform a stack check. So push it onto the stack temporarily. This // to perform a stack check. So push it onto the stack temporarily. This
// might cause stack overflow, but it will be detected by the check. // might cause stack overflow, but it will be detected by the check.
__ Push(edi); __ Push(edi);
Generate_StackOverflowCheck(masm, ecx, edx, edi, &stack_overflow); Generate_StackOverflowCheck(masm, ecx, edx, &stack_overflow);
__ Pop(edi); __ Pop(edi);
// Pop return address to allow tail-call after pushing arguments. // Pop return address to allow tail-call after pushing arguments.
...@@ -1033,13 +1031,11 @@ void Generate_InterpreterPushZeroAndArgsAndReturnAddress( ...@@ -1033,13 +1031,11 @@ void Generate_InterpreterPushZeroAndArgsAndReturnAddress(
// | return addr | | receiver slot | // | return addr | | receiver slot |
// Check for stack overflow before we increment the stack pointer. // Check for stack overflow before we increment the stack pointer.
Generate_StackOverflowCheck(masm, num_args, scratch1, scratch2, Generate_StackOverflowCheck(masm, num_args, scratch1, stack_overflow, true);
stack_overflow, true);
// Step 1 - Update the stack pointer. scratch1 already contains the required // Step 1 - Update the stack pointer.
// increment to the stack. i.e. num_args + 1 stack slots. This is computed in
// Generate_StackOverflowCheck.
__ lea(scratch1, Operand(num_args, times_4, kPointerSize));
__ AllocateStackFrame(scratch1); __ AllocateStackFrame(scratch1);
// Step 2 move return_address and slots above it to the correct locations. // Step 2 move return_address and slots above it to the correct locations.
...@@ -2242,7 +2238,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2242,7 +2238,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
// edi is used as a scratch register. It should be restored from the frame // edi is used as a scratch register. It should be restored from the frame
// when needed. // when needed.
Generate_StackOverflowCheck(masm, ebx, ecx, edi, &stack_overflow); Generate_StackOverflowCheck(masm, ebx, ecx, &stack_overflow);
// Copy receiver and all expected arguments. // Copy receiver and all expected arguments.
const int offset = StandardFrameConstants::kCallerSPOffset; const int offset = StandardFrameConstants::kCallerSPOffset;
...@@ -2265,7 +2261,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { ...@@ -2265,7 +2261,7 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
EnterArgumentsAdaptorFrame(masm); EnterArgumentsAdaptorFrame(masm);
// edi is used as a scratch register. It should be restored from the frame // edi is used as a scratch register. It should be restored from the frame
// when needed. // when needed.
Generate_StackOverflowCheck(masm, ebx, ecx, edi, &stack_overflow); Generate_StackOverflowCheck(masm, ebx, ecx, &stack_overflow);
// Remember expected arguments in ecx. // Remember expected arguments in ecx.
__ mov(ecx, ebx); __ mov(ecx, ebx);
......
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