Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ |
| 6 | #define V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ |
| 7 | |
| 8 | #include "src/allocation.h" |
| 9 | #include "src/base/smart-pointers.h" |
| 10 | #include "src/builtins.h" |
| 11 | #include "src/frames.h" |
| 12 | #include "src/interpreter/bytecodes.h" |
| 13 | #include "src/interpreter/interpreter-assembler.h" |
| 14 | #include "src/runtime/runtime.h" |
| 15 | |
| 16 | namespace v8 { |
| 17 | namespace internal { |
| 18 | |
| 19 | namespace compiler { |
| 20 | class Node; |
| 21 | } // namespace compiler |
| 22 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 23 | namespace interpreter { |
| 24 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 25 | // List of supported intrisics, with upper case name, lower case name and |
| 26 | // expected number of arguments (-1 denoting argument count is variable). |
| 27 | #define INTRINSICS_LIST(V) \ |
| 28 | V(Call, call, -1) \ |
| 29 | V(HasProperty, has_property, 2) \ |
| 30 | V(IsArray, is_array, 1) \ |
| 31 | V(IsJSProxy, is_js_proxy, 1) \ |
| 32 | V(IsJSReceiver, is_js_receiver, 1) \ |
| 33 | V(IsRegExp, is_regexp, 1) \ |
| 34 | V(IsSmi, is_smi, 1) \ |
| 35 | V(IsTypedArray, is_typed_array, 1) \ |
| 36 | V(MathPow, math_pow, 2) \ |
| 37 | V(NewObject, new_object, 2) \ |
| 38 | V(NumberToString, number_to_string, 1) \ |
| 39 | V(RegExpConstructResult, reg_exp_construct_result, 3) \ |
| 40 | V(RegExpExec, reg_exp_exec, 4) \ |
| 41 | V(SubString, sub_string, 3) \ |
| 42 | V(ToString, to_string, 1) \ |
| 43 | V(ToName, to_name, 1) \ |
| 44 | V(ToLength, to_length, 1) \ |
| 45 | V(ToInteger, to_integer, 1) \ |
| 46 | V(ToNumber, to_number, 1) \ |
| 47 | V(ToObject, to_object, 1) \ |
| 48 | V(ValueOf, value_of, 1) |
| 49 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 50 | class IntrinsicsHelper { |
| 51 | public: |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 52 | enum class IntrinsicId { |
| 53 | #define DECLARE_INTRINSIC_ID(name, lower_case, count) k##name, |
| 54 | INTRINSICS_LIST(DECLARE_INTRINSIC_ID) |
| 55 | #undef DECLARE_INTRINSIC_ID |
| 56 | kIdCount |
| 57 | }; |
| 58 | STATIC_ASSERT(static_cast<uint32_t>(IntrinsicId::kIdCount) <= kMaxUInt8); |
| 59 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 60 | explicit IntrinsicsHelper(InterpreterAssembler* assembler); |
| 61 | |
| 62 | compiler::Node* InvokeIntrinsic(compiler::Node* function_id, |
| 63 | compiler::Node* context, |
| 64 | compiler::Node* first_arg_reg, |
| 65 | compiler::Node* arg_count); |
| 66 | |
| 67 | static bool IsSupported(Runtime::FunctionId function_id); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 68 | static IntrinsicId FromRuntimeId(Runtime::FunctionId function_id); |
| 69 | static Runtime::FunctionId ToRuntimeId(IntrinsicId intrinsic_id); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 70 | |
| 71 | private: |
| 72 | enum InstanceTypeCompareMode { |
| 73 | kInstanceTypeEqual, |
| 74 | kInstanceTypeGreaterThanOrEqual |
| 75 | }; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 76 | |
| 77 | compiler::Node* IsInstanceType(compiler::Node* input, int type); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 78 | compiler::Node* CompareInstanceType(compiler::Node* map, int type, |
| 79 | InstanceTypeCompareMode mode); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 80 | compiler::Node* IntrinsicAsStubCall(compiler::Node* input, |
| 81 | compiler::Node* context, |
| 82 | Callable const& callable); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 83 | void AbortIfArgCountMismatch(int expected, compiler::Node* actual); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 84 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 85 | #define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \ |
| 86 | compiler::Node* name(compiler::Node* input, compiler::Node* arg_count, \ |
| 87 | compiler::Node* context); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 88 | INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER) |
| 89 | #undef DECLARE_INTRINSIC_HELPER |
| 90 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 91 | Isolate* isolate() { return isolate_; } |
| 92 | Zone* zone() { return zone_; } |
| 93 | |
| 94 | Isolate* isolate_; |
| 95 | Zone* zone_; |
| 96 | InterpreterAssembler* assembler_; |
| 97 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 98 | DISALLOW_COPY_AND_ASSIGN(IntrinsicsHelper); |
| 99 | }; |
| 100 | |
| 101 | } // namespace interpreter |
| 102 | } // namespace internal |
| 103 | } // namespace v8 |
| 104 | |
| 105 | #endif |