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

Side by Side Diff: src/compiler/wasm-linkage.cc

Issue 2202433003: [wasm] Use a LazyInstance in wasm-linkage.cc to avoid a data race. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months 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/compiler/c-linkage.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/assembler.h" 5 #include "src/assembler.h"
6 #include "src/base/lazy-instance.h"
6 #include "src/macro-assembler.h" 7 #include "src/macro-assembler.h"
7 #include "src/register-configuration.h" 8 #include "src/register-configuration.h"
8 9
9 #include "src/wasm/wasm-module.h" 10 #include "src/wasm/wasm-module.h"
10 11
11 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
12 13
13 #include "src/zone.h" 14 #include "src/zone.h"
14 15
15 namespace v8 { 16 namespace v8 {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 200 }
200 int Words(LocalType type) { 201 int Words(LocalType type) {
201 if (kPointerSize < 8 && (type == kAstI64 || type == kAstF64)) { 202 if (kPointerSize < 8 && (type == kAstI64 || type == kAstF64)) {
202 return 2; 203 return 2;
203 } 204 }
204 return 1; 205 return 1;
205 } 206 }
206 }; 207 };
207 } // namespace 208 } // namespace
208 209
209 static Allocator GetReturnRegisters() { 210 struct ParameterRegistersCreateTrait {
211 static void Construct(Allocator* allocated_ptr) {
212 #ifdef GP_PARAM_REGISTERS
213 static const Register kGPParamRegisters[] = {GP_PARAM_REGISTERS};
214 static const int kGPParamRegistersCount =
215 static_cast<int>(arraysize(kGPParamRegisters));
216 #else
217 static const Register* kGPParamRegisters = nullptr;
218 static const int kGPParamRegistersCount = 0;
219 #endif
220
221 #ifdef FP_PARAM_REGISTERS
222 static const DoubleRegister kFPParamRegisters[] = {FP_PARAM_REGISTERS};
223 static const int kFPParamRegistersCount =
224 static_cast<int>(arraysize(kFPParamRegisters));
225 #else
226 static const DoubleRegister* kFPParamRegisters = nullptr;
227 static const int kFPParamRegistersCount = 0;
228 #endif
229
230 new (allocated_ptr) Allocator(kGPParamRegisters, kGPParamRegistersCount,
231 kFPParamRegisters, kFPParamRegistersCount);
232 }
233 };
234
235 static base::LazyInstance<Allocator, ParameterRegistersCreateTrait>::type
236 parameter_registers = LAZY_INSTANCE_INITIALIZER;
237
238 struct ReturnRegistersCreateTrait {
239 static void Construct(Allocator* allocated_ptr) {
210 #ifdef GP_RETURN_REGISTERS 240 #ifdef GP_RETURN_REGISTERS
211 static const Register kGPReturnRegisters[] = {GP_RETURN_REGISTERS}; 241 static const Register kGPReturnRegisters[] = {GP_RETURN_REGISTERS};
212 static const int kGPReturnRegistersCount = 242 static const int kGPReturnRegistersCount =
213 static_cast<int>(arraysize(kGPReturnRegisters)); 243 static_cast<int>(arraysize(kGPReturnRegisters));
214 #else 244 #else
215 static const Register* kGPReturnRegisters = nullptr; 245 static const Register* kGPReturnRegisters = nullptr;
216 static const int kGPReturnRegistersCount = 0; 246 static const int kGPReturnRegistersCount = 0;
217 #endif 247 #endif
218 248
219 #ifdef FP_RETURN_REGISTERS 249 #ifdef FP_RETURN_REGISTERS
220 static const DoubleRegister kFPReturnRegisters[] = {FP_RETURN_REGISTERS}; 250 static const DoubleRegister kFPReturnRegisters[] = {FP_RETURN_REGISTERS};
221 static const int kFPReturnRegistersCount = 251 static const int kFPReturnRegistersCount =
222 static_cast<int>(arraysize(kFPReturnRegisters)); 252 static_cast<int>(arraysize(kFPReturnRegisters));
223 #else 253 #else
224 static const DoubleRegister* kFPReturnRegisters = nullptr; 254 static const DoubleRegister* kFPReturnRegisters = nullptr;
225 static const int kFPReturnRegistersCount = 0; 255 static const int kFPReturnRegistersCount = 0;
226 #endif 256 #endif
227 257
228 Allocator rets(kGPReturnRegisters, kGPReturnRegistersCount, 258 new (allocated_ptr) Allocator(kGPReturnRegisters, kGPReturnRegistersCount,
229 kFPReturnRegisters, kFPReturnRegistersCount); 259 kFPReturnRegisters, kFPReturnRegistersCount);
260 }
261 };
230 262
231 return rets; 263 static base::LazyInstance<Allocator, ReturnRegistersCreateTrait>::type
232 } 264 return_registers = LAZY_INSTANCE_INITIALIZER;
233
234 static Allocator GetParameterRegisters() {
235 #ifdef GP_PARAM_REGISTERS
236 static const Register kGPParamRegisters[] = {GP_PARAM_REGISTERS};
237 static const int kGPParamRegistersCount =
238 static_cast<int>(arraysize(kGPParamRegisters));
239 #else
240 static const Register* kGPParamRegisters = nullptr;
241 static const int kGPParamRegistersCount = 0;
242 #endif
243
244 #ifdef FP_PARAM_REGISTERS
245 static const DoubleRegister kFPParamRegisters[] = {FP_PARAM_REGISTERS};
246 static const int kFPParamRegistersCount =
247 static_cast<int>(arraysize(kFPParamRegisters));
248 #else
249 static const DoubleRegister* kFPParamRegisters = nullptr;
250 static const int kFPParamRegistersCount = 0;
251 #endif
252
253 Allocator params(kGPParamRegisters, kGPParamRegistersCount, kFPParamRegisters,
254 kFPParamRegistersCount);
255
256 return params;
257 }
258 265
259 // General code uses the above configuration data. 266 // General code uses the above configuration data.
260 CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone, 267 CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
261 FunctionSig* fsig) { 268 FunctionSig* fsig) {
262 LocationSignature::Builder locations(zone, fsig->return_count(), 269 LocationSignature::Builder locations(zone, fsig->return_count(),
263 fsig->parameter_count()); 270 fsig->parameter_count());
264 271
265 Allocator rets = GetReturnRegisters(); 272 Allocator rets = return_registers.Get();
266 273
267 // Add return location(s). 274 // Add return location(s).
268 const int return_count = static_cast<int>(locations.return_count_); 275 const int return_count = static_cast<int>(locations.return_count_);
269 for (int i = 0; i < return_count; i++) { 276 for (int i = 0; i < return_count; i++) {
270 LocalType ret = fsig->GetReturn(i); 277 LocalType ret = fsig->GetReturn(i);
271 locations.AddReturn(rets.Next(ret)); 278 locations.AddReturn(rets.Next(ret));
272 } 279 }
273 280
274 Allocator params = GetParameterRegisters(); 281 Allocator params = parameter_registers.Get();
275 282
276 // Add register and/or stack parameter(s). 283 // Add register and/or stack parameter(s).
277 const int parameter_count = static_cast<int>(fsig->parameter_count()); 284 const int parameter_count = static_cast<int>(fsig->parameter_count());
278 for (int i = 0; i < parameter_count; i++) { 285 for (int i = 0; i < parameter_count; i++) {
279 LocalType param = fsig->GetParam(i); 286 LocalType param = fsig->GetParam(i);
280 locations.AddParam(params.Next(param)); 287 locations.AddParam(params.Next(param));
281 } 288 }
282 289
283 const RegList kCalleeSaveRegisters = 0; 290 const RegList kCalleeSaveRegisters = 0;
284 const RegList kCalleeSaveFPRegisters = 0; 291 const RegList kCalleeSaveFPRegisters = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 325 }
319 if (parameter_count == descriptor->ParameterCount() && 326 if (parameter_count == descriptor->ParameterCount() &&
320 return_count == descriptor->ReturnCount()) { 327 return_count == descriptor->ReturnCount()) {
321 // If there is no int64 parameter or return value, we can just return the 328 // If there is no int64 parameter or return value, we can just return the
322 // original descriptor. 329 // original descriptor.
323 return descriptor; 330 return descriptor;
324 } 331 }
325 332
326 LocationSignature::Builder locations(zone, return_count, parameter_count); 333 LocationSignature::Builder locations(zone, return_count, parameter_count);
327 334
328 Allocator rets = GetReturnRegisters(); 335 Allocator rets = return_registers.Get();
329 336
330 for (size_t i = 0; i < descriptor->ReturnCount(); i++) { 337 for (size_t i = 0; i < descriptor->ReturnCount(); i++) {
331 if (descriptor->GetReturnType(i) == MachineType::Int64()) { 338 if (descriptor->GetReturnType(i) == MachineType::Int64()) {
332 // For each int64 return we get two int32 returns. 339 // For each int64 return we get two int32 returns.
333 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); 340 locations.AddReturn(rets.Next(MachineRepresentation::kWord32));
334 locations.AddReturn(rets.Next(MachineRepresentation::kWord32)); 341 locations.AddReturn(rets.Next(MachineRepresentation::kWord32));
335 } else { 342 } else {
336 locations.AddReturn( 343 locations.AddReturn(
337 rets.Next(descriptor->GetReturnType(i).representation())); 344 rets.Next(descriptor->GetReturnType(i).representation()));
338 } 345 }
339 } 346 }
340 347
341 Allocator params = GetParameterRegisters(); 348 Allocator params = parameter_registers.Get();
342 349
343 for (size_t i = 0; i < descriptor->ParameterCount(); i++) { 350 for (size_t i = 0; i < descriptor->ParameterCount(); i++) {
344 if (descriptor->GetParameterType(i) == MachineType::Int64()) { 351 if (descriptor->GetParameterType(i) == MachineType::Int64()) {
345 // For each int64 input we get two int32 inputs. 352 // For each int64 input we get two int32 inputs.
346 locations.AddParam(params.Next(MachineRepresentation::kWord32)); 353 locations.AddParam(params.Next(MachineRepresentation::kWord32));
347 locations.AddParam(params.Next(MachineRepresentation::kWord32)); 354 locations.AddParam(params.Next(MachineRepresentation::kWord32));
348 } else { 355 } else {
349 locations.AddParam( 356 locations.AddParam(
350 params.Next(descriptor->GetParameterType(i).representation())); 357 params.Next(descriptor->GetParameterType(i).representation()));
351 } 358 }
(...skipping 10 matching lines...) Expand all
362 descriptor->CalleeSavedFPRegisters(), // callee-saved fp regs 369 descriptor->CalleeSavedFPRegisters(), // callee-saved fp regs
363 descriptor->flags(), // flags 370 descriptor->flags(), // flags
364 descriptor->debug_name()); 371 descriptor->debug_name());
365 372
366 return descriptor; 373 return descriptor;
367 } 374 }
368 375
369 } // namespace wasm 376 } // namespace wasm
370 } // namespace internal 377 } // namespace internal
371 } // namespace v8 378 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/c-linkage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698