| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ | 5 #ifndef V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ |
| 6 #define V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ | 6 #define V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/base/smart-pointers.h" | 9 #include "src/base/smart-pointers.h" |
| 10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
| 11 #include "src/frames.h" | 11 #include "src/frames.h" |
| 12 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
| 13 #include "src/interpreter/interpreter-assembler.h" | 13 #include "src/interpreter/interpreter-assembler.h" |
| 14 #include "src/runtime/runtime.h" | 14 #include "src/runtime/runtime.h" |
| 15 | 15 |
| 16 namespace v8 { | 16 namespace v8 { |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 namespace compiler { | 19 namespace compiler { |
| 20 class Node; | 20 class Node; |
| 21 } // namespace compiler | 21 } // namespace compiler |
| 22 | 22 |
| 23 namespace interpreter { |
| 24 |
| 23 // List of supported intrisics, with upper case name, lower case name and | 25 // List of supported intrisics, with upper case name, lower case name and |
| 24 // expected number of arguments (-1 denoting argument count is variable). | 26 // expected number of arguments (-1 denoting argument count is variable). |
| 25 #define INTRINSICS_LIST(V) \ | 27 #define INTRINSICS_LIST(V) \ |
| 26 V(Call, call, -1) \ | 28 V(Call, call, -1) \ |
| 27 V(IsArray, is_array, 1) \ | 29 V(IsArray, is_array, 1) \ |
| 28 V(IsJSProxy, is_js_proxy, 1) \ | 30 V(IsJSProxy, is_js_proxy, 1) \ |
| 29 V(IsJSReceiver, is_js_receiver, 1) \ | 31 V(IsJSReceiver, is_js_receiver, 1) \ |
| 30 V(IsRegExp, is_regexp, 1) \ | 32 V(IsRegExp, is_regexp, 1) \ |
| 31 V(IsSmi, is_smi, 1) \ | 33 V(IsSmi, is_smi, 1) \ |
| 32 V(IsTypedArray, is_typed_array, 1) | 34 V(IsTypedArray, is_typed_array, 1) |
| 33 | 35 |
| 34 namespace interpreter { | |
| 35 | |
| 36 class IntrinsicsHelper { | 36 class IntrinsicsHelper { |
| 37 public: | 37 public: |
| 38 enum class IntrinsicId { |
| 39 #define DECLARE_INTRINSIC_ID(name, lower_case, count) k##name, |
| 40 INTRINSICS_LIST(DECLARE_INTRINSIC_ID) |
| 41 #undef DECLARE_INTRINSIC_ID |
| 42 kIdCount |
| 43 }; |
| 44 STATIC_ASSERT(static_cast<uint32_t>(IntrinsicId::kIdCount) <= kMaxUInt8); |
| 45 |
| 38 explicit IntrinsicsHelper(InterpreterAssembler* assembler); | 46 explicit IntrinsicsHelper(InterpreterAssembler* assembler); |
| 39 | 47 |
| 40 compiler::Node* InvokeIntrinsic(compiler::Node* function_id, | 48 compiler::Node* InvokeIntrinsic(compiler::Node* function_id, |
| 41 compiler::Node* context, | 49 compiler::Node* context, |
| 42 compiler::Node* first_arg_reg, | 50 compiler::Node* first_arg_reg, |
| 43 compiler::Node* arg_count); | 51 compiler::Node* arg_count); |
| 44 | 52 |
| 45 static bool IsSupported(Runtime::FunctionId function_id); | 53 static bool IsSupported(Runtime::FunctionId function_id); |
| 54 static IntrinsicId FromRuntimeId(Runtime::FunctionId function_id); |
| 55 static Runtime::FunctionId ToRuntimeId(IntrinsicId intrinsic_id); |
| 46 | 56 |
| 47 private: | 57 private: |
| 48 enum InstanceTypeCompareMode { | 58 enum InstanceTypeCompareMode { |
| 49 kInstanceTypeEqual, | 59 kInstanceTypeEqual, |
| 50 kInstanceTypeGreaterThanOrEqual | 60 kInstanceTypeGreaterThanOrEqual |
| 51 }; | 61 }; |
| 52 | 62 |
| 53 compiler::Node* IsInstanceType(compiler::Node* input, int type); | 63 compiler::Node* IsInstanceType(compiler::Node* input, int type); |
| 54 compiler::Node* CompareInstanceType(compiler::Node* map, int type, | 64 compiler::Node* CompareInstanceType(compiler::Node* map, int type, |
| 55 InstanceTypeCompareMode mode); | 65 InstanceTypeCompareMode mode); |
| 56 void AbortIfArgCountMismatch(int expected, compiler::Node* actual); | 66 void AbortIfArgCountMismatch(int expected, compiler::Node* actual); |
| 57 | 67 |
| 58 #define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \ | 68 #define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \ |
| 59 compiler::Node* name(compiler::Node* input, compiler::Node* arg_count, \ | 69 compiler::Node* name(compiler::Node* input, compiler::Node* arg_count, \ |
| 60 compiler::Node* context); | 70 compiler::Node* context); |
| 61 INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER) | 71 INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER) |
| 62 #undef DECLARE_INTRINSIC_HELPER | 72 #undef DECLARE_INTRINSIC_HELPER |
| 63 | 73 |
| 64 InterpreterAssembler* assembler_; | 74 InterpreterAssembler* assembler_; |
| 65 | 75 |
| 66 DISALLOW_COPY_AND_ASSIGN(IntrinsicsHelper); | 76 DISALLOW_COPY_AND_ASSIGN(IntrinsicsHelper); |
| 67 }; | 77 }; |
| 68 | 78 |
| 69 } // namespace interpreter | 79 } // namespace interpreter |
| 70 } // namespace internal | 80 } // namespace internal |
| 71 } // namespace v8 | 81 } // namespace v8 |
| 72 | 82 |
| 73 #endif | 83 #endif |
| OLD | NEW |