Commit 46d0e481 authored by bmeurer's avatar bmeurer Committed by Commit bot

[stubs] Drop CallApiCallbackStub::call_data_undefined optimization.

The CallApiCallbackStub can avoid loading undefined in case the
call_data is already undefined, which doubles the number of versions of
the stub and adds unnecessary complexity (at the benefit of saving one
stupid load). The idea is to turn the CallApiCallbackStub into a single
builtin instead, which does the right thing, so this is the first step
towards that goal.

R=yangguo@chromium.org
BUG=v8:6304

Review-Url: https://codereview.chromium.org/2838143003
Cr-Commit-Position: refs/heads/master@{#44869}
parent f385b747
......@@ -2799,9 +2799,7 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
__ push(call_data);
Register scratch = call_data;
if (!call_data_undefined()) {
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
}
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
// return value
__ push(scratch);
// return value default
......
......@@ -3031,9 +3031,7 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
__ Ldr(context, FieldMemOperand(callee, JSFunction::kContextOffset));
}
if (!call_data_undefined()) {
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
}
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
Register isolate_reg = x5;
__ Mov(isolate_reg, ExternalReference::isolate_address(masm->isolate()));
......
......@@ -827,39 +827,29 @@ class CallApiCallbackStub : public PlatformCodeStub {
static const int kArgMax = (1 << kArgBits) - 1;
// CallApiCallbackStub for regular setters and getters.
CallApiCallbackStub(Isolate* isolate, bool is_store, bool call_data_undefined,
bool is_lazy)
: CallApiCallbackStub(isolate, is_store ? 1 : 0, is_store,
call_data_undefined, is_lazy) {}
CallApiCallbackStub(Isolate* isolate, bool is_store, bool is_lazy)
: CallApiCallbackStub(isolate, is_store ? 1 : 0, is_store, is_lazy) {}
// CallApiCallbackStub for callback functions.
CallApiCallbackStub(Isolate* isolate, int argc, bool call_data_undefined,
bool is_lazy)
: CallApiCallbackStub(isolate, argc, false, call_data_undefined,
is_lazy) {}
CallApiCallbackStub(Isolate* isolate, int argc, bool is_lazy)
: CallApiCallbackStub(isolate, argc, false, is_lazy) {}
private:
CallApiCallbackStub(Isolate* isolate, int argc, bool is_store,
bool call_data_undefined, bool is_lazy)
CallApiCallbackStub(Isolate* isolate, int argc, bool is_store, bool is_lazy)
: PlatformCodeStub(isolate) {
CHECK(0 <= argc && argc <= kArgMax);
minor_key_ = IsStoreBits::encode(is_store) |
CallDataUndefinedBits::encode(call_data_undefined) |
ArgumentBits::encode(argc) |
IsLazyAccessorBits::encode(is_lazy);
}
bool is_store() const { return IsStoreBits::decode(minor_key_); }
bool is_lazy() const { return IsLazyAccessorBits::decode(minor_key_); }
bool call_data_undefined() const {
return CallDataUndefinedBits::decode(minor_key_);
}
int argc() const { return ArgumentBits::decode(minor_key_); }
class IsStoreBits: public BitField<bool, 0, 1> {};
class CallDataUndefinedBits: public BitField<bool, 1, 1> {};
class IsLazyAccessorBits : public BitField<bool, 1, 1> {};
class ArgumentBits : public BitField<int, 2, kArgBits> {};
class IsLazyAccessorBits : public BitField<bool, 3 + kArgBits, 1> {};
DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiCallback);
DEFINE_PLATFORM_CODE_STUB(CallApiCallback, PlatformCodeStub);
......
......@@ -439,7 +439,7 @@ Reduction JSCallReducer::ReduceCallApiFunction(
// the receiver (which is implicitly counted by CallApiCallbackStub) from the
// arguments count.
int const argc = static_cast<int>(params.arity() - 2);
CallApiCallbackStub stub(isolate, argc, data->IsUndefined(isolate), false);
CallApiCallbackStub stub(isolate, argc, false);
CallInterfaceDescriptor cid = stub.GetCallInterfaceDescriptor();
CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
isolate, zone, cid,
......
......@@ -2215,7 +2215,7 @@ JSNativeContextSpecialization::InlineApiCall(
int const argc = value == nullptr ? 0 : 1;
// The stub always expects the receiver as the first param on the stack.
CallApiCallbackStub stub(
isolate(), argc, call_data_object->IsUndefined(isolate()),
isolate(), argc,
true /* FunctionTemplateInfo doesn't have an associated context. */);
CallInterfaceDescriptor call_interface_descriptor =
stub.GetCallInterfaceDescriptor();
......
......@@ -9102,7 +9102,6 @@ bool HOptimizedGraphBuilder::TryInlineApiCall(
}
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
Handle<Object> call_data_obj(api_call_info->data(), isolate());
bool call_data_undefined = call_data_obj->IsUndefined(isolate());
HValue* call_data = Add<HConstant>(call_data_obj);
ApiFunction fun(v8::ToCData<Address>(api_call_info->callback()));
ExternalReference ref = ExternalReference(&fun,
......@@ -9116,7 +9115,7 @@ bool HOptimizedGraphBuilder::TryInlineApiCall(
HInstruction* call = nullptr;
CHECK(argc <= CallApiCallbackStub::kArgMax);
if (!is_function) {
CallApiCallbackStub stub(isolate(), is_store, call_data_undefined,
CallApiCallbackStub stub(isolate(), is_store,
!optimization.is_constant_call());
Handle<Code> code = stub.GetCode();
HConstant* code_value = Add<HConstant>(code);
......@@ -9124,7 +9123,7 @@ bool HOptimizedGraphBuilder::TryInlineApiCall(
code_value, argc + 1, stub.GetCallInterfaceDescriptor(),
Vector<HValue*>(op_vals, arraysize(op_vals)), syntactic_tail_call_mode);
} else {
CallApiCallbackStub stub(isolate(), argc, call_data_undefined, false);
CallApiCallbackStub stub(isolate(), argc, false);
Handle<Code> code = stub.GetCode();
HConstant* code_value = Add<HConstant>(code);
call = New<HCallWithDescriptor>(
......
......@@ -2780,23 +2780,16 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
// call data
__ push(call_data);
Register scratch = call_data;
if (!call_data_undefined()) {
// return value
__ push(Immediate(masm->isolate()->factory()->undefined_value()));
// return value default
__ push(Immediate(masm->isolate()->factory()->undefined_value()));
} else {
// return value
__ push(scratch);
// return value default
__ push(scratch);
}
// return value
__ push(Immediate(masm->isolate()->factory()->undefined_value()));
// return value default
__ push(Immediate(masm->isolate()->factory()->undefined_value()));
// isolate
__ push(Immediate(reinterpret_cast<int>(masm->isolate())));
// holder
__ push(holder);
Register scratch = call_data;
__ mov(scratch, esp);
// push return address
......
......@@ -221,10 +221,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ LoadRoot(data, Heap::kUndefinedValueRootIndex);
} else {
if (optimization.is_constant_call()) {
......@@ -249,8 +247,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ mov(api_function_address, Operand(ref));
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -156,10 +156,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ LoadRoot(data, Heap::kUndefinedValueRootIndex);
} else {
if (optimization.is_constant_call()) {
......@@ -184,8 +182,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ Mov(api_function_address, ref);
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -161,10 +161,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ mov(data, Immediate(isolate->factory()->undefined_value()));
} else {
if (optimization.is_constant_call()) {
......@@ -182,8 +180,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ mov(api_function_address, Immediate(function_address));
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -211,10 +211,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ LoadRoot(data, Heap::kUndefinedValueRootIndex);
} else {
if (optimization.is_constant_call()) {
......@@ -238,8 +236,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ li(api_function_address, Operand(ref));
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -210,10 +210,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ LoadRoot(data, Heap::kUndefinedValueRootIndex);
} else {
if (optimization.is_constant_call()) {
......@@ -237,8 +235,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ li(api_function_address, Operand(ref));
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -139,10 +139,8 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
Isolate* isolate = masm->isolate();
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
bool call_data_undefined = false;
// Put call data in place.
if (api_call_info->data()->IsUndefined(isolate)) {
call_data_undefined = true;
__ LoadRoot(data, Heap::kUndefinedValueRootIndex);
} else {
if (optimization.is_constant_call()) {
......@@ -164,8 +162,7 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
RelocInfo::EXTERNAL_REFERENCE);
// Jump to stub.
CallApiCallbackStub stub(isolate, is_store, call_data_undefined,
!optimization.is_constant_call());
CallApiCallbackStub stub(isolate, is_store, !optimization.is_constant_call());
__ TailCallStub(&stub);
}
......
......@@ -2973,9 +2973,7 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
}
Register scratch = call_data;
if (!call_data_undefined()) {
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
}
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
// Push return value and default return value.
__ Push(scratch, scratch);
__ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
......
......@@ -2976,9 +2976,7 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
}
Register scratch = call_data;
if (!call_data_undefined()) {
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
}
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
// Push return value and default return value.
__ Push(scratch, scratch);
__ li(scratch, Operand(ExternalReference::isolate_address(masm->isolate())));
......
......@@ -2743,15 +2743,13 @@ void CallApiCallbackStub::Generate(MacroAssembler* masm) {
// call data
__ Push(call_data);
Register scratch = call_data;
if (!this->call_data_undefined()) {
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
}
// return value
__ Push(scratch);
__ PushRoot(Heap::kUndefinedValueRootIndex);
// return value default
__ Push(scratch);
__ PushRoot(Heap::kUndefinedValueRootIndex);
// isolate
Register scratch = call_data;
__ Move(scratch, ExternalReference::isolate_address(masm->isolate()));
__ Push(scratch);
// holder
......
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