Commit 411efc16 authored by bjaideep's avatar bjaideep Committed by Commit bot

PPC/s390: [cleanup] combine 3 ResumeGenerator stubs into one

Port 5615e5b8

Original Commit Message:

    This hopefully shrinks binary size a bit, at the cost of (slightly)
    increasing the complexity of the ResumeGenerator stub. Includes ia32,
    x64, mips, mips64, arm and arm64 ports.

R=caitp@igalia.com, joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=v8:5855
LOG=N

Review-Url: https://codereview.chromium.org/2783043002
Cr-Commit-Position: refs/heads/master@{#44253}
parent 459b881c
......@@ -655,40 +655,40 @@ void Builtins::Generate_JSBuiltinsConstructStubForDerived(
// static
void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kGenerator);
}
// static
void Builtins::Generate_ResumeAsyncGeneratorTrampoline(MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kAsyncGenerator);
}
// static
void Builtins::Generate_ResumeAwaitedAsyncGeneratorTrampoline(
MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kAwaitedAsyncGenerator);
}
void Builtins::Generate_ResumeGenerator(MacroAssembler* masm,
ResumeGeneratorType type) {
// ----------- S t a t e -------------
// -- r3 : the value to pass to the generator
// -- r4 : the JSGeneratorObject to resume
// -- r5 : the resume mode (tagged)
// -- r6 : the SuspendFlags of the earlier suspend call (tagged)
// -- lr : return address
// -----------------------------------
if (type == ResumeGeneratorType::kGenerator) {
__ AssertGeneratorObject(r4);
} else {
__ AssertAsyncGeneratorObject(r4);
}
__ SmiUntag(r6);
__ AssertGeneratorObject(r4, r6);
// Store input value into generator object.
int offset = type == ResumeGeneratorType::kAwaitedAsyncGenerator
? JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset
: JSGeneratorObject::kInputOrDebugPosOffset;
__ StoreP(r3, FieldMemOperand(r4, offset), r0);
__ RecordWriteField(r4, offset, r3, r6, kLRHasNotBeenSaved, kDontSaveFPRegs);
Label async_await, done_store_input;
__ And(r6, r6, Operand(static_cast<int>(SuspendFlags::kAsyncGeneratorAwait)));
__ cmpi(r6, Operand(static_cast<int>(SuspendFlags::kAsyncGeneratorAwait)));
__ beq(&async_await);
__ StoreP(r3, FieldMemOperand(r4, JSGeneratorObject::kInputOrDebugPosOffset),
r0);
__ RecordWriteField(r4, JSGeneratorObject::kInputOrDebugPosOffset, r3, r6,
kLRHasNotBeenSaved, kDontSaveFPRegs);
__ b(&done_store_input);
__ bind(&async_await);
__ StoreP(
r3,
FieldMemOperand(r4, JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset),
r0);
__ RecordWriteField(r4, JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset,
r3, r6, kLRHasNotBeenSaved, kDontSaveFPRegs);
__ b(&done_store_input);
__ bind(&done_store_input);
// `r6` no longer holds SuspendFlags
// Store resume mode into generator object.
__ StoreP(r5, FieldMemOperand(r4, JSGeneratorObject::kResumeModeOffset), r0);
......
......@@ -653,40 +653,40 @@ void Builtins::Generate_JSBuiltinsConstructStubForDerived(
// static
void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kGenerator);
}
// static
void Builtins::Generate_ResumeAsyncGeneratorTrampoline(MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kAsyncGenerator);
}
// static
void Builtins::Generate_ResumeAwaitedAsyncGeneratorTrampoline(
MacroAssembler* masm) {
Generate_ResumeGenerator(masm, ResumeGeneratorType::kAwaitedAsyncGenerator);
}
void Builtins::Generate_ResumeGenerator(MacroAssembler* masm,
ResumeGeneratorType type) {
// ----------- S t a t e -------------
// -- r2 : the value to pass to the generator
// -- r3 : the JSGeneratorObject to resume
// -- r4 : the resume mode (tagged)
// -- r5 : the SuspendFlags of the earlier suspend call (tagged)
// -- lr : return address
// -----------------------------------
if (type == ResumeGeneratorType::kGenerator) {
__ AssertGeneratorObject(r3);
} else {
__ AssertAsyncGeneratorObject(r3);
}
__ SmiUntag(r5);
__ AssertGeneratorObject(r3, r5);
// Store input value into generator object.
int offset = type == ResumeGeneratorType::kAwaitedAsyncGenerator
? JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset
: JSGeneratorObject::kInputOrDebugPosOffset;
__ StoreP(r2, FieldMemOperand(r3, offset), r0);
__ RecordWriteField(r3, offset, r2, r5, kLRHasNotBeenSaved, kDontSaveFPRegs);
Label async_await, done_store_input;
__ And(r5, r5, Operand(static_cast<int>(SuspendFlags::kAsyncGeneratorAwait)));
__ CmpP(r5, Operand(static_cast<int>(SuspendFlags::kAsyncGeneratorAwait)));
__ beq(&async_await);
__ StoreP(r2, FieldMemOperand(r3, JSGeneratorObject::kInputOrDebugPosOffset),
r0);
__ RecordWriteField(r3, JSGeneratorObject::kInputOrDebugPosOffset, r2, r5,
kLRHasNotBeenSaved, kDontSaveFPRegs);
__ b(&done_store_input);
__ bind(&async_await);
__ StoreP(
r2,
FieldMemOperand(r3, JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset),
r0);
__ RecordWriteField(r3, JSAsyncGeneratorObject::kAwaitInputOrDebugPosOffset,
r2, r5, kLRHasNotBeenSaved, kDontSaveFPRegs);
__ b(&done_store_input);
__ bind(&done_store_input);
// `r5` no longer holds SuspendFlags
// Store resume mode into generator object.
__ StoreP(r4, FieldMemOperand(r3, JSGeneratorObject::kResumeModeOffset));
......
......@@ -391,7 +391,8 @@ void ResumeGeneratorDescriptor::InitializePlatformSpecific(
Register registers[] = {
r3, // the value to pass to the generator
r4, // the JSGeneratorObject to resume
r5 // the resume mode (tagged)
r5, // the resume mode (tagged)
r6 // SuspendFlags (tagged)
};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
......
......@@ -2625,28 +2625,34 @@ void MacroAssembler::AssertBoundFunction(Register object) {
}
}
void MacroAssembler::AssertGeneratorObject(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object, r0);
Check(ne, kOperandIsASmiAndNotAGeneratorObject, cr0);
push(object);
CompareObjectType(object, object, object, JS_GENERATOR_OBJECT_TYPE);
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
}
void MacroAssembler::AssertGeneratorObject(Register object, Register flags) {
// `flags` should be an untagged integer. See `SuspendFlags` in src/globals.h
if (!emit_debug_code()) return;
TestIfSmi(object, r0);
Check(ne, kOperandIsASmiAndNotAGeneratorObject);
// Load map
Register map = object;
push(object);
LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset));
void MacroAssembler::AssertAsyncGeneratorObject(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object, r0);
Check(ne, kOperandIsASmiAndNotAGeneratorObject);
push(object);
CompareObjectType(object, object, object, JS_ASYNC_GENERATOR_OBJECT_TYPE);
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
Label async, do_check;
And(ip, flags, Operand(static_cast<int>(SuspendFlags::kGeneratorTypeMask)));
cmpi(ip, Operand(static_cast<int>(SuspendFlags::kGeneratorTypeMask)));
bne(&async);
// Check if JSGeneratorObject
CompareInstanceType(map, object, JS_GENERATOR_OBJECT_TYPE);
b(&do_check);
bind(&async);
// Check if JSAsyncGeneratorObject
CompareInstanceType(map, object, JS_ASYNC_GENERATOR_OBJECT_TYPE);
bind(&do_check);
// Restore generator object to register and perform assertion
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
......
......@@ -1311,8 +1311,7 @@ class MacroAssembler : public Assembler {
// Abort execution if argument is not a JSGeneratorObject,
// enabled via --debug-code.
void AssertGeneratorObject(Register object);
void AssertAsyncGeneratorObject(Register object);
void AssertGeneratorObject(Register object, Register suspend_flags);
// Abort execution if argument is not undefined or an AllocationSite, enabled
// via --debug-code.
......
......@@ -371,7 +371,8 @@ void ResumeGeneratorDescriptor::InitializePlatformSpecific(
Register registers[] = {
r2, // the value to pass to the generator
r3, // the JSGeneratorObject to resume
r4 // the resume mode (tagged)
r4, // the resume mode (tagged)
r5 // SuspendFlags (tagged)
};
data->InitializePlatformSpecific(arraysize(registers), registers);
}
......
......@@ -2401,28 +2401,34 @@ void MacroAssembler::AssertBoundFunction(Register object) {
}
}
void MacroAssembler::AssertGeneratorObject(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object);
Check(ne, kOperandIsASmiAndNotAGeneratorObject, cr0);
push(object);
CompareObjectType(object, object, object, JS_GENERATOR_OBJECT_TYPE);
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
}
void MacroAssembler::AssertGeneratorObject(Register object, Register flags) {
// `flags` should be an untagged integer. See `SuspendFlags` in src/globals.h
if (!emit_debug_code()) return;
TestIfSmi(object);
Check(ne, kOperandIsASmiAndNotAGeneratorObject, cr0);
// Load map
Register map = object;
push(object);
LoadP(map, FieldMemOperand(object, HeapObject::kMapOffset));
void MacroAssembler::AssertAsyncGeneratorObject(Register object) {
if (emit_debug_code()) {
STATIC_ASSERT(kSmiTag == 0);
TestIfSmi(object);
Check(ne, kOperandIsASmiAndNotAGeneratorObject);
push(object);
CompareObjectType(object, object, object, JS_ASYNC_GENERATOR_OBJECT_TYPE);
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
Label async, do_check;
And(ip, flags, Operand(static_cast<int>(SuspendFlags::kGeneratorTypeMask)));
CmpP(ip, Operand(static_cast<int>(SuspendFlags::kGeneratorTypeMask)));
bne(&async);
// Check if JSGeneratorObject
CompareInstanceType(map, object, JS_GENERATOR_OBJECT_TYPE);
b(&do_check);
bind(&async);
// Check if JSAsyncGeneratorObject
CompareInstanceType(map, object, JS_ASYNC_GENERATOR_OBJECT_TYPE);
bind(&do_check);
// Restore generator object to register and perform assertion
pop(object);
Check(eq, kOperandIsNotAGeneratorObject);
}
void MacroAssembler::AssertUndefinedOrAllocationSite(Register object,
......
......@@ -1629,8 +1629,7 @@ class MacroAssembler : public Assembler {
// Abort execution if argument is not a JSGeneratorObject,
// enabled via --debug-code.
void AssertGeneratorObject(Register object);
void AssertAsyncGeneratorObject(Register object);
void AssertGeneratorObject(Register object, Register suspend_flags);
// Abort execution if argument is not undefined or an AllocationSite, enabled
// via --debug-code.
......
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