| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // Clobbers R10. | 220 // Clobbers R10. |
| 221 RawSubtypeTestCache* | 221 RawSubtypeTestCache* |
| 222 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( | 222 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( |
| 223 intptr_t token_pos, | 223 intptr_t token_pos, |
| 224 const AbstractType& type, | 224 const AbstractType& type, |
| 225 Label* is_instance_lbl, | 225 Label* is_instance_lbl, |
| 226 Label* is_not_instance_lbl) { | 226 Label* is_not_instance_lbl) { |
| 227 __ Comment("InstantiatedTypeWithArgumentsTest"); | 227 __ Comment("InstantiatedTypeWithArgumentsTest"); |
| 228 ASSERT(type.IsInstantiated()); | 228 ASSERT(type.IsInstantiated()); |
| 229 const Class& type_class = Class::ZoneHandle(type.type_class()); | 229 const Class& type_class = Class::ZoneHandle(type.type_class()); |
| 230 ASSERT(type_class.HasTypeArguments()); | 230 ASSERT(type_class.HasTypeArguments() || type_class.IsSignatureClass()); |
| 231 const Register kInstanceReg = RAX; | 231 const Register kInstanceReg = RAX; |
| 232 Error& malformed_error = Error::Handle(); | 232 Error& malformed_error = Error::Handle(); |
| 233 const Type& int_type = Type::Handle(Type::IntType()); | 233 const Type& int_type = Type::Handle(Type::IntType()); |
| 234 const bool smi_is_ok = int_type.IsSubtypeOf(type, &malformed_error); | 234 const bool smi_is_ok = int_type.IsSubtypeOf(type, &malformed_error); |
| 235 // Malforrmed type should have been handled at graph construction time. | 235 // Malformed type should have been handled at graph construction time. |
| 236 ASSERT(smi_is_ok || malformed_error.IsNull()); | 236 ASSERT(smi_is_ok || malformed_error.IsNull()); |
| 237 __ testq(kInstanceReg, Immediate(kSmiTagMask)); | 237 __ testq(kInstanceReg, Immediate(kSmiTagMask)); |
| 238 if (smi_is_ok) { | 238 if (smi_is_ok) { |
| 239 __ j(ZERO, is_instance_lbl); | 239 __ j(ZERO, is_instance_lbl); |
| 240 } else { | 240 } else { |
| 241 __ j(ZERO, is_not_instance_lbl); | 241 __ j(ZERO, is_not_instance_lbl); |
| 242 } | 242 } |
| 243 const AbstractTypeArguments& type_arguments = | 243 const AbstractTypeArguments& type_arguments = |
| 244 AbstractTypeArguments::ZoneHandle(type.arguments()); | 244 AbstractTypeArguments::ZoneHandle(type.arguments()); |
| 245 const bool is_raw_type = type_arguments.IsNull() || | 245 const bool is_raw_type = type_arguments.IsNull() || |
| 246 type_arguments.IsRaw(type_arguments.Length()); | 246 type_arguments.IsRaw(type_arguments.Length()); |
| 247 if (is_raw_type) { | 247 if (!type_class.IsSignatureClass()) { |
| 248 const Register kClassIdReg = R10; | 248 if (is_raw_type) { |
| 249 // dynamic type argument, check only classes. | 249 const Register kClassIdReg = R10; |
| 250 __ LoadClassId(kClassIdReg, kInstanceReg); | 250 // dynamic type argument, check only classes. |
| 251 __ cmpl(kClassIdReg, Immediate(type_class.id())); | 251 __ LoadClassId(kClassIdReg, kInstanceReg); |
| 252 __ j(EQUAL, is_instance_lbl); | 252 __ cmpl(kClassIdReg, Immediate(type_class.id())); |
| 253 // List is a very common case. | 253 __ j(EQUAL, is_instance_lbl); |
| 254 if (IsListClass(type_class)) { | 254 // List is a very common case. |
| 255 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); | 255 if (IsListClass(type_class)) { |
| 256 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); |
| 257 } |
| 258 return GenerateSubtype1TestCacheLookup( |
| 259 token_pos, type_class, is_instance_lbl, is_not_instance_lbl); |
| 256 } | 260 } |
| 257 return GenerateSubtype1TestCacheLookup( | 261 // If one type argument only, check if type argument is Object or dynamic. |
| 258 token_pos, type_class, is_instance_lbl, is_not_instance_lbl); | 262 if (type_arguments.Length() == 1) { |
| 259 } | 263 const AbstractType& tp_argument = AbstractType::ZoneHandle( |
| 260 // If one type argument only, check if type argument is Object or dynamic. | 264 type_arguments.TypeAt(0)); |
| 261 if (type_arguments.Length() == 1) { | 265 ASSERT(!tp_argument.IsMalformed()); |
| 262 const AbstractType& tp_argument = AbstractType::ZoneHandle( | 266 if (tp_argument.IsType()) { |
| 263 type_arguments.TypeAt(0)); | 267 ASSERT(tp_argument.HasResolvedTypeClass()); |
| 264 ASSERT(!tp_argument.IsMalformed()); | 268 // Check if type argument is dynamic or Object. |
| 265 if (tp_argument.IsType()) { | 269 const Type& object_type = Type::Handle(Type::ObjectType()); |
| 266 ASSERT(tp_argument.HasResolvedTypeClass()); | 270 if (object_type.IsSubtypeOf(tp_argument, NULL)) { |
| 267 // Check if type argument is dynamic or Object. | 271 // Instance class test only necessary. |
| 268 const Type& object_type = Type::Handle(Type::ObjectType()); | 272 return GenerateSubtype1TestCacheLookup( |
| 269 if (object_type.IsSubtypeOf(tp_argument, NULL)) { | 273 token_pos, type_class, is_instance_lbl, is_not_instance_lbl); |
| 270 // Instance class test only necessary. | 274 } |
| 271 return GenerateSubtype1TestCacheLookup( | |
| 272 token_pos, type_class, is_instance_lbl, is_not_instance_lbl); | |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 } | 277 } |
| 276 // Regular subtype test cache involving instance's type arguments. | 278 // Regular subtype test cache involving instance's type arguments. |
| 277 const Register kTypeArgumentsReg = kNoRegister; | 279 const Register kTypeArgumentsReg = kNoRegister; |
| 278 const Register kTempReg = R10; | 280 const Register kTempReg = R10; |
| 279 return GenerateCallSubtypeTestStub(kTestTypeTwoArgs, | 281 return GenerateCallSubtypeTestStub(kTestTypeTwoArgs, |
| 280 kInstanceReg, | 282 kInstanceReg, |
| 281 kTypeArgumentsReg, | 283 kTypeArgumentsReg, |
| 282 kTempReg, | 284 kTempReg, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 __ CompareClassId(kInstanceReg, type_cid); | 515 __ CompareClassId(kInstanceReg, type_cid); |
| 514 __ j(EQUAL, is_instance_lbl); | 516 __ j(EQUAL, is_instance_lbl); |
| 515 } | 517 } |
| 516 __ jmp(is_not_instance_lbl); | 518 __ jmp(is_not_instance_lbl); |
| 517 return SubtypeTestCache::null(); | 519 return SubtypeTestCache::null(); |
| 518 } | 520 } |
| 519 if (type.IsInstantiated()) { | 521 if (type.IsInstantiated()) { |
| 520 const Class& type_class = Class::ZoneHandle(type.type_class()); | 522 const Class& type_class = Class::ZoneHandle(type.type_class()); |
| 521 // A class equality check is only applicable with a dst type of a | 523 // A class equality check is only applicable with a dst type of a |
| 522 // non-parameterized class or with a raw dst type of a parameterized class. | 524 // non-parameterized class or with a raw dst type of a parameterized class. |
| 523 if (type_class.HasTypeArguments()) { | 525 if (type_class.IsSignatureClass() || type_class.HasTypeArguments()) { |
| 524 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, | 526 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, |
| 525 type, | 527 type, |
| 526 is_instance_lbl, | 528 is_instance_lbl, |
| 527 is_not_instance_lbl); | 529 is_not_instance_lbl); |
| 528 // Fall through to runtime call. | 530 // Fall through to runtime call. |
| 529 } | 531 } |
| 530 const bool has_fall_through = | 532 const bool has_fall_through = |
| 531 GenerateInstantiatedTypeNoArgumentsTest(token_pos, | 533 GenerateInstantiatedTypeNoArgumentsTest(token_pos, |
| 532 type, | 534 type, |
| 533 is_instance_lbl, | 535 is_instance_lbl, |
| (...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 __ movups(reg, Address(RSP, 0)); | 1887 __ movups(reg, Address(RSP, 0)); |
| 1886 __ addq(RSP, Immediate(kFpuRegisterSize)); | 1888 __ addq(RSP, Immediate(kFpuRegisterSize)); |
| 1887 } | 1889 } |
| 1888 | 1890 |
| 1889 | 1891 |
| 1890 #undef __ | 1892 #undef __ |
| 1891 | 1893 |
| 1892 } // namespace dart | 1894 } // namespace dart |
| 1893 | 1895 |
| 1894 #endif // defined TARGET_ARCH_X64 | 1896 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |