| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 // - preserved instance in RAX and optional instantiator type arguments in RDX. | 414 // - preserved instance in RAX and optional instantiator type arguments in RDX. |
| 415 // Note that this inlined code must be followed by the runtime_call code, as it | 415 // Note that this inlined code must be followed by the runtime_call code, as it |
| 416 // may fall through to it. Otherwise, this inline code will jump to the label | 416 // may fall through to it. Otherwise, this inline code will jump to the label |
| 417 // is_instance or to the label is_not_instance. | 417 // is_instance or to the label is_not_instance. |
| 418 RawSubtypeTestCache* FlowGraphCompiler::GenerateInlineInstanceof( | 418 RawSubtypeTestCache* FlowGraphCompiler::GenerateInlineInstanceof( |
| 419 intptr_t cid, | 419 intptr_t cid, |
| 420 intptr_t token_pos, | 420 intptr_t token_pos, |
| 421 const AbstractType& type, | 421 const AbstractType& type, |
| 422 Label* is_instance_lbl, | 422 Label* is_instance_lbl, |
| 423 Label* is_not_instance_lbl) { | 423 Label* is_not_instance_lbl) { |
| 424 if (type.IsVoidType()) { | |
| 425 // A non-null value is returned from a void function, which will result in a | |
| 426 // type error. A null value is handled prior to executing this inline code. | |
| 427 return SubtypeTestCache::null(); | |
| 428 } | |
| 429 if (type.IsInstantiated()) { | 424 if (type.IsInstantiated()) { |
| 430 const Class& type_class = Class::ZoneHandle(type.type_class()); | 425 const Class& type_class = Class::ZoneHandle(type.type_class()); |
| 431 // A Smi object cannot be the instance of a parameterized class. | 426 // A Smi object cannot be the instance of a parameterized class. |
| 432 // A class equality check is only applicable with a dst type of a | 427 // A class equality check is only applicable with a dst type of a |
| 433 // non-parameterized class or with a raw dst type of a parameterized class. | 428 // non-parameterized class or with a raw dst type of a parameterized class. |
| 434 if (type_class.HasTypeArguments()) { | 429 if (type_class.HasTypeArguments()) { |
| 435 return GenerateInstantiatedTypeWithArgumentsTest(cid, | 430 return GenerateInstantiatedTypeWithArgumentsTest(cid, |
| 436 token_pos, | 431 token_pos, |
| 437 type, | 432 type, |
| 438 is_instance_lbl, | 433 is_instance_lbl, |
| 439 is_not_instance_lbl); | 434 is_not_instance_lbl); |
| 440 // Fall through to runtime call. | 435 // Fall through to runtime call. |
| 436 } else { |
| 437 GenerateInstantiatedTypeNoArgumentsTest(cid, |
| 438 token_pos, |
| 439 type, |
| 440 is_instance_lbl, |
| 441 is_not_instance_lbl); |
| 442 // If test non-conclusive so far, try the inlined type-test cache. |
| 443 // 'type' is known at compile time. |
| 444 return GenerateSubtype1TestCacheLookup( |
| 445 cid, token_pos, type_class, |
| 446 is_instance_lbl, is_not_instance_lbl); |
| 441 } | 447 } |
| 442 GenerateInstantiatedTypeNoArgumentsTest(cid, | 448 } else { |
| 443 token_pos, | 449 return GenerateUninstantiatedTypeTest(cid, |
| 444 type, | 450 token_pos, |
| 445 is_instance_lbl, | 451 type, |
| 446 is_not_instance_lbl); | 452 is_instance_lbl, |
| 447 // If test non-conclusive so far, try the inlined type-test cache. | 453 is_not_instance_lbl); |
| 448 // 'type' is known at compile time. | |
| 449 return GenerateSubtype1TestCacheLookup( | |
| 450 cid, token_pos, type_class, | |
| 451 is_instance_lbl, is_not_instance_lbl); | |
| 452 } | 454 } |
| 453 return GenerateUninstantiatedTypeTest(cid, | 455 return SubtypeTestCache::null(); |
| 454 token_pos, | |
| 455 type, | |
| 456 is_instance_lbl, | |
| 457 is_not_instance_lbl); | |
| 458 } | 456 } |
| 459 | 457 |
| 460 | 458 |
| 461 // If instanceof type test cannot be performed successfully at compile time and | 459 // If instanceof type test cannot be performed successfully at compile time and |
| 462 // therefore eliminated, optimize it by adding inlined tests for: | 460 // therefore eliminated, optimize it by adding inlined tests for: |
| 463 // - NULL -> return false. | 461 // - NULL -> return false. |
| 464 // - Smi -> compile time subtype check (only if dst class is not parameterized). | 462 // - Smi -> compile time subtype check (only if dst class is not parameterized). |
| 465 // - Class equality (only if class is not parameterized). | 463 // - Class equality (only if class is not parameterized). |
| 466 // Inputs: | 464 // Inputs: |
| 467 // - RAX: object. | 465 // - RAX: object. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 intptr_t token_pos, | 554 intptr_t token_pos, |
| 557 intptr_t try_index, | 555 intptr_t try_index, |
| 558 const AbstractType& dst_type, | 556 const AbstractType& dst_type, |
| 559 const String& dst_name) { | 557 const String& dst_name) { |
| 560 ASSERT(token_pos >= 0); | 558 ASSERT(token_pos >= 0); |
| 561 ASSERT(!dst_type.IsNull()); | 559 ASSERT(!dst_type.IsNull()); |
| 562 ASSERT(dst_type.IsFinalized()); | 560 ASSERT(dst_type.IsFinalized()); |
| 563 // Assignable check is skipped in FlowGraphBuilder, not here. | 561 // Assignable check is skipped in FlowGraphBuilder, not here. |
| 564 ASSERT(dst_type.IsMalformed() || | 562 ASSERT(dst_type.IsMalformed() || |
| 565 (!dst_type.IsDynamicType() && !dst_type.IsObjectType())); | 563 (!dst_type.IsDynamicType() && !dst_type.IsObjectType())); |
| 564 ASSERT(!dst_type.IsVoidType()); |
| 566 __ pushq(RCX); // Store instantiator. | 565 __ pushq(RCX); // Store instantiator. |
| 567 __ pushq(RDX); // Store instantiator type arguments. | 566 __ pushq(RDX); // Store instantiator type arguments. |
| 568 // A null object is always assignable and is returned as result. | 567 // A null object is always assignable and is returned as result. |
| 569 const Immediate raw_null = | 568 const Immediate raw_null = |
| 570 Immediate(reinterpret_cast<intptr_t>(Object::null())); | 569 Immediate(reinterpret_cast<intptr_t>(Object::null())); |
| 571 Label is_assignable, runtime_call; | 570 Label is_assignable, runtime_call; |
| 572 __ cmpq(RAX, raw_null); | 571 __ cmpq(RAX, raw_null); |
| 573 __ j(EQUAL, &is_assignable); | 572 __ j(EQUAL, &is_assignable); |
| 574 | 573 |
| 575 // Generate throw new TypeError() if the type is malformed. | 574 // Generate throw new TypeError() if the type is malformed. |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 } | 1141 } |
| 1143 } | 1142 } |
| 1144 } | 1143 } |
| 1145 | 1144 |
| 1146 | 1145 |
| 1147 #undef __ | 1146 #undef __ |
| 1148 | 1147 |
| 1149 } // namespace dart | 1148 } // namespace dart |
| 1150 | 1149 |
| 1151 #endif // defined TARGET_ARCH_X64 | 1150 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |