Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: src/builtins/ia32/builtins-ia32.cc

Issue 2649143002: [Turbofan] Implement call with spread bytecode in assembly code. (Closed)
Patch Set: Rename PushArgsMode to InterpreterPushArgsMode Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins-interpreter.cc ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/ia32/builtins-ia32.cc
diff --git a/src/builtins/ia32/builtins-ia32.cc b/src/builtins/ia32/builtins-ia32.cc
index 4d366f6a06fb474d7217cee9b8e072c1f6a54b26..cde039664caae2802941c23f079c22093673e438 100644
--- a/src/builtins/ia32/builtins-ia32.cc
+++ b/src/builtins/ia32/builtins-ia32.cc
@@ -693,7 +693,7 @@ static void Generate_InterpreterPushArgs(MacroAssembler* masm,
// static
void Builtins::Generate_InterpreterPushArgsAndCallImpl(
MacroAssembler* masm, TailCallMode tail_call_mode,
- CallableType function_type) {
+ InterpreterPushArgsMode mode) {
// ----------- S t a t e -------------
// -- eax : the number of arguments (not including the receiver)
// -- ebx : the address of the first argument to be pushed. Subsequent
@@ -725,12 +725,14 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl(
// Call the target.
__ Push(edx); // Re-push return address.
- if (function_type == CallableType::kJSFunction) {
+ if (mode == InterpreterPushArgsMode::kJSFunction) {
__ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny,
tail_call_mode),
RelocInfo::CODE_TARGET);
+ } else if (mode == InterpreterPushArgsMode::kWithFinalSpread) {
+ __ Jump(masm->isolate()->builtins()->CallWithSpread(),
+ RelocInfo::CODE_TARGET);
} else {
- DCHECK_EQ(function_type, CallableType::kAny);
__ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
tail_call_mode),
RelocInfo::CODE_TARGET);
@@ -843,7 +845,7 @@ void Generate_InterpreterPushArgsAndReturnAddress(
// static
void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
- MacroAssembler* masm, PushArgsConstructMode mode) {
+ MacroAssembler* masm, InterpreterPushArgsMode mode) {
// ----------- S t a t e -------------
// -- eax : the number of arguments (not including the receiver)
// -- edx : the new target
@@ -869,7 +871,7 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
__ Pop(edi);
__ AssertUndefinedOrAllocationSite(ebx);
- if (mode == PushArgsConstructMode::kJSFunction) {
+ if (mode == InterpreterPushArgsMode::kJSFunction) {
// Tail call to the function-specific construct stub (still in the caller
// context at this point).
__ AssertFunction(edi);
@@ -878,12 +880,12 @@ void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
__ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
__ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
__ jmp(ecx);
- } else if (mode == PushArgsConstructMode::kWithFinalSpread) {
+ } else if (mode == InterpreterPushArgsMode::kWithFinalSpread) {
// Call the constructor with unmodified eax, edi, edx values.
__ Jump(masm->isolate()->builtins()->ConstructWithSpread(),
RelocInfo::CODE_TARGET);
} else {
- DCHECK_EQ(PushArgsConstructMode::kOther, mode);
+ DCHECK_EQ(InterpreterPushArgsMode::kOther, mode);
// Call the constructor with unmodified eax, edi, edx values.
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
}
@@ -2673,137 +2675,7 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
}
}
-// static
-void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- eax : the number of arguments (not including the receiver)
- // -- edx : the new target (checked to be a constructor)
- // -- edi : the constructor to call (checked to be a JSFunction)
- // -----------------------------------
- __ AssertFunction(edi);
-
- // Calling convention for function specific ConstructStubs require
- // ebx to contain either an AllocationSite or undefined.
- __ LoadRoot(ebx, Heap::kUndefinedValueRootIndex);
-
- // Tail call to the function-specific construct stub (still in the caller
- // context at this point).
- __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
- __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
- __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
- __ jmp(ecx);
-}
-
-// static
-void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- eax : the number of arguments (not including the receiver)
- // -- edx : the new target (checked to be a constructor)
- // -- edi : the constructor to call (checked to be a JSBoundFunction)
- // -----------------------------------
- __ AssertBoundFunction(edi);
-
- // Push the [[BoundArguments]] onto the stack.
- Generate_PushBoundArguments(masm);
-
- // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
- {
- Label done;
- __ cmp(edi, edx);
- __ j(not_equal, &done, Label::kNear);
- __ mov(edx, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset));
- __ bind(&done);
- }
-
- // Construct the [[BoundTargetFunction]] via the Construct builtin.
- __ mov(edi, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset));
- __ mov(ecx, Operand::StaticVariable(
- ExternalReference(Builtins::kConstruct, masm->isolate())));
- __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
- __ jmp(ecx);
-}
-
-// static
-void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- eax : the number of arguments (not including the receiver)
- // -- edi : the constructor to call (checked to be a JSProxy)
- // -- edx : the new target (either the same as the constructor or
- // the JSFunction on which new was invoked initially)
- // -----------------------------------
-
- // Call into the Runtime for Proxy [[Construct]].
- __ PopReturnAddressTo(ecx);
- __ Push(edi);
- __ Push(edx);
- __ PushReturnAddressFrom(ecx);
- // Include the pushed new_target, constructor and the receiver.
- __ add(eax, Immediate(3));
- // Tail-call to the runtime.
- __ JumpToExternalReference(
- ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()));
-}
-
-// static
-void Builtins::Generate_Construct(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- eax : the number of arguments (not including the receiver)
- // -- edx : the new target (either the same as the constructor or
- // the JSFunction on which new was invoked initially)
- // -- edi : the constructor to call (can be any Object)
- // -----------------------------------
-
- // Check if target is a Smi.
- Label non_constructor;
- __ JumpIfSmi(edi, &non_constructor, Label::kNear);
-
- // Dispatch based on instance type.
- __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
- __ j(equal, masm->isolate()->builtins()->ConstructFunction(),
- RelocInfo::CODE_TARGET);
-
- // Check if target has a [[Construct]] internal method.
- __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
- Immediate(1 << Map::kIsConstructor));
- __ j(zero, &non_constructor, Label::kNear);
-
- // Only dispatch to bound functions after checking whether they are
- // constructors.
- __ CmpInstanceType(ecx, JS_BOUND_FUNCTION_TYPE);
- __ j(equal, masm->isolate()->builtins()->ConstructBoundFunction(),
- RelocInfo::CODE_TARGET);
-
- // Only dispatch to proxies after checking whether they are constructors.
- __ CmpInstanceType(ecx, JS_PROXY_TYPE);
- __ j(equal, masm->isolate()->builtins()->ConstructProxy(),
- RelocInfo::CODE_TARGET);
-
- // Called Construct on an exotic Object with a [[Construct]] internal method.
- {
- // Overwrite the original receiver with the (original) target.
- __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi);
- // Let the "call_as_constructor_delegate" take care of the rest.
- __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi);
- __ Jump(masm->isolate()->builtins()->CallFunction(),
- RelocInfo::CODE_TARGET);
- }
-
- // Called Construct on an Object that doesn't have a [[Construct]] internal
- // method.
- __ bind(&non_constructor);
- __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(),
- RelocInfo::CODE_TARGET);
-}
-
-// static
-void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
- // ----------- S t a t e -------------
- // -- eax : the number of arguments (not including the receiver)
- // -- edx : the new target (either the same as the constructor or
- // the JSFunction on which new was invoked initially)
- // -- edi : the constructor to call (can be any Object)
- // -----------------------------------
-
+static void CheckSpreadAndPushToStack(MacroAssembler* masm) {
// Free up some registers.
__ movd(xmm0, edx);
__ movd(xmm1, edi);
@@ -2816,6 +2688,8 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
Register spread = ebx;
Register spread_map = edx;
+ Register spread_len = edx;
+
__ mov(spread, Operand(esp, kPointerSize));
__ mov(spread_map, FieldOperand(spread, HeapObject::kMapOffset));
@@ -2868,9 +2742,10 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
__ j(not_equal, &runtime_call);
__ bind(&no_protector_check);
- // Load the FixedArray backing store.
+ // Load the FixedArray backing store, but use the length from the array.
+ __ mov(spread_len, FieldOperand(spread, JSArray::kLengthOffset));
+ __ SmiUntag(spread_len);
__ mov(spread, FieldOperand(spread, JSArray::kElementsOffset));
- // Free up some registers.
__ jmp(&push_args);
__ bind(&runtime_call);
@@ -2896,19 +2771,19 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
__ movd(xmm1, edi);
}
- Register spread_len = edx;
Register return_address = edi;
- __ bind(&push_args);
{
- // Pop the return address and spread argument.
- __ PopReturnAddressTo(return_address);
- __ Pop(scratch);
-
// Calculate the new nargs including the result of the spread.
__ mov(spread_len, FieldOperand(spread, FixedArray::kLengthOffset));
__ SmiUntag(spread_len);
+
+ __ bind(&push_args);
// argc += spread_len - 1. Subtract 1 for the spread itself.
__ lea(argc, Operand(argc, spread_len, times_1, -1));
+
+ // Pop the return address and spread argument.
+ __ PopReturnAddressTo(return_address);
+ __ Pop(scratch);
}
// Check for stack overflow.
@@ -2950,8 +2825,155 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
__ movd(edi, xmm1);
__ movd(edx, xmm0);
}
+}
+
+// static
+void Builtins::Generate_CallWithSpread(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edi : the target to call (can be any Object)
+ // -----------------------------------
+
+ // CheckSpreadAndPushToStack will push edx to save it.
+ __ LoadRoot(edx, Heap::kUndefinedValueRootIndex);
+ CheckSpreadAndPushToStack(masm);
+ __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
+ TailCallMode::kDisallow),
+ RelocInfo::CODE_TARGET);
+}
+
+// static
+void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edx : the new target (checked to be a constructor)
+ // -- edi : the constructor to call (checked to be a JSFunction)
+ // -----------------------------------
+ __ AssertFunction(edi);
+
+ // Calling convention for function specific ConstructStubs require
+ // ebx to contain either an AllocationSite or undefined.
+ __ LoadRoot(ebx, Heap::kUndefinedValueRootIndex);
+
+ // Tail call to the function-specific construct stub (still in the caller
+ // context at this point).
+ __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
+ __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
+ __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
+ __ jmp(ecx);
+}
+
+// static
+void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edx : the new target (checked to be a constructor)
+ // -- edi : the constructor to call (checked to be a JSBoundFunction)
+ // -----------------------------------
+ __ AssertBoundFunction(edi);
+
+ // Push the [[BoundArguments]] onto the stack.
+ Generate_PushBoundArguments(masm);
+
+ // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
+ {
+ Label done;
+ __ cmp(edi, edx);
+ __ j(not_equal, &done, Label::kNear);
+ __ mov(edx, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset));
+ __ bind(&done);
+ }
+
+ // Construct the [[BoundTargetFunction]] via the Construct builtin.
+ __ mov(edi, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset));
+ __ mov(ecx, Operand::StaticVariable(
+ ExternalReference(Builtins::kConstruct, masm->isolate())));
+ __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
+ __ jmp(ecx);
+}
+
+// static
+void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edi : the constructor to call (checked to be a JSProxy)
+ // -- edx : the new target (either the same as the constructor or
+ // the JSFunction on which new was invoked initially)
+ // -----------------------------------
+
+ // Call into the Runtime for Proxy [[Construct]].
+ __ PopReturnAddressTo(ecx);
+ __ Push(edi);
+ __ Push(edx);
+ __ PushReturnAddressFrom(ecx);
+ // Include the pushed new_target, constructor and the receiver.
+ __ add(eax, Immediate(3));
+ // Tail-call to the runtime.
+ __ JumpToExternalReference(
+ ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()));
+}
+
+// static
+void Builtins::Generate_Construct(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edx : the new target (either the same as the constructor or
+ // the JSFunction on which new was invoked initially)
+ // -- edi : the constructor to call (can be any Object)
+ // -----------------------------------
+
+ // Check if target is a Smi.
+ Label non_constructor;
+ __ JumpIfSmi(edi, &non_constructor, Label::kNear);
+
+ // Dispatch based on instance type.
+ __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
+ __ j(equal, masm->isolate()->builtins()->ConstructFunction(),
+ RelocInfo::CODE_TARGET);
+
+ // Check if target has a [[Construct]] internal method.
+ __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
+ Immediate(1 << Map::kIsConstructor));
+ __ j(zero, &non_constructor, Label::kNear);
+
+ // Only dispatch to bound functions after checking whether they are
+ // constructors.
+ __ CmpInstanceType(ecx, JS_BOUND_FUNCTION_TYPE);
+ __ j(equal, masm->isolate()->builtins()->ConstructBoundFunction(),
+ RelocInfo::CODE_TARGET);
+
+ // Only dispatch to proxies after checking whether they are constructors.
+ __ CmpInstanceType(ecx, JS_PROXY_TYPE);
+ __ j(equal, masm->isolate()->builtins()->ConstructProxy(),
+ RelocInfo::CODE_TARGET);
+
+ // Called Construct on an exotic Object with a [[Construct]] internal method.
+ {
+ // Overwrite the original receiver with the (original) target.
+ __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi);
+ // Let the "call_as_constructor_delegate" take care of the rest.
+ __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi);
+ __ Jump(masm->isolate()->builtins()->CallFunction(),
+ RelocInfo::CODE_TARGET);
+ }
+
+ // Called Construct on an Object that doesn't have a [[Construct]] internal
+ // method.
+ __ bind(&non_constructor);
+ __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(),
+ RelocInfo::CODE_TARGET);
+}
+
+// static
+void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- eax : the number of arguments (not including the receiver)
+ // -- edx : the new target (either the same as the constructor or
+ // the JSFunction on which new was invoked initially)
+ // -- edi : the constructor to call (can be any Object)
+ // -----------------------------------
- // Dispatch.
+ CheckSpreadAndPushToStack(masm);
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
}
« no previous file with comments | « src/builtins/builtins-interpreter.cc ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698