Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: src/builtins/builtins-sharedarraybuffer.cc

Issue 2502293002: Reland of [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: fix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-regexp.cc ('k') | src/builtins/builtins-string.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 return array_buffer->byte_length(); 25 return array_buffer->byte_length();
26 } 26 }
27 27
28 namespace { 28 namespace {
29 29
30 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, 30 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged,
31 compiler::Node* context, 31 compiler::Node* context,
32 compiler::Node** out_instance_type, 32 compiler::Node** out_instance_type,
33 compiler::Node** out_backing_store) { 33 compiler::Node** out_backing_store) {
34 using namespace compiler; 34 using compiler::Node;
35 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a), 35 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a),
36 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a), 36 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a),
37 not_float_or_clamped(a), invalid(a); 37 not_float_or_clamped(a), invalid(a);
38 38
39 // Fail if it is not a heap object. 39 // Fail if it is not a heap object.
40 a->Branch(a->TaggedIsSmi(tagged), &is_smi, &not_smi); 40 a->Branch(a->TaggedIsSmi(tagged), &is_smi, &not_smi);
41 a->Bind(&is_smi); 41 a->Bind(&is_smi);
42 a->Goto(&invalid); 42 a->Goto(&invalid);
43 43
44 // Fail if the array's instance type is not JSTypedArray. 44 // Fail if the array's instance type is not JSTypedArray.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 Node* byte_offset = a->ChangeUint32ToWord(a->TruncateTaggedToWord32( 88 Node* byte_offset = a->ChangeUint32ToWord(a->TruncateTaggedToWord32(
89 context, 89 context,
90 a->LoadObjectField(tagged, JSArrayBufferView::kByteOffsetOffset))); 90 a->LoadObjectField(tagged, JSArrayBufferView::kByteOffsetOffset)));
91 *out_backing_store = a->IntPtrAdd(backing_store, byte_offset); 91 *out_backing_store = a->IntPtrAdd(backing_store, byte_offset);
92 } 92 }
93 93
94 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access 94 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access
95 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a, 95 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a,
96 compiler::Node* tagged, 96 compiler::Node* tagged,
97 compiler::Node* context) { 97 compiler::Node* context) {
98 using namespace compiler; 98 using compiler::Node;
99 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); 99 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32);
100 100
101 Callable to_number = CodeFactory::ToNumber(a->isolate()); 101 Callable to_number = CodeFactory::ToNumber(a->isolate());
102 Node* number_index = a->CallStub(to_number, context, tagged); 102 Node* number_index = a->CallStub(to_number, context, tagged);
103 CodeStubAssembler::Label done(a, &var_result); 103 CodeStubAssembler::Label done(a, &var_result);
104 104
105 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a); 105 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a);
106 a->Branch(a->TaggedIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi); 106 a->Branch(a->TaggedIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi);
107 107
108 a->Bind(&if_numberissmi); 108 a->Bind(&if_numberissmi);
(...skipping 23 matching lines...) Expand all
132 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); 132 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
133 } 133 }
134 134
135 a->Bind(&done); 135 a->Bind(&done);
136 return var_result.value(); 136 return var_result.value();
137 } 137 }
138 138
139 void ValidateAtomicIndex(CodeStubAssembler* a, compiler::Node* index_word, 139 void ValidateAtomicIndex(CodeStubAssembler* a, compiler::Node* index_word,
140 compiler::Node* array_length_word, 140 compiler::Node* array_length_word,
141 compiler::Node* context) { 141 compiler::Node* context) {
142 using namespace compiler; 142 using compiler::Node;
143 // Check if the index is in bounds. If not, throw RangeError. 143 // Check if the index is in bounds. If not, throw RangeError.
144 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a); 144 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a);
145 // TODO(jkummerow): Use unsigned comparison instead of "i<0 || i>length". 145 // TODO(jkummerow): Use unsigned comparison instead of "i<0 || i>length".
146 a->Branch( 146 a->Branch(
147 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)), 147 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)),
148 a->Int32GreaterThanOrEqual(index_word, array_length_word)), 148 a->Int32GreaterThanOrEqual(index_word, array_length_word)),
149 &if_notinbounds, &if_inbounds); 149 &if_notinbounds, &if_inbounds);
150 a->Bind(&if_notinbounds); 150 a->Bind(&if_notinbounds);
151 a->Return( 151 a->Return(
152 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); 152 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
153 a->Bind(&if_inbounds); 153 a->Bind(&if_inbounds);
154 } 154 }
155 155
156 } // anonymous namespace 156 } // anonymous namespace
157 157
158 void Builtins::Generate_AtomicsLoad(CodeStubAssembler* a) { 158 void Builtins::Generate_AtomicsLoad(compiler::CodeAssemblerState* state) {
159 using namespace compiler; 159 using compiler::Node;
160 Node* array = a->Parameter(1); 160 CodeStubAssembler a(state);
161 Node* index = a->Parameter(2); 161 Node* array = a.Parameter(1);
162 Node* context = a->Parameter(3 + 2); 162 Node* index = a.Parameter(2);
163 Node* context = a.Parameter(3 + 2);
163 164
164 Node* instance_type; 165 Node* instance_type;
165 Node* backing_store; 166 Node* backing_store;
166 ValidateSharedTypedArray(a, array, context, &instance_type, &backing_store); 167 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store);
167 168
168 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(a, index, context); 169 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context);
169 Node* array_length_word32 = a->TruncateTaggedToWord32( 170 Node* array_length_word32 = a.TruncateTaggedToWord32(
170 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset)); 171 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset));
171 ValidateAtomicIndex(a, index_word32, array_length_word32, context); 172 ValidateAtomicIndex(&a, index_word32, array_length_word32, context);
172 Node* index_word = a->ChangeUint32ToWord(index_word32); 173 Node* index_word = a.ChangeUint32ToWord(index_word32);
173 174
174 CodeStubAssembler::Label i8(a), u8(a), i16(a), u16(a), i32(a), u32(a), 175 CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a),
175 other(a); 176 other(&a);
176 int32_t case_values[] = { 177 int32_t case_values[] = {
177 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, 178 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE,
178 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, 179 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE,
179 }; 180 };
180 CodeStubAssembler::Label* case_labels[] = { 181 CodeStubAssembler::Label* case_labels[] = {
181 &i8, &u8, &i16, &u16, &i32, &u32, 182 &i8, &u8, &i16, &u16, &i32, &u32,
182 }; 183 };
183 a->Switch(instance_type, &other, case_values, case_labels, 184 a.Switch(instance_type, &other, case_values, case_labels,
184 arraysize(case_labels)); 185 arraysize(case_labels));
185 186
186 a->Bind(&i8); 187 a.Bind(&i8);
187 a->Return( 188 a.Return(
188 a->SmiTag(a->AtomicLoad(MachineType::Int8(), backing_store, index_word))); 189 a.SmiTag(a.AtomicLoad(MachineType::Int8(), backing_store, index_word)));
189 190
190 a->Bind(&u8); 191 a.Bind(&u8);
191 a->Return(a->SmiTag( 192 a.Return(
192 a->AtomicLoad(MachineType::Uint8(), backing_store, index_word))); 193 a.SmiTag(a.AtomicLoad(MachineType::Uint8(), backing_store, index_word)));
193 194
194 a->Bind(&i16); 195 a.Bind(&i16);
195 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Int16(), backing_store, 196 a.Return(a.SmiTag(a.AtomicLoad(MachineType::Int16(), backing_store,
196 a->WordShl(index_word, 1)))); 197 a.WordShl(index_word, 1))));
197 198
198 a->Bind(&u16); 199 a.Bind(&u16);
199 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Uint16(), backing_store, 200 a.Return(a.SmiTag(a.AtomicLoad(MachineType::Uint16(), backing_store,
200 a->WordShl(index_word, 1)))); 201 a.WordShl(index_word, 1))));
201 202
202 a->Bind(&i32); 203 a.Bind(&i32);
203 a->Return(a->ChangeInt32ToTagged(a->AtomicLoad( 204 a.Return(a.ChangeInt32ToTagged(a.AtomicLoad(
204 MachineType::Int32(), backing_store, a->WordShl(index_word, 2)))); 205 MachineType::Int32(), backing_store, a.WordShl(index_word, 2))));
205 206
206 a->Bind(&u32); 207 a.Bind(&u32);
207 a->Return(a->ChangeUint32ToTagged(a->AtomicLoad( 208 a.Return(a.ChangeUint32ToTagged(a.AtomicLoad(
208 MachineType::Uint32(), backing_store, a->WordShl(index_word, 2)))); 209 MachineType::Uint32(), backing_store, a.WordShl(index_word, 2))));
209 210
210 // This shouldn't happen, we've already validated the type. 211 // This shouldn't happen, we've already validated the type.
211 a->Bind(&other); 212 a.Bind(&other);
212 a->Return(a->Int32Constant(0)); 213 a.Return(a.Int32Constant(0));
213 } 214 }
214 215
215 void Builtins::Generate_AtomicsStore(CodeStubAssembler* a) { 216 void Builtins::Generate_AtomicsStore(compiler::CodeAssemblerState* state) {
216 using namespace compiler; 217 using compiler::Node;
217 Node* array = a->Parameter(1); 218 CodeStubAssembler a(state);
218 Node* index = a->Parameter(2); 219 Node* array = a.Parameter(1);
219 Node* value = a->Parameter(3); 220 Node* index = a.Parameter(2);
220 Node* context = a->Parameter(4 + 2); 221 Node* value = a.Parameter(3);
222 Node* context = a.Parameter(4 + 2);
221 223
222 Node* instance_type; 224 Node* instance_type;
223 Node* backing_store; 225 Node* backing_store;
224 ValidateSharedTypedArray(a, array, context, &instance_type, &backing_store); 226 ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store);
225 227
226 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(a, index, context); 228 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context);
227 Node* array_length_word32 = a->TruncateTaggedToWord32( 229 Node* array_length_word32 = a.TruncateTaggedToWord32(
228 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset)); 230 context, a.LoadObjectField(array, JSTypedArray::kLengthOffset));
229 ValidateAtomicIndex(a, index_word32, array_length_word32, context); 231 ValidateAtomicIndex(&a, index_word32, array_length_word32, context);
230 Node* index_word = a->ChangeUint32ToWord(index_word32); 232 Node* index_word = a.ChangeUint32ToWord(index_word32);
231 233
232 Node* value_integer = a->ToInteger(context, value); 234 Node* value_integer = a.ToInteger(context, value);
233 Node* value_word32 = a->TruncateTaggedToWord32(context, value_integer); 235 Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer);
234 236
235 CodeStubAssembler::Label u8(a), u16(a), u32(a), other(a); 237 CodeStubAssembler::Label u8(&a), u16(&a), u32(&a), other(&a);
236 int32_t case_values[] = { 238 int32_t case_values[] = {
237 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, 239 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE,
238 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, 240 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE,
239 }; 241 };
240 CodeStubAssembler::Label* case_labels[] = { 242 CodeStubAssembler::Label* case_labels[] = {
241 &u8, &u8, &u16, &u16, &u32, &u32, 243 &u8, &u8, &u16, &u16, &u32, &u32,
242 }; 244 };
243 a->Switch(instance_type, &other, case_values, case_labels, 245 a.Switch(instance_type, &other, case_values, case_labels,
244 arraysize(case_labels)); 246 arraysize(case_labels));
245 247
246 a->Bind(&u8); 248 a.Bind(&u8);
247 a->AtomicStore(MachineRepresentation::kWord8, backing_store, index_word, 249 a.AtomicStore(MachineRepresentation::kWord8, backing_store, index_word,
248 value_word32); 250 value_word32);
249 a->Return(value_integer); 251 a.Return(value_integer);
250 252
251 a->Bind(&u16); 253 a.Bind(&u16);
252 a->AtomicStore(MachineRepresentation::kWord16, backing_store, 254 a.AtomicStore(MachineRepresentation::kWord16, backing_store,
253 a->WordShl(index_word, 1), value_word32); 255 a.WordShl(index_word, 1), value_word32);
254 a->Return(value_integer); 256 a.Return(value_integer);
255 257
256 a->Bind(&u32); 258 a.Bind(&u32);
257 a->AtomicStore(MachineRepresentation::kWord32, backing_store, 259 a.AtomicStore(MachineRepresentation::kWord32, backing_store,
258 a->WordShl(index_word, 2), value_word32); 260 a.WordShl(index_word, 2), value_word32);
259 a->Return(value_integer); 261 a.Return(value_integer);
260 262
261 // This shouldn't happen, we've already validated the type. 263 // This shouldn't happen, we've already validated the type.
262 a->Bind(&other); 264 a.Bind(&other);
263 a->Return(a->Int32Constant(0)); 265 a.Return(a.Int32Constant(0));
264 } 266 }
265 267
266 } // namespace internal 268 } // namespace internal
267 } // namespace v8 269 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-regexp.cc ('k') | src/builtins/builtins-string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698