From 8c990d1716d33db4834b7e3c115874d482291e8c Mon Sep 17 00:00:00 2001 From: dcarney Date: Mon, 19 Jan 2015 06:17:23 -0800 Subject: [PATCH] add stub for api function calls with known number of parameters BUG=449930 LOG=N Review URL: https://codereview.chromium.org/859783002 Cr-Commit-Position: refs/heads/master@{#26137} --- src/arm/code-stubs-arm.cc | 2 +- src/arm64/code-stubs-arm64.cc | 2 +- src/code-stubs.h | 33 ++++++++++++++++++++++++++++++++- src/hydrogen.cc | 10 ++++++++++ src/ia32/code-stubs-ia32.cc | 2 +- src/mips/code-stubs-mips.cc | 2 +- src/mips64/code-stubs-mips64.cc | 2 +- src/x64/code-stubs-x64.cc | 2 +- 8 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index a6af8f3..c923d48 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -4748,7 +4748,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index fa450d7..86ad0cf 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -5175,7 +5175,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); diff --git a/src/code-stubs.h b/src/code-stubs.h index 4fa440b..03075d9 100644 --- a/src/code-stubs.h +++ b/src/code-stubs.h @@ -1153,7 +1153,18 @@ class CallApiAccessorStub : public PlatformCodeStub { CallApiAccessorStub(Isolate* isolate, bool is_store, bool call_data_undefined) : PlatformCodeStub(isolate) { minor_key_ = IsStoreBits::encode(is_store) | - CallDataUndefinedBits::encode(call_data_undefined); + CallDataUndefinedBits::encode(call_data_undefined) | + ArgumentBits::encode(is_store ? 1 : 0); + } + + protected: + // For CallApiFunctionWithFixedArgsStub, see below. + static const int kArgBits = 3; + CallApiAccessorStub(Isolate* isolate, int argc, bool call_data_undefined) + : PlatformCodeStub(isolate) { + minor_key_ = IsStoreBits::encode(false) | + CallDataUndefinedBits::encode(call_data_undefined) | + ArgumentBits::encode(argc); } private: @@ -1161,15 +1172,35 @@ class CallApiAccessorStub : public PlatformCodeStub { bool call_data_undefined() const { return CallDataUndefinedBits::decode(minor_key_); } + int argc() const { return ArgumentBits::decode(minor_key_); } class IsStoreBits: public BitField {}; class CallDataUndefinedBits: public BitField {}; + class ArgumentBits : public BitField {}; DEFINE_CALL_INTERFACE_DESCRIPTOR(ApiAccessor); DEFINE_PLATFORM_CODE_STUB(CallApiAccessor, PlatformCodeStub); }; +// TODO(dcarney): see if it's possible to remove this later without performance +// degradation. +// This is not a real stub, but a way of generating the CallApiAccessorStub +// (which has the same abi) which makes it clear that it is not an accessor. +class CallApiFunctionWithFixedArgsStub : public CallApiAccessorStub { + public: + static const int kMaxFixedArgs = (1 << kArgBits) - 1; + CallApiFunctionWithFixedArgsStub(Isolate* isolate, int argc, + bool call_data_undefined) + : CallApiAccessorStub(isolate, argc, call_data_undefined) { + DCHECK(0 <= argc && argc <= kMaxFixedArgs); + } +}; + + +typedef ApiAccessorDescriptor ApiFunctionWithFixedArgsDescriptor; + + class CallApiGetterStub : public PlatformCodeStub { public: explicit CallApiGetterStub(Isolate* isolate) : PlatformCodeStub(isolate) {} diff --git a/src/hydrogen.cc b/src/hydrogen.cc index a288dbd..cfdb3c8 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -8776,6 +8776,16 @@ bool HOptimizedGraphBuilder::TryInlineApiCall(Handle function, call = New( code_value, argc + 1, descriptor, Vector(op_vals, descriptor.GetEnvironmentLength())); + } else if (argc <= CallApiFunctionWithFixedArgsStub::kMaxFixedArgs) { + CallApiFunctionWithFixedArgsStub stub(isolate(), argc, call_data_undefined); + Handle code = stub.GetCode(); + HConstant* code_value = Add(code); + ApiFunctionWithFixedArgsDescriptor descriptor(isolate()); + DCHECK(arraysize(op_vals) - 1 == descriptor.GetEnvironmentLength()); + call = New( + code_value, argc + 1, descriptor, + Vector(op_vals, descriptor.GetEnvironmentLength())); + Drop(1); // Drop function. } else { op_vals[arraysize(op_vals) - 1] = Add(argc); CallApiFunctionStub stub(isolate(), call_data_undefined); diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index bd91cd6..d977d39 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -4829,7 +4829,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index 894747f..29475eb 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -4962,7 +4962,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); diff --git a/src/mips64/code-stubs-mips64.cc b/src/mips64/code-stubs-mips64.cc index 944ed3c..713dd14 100644 --- a/src/mips64/code-stubs-mips64.cc +++ b/src/mips64/code-stubs-mips64.cc @@ -5001,7 +5001,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index 1149348..56b4075 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -4772,7 +4772,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) { void CallApiAccessorStub::Generate(MacroAssembler* masm) { bool is_store = this->is_store(); - int argc = is_store ? 1 : 0; + int argc = this->argc(); bool call_data_undefined = this->call_data_undefined(); CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, call_data_undefined); -- 2.7.4