OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/builtins/builtins-utils.h" | 5 #include "src/builtins/builtins-utils.h" |
6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/counters.h" | 8 #include "src/counters.h" |
9 #include "src/interface-descriptors.h" | 9 #include "src/interface-descriptors.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 masm->TailCallRuntime(Runtime::kInterrupt); | 49 masm->TailCallRuntime(Runtime::kInterrupt); |
50 } | 50 } |
51 | 51 |
52 void Builtins::Generate_StackCheck(MacroAssembler* masm) { | 52 void Builtins::Generate_StackCheck(MacroAssembler* masm) { |
53 masm->TailCallRuntime(Runtime::kStackGuard); | 53 masm->TailCallRuntime(Runtime::kStackGuard); |
54 } | 54 } |
55 | 55 |
56 // ----------------------------------------------------------------------------- | 56 // ----------------------------------------------------------------------------- |
57 // TurboFan support builtins. | 57 // TurboFan support builtins. |
58 | 58 |
59 void Builtins::Generate_CopyFastSmiOrObjectElements( | 59 TF_BUILTIN(CopyFastSmiOrObjectElements, CodeStubAssembler) { |
60 compiler::CodeAssemblerState* state) { | |
61 typedef CodeStubAssembler::Label Label; | |
62 typedef compiler::Node Node; | |
63 typedef CopyFastSmiOrObjectElementsDescriptor Descriptor; | 60 typedef CopyFastSmiOrObjectElementsDescriptor Descriptor; |
64 CodeStubAssembler assembler(state); | |
65 | 61 |
66 Node* object = assembler.Parameter(Descriptor::kObject); | 62 Node* object = Parameter(Descriptor::kObject); |
67 | 63 |
68 // Load the {object}s elements. | 64 // Load the {object}s elements. |
69 Node* source = assembler.LoadObjectField(object, JSObject::kElementsOffset); | 65 Node* source = LoadObjectField(object, JSObject::kElementsOffset); |
70 | 66 |
71 CodeStubAssembler::ParameterMode mode = assembler.OptimalParameterMode(); | 67 ParameterMode mode = OptimalParameterMode(); |
72 Node* length = assembler.TaggedToParameter( | 68 Node* length = TaggedToParameter(LoadFixedArrayBaseLength(source), mode); |
73 assembler.LoadFixedArrayBaseLength(source), mode); | |
74 | 69 |
75 // Check if we can allocate in new space. | 70 // Check if we can allocate in new space. |
76 ElementsKind kind = FAST_ELEMENTS; | 71 ElementsKind kind = FAST_ELEMENTS; |
77 int max_elements = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind); | 72 int max_elements = FixedArrayBase::GetMaxLengthForNewSpaceAllocation(kind); |
78 Label if_newspace(&assembler), if_oldspace(&assembler); | 73 Label if_newspace(this), if_oldspace(this); |
79 assembler.Branch( | 74 Branch(UintPtrOrSmiLessThan(length, IntPtrOrSmiConstant(max_elements, mode), |
80 assembler.UintPtrOrSmiLessThan( | 75 mode), |
81 length, assembler.IntPtrOrSmiConstant(max_elements, mode), mode), | 76 &if_newspace, &if_oldspace); |
82 &if_newspace, &if_oldspace); | |
83 | 77 |
84 assembler.Bind(&if_newspace); | 78 Bind(&if_newspace); |
85 { | 79 { |
86 Node* target = assembler.AllocateFixedArray(kind, length, mode); | 80 Node* target = AllocateFixedArray(kind, length, mode); |
87 assembler.CopyFixedArrayElements(kind, source, target, length, | 81 CopyFixedArrayElements(kind, source, target, length, SKIP_WRITE_BARRIER, |
88 SKIP_WRITE_BARRIER, mode); | 82 mode); |
89 assembler.StoreObjectField(object, JSObject::kElementsOffset, target); | 83 StoreObjectField(object, JSObject::kElementsOffset, target); |
90 assembler.Return(target); | 84 Return(target); |
91 } | 85 } |
92 | 86 |
93 assembler.Bind(&if_oldspace); | 87 Bind(&if_oldspace); |
94 { | 88 { |
95 Node* target = assembler.AllocateFixedArray(kind, length, mode, | 89 Node* target = AllocateFixedArray(kind, length, mode, kPretenured); |
96 CodeStubAssembler::kPretenured); | 90 CopyFixedArrayElements(kind, source, target, length, UPDATE_WRITE_BARRIER, |
97 assembler.CopyFixedArrayElements(kind, source, target, length, | 91 mode); |
98 UPDATE_WRITE_BARRIER, mode); | 92 StoreObjectField(object, JSObject::kElementsOffset, target); |
99 assembler.StoreObjectField(object, JSObject::kElementsOffset, target); | 93 Return(target); |
100 assembler.Return(target); | |
101 } | 94 } |
102 } | 95 } |
103 | 96 |
104 void Builtins::Generate_GrowFastDoubleElements( | 97 TF_BUILTIN(GrowFastDoubleElements, CodeStubAssembler) { |
105 compiler::CodeAssemblerState* state) { | |
106 typedef CodeStubAssembler::Label Label; | |
107 typedef compiler::Node Node; | |
108 typedef GrowArrayElementsDescriptor Descriptor; | 98 typedef GrowArrayElementsDescriptor Descriptor; |
109 CodeStubAssembler assembler(state); | |
110 | 99 |
111 Node* object = assembler.Parameter(Descriptor::kObject); | 100 Node* object = Parameter(Descriptor::kObject); |
112 Node* key = assembler.Parameter(Descriptor::kKey); | 101 Node* key = Parameter(Descriptor::kKey); |
113 Node* context = assembler.Parameter(Descriptor::kContext); | 102 Node* context = Parameter(Descriptor::kContext); |
114 | 103 |
115 Label runtime(&assembler, CodeStubAssembler::Label::kDeferred); | 104 Label runtime(this, Label::kDeferred); |
116 Node* elements = assembler.LoadElements(object); | 105 Node* elements = LoadElements(object); |
117 elements = assembler.TryGrowElementsCapacity( | 106 elements = TryGrowElementsCapacity(object, elements, FAST_DOUBLE_ELEMENTS, |
118 object, elements, FAST_DOUBLE_ELEMENTS, key, &runtime); | 107 key, &runtime); |
119 assembler.Return(elements); | 108 Return(elements); |
120 | 109 |
121 assembler.Bind(&runtime); | 110 Bind(&runtime); |
122 assembler.TailCallRuntime(Runtime::kGrowArrayElements, context, object, key); | 111 TailCallRuntime(Runtime::kGrowArrayElements, context, object, key); |
123 } | 112 } |
124 | 113 |
125 void Builtins::Generate_GrowFastSmiOrObjectElements( | 114 TF_BUILTIN(GrowFastSmiOrObjectElements, CodeStubAssembler) { |
126 compiler::CodeAssemblerState* state) { | |
127 typedef CodeStubAssembler::Label Label; | |
128 typedef compiler::Node Node; | |
129 typedef GrowArrayElementsDescriptor Descriptor; | 115 typedef GrowArrayElementsDescriptor Descriptor; |
130 CodeStubAssembler assembler(state); | |
131 | 116 |
132 Node* object = assembler.Parameter(Descriptor::kObject); | 117 Node* object = Parameter(Descriptor::kObject); |
133 Node* key = assembler.Parameter(Descriptor::kKey); | 118 Node* key = Parameter(Descriptor::kKey); |
134 Node* context = assembler.Parameter(Descriptor::kContext); | 119 Node* context = Parameter(Descriptor::kContext); |
135 | 120 |
136 Label runtime(&assembler, CodeStubAssembler::Label::kDeferred); | 121 Label runtime(this, Label::kDeferred); |
137 Node* elements = assembler.LoadElements(object); | 122 Node* elements = LoadElements(object); |
138 elements = assembler.TryGrowElementsCapacity(object, elements, FAST_ELEMENTS, | 123 elements = |
139 key, &runtime); | 124 TryGrowElementsCapacity(object, elements, FAST_ELEMENTS, key, &runtime); |
140 assembler.Return(elements); | 125 Return(elements); |
141 | 126 |
142 assembler.Bind(&runtime); | 127 Bind(&runtime); |
143 assembler.TailCallRuntime(Runtime::kGrowArrayElements, context, object, key); | 128 TailCallRuntime(Runtime::kGrowArrayElements, context, object, key); |
144 } | 129 } |
145 | 130 |
146 namespace { | 131 TF_BUILTIN(NewUnmappedArgumentsElements, CodeStubAssembler) { |
| 132 typedef NewArgumentsElementsDescriptor Descriptor; |
147 | 133 |
148 void Generate_NewArgumentsElements(CodeStubAssembler* assembler, | 134 Node* frame = Parameter(Descriptor::kFrame); |
149 compiler::Node* frame, | 135 Node* length = SmiToWord(Parameter(Descriptor::kLength)); |
150 compiler::Node* length) { | |
151 typedef CodeStubAssembler::Label Label; | |
152 typedef CodeStubAssembler::Variable Variable; | |
153 typedef compiler::Node Node; | |
154 | 136 |
155 // Check if we can allocate in new space. | 137 // Check if we can allocate in new space. |
156 ElementsKind kind = FAST_ELEMENTS; | 138 ElementsKind kind = FAST_ELEMENTS; |
157 int max_elements = FixedArray::GetMaxLengthForNewSpaceAllocation(kind); | 139 int max_elements = FixedArray::GetMaxLengthForNewSpaceAllocation(kind); |
158 Label if_newspace(assembler), if_oldspace(assembler, Label::kDeferred); | 140 Label if_newspace(this), if_oldspace(this, Label::kDeferred); |
159 assembler->Branch(assembler->IntPtrLessThan( | 141 Branch(IntPtrLessThan(length, IntPtrConstant(max_elements)), &if_newspace, |
160 length, assembler->IntPtrConstant(max_elements)), | 142 &if_oldspace); |
161 &if_newspace, &if_oldspace); | |
162 | 143 |
163 assembler->Bind(&if_newspace); | 144 Bind(&if_newspace); |
164 { | 145 { |
165 // Prefer EmptyFixedArray in case of non-positive {length} (the {length} | 146 // Prefer EmptyFixedArray in case of non-positive {length} (the {length} |
166 // can be negative here for rest parameters). | 147 // can be negative here for rest parameters). |
167 Label if_empty(assembler), if_notempty(assembler); | 148 Label if_empty(this), if_notempty(this); |
168 assembler->Branch( | 149 Branch(IntPtrLessThanOrEqual(length, IntPtrConstant(0)), &if_empty, |
169 assembler->IntPtrLessThanOrEqual(length, assembler->IntPtrConstant(0)), | 150 &if_notempty); |
170 &if_empty, &if_notempty); | |
171 | 151 |
172 assembler->Bind(&if_empty); | 152 Bind(&if_empty); |
173 assembler->Return(assembler->EmptyFixedArrayConstant()); | 153 Return(EmptyFixedArrayConstant()); |
174 | 154 |
175 assembler->Bind(&if_notempty); | 155 Bind(&if_notempty); |
176 { | 156 { |
177 // Allocate a FixedArray in new space. | 157 // Allocate a FixedArray in new space. |
178 Node* result = assembler->AllocateFixedArray(kind, length); | 158 Node* result = AllocateFixedArray(kind, length); |
179 | 159 |
180 // Compute the effective {offset} into the {frame}. | 160 // Compute the effective {offset} into the {frame}. |
181 Node* offset = assembler->IntPtrAdd(length, assembler->IntPtrConstant(1)); | 161 Node* offset = IntPtrAdd(length, IntPtrConstant(1)); |
182 | 162 |
183 // Copy the parameters from {frame} (starting at {offset}) to {result}. | 163 // Copy the parameters from {frame} (starting at {offset}) to {result}. |
184 Variable var_index(assembler, MachineType::PointerRepresentation()); | 164 Variable var_index(this, MachineType::PointerRepresentation()); |
185 Label loop(assembler, &var_index), done_loop(assembler); | 165 Label loop(this, &var_index), done_loop(this); |
186 var_index.Bind(assembler->IntPtrConstant(0)); | 166 var_index.Bind(IntPtrConstant(0)); |
187 assembler->Goto(&loop); | 167 Goto(&loop); |
188 assembler->Bind(&loop); | 168 Bind(&loop); |
189 { | 169 { |
190 // Load the current {index}. | 170 // Load the current {index}. |
191 Node* index = var_index.value(); | 171 Node* index = var_index.value(); |
192 | 172 |
193 // Check if we are done. | 173 // Check if we are done. |
194 assembler->GotoIf(assembler->WordEqual(index, length), &done_loop); | 174 GotoIf(WordEqual(index, length), &done_loop); |
195 | 175 |
196 // Load the parameter at the given {index}. | 176 // Load the parameter at the given {index}. |
197 Node* value = assembler->Load( | 177 Node* value = Load(MachineType::AnyTagged(), frame, |
198 MachineType::AnyTagged(), frame, | 178 WordShl(IntPtrSub(offset, index), |
199 assembler->WordShl(assembler->IntPtrSub(offset, index), | 179 IntPtrConstant(kPointerSizeLog2))); |
200 assembler->IntPtrConstant(kPointerSizeLog2))); | |
201 | 180 |
202 // Store the {value} into the {result}. | 181 // Store the {value} into the {result}. |
203 assembler->StoreFixedArrayElement(result, index, value, | 182 StoreFixedArrayElement(result, index, value, SKIP_WRITE_BARRIER); |
204 SKIP_WRITE_BARRIER); | |
205 | 183 |
206 // Continue with next {index}. | 184 // Continue with next {index}. |
207 var_index.Bind( | 185 var_index.Bind(IntPtrAdd(index, IntPtrConstant(1))); |
208 assembler->IntPtrAdd(index, assembler->IntPtrConstant(1))); | 186 Goto(&loop); |
209 assembler->Goto(&loop); | |
210 } | 187 } |
211 | 188 |
212 assembler->Bind(&done_loop); | 189 Bind(&done_loop); |
213 assembler->Return(result); | 190 Return(result); |
214 } | 191 } |
215 } | 192 } |
216 | 193 |
217 assembler->Bind(&if_oldspace); | 194 Bind(&if_oldspace); |
218 { | 195 { |
219 // Allocate in old space (or large object space). | 196 // Allocate in old space (or large object space). |
220 assembler->TailCallRuntime( | 197 TailCallRuntime(Runtime::kNewArgumentsElements, NoContextConstant(), |
221 Runtime::kNewArgumentsElements, assembler->NoContextConstant(), | 198 BitcastWordToTagged(frame), SmiFromWord(length)); |
222 assembler->BitcastWordToTagged(frame), assembler->SmiFromWord(length)); | |
223 } | 199 } |
224 } | 200 } |
225 | 201 |
226 } // namespace | 202 TF_BUILTIN(ReturnReceiver, CodeStubAssembler) { Return(Parameter(0)); } |
227 | |
228 void Builtins::Generate_NewUnmappedArgumentsElements( | |
229 compiler::CodeAssemblerState* state) { | |
230 typedef compiler::Node Node; | |
231 typedef NewArgumentsElementsDescriptor Descriptor; | |
232 CodeStubAssembler assembler(state); | |
233 | |
234 Node* frame = assembler.Parameter(Descriptor::kFrame); | |
235 Node* length = assembler.Parameter(Descriptor::kLength); | |
236 Generate_NewArgumentsElements(&assembler, frame, assembler.SmiToWord(length)); | |
237 } | |
238 | |
239 void Builtins::Generate_ReturnReceiver(compiler::CodeAssemblerState* state) { | |
240 CodeStubAssembler assembler(state); | |
241 assembler.Return(assembler.Parameter(0)); | |
242 } | |
243 | 203 |
244 } // namespace internal | 204 } // namespace internal |
245 } // namespace v8 | 205 } // namespace v8 |
OLD | NEW |