Line data Source code
1 : // Copyright 2017 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_BUILTINS_BUILTINS_ARRAY_GEN_H_
6 : #define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
7 :
8 : #include "src/code-stub-assembler.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 :
13 7504 : class ArrayBuiltinsAssembler : public CodeStubAssembler {
14 : public:
15 : explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state);
16 :
17 : typedef std::function<void(ArrayBuiltinsAssembler* masm)>
18 : BuiltinResultGenerator;
19 :
20 : typedef std::function<Node*(ArrayBuiltinsAssembler* masm, Node* k_value,
21 : Node* k)>
22 : CallResultProcessor;
23 :
24 : typedef std::function<void(ArrayBuiltinsAssembler* masm)> PostLoopAction;
25 :
26 : enum class MissingPropertyMode { kSkip, kUseUndefined };
27 :
28 : void FindResultGenerator();
29 :
30 : Node* FindProcessor(Node* k_value, Node* k);
31 :
32 : void FindIndexResultGenerator();
33 :
34 : Node* FindIndexProcessor(Node* k_value, Node* k);
35 :
36 : void ForEachResultGenerator();
37 :
38 : Node* ForEachProcessor(Node* k_value, Node* k);
39 :
40 : void SomeResultGenerator();
41 :
42 : Node* SomeProcessor(Node* k_value, Node* k);
43 :
44 : void EveryResultGenerator();
45 :
46 : Node* EveryProcessor(Node* k_value, Node* k);
47 :
48 : void ReduceResultGenerator();
49 :
50 : Node* ReduceProcessor(Node* k_value, Node* k);
51 :
52 : void ReducePostLoopAction();
53 :
54 : void FilterResultGenerator();
55 :
56 : Node* FilterProcessor(Node* k_value, Node* k);
57 :
58 : void MapResultGenerator();
59 :
60 : void TypedArrayMapResultGenerator();
61 :
62 : Node* SpecCompliantMapProcessor(Node* k_value, Node* k);
63 :
64 : Node* FastMapProcessor(Node* k_value, Node* k);
65 :
66 : // See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map.
67 : Node* TypedArrayMapProcessor(Node* k_value, Node* k);
68 :
69 : void NullPostLoopAction();
70 :
71 : // Uses memset to effectively initialize the given FixedArray with Smi zeroes.
72 : void FillFixedArrayWithSmiZero(TNode<FixedArray> array,
73 : TNode<Smi> smi_length);
74 :
75 224 : TNode<String> CallJSArrayArrayJoinConcatToSequentialString(
76 : TNode<FixedArray> fixed_array, TNode<IntPtrT> length, TNode<String> sep,
77 : TNode<String> dest) {
78 : TNode<ExternalReference> func = ExternalConstant(
79 224 : ExternalReference::jsarray_array_join_concat_to_sequential_string());
80 : TNode<ExternalReference> isolate_ptr =
81 224 : ExternalConstant(ExternalReference::isolate_address(isolate()));
82 : return UncheckedCast<String>(
83 : CallCFunction5(MachineType::AnyTagged(), // <return> String
84 : MachineType::Pointer(), // Isolate*
85 : MachineType::AnyTagged(), // FixedArray fixed_array
86 : MachineType::IntPtr(), // intptr_t length
87 : MachineType::AnyTagged(), // String sep
88 : MachineType::AnyTagged(), // String dest
89 224 : func, isolate_ptr, fixed_array, length, sep, dest));
90 : }
91 :
92 : protected:
93 : TNode<Context> context() { return context_; }
94 : TNode<Object> receiver() { return receiver_; }
95 : TNode<IntPtrT> argc() { return argc_; }
96 : TNode<JSReceiver> o() { return o_; }
97 : TNode<Number> len() { return len_; }
98 : Node* callbackfn() { return callbackfn_; }
99 : Node* this_arg() { return this_arg_; }
100 2632 : TNode<Number> k() { return CAST(k_.value()); }
101 11312 : Node* a() { return a_.value(); }
102 :
103 : void ReturnFromBuiltin(Node* value);
104 :
105 : void InitIteratingArrayBuiltinBody(TNode<Context> context,
106 : TNode<Object> receiver, Node* callbackfn,
107 : Node* this_arg, TNode<IntPtrT> argc);
108 :
109 : void GenerateIteratingArrayBuiltinBody(
110 : const char* name, const BuiltinResultGenerator& generator,
111 : const CallResultProcessor& processor, const PostLoopAction& action,
112 : const Callable& slow_case_continuation,
113 : MissingPropertyMode missing_property_mode,
114 : ForEachDirection direction = ForEachDirection::kForward);
115 : void InitIteratingArrayBuiltinLoopContinuation(
116 : TNode<Context> context, TNode<Object> receiver, Node* callbackfn,
117 : Node* this_arg, Node* a, TNode<JSReceiver> o, Node* initial_k,
118 : TNode<Number> len, Node* to);
119 :
120 : void GenerateIteratingTypedArrayBuiltinBody(
121 : const char* name, const BuiltinResultGenerator& generator,
122 : const CallResultProcessor& processor, const PostLoopAction& action,
123 : ForEachDirection direction = ForEachDirection::kForward);
124 :
125 : void GenerateIteratingArrayBuiltinLoopContinuation(
126 : const CallResultProcessor& processor, const PostLoopAction& action,
127 : MissingPropertyMode missing_property_mode,
128 : ForEachDirection direction = ForEachDirection::kForward);
129 :
130 : void TailCallArrayConstructorStub(
131 : const Callable& callable, TNode<Context> context,
132 : TNode<JSFunction> target, TNode<HeapObject> allocation_site_or_undefined,
133 : TNode<Int32T> argc);
134 :
135 : void GenerateDispatchToArrayStub(
136 : TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
137 : AllocationSiteOverrideMode mode,
138 : TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
139 :
140 : void CreateArrayDispatchNoArgument(
141 : TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
142 : AllocationSiteOverrideMode mode,
143 : TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
144 :
145 : void CreateArrayDispatchSingleArgument(
146 : TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
147 : AllocationSiteOverrideMode mode,
148 : TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
149 :
150 : void GenerateConstructor(Node* context, Node* array_function, Node* array_map,
151 : Node* array_size, Node* allocation_site,
152 : ElementsKind elements_kind, AllocationSiteMode mode);
153 : void GenerateArrayNoArgumentConstructor(ElementsKind kind,
154 : AllocationSiteOverrideMode mode);
155 : void GenerateArraySingleArgumentConstructor(ElementsKind kind,
156 : AllocationSiteOverrideMode mode);
157 : void GenerateArrayNArgumentsConstructor(
158 : TNode<Context> context, TNode<JSFunction> target,
159 : TNode<Object> new_target, TNode<Int32T> argc,
160 : TNode<HeapObject> maybe_allocation_site);
161 :
162 : private:
163 : static ElementsKind ElementsKindForInstanceType(InstanceType type);
164 :
165 : void VisitAllTypedArrayElements(Node* array_buffer,
166 : const CallResultProcessor& processor,
167 : Label* detached, ForEachDirection direction,
168 : TNode<JSTypedArray> typed_array);
169 :
170 : void VisitAllFastElementsOneKind(ElementsKind kind,
171 : const CallResultProcessor& processor,
172 : Label* array_changed, ParameterMode mode,
173 : ForEachDirection direction,
174 : MissingPropertyMode missing_property_mode,
175 : TNode<Smi> length);
176 :
177 : void HandleFastElements(const CallResultProcessor& processor,
178 : const PostLoopAction& action, Label* slow,
179 : ForEachDirection direction,
180 : MissingPropertyMode missing_property_mode);
181 :
182 : // Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
183 : // This version is specialized to create a zero length array
184 : // of the elements kind of the input array.
185 : void GenerateArraySpeciesCreate();
186 :
187 : // Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
188 : void GenerateArraySpeciesCreate(TNode<Number> len);
189 :
190 : Node* callbackfn_ = nullptr;
191 : TNode<JSReceiver> o_;
192 : Node* this_arg_ = nullptr;
193 : TNode<Number> len_;
194 : TNode<Context> context_;
195 : TNode<Object> receiver_;
196 : TNode<IntPtrT> argc_;
197 : Node* fast_typed_array_target_ = nullptr;
198 : const char* name_ = nullptr;
199 : Variable k_;
200 : Variable a_;
201 : Variable to_;
202 : Label fully_spec_compliant_;
203 : ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS;
204 : };
205 :
206 : } // namespace internal
207 : } // namespace v8
208 :
209 : #endif // V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
|