OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/js-operator.h" | 5 #include "src/compiler/js-operator.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/lazy-instance.h" | 9 #include "src/base/lazy-instance.h" |
10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 V(ForInPrepare, Operator::kNoProperties, 1, 3) \ | 327 V(ForInPrepare, Operator::kNoProperties, 1, 3) \ |
328 V(ForInStep, Operator::kPure, 1, 1) \ | 328 V(ForInStep, Operator::kPure, 1, 1) \ |
329 V(StackCheck, Operator::kNoProperties, 0, 0) \ | 329 V(StackCheck, Operator::kNoProperties, 0, 0) \ |
330 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \ | 330 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \ |
331 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ | 331 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ |
332 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \ | 332 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \ |
333 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \ | 333 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \ |
334 V(CreateScriptContext, Operator::kNoProperties, 2, 1) | 334 V(CreateScriptContext, Operator::kNoProperties, 2, 1) |
335 | 335 |
336 | 336 |
337 #define CACHED_OP_LIST_WITH_LANGUAGE_MODE(V) \ | 337 #define CACHED_OP_LIST_WITH_STRENGTH(V) \ |
338 V(LessThan, Operator::kNoProperties, 2, 1) \ | 338 V(LessThan, Operator::kNoProperties, 2, 1) \ |
339 V(GreaterThan, Operator::kNoProperties, 2, 1) \ | 339 V(GreaterThan, Operator::kNoProperties, 2, 1) \ |
340 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \ | 340 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
341 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \ | 341 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \ |
342 V(BitwiseOr, Operator::kNoProperties, 2, 1) \ | 342 V(BitwiseOr, Operator::kNoProperties, 2, 1) \ |
343 V(BitwiseXor, Operator::kNoProperties, 2, 1) \ | 343 V(BitwiseXor, Operator::kNoProperties, 2, 1) \ |
344 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \ | 344 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \ |
345 V(ShiftLeft, Operator::kNoProperties, 2, 1) \ | 345 V(ShiftLeft, Operator::kNoProperties, 2, 1) \ |
346 V(ShiftRight, Operator::kNoProperties, 2, 1) \ | 346 V(ShiftRight, Operator::kNoProperties, 2, 1) \ |
347 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \ | 347 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \ |
348 V(Add, Operator::kNoProperties, 2, 1) \ | 348 V(Add, Operator::kNoProperties, 2, 1) \ |
349 V(Subtract, Operator::kNoProperties, 2, 1) \ | 349 V(Subtract, Operator::kNoProperties, 2, 1) \ |
350 V(Multiply, Operator::kNoProperties, 2, 1) \ | 350 V(Multiply, Operator::kNoProperties, 2, 1) \ |
351 V(Divide, Operator::kNoProperties, 2, 1) \ | 351 V(Divide, Operator::kNoProperties, 2, 1) \ |
352 V(Modulus, Operator::kNoProperties, 2, 1) \ | 352 V(Modulus, Operator::kNoProperties, 2, 1) |
353 V(StoreProperty, Operator::kNoProperties, 3, 0) | |
354 | 353 |
355 | 354 |
356 struct JSOperatorGlobalCache final { | 355 struct JSOperatorGlobalCache final { |
357 #define CACHED(Name, properties, value_input_count, value_output_count) \ | 356 #define CACHED(Name, properties, value_input_count, value_output_count) \ |
358 struct Name##Operator final : public Operator { \ | 357 struct Name##Operator final : public Operator { \ |
359 Name##Operator() \ | 358 Name##Operator() \ |
360 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \ | 359 : Operator(IrOpcode::kJS##Name, properties, "JS" #Name, \ |
361 value_input_count, Operator::ZeroIfPure(properties), \ | 360 value_input_count, Operator::ZeroIfPure(properties), \ |
362 Operator::ZeroIfEliminatable(properties), \ | 361 Operator::ZeroIfEliminatable(properties), \ |
363 value_output_count, Operator::ZeroIfPure(properties), \ | 362 value_output_count, Operator::ZeroIfPure(properties), \ |
364 Operator::ZeroIfNoThrow(properties)) {} \ | 363 Operator::ZeroIfNoThrow(properties)) {} \ |
365 }; \ | 364 }; \ |
366 Name##Operator k##Name##Operator; | 365 Name##Operator k##Name##Operator; |
367 CACHED_OP_LIST(CACHED) | 366 CACHED_OP_LIST(CACHED) |
368 #undef CACHED | 367 #undef CACHED |
369 | 368 |
370 | 369 |
371 #define CACHED_WITH_LANGUAGE_MODE(Name, properties, value_input_count, \ | 370 #define CACHED_WITH_STRENGTH(Name, properties, value_input_count, \ |
372 value_output_count) \ | 371 value_output_count) \ |
373 template <LanguageMode kLanguageMode> \ | 372 template <Strength kStrength> \ |
374 struct Name##Operator final : public Operator1<LanguageMode> { \ | 373 struct Name##Operator final : public Operator1<Strength> { \ |
375 Name##Operator() \ | 374 Name##Operator() \ |
376 : Operator1<LanguageMode>( \ | 375 : Operator1<Strength>( \ |
377 IrOpcode::kJS##Name, properties, "JS" #Name, value_input_count, \ | 376 IrOpcode::kJS##Name, properties, "JS" #Name, value_input_count, \ |
378 Operator::ZeroIfPure(properties), \ | 377 Operator::ZeroIfPure(properties), \ |
379 Operator::ZeroIfEliminatable(properties), value_output_count, \ | 378 Operator::ZeroIfEliminatable(properties), value_output_count, \ |
380 Operator::ZeroIfPure(properties), \ | 379 Operator::ZeroIfPure(properties), \ |
381 Operator::ZeroIfNoThrow(properties), kLanguageMode) {} \ | 380 Operator::ZeroIfNoThrow(properties), kStrength) {} \ |
382 }; \ | 381 }; \ |
383 Name##Operator<SLOPPY> k##Name##SloppyOperator; \ | 382 Name##Operator<Strength::WEAK> k##Name##SloppyOperator; \ |
384 Name##Operator<STRICT> k##Name##StrictOperator; \ | 383 Name##Operator<Strength::FIRM> k##Name##StrongOperator; |
385 Name##Operator<STRONG> k##Name##StrongOperator; | 384 CACHED_OP_LIST_WITH_STRENGTH(CACHED_WITH_STRENGTH) |
386 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_LANGUAGE_MODE) | 385 #undef CACHED_WITH_STRENGTH |
387 #undef CACHED_WITH_LANGUAGE_MODE | 386 |
| 387 |
| 388 template <LanguageMode kLanguageMode> |
| 389 struct StorePropertyOperator final : public Operator1<LanguageMode> { |
| 390 StorePropertyOperator() |
| 391 : Operator1<LanguageMode>(IrOpcode::kJSStoreProperty, |
| 392 Operator::kNoProperties, "JSStoreProperty", 3, |
| 393 1, 1, 0, 1, 2, kLanguageMode) {} |
| 394 }; |
| 395 StorePropertyOperator<SLOPPY> kStorePropertySloppyOperator; |
| 396 StorePropertyOperator<STRICT> kStorePropertyStrictOperator; |
| 397 StorePropertyOperator<STRONG> kStorePropertyStrongOperator; |
388 }; | 398 }; |
389 | 399 |
390 | 400 |
391 static base::LazyInstance<JSOperatorGlobalCache>::type kCache = | 401 static base::LazyInstance<JSOperatorGlobalCache>::type kCache = |
392 LAZY_INSTANCE_INITIALIZER; | 402 LAZY_INSTANCE_INITIALIZER; |
393 | 403 |
394 | 404 |
395 JSOperatorBuilder::JSOperatorBuilder(Zone* zone) | 405 JSOperatorBuilder::JSOperatorBuilder(Zone* zone) |
396 : cache_(kCache.Get()), zone_(zone) {} | 406 : cache_(kCache.Get()), zone_(zone) {} |
397 | 407 |
398 | 408 |
399 #define CACHED(Name, properties, value_input_count, value_output_count) \ | 409 #define CACHED(Name, properties, value_input_count, value_output_count) \ |
400 const Operator* JSOperatorBuilder::Name() { \ | 410 const Operator* JSOperatorBuilder::Name() { \ |
401 return &cache_.k##Name##Operator; \ | 411 return &cache_.k##Name##Operator; \ |
402 } | 412 } |
403 CACHED_OP_LIST(CACHED) | 413 CACHED_OP_LIST(CACHED) |
404 #undef CACHED | 414 #undef CACHED |
405 | 415 |
406 | 416 |
407 #define CACHED_WITH_LANGUAGE_MODE(Name, properties, value_input_count, \ | 417 #define CACHED_WITH_STRENGTH(Name, properties, value_input_count, \ |
408 value_output_count) \ | 418 value_output_count) \ |
409 const Operator* JSOperatorBuilder::Name(LanguageMode language_mode) { \ | 419 const Operator* JSOperatorBuilder::Name(Strength strength) { \ |
410 switch (language_mode) { \ | 420 if (is_strong(strength)) { \ |
411 case SLOPPY: \ | 421 return &cache_.k##Name##StrongOperator; \ |
412 return &cache_.k##Name##SloppyOperator; \ | 422 } \ |
413 case STRICT: \ | 423 return &cache_.k##Name##SloppyOperator; \ |
414 return &cache_.k##Name##StrictOperator; \ | |
415 case STRONG: \ | |
416 return &cache_.k##Name##StrongOperator; \ | |
417 case STRONG_BIT: \ | |
418 break; /* %*!%^$#@ */ \ | |
419 } \ | |
420 UNREACHABLE(); \ | |
421 return nullptr; \ | |
422 } | 424 } |
423 CACHED_OP_LIST_WITH_LANGUAGE_MODE(CACHED_WITH_LANGUAGE_MODE) | 425 CACHED_OP_LIST_WITH_STRENGTH(CACHED_WITH_STRENGTH) |
424 #undef CACHED_WITH_LANGUAGE_MODE | 426 #undef CACHED_WITH_STRENGTH |
| 427 |
| 428 const Operator* JSOperatorBuilder::StoreProperty(LanguageMode language_mode) { |
| 429 switch (language_mode) { |
| 430 case SLOPPY: |
| 431 return &cache_.kStorePropertySloppyOperator; |
| 432 case STRICT: |
| 433 return &cache_.kStorePropertyStrictOperator; |
| 434 case STRONG: |
| 435 return &cache_.kStorePropertyStrongOperator; |
| 436 default: |
| 437 UNREACHABLE(); |
| 438 return nullptr; |
| 439 } |
| 440 } |
425 | 441 |
426 | 442 |
427 const Operator* JSOperatorBuilder::CallFunction(size_t arity, | 443 const Operator* JSOperatorBuilder::CallFunction(size_t arity, |
428 CallFunctionFlags flags, | 444 CallFunctionFlags flags, |
429 LanguageMode language_mode) { | 445 LanguageMode language_mode) { |
430 CallFunctionParameters parameters(arity, flags, language_mode); | 446 CallFunctionParameters parameters(arity, flags, language_mode); |
431 return new (zone()) Operator1<CallFunctionParameters>( // -- | 447 return new (zone()) Operator1<CallFunctionParameters>( // -- |
432 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode | 448 IrOpcode::kJSCallFunction, Operator::kNoProperties, // opcode |
433 "JSCallFunction", // name | 449 "JSCallFunction", // name |
434 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs | 450 parameters.arity(), 1, 1, 1, 1, 2, // inputs/outputs |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 return new (zone()) Operator1<Unique<String>>( // -- | 599 return new (zone()) Operator1<Unique<String>>( // -- |
584 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode | 600 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, // opcode |
585 "JSCreateCatchContext", // name | 601 "JSCreateCatchContext", // name |
586 2, 1, 1, 1, 1, 2, // counts | 602 2, 1, 1, 1, 1, 2, // counts |
587 name); // parameter | 603 name); // parameter |
588 } | 604 } |
589 | 605 |
590 } // namespace compiler | 606 } // namespace compiler |
591 } // namespace internal | 607 } // namespace internal |
592 } // namespace v8 | 608 } // namespace v8 |
OLD | NEW |