| Index: src/interpreter/interpreter-intrinsics-generator.cc
|
| diff --git a/src/interpreter/interpreter-intrinsics.cc b/src/interpreter/interpreter-intrinsics-generator.cc
|
| similarity index 66%
|
| copy from src/interpreter/interpreter-intrinsics.cc
|
| copy to src/interpreter/interpreter-intrinsics-generator.cc
|
| index 78de42b634d3e4b0a566031499e1abb239bd4226..25e942ac896b9ada37ec11144be57f1872c591e2 100644
|
| --- a/src/interpreter/interpreter-intrinsics.cc
|
| +++ b/src/interpreter/interpreter-intrinsics-generator.cc
|
| @@ -1,11 +1,16 @@
|
| -// Copyright 2015 the V8 project authors. All rights reserved.
|
| +// Copyright 2017 the V8 project authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "src/interpreter/interpreter-intrinsics.h"
|
| +#include "src/interpreter/interpreter-intrinsics-generator.h"
|
|
|
| +#include "src/allocation.h"
|
| +#include "src/builtins/builtins.h"
|
| #include "src/code-factory.h"
|
| -#include "src/objects-inl.h"
|
| +#include "src/frames.h"
|
| +#include "src/interpreter/bytecodes.h"
|
| +#include "src/interpreter/interpreter-assembler.h"
|
| +#include "src/interpreter/interpreter-intrinsics.h"
|
|
|
| namespace v8 {
|
| namespace internal {
|
| @@ -13,57 +18,56 @@ namespace interpreter {
|
|
|
| using compiler::Node;
|
|
|
| -#define __ assembler_->
|
| -
|
| -IntrinsicsHelper::IntrinsicsHelper(InterpreterAssembler* assembler)
|
| - : isolate_(assembler->isolate()),
|
| - zone_(assembler->zone()),
|
| - assembler_(assembler) {}
|
| -
|
| -// static
|
| -bool IntrinsicsHelper::IsSupported(Runtime::FunctionId function_id) {
|
| - switch (function_id) {
|
| -#define SUPPORTED(name, lower_case, count) case Runtime::kInline##name:
|
| - INTRINSICS_LIST(SUPPORTED)
|
| - return true;
|
| -#undef SUPPORTED
|
| - default:
|
| - return false;
|
| - }
|
| -}
|
| -
|
| -// static
|
| -IntrinsicsHelper::IntrinsicId IntrinsicsHelper::FromRuntimeId(
|
| - Runtime::FunctionId function_id) {
|
| - switch (function_id) {
|
| -#define TO_RUNTIME_ID(name, lower_case, count) \
|
| - case Runtime::kInline##name: \
|
| - return IntrinsicId::k##name;
|
| - INTRINSICS_LIST(TO_RUNTIME_ID)
|
| -#undef TO_RUNTIME_ID
|
| - default:
|
| - UNREACHABLE();
|
| - return static_cast<IntrinsicsHelper::IntrinsicId>(-1);
|
| - }
|
| +class IntrinsicsGenerator {
|
| + public:
|
| + explicit IntrinsicsGenerator(InterpreterAssembler* assembler)
|
| + : isolate_(assembler->isolate()),
|
| + zone_(assembler->zone()),
|
| + assembler_(assembler) {}
|
| +
|
| + Node* InvokeIntrinsic(Node* function_id, Node* context, Node* first_arg_reg,
|
| + Node* arg_count);
|
| +
|
| + private:
|
| + enum InstanceTypeCompareMode {
|
| + kInstanceTypeEqual,
|
| + kInstanceTypeGreaterThanOrEqual
|
| + };
|
| +
|
| + Node* IsInstanceType(Node* input, int type);
|
| + Node* CompareInstanceType(Node* map, int type, InstanceTypeCompareMode mode);
|
| + Node* IntrinsicAsStubCall(Node* input, Node* context,
|
| + Callable const& callable);
|
| + void AbortIfArgCountMismatch(int expected, compiler::Node* actual);
|
| +
|
| +#define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \
|
| + Node* name(Node* input, Node* arg_count, Node* context);
|
| + INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER)
|
| +#undef DECLARE_INTRINSIC_HELPER
|
| +
|
| + Isolate* isolate() { return isolate_; }
|
| + Zone* zone() { return zone_; }
|
| +
|
| + Isolate* isolate_;
|
| + Zone* zone_;
|
| + InterpreterAssembler* assembler_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(IntrinsicsGenerator);
|
| +};
|
| +
|
| +Node* GenerateInvokeIntrinsic(InterpreterAssembler* assembler,
|
| + Node* function_id, Node* context,
|
| + Node* first_arg_reg, Node* arg_count) {
|
| + IntrinsicsGenerator generator(assembler);
|
| + return generator.InvokeIntrinsic(function_id, context, first_arg_reg,
|
| + arg_count);
|
| }
|
|
|
| -// static
|
| -Runtime::FunctionId IntrinsicsHelper::ToRuntimeId(
|
| - IntrinsicsHelper::IntrinsicId intrinsic_id) {
|
| - switch (intrinsic_id) {
|
| -#define TO_INTRINSIC_ID(name, lower_case, count) \
|
| - case IntrinsicId::k##name: \
|
| - return Runtime::kInline##name;
|
| - INTRINSICS_LIST(TO_INTRINSIC_ID)
|
| -#undef TO_INTRINSIC_ID
|
| - default:
|
| - UNREACHABLE();
|
| - return static_cast<Runtime::FunctionId>(-1);
|
| - }
|
| -}
|
| +#define __ assembler_->
|
|
|
| -Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context,
|
| - Node* first_arg_reg, Node* arg_count) {
|
| +Node* IntrinsicsGenerator::InvokeIntrinsic(Node* function_id, Node* context,
|
| + Node* first_arg_reg,
|
| + Node* arg_count) {
|
| InterpreterAssembler::Label abort(assembler_), end(assembler_);
|
| InterpreterAssembler::Variable result(assembler_,
|
| MachineRepresentation::kTagged);
|
| @@ -78,7 +82,7 @@ Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context,
|
| #undef LABEL_POINTER
|
|
|
| #define CASE(name, lower_case, count) \
|
| - static_cast<int32_t>(IntrinsicId::k##name),
|
| + static_cast<int32_t>(IntrinsicsHelper::IntrinsicId::k##name),
|
| int32_t cases[] = {INTRINSICS_LIST(CASE)};
|
| #undef CASE
|
|
|
| @@ -104,8 +108,8 @@ Node* IntrinsicsHelper::InvokeIntrinsic(Node* function_id, Node* context,
|
| return result.value();
|
| }
|
|
|
| -Node* IntrinsicsHelper::CompareInstanceType(Node* object, int type,
|
| - InstanceTypeCompareMode mode) {
|
| +Node* IntrinsicsGenerator::CompareInstanceType(Node* object, int type,
|
| + InstanceTypeCompareMode mode) {
|
| Node* instance_type = __ LoadInstanceType(object);
|
|
|
| if (mode == kInstanceTypeEqual) {
|
| @@ -116,7 +120,7 @@ Node* IntrinsicsHelper::CompareInstanceType(Node* object, int type,
|
| }
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsInstanceType(Node* input, int type) {
|
| +Node* IntrinsicsGenerator::IsInstanceType(Node* input, int type) {
|
| InterpreterAssembler::Variable return_value(assembler_,
|
| MachineRepresentation::kTagged);
|
| // TODO(ishell): Use Select here.
|
| @@ -144,8 +148,8 @@ Node* IntrinsicsHelper::IsInstanceType(Node* input, int type) {
|
| return return_value.value();
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsJSReceiver(Node* input, Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::IsJSReceiver(Node* input, Node* arg_count,
|
| + Node* context) {
|
| // TODO(ishell): Use Select here.
|
| // TODO(ishell): Use CSA::IsJSReceiverInstanceType here.
|
| InterpreterAssembler::Variable return_value(assembler_,
|
| @@ -177,20 +181,22 @@ Node* IntrinsicsHelper::IsJSReceiver(Node* input, Node* arg_count,
|
| return return_value.value();
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsArray(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::IsArray(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IsInstanceType(input, JS_ARRAY_TYPE);
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsJSProxy(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::IsJSProxy(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IsInstanceType(input, JS_PROXY_TYPE);
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsTypedArray(Node* input, Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::IsTypedArray(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IsInstanceType(input, JS_TYPED_ARRAY_TYPE);
|
| }
|
|
|
| -Node* IntrinsicsHelper::IsSmi(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::IsSmi(Node* input, Node* arg_count, Node* context) {
|
| // TODO(ishell): Use SelectBooleanConstant here.
|
| InterpreterAssembler::Variable return_value(assembler_,
|
| MachineRepresentation::kTagged);
|
| @@ -216,8 +222,8 @@ Node* IntrinsicsHelper::IsSmi(Node* input, Node* arg_count, Node* context) {
|
| return return_value.value();
|
| }
|
|
|
| -Node* IntrinsicsHelper::IntrinsicAsStubCall(Node* args_reg, Node* context,
|
| - Callable const& callable) {
|
| +Node* IntrinsicsGenerator::IntrinsicAsStubCall(Node* args_reg, Node* context,
|
| + Callable const& callable) {
|
| int param_count = callable.descriptor().GetParameterCount();
|
| int input_count = param_count + 2; // +2 for target and context
|
| Node** args = zone()->NewArray<Node*>(input_count);
|
| @@ -231,43 +237,50 @@ Node* IntrinsicsHelper::IntrinsicAsStubCall(Node* args_reg, Node* context,
|
| return __ CallStubN(callable.descriptor(), 1, input_count, args);
|
| }
|
|
|
| -Node* IntrinsicsHelper::CreateIterResultObject(Node* input, Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::CreateIterResultObject(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context,
|
| CodeFactory::CreateIterResultObject(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::HasProperty(Node* input, Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::HasProperty(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context,
|
| CodeFactory::HasProperty(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::SubString(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::SubString(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::SubString(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::ToString(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::ToString(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::ToString(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::ToLength(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::ToLength(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::ToLength(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::ToInteger(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::ToInteger(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::ToInteger(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::ToNumber(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::ToNumber(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::ToNumber(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::ToObject(Node* input, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::ToObject(Node* input, Node* arg_count,
|
| + Node* context) {
|
| return IntrinsicAsStubCall(input, context, CodeFactory::ToObject(isolate()));
|
| }
|
|
|
| -Node* IntrinsicsHelper::Call(Node* args_reg, Node* arg_count, Node* context) {
|
| +Node* IntrinsicsGenerator::Call(Node* args_reg, Node* arg_count,
|
| + Node* context) {
|
| // First argument register contains the function target.
|
| Node* function = __ LoadRegister(args_reg);
|
|
|
| @@ -293,15 +306,15 @@ Node* IntrinsicsHelper::Call(Node* args_reg, Node* arg_count, Node* context) {
|
| return result;
|
| }
|
|
|
| -Node* IntrinsicsHelper::ClassOf(Node* args_reg, Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::ClassOf(Node* args_reg, Node* arg_count,
|
| + Node* context) {
|
| Node* value = __ LoadRegister(args_reg);
|
| return __ ClassOf(value);
|
| }
|
|
|
| -Node* IntrinsicsHelper::CreateAsyncFromSyncIterator(Node* args_reg,
|
| - Node* arg_count,
|
| - Node* context) {
|
| +Node* IntrinsicsGenerator::CreateAsyncFromSyncIterator(Node* args_reg,
|
| + Node* arg_count,
|
| + Node* context) {
|
| InterpreterAssembler::Label not_receiver(
|
| assembler_, InterpreterAssembler::Label::kDeferred);
|
| InterpreterAssembler::Label done(assembler_);
|
| @@ -337,7 +350,7 @@ Node* IntrinsicsHelper::CreateAsyncFromSyncIterator(Node* args_reg,
|
| return return_value.value();
|
| }
|
|
|
| -void IntrinsicsHelper::AbortIfArgCountMismatch(int expected, Node* actual) {
|
| +void IntrinsicsGenerator::AbortIfArgCountMismatch(int expected, Node* actual) {
|
| InterpreterAssembler::Label match(assembler_);
|
| Node* comparison = __ Word32Equal(actual, __ Int32Constant(expected));
|
| __ GotoIf(comparison, &match);
|
|
|