OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // Clobbers R2. | 258 // Clobbers R2. |
259 RawSubtypeTestCache* | 259 RawSubtypeTestCache* |
260 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( | 260 FlowGraphCompiler::GenerateInstantiatedTypeWithArgumentsTest( |
261 intptr_t token_pos, | 261 intptr_t token_pos, |
262 const AbstractType& type, | 262 const AbstractType& type, |
263 Label* is_instance_lbl, | 263 Label* is_instance_lbl, |
264 Label* is_not_instance_lbl) { | 264 Label* is_not_instance_lbl) { |
265 __ Comment("InstantiatedTypeWithArgumentsTest"); | 265 __ Comment("InstantiatedTypeWithArgumentsTest"); |
266 ASSERT(type.IsInstantiated()); | 266 ASSERT(type.IsInstantiated()); |
267 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); | 267 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); |
268 ASSERT((type_class.NumTypeArguments() > 0) || type_class.IsSignatureClass()); | 268 ASSERT(type.IsFunctionType() || (type_class.NumTypeArguments() > 0)); |
269 const Register kInstanceReg = R0; | 269 const Register kInstanceReg = R0; |
270 Error& bound_error = Error::Handle(zone()); | 270 Error& bound_error = Error::Handle(zone()); |
271 const Type& int_type = Type::Handle(zone(), Type::IntType()); | 271 const Type& int_type = Type::Handle(zone(), Type::IntType()); |
272 const bool smi_is_ok = int_type.IsSubtypeOf(type, &bound_error, Heap::kOld); | 272 const bool smi_is_ok = int_type.IsSubtypeOf(type, &bound_error, Heap::kOld); |
273 // Malformed type should have been handled at graph construction time. | 273 // Malformed type should have been handled at graph construction time. |
274 ASSERT(smi_is_ok || bound_error.IsNull()); | 274 ASSERT(smi_is_ok || bound_error.IsNull()); |
275 __ tsti(kInstanceReg, Immediate(kSmiTagMask)); | 275 __ tsti(kInstanceReg, Immediate(kSmiTagMask)); |
276 if (smi_is_ok) { | 276 if (smi_is_ok) { |
277 __ b(is_instance_lbl, EQ); | 277 __ b(is_instance_lbl, EQ); |
278 } else { | 278 } else { |
279 __ b(is_not_instance_lbl, EQ); | 279 __ b(is_not_instance_lbl, EQ); |
280 } | 280 } |
281 const intptr_t num_type_args = type_class.NumTypeArguments(); | 281 // A function type test requires checking the function signature. |
282 const intptr_t num_type_params = type_class.NumTypeParameters(); | 282 if (!type.IsFunctionType()) { |
283 const intptr_t from_index = num_type_args - num_type_params; | 283 const intptr_t num_type_args = type_class.NumTypeArguments(); |
284 const TypeArguments& type_arguments = | 284 const intptr_t num_type_params = type_class.NumTypeParameters(); |
285 TypeArguments::ZoneHandle(zone(), type.arguments()); | 285 const intptr_t from_index = num_type_args - num_type_params; |
286 const bool is_raw_type = type_arguments.IsNull() || | 286 const TypeArguments& type_arguments = |
287 type_arguments.IsRaw(from_index, num_type_params); | 287 TypeArguments::ZoneHandle(zone(), type.arguments()); |
288 // Signature class is an instantiated parameterized type. | 288 const bool is_raw_type = type_arguments.IsNull() || |
289 if (!type_class.IsSignatureClass()) { | 289 type_arguments.IsRaw(from_index, num_type_params); |
290 if (is_raw_type) { | 290 if (is_raw_type) { |
291 const Register kClassIdReg = R2; | 291 const Register kClassIdReg = R2; |
292 // dynamic type argument, check only classes. | 292 // dynamic type argument, check only classes. |
293 __ LoadClassId(kClassIdReg, kInstanceReg); | 293 __ LoadClassId(kClassIdReg, kInstanceReg); |
294 __ CompareImmediate(kClassIdReg, type_class.id()); | 294 __ CompareImmediate(kClassIdReg, type_class.id()); |
295 __ b(is_instance_lbl, EQ); | 295 __ b(is_instance_lbl, EQ); |
296 // List is a very common case. | 296 // List is a very common case. |
297 if (IsListClass(type_class)) { | 297 if (IsListClass(type_class)) { |
298 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); | 298 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); |
299 } | 299 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // R0: instance being type checked (preserved). | 347 // R0: instance being type checked (preserved). |
348 // Clobbers R2, R3. | 348 // Clobbers R2, R3. |
349 // Returns true if there is a fallthrough. | 349 // Returns true if there is a fallthrough. |
350 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( | 350 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( |
351 intptr_t token_pos, | 351 intptr_t token_pos, |
352 const AbstractType& type, | 352 const AbstractType& type, |
353 Label* is_instance_lbl, | 353 Label* is_instance_lbl, |
354 Label* is_not_instance_lbl) { | 354 Label* is_not_instance_lbl) { |
355 __ Comment("InstantiatedTypeNoArgumentsTest"); | 355 __ Comment("InstantiatedTypeNoArgumentsTest"); |
356 ASSERT(type.IsInstantiated()); | 356 ASSERT(type.IsInstantiated()); |
| 357 if (type.IsFunctionType()) { |
| 358 // Fallthrough. |
| 359 return true; |
| 360 } |
357 const Class& type_class = Class::Handle(zone(), type.type_class()); | 361 const Class& type_class = Class::Handle(zone(), type.type_class()); |
358 ASSERT(type_class.NumTypeArguments() == 0); | 362 ASSERT(type_class.NumTypeArguments() == 0); |
359 | 363 |
360 const Register kInstanceReg = R0; | 364 const Register kInstanceReg = R0; |
361 __ tsti(kInstanceReg, Immediate(kSmiTagMask)); | 365 __ tsti(kInstanceReg, Immediate(kSmiTagMask)); |
362 // If instance is Smi, check directly. | 366 // If instance is Smi, check directly. |
363 const Class& smi_class = Class::Handle(zone(), Smi::Class()); | 367 const Class& smi_class = Class::Handle(zone(), Smi::Class()); |
364 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), | 368 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), |
365 type_class, | 369 type_class, |
366 TypeArguments::Handle(zone()), | 370 TypeArguments::Handle(zone()), |
(...skipping 10 matching lines...) Expand all Loading... |
377 __ b(is_instance_lbl, EQ); | 381 __ b(is_instance_lbl, EQ); |
378 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted | 382 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted |
379 // interfaces. | 383 // interfaces. |
380 // Bool interface can be implemented only by core class Bool. | 384 // Bool interface can be implemented only by core class Bool. |
381 if (type.IsBoolType()) { | 385 if (type.IsBoolType()) { |
382 __ CompareImmediate(kClassIdReg, kBoolCid); | 386 __ CompareImmediate(kClassIdReg, kBoolCid); |
383 __ b(is_instance_lbl, EQ); | 387 __ b(is_instance_lbl, EQ); |
384 __ b(is_not_instance_lbl); | 388 __ b(is_not_instance_lbl); |
385 return false; | 389 return false; |
386 } | 390 } |
387 if (type.IsFunctionType()) { | 391 if (type.IsDartFunctionType()) { |
388 // Check if instance is a closure. | 392 // Check if instance is a closure. |
389 __ LoadClassById(R3, kClassIdReg); | 393 __ CompareImmediate(kClassIdReg, kClosureCid); |
390 __ LoadFieldFromOffset(R3, R3, Class::signature_function_offset()); | 394 __ b(is_instance_lbl, EQ); |
391 __ CompareObject(R3, Object::null_object()); | |
392 __ b(is_instance_lbl, NE); | |
393 } | 395 } |
394 // Custom checking for numbers (Smi, Mint, Bigint and Double). | 396 // Custom checking for numbers (Smi, Mint, Bigint and Double). |
395 // Note that instance is not Smi (checked above). | 397 // Note that instance is not Smi (checked above). |
396 if (type.IsSubtypeOf( | 398 if (type.IsSubtypeOf( |
397 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { | 399 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { |
398 GenerateNumberTypeCheck( | 400 GenerateNumberTypeCheck( |
399 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); | 401 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); |
400 return false; | 402 return false; |
401 } | 403 } |
402 if (type.IsStringType()) { | 404 if (type.IsStringType()) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 Label* is_instance_lbl, | 534 Label* is_instance_lbl, |
533 Label* is_not_instance_lbl) { | 535 Label* is_not_instance_lbl) { |
534 __ Comment("InlineInstanceof"); | 536 __ Comment("InlineInstanceof"); |
535 if (type.IsVoidType()) { | 537 if (type.IsVoidType()) { |
536 // A non-null value is returned from a void function, which will result in a | 538 // A non-null value is returned from a void function, which will result in a |
537 // type error. A null value is handled prior to executing this inline code. | 539 // type error. A null value is handled prior to executing this inline code. |
538 return SubtypeTestCache::null(); | 540 return SubtypeTestCache::null(); |
539 } | 541 } |
540 if (type.IsInstantiated()) { | 542 if (type.IsInstantiated()) { |
541 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); | 543 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); |
542 // A class equality check is only applicable with a dst type of a | 544 // A class equality check is only applicable with a dst type (not a |
543 // non-parameterized class, non-signature class, or with a raw dst type of | 545 // function type) of a non-parameterized class or with a raw dst type of |
544 // a parameterized class. | 546 // a parameterized class. |
545 if (type_class.IsSignatureClass() || (type_class.NumTypeArguments() > 0)) { | 547 if (type.IsFunctionType() || (type_class.NumTypeArguments() > 0)) { |
546 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, | 548 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, |
547 type, | 549 type, |
548 is_instance_lbl, | 550 is_instance_lbl, |
549 is_not_instance_lbl); | 551 is_not_instance_lbl); |
550 // Fall through to runtime call. | 552 // Fall through to runtime call. |
551 } | 553 } |
552 const bool has_fall_through = | 554 const bool has_fall_through = |
553 GenerateInstantiatedTypeNoArgumentsTest(token_pos, | 555 GenerateInstantiatedTypeNoArgumentsTest(token_pos, |
554 type, | 556 type, |
555 is_instance_lbl, | 557 is_instance_lbl, |
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { | 1872 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { |
1871 __ PopDouble(reg); | 1873 __ PopDouble(reg); |
1872 } | 1874 } |
1873 | 1875 |
1874 | 1876 |
1875 #undef __ | 1877 #undef __ |
1876 | 1878 |
1877 } // namespace dart | 1879 } // namespace dart |
1878 | 1880 |
1879 #endif // defined TARGET_ARCH_ARM64 | 1881 #endif // defined TARGET_ARCH_ARM64 |
OLD | NEW |