| 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_MIPS. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. |
| 6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
| 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 T0. | 258 // Clobbers T0. |
| 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 = A0; | 269 const Register kInstanceReg = A0; |
| 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 __ andi(CMPRES1, kInstanceReg, Immediate(kSmiTagMask)); | 275 __ andi(CMPRES1, kInstanceReg, Immediate(kSmiTagMask)); |
| 276 if (smi_is_ok) { | 276 if (smi_is_ok) { |
| 277 __ beq(CMPRES1, ZR, is_instance_lbl); | 277 __ beq(CMPRES1, ZR, is_instance_lbl); |
| 278 } else { | 278 } else { |
| 279 __ beq(CMPRES1, ZR, is_not_instance_lbl); | 279 __ beq(CMPRES1, ZR, is_not_instance_lbl); |
| 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 = T0; | 291 const Register kClassIdReg = T0; |
| 292 // dynamic type argument, check only classes. | 292 // dynamic type argument, check only classes. |
| 293 __ LoadClassId(kClassIdReg, kInstanceReg); | 293 __ LoadClassId(kClassIdReg, kInstanceReg); |
| 294 __ BranchEqual(kClassIdReg, Immediate(type_class.id()), is_instance_lbl); | 294 __ BranchEqual(kClassIdReg, Immediate(type_class.id()), is_instance_lbl); |
| 295 // List is a very common case. | 295 // List is a very common case. |
| 296 if (IsListClass(type_class)) { | 296 if (IsListClass(type_class)) { |
| 297 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); | 297 GenerateListTypeCheck(kClassIdReg, is_instance_lbl); |
| 298 } | 298 } |
| 299 return GenerateSubtype1TestCacheLookup( | 299 return GenerateSubtype1TestCacheLookup( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 // A0: instance being type checked (preserved). | 346 // A0: instance being type checked (preserved). |
| 347 // Clobbers: T0, T1, T2 | 347 // Clobbers: T0, T1, T2 |
| 348 // Returns true if there is a fallthrough. | 348 // Returns true if there is a fallthrough. |
| 349 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( | 349 bool FlowGraphCompiler::GenerateInstantiatedTypeNoArgumentsTest( |
| 350 intptr_t token_pos, | 350 intptr_t token_pos, |
| 351 const AbstractType& type, | 351 const AbstractType& type, |
| 352 Label* is_instance_lbl, | 352 Label* is_instance_lbl, |
| 353 Label* is_not_instance_lbl) { | 353 Label* is_not_instance_lbl) { |
| 354 __ Comment("InstantiatedTypeNoArgumentsTest"); | 354 __ Comment("InstantiatedTypeNoArgumentsTest"); |
| 355 ASSERT(type.IsInstantiated()); | 355 ASSERT(type.IsInstantiated()); |
| 356 if (type.IsFunctionType()) { |
| 357 // Fallthrough. |
| 358 return true; |
| 359 } |
| 356 const Class& type_class = Class::Handle(zone(), type.type_class()); | 360 const Class& type_class = Class::Handle(zone(), type.type_class()); |
| 357 ASSERT(type_class.NumTypeArguments() == 0); | 361 ASSERT(type_class.NumTypeArguments() == 0); |
| 358 | 362 |
| 359 const Register kInstanceReg = A0; | 363 const Register kInstanceReg = A0; |
| 360 __ andi(T0, A0, Immediate(kSmiTagMask)); | 364 __ andi(T0, A0, Immediate(kSmiTagMask)); |
| 361 // If instance is Smi, check directly. | 365 // If instance is Smi, check directly. |
| 362 const Class& smi_class = Class::Handle(zone(), Smi::Class()); | 366 const Class& smi_class = Class::Handle(zone(), Smi::Class()); |
| 363 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), | 367 if (smi_class.IsSubtypeOf(TypeArguments::Handle(zone()), |
| 364 type_class, | 368 type_class, |
| 365 TypeArguments::Handle(zone()), | 369 TypeArguments::Handle(zone()), |
| 366 NULL, | 370 NULL, |
| 367 Heap::kOld)) { | 371 Heap::kOld)) { |
| 368 __ beq(T0, ZR, is_instance_lbl); | 372 __ beq(T0, ZR, is_instance_lbl); |
| 369 } else { | 373 } else { |
| 370 __ beq(T0, ZR, is_not_instance_lbl); | 374 __ beq(T0, ZR, is_not_instance_lbl); |
| 371 } | 375 } |
| 372 // Compare if the classes are equal. | 376 // Compare if the classes are equal. |
| 373 const Register kClassIdReg = T0; | 377 const Register kClassIdReg = T0; |
| 374 __ LoadClassId(kClassIdReg, kInstanceReg); | 378 __ LoadClassId(kClassIdReg, kInstanceReg); |
| 375 __ BranchEqual(kClassIdReg, Immediate(type_class.id()), is_instance_lbl); | 379 __ BranchEqual(kClassIdReg, Immediate(type_class.id()), is_instance_lbl); |
| 376 | 380 |
| 377 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted | 381 // See ClassFinalizer::ResolveSuperTypeAndInterfaces for list of restricted |
| 378 // interfaces. | 382 // interfaces. |
| 379 // Bool interface can be implemented only by core class Bool. | 383 // Bool interface can be implemented only by core class Bool. |
| 380 if (type.IsBoolType()) { | 384 if (type.IsBoolType()) { |
| 381 __ BranchEqual(kClassIdReg, Immediate(kBoolCid), is_instance_lbl); | 385 __ BranchEqual(kClassIdReg, Immediate(kBoolCid), is_instance_lbl); |
| 382 __ b(is_not_instance_lbl); | 386 __ b(is_not_instance_lbl); |
| 383 return false; | 387 return false; |
| 384 } | 388 } |
| 385 if (type.IsFunctionType()) { | 389 if (type.IsDartFunctionType()) { |
| 386 // Check if instance is a closure. | 390 // Check if instance is a closure. |
| 387 __ LoadClassById(T1, kClassIdReg); | 391 __ BranchEqual(kClassIdReg, Immediate(kClosureCid), is_instance_lbl); |
| 388 __ lw(T1, FieldAddress(T1, Class::signature_function_offset())); | |
| 389 __ BranchNotEqual(T1, Object::null_object(), is_instance_lbl); | |
| 390 } | 392 } |
| 391 // Custom checking for numbers (Smi, Mint, Bigint and Double). | 393 // Custom checking for numbers (Smi, Mint, Bigint and Double). |
| 392 // Note that instance is not Smi (checked above). | 394 // Note that instance is not Smi (checked above). |
| 393 if (type.IsSubtypeOf( | 395 if (type.IsSubtypeOf( |
| 394 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { | 396 Type::Handle(zone(), Type::Number()), NULL, Heap::kOld)) { |
| 395 GenerateNumberTypeCheck( | 397 GenerateNumberTypeCheck( |
| 396 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); | 398 kClassIdReg, type, is_instance_lbl, is_not_instance_lbl); |
| 397 return false; | 399 return false; |
| 398 } | 400 } |
| 399 if (type.IsStringType()) { | 401 if (type.IsStringType()) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 Label* is_instance_lbl, | 530 Label* is_instance_lbl, |
| 529 Label* is_not_instance_lbl) { | 531 Label* is_not_instance_lbl) { |
| 530 __ Comment("InlineInstanceof"); | 532 __ Comment("InlineInstanceof"); |
| 531 if (type.IsVoidType()) { | 533 if (type.IsVoidType()) { |
| 532 // A non-null value is returned from a void function, which will result in a | 534 // A non-null value is returned from a void function, which will result in a |
| 533 // type error. A null value is handled prior to executing this inline code. | 535 // type error. A null value is handled prior to executing this inline code. |
| 534 return SubtypeTestCache::null(); | 536 return SubtypeTestCache::null(); |
| 535 } | 537 } |
| 536 if (type.IsInstantiated()) { | 538 if (type.IsInstantiated()) { |
| 537 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); | 539 const Class& type_class = Class::ZoneHandle(zone(), type.type_class()); |
| 538 // A class equality check is only applicable with a dst type of a | 540 // A class equality check is only applicable with a dst type (not a |
| 539 // non-parameterized class, non-signature class, or with a raw dst type of | 541 // function type) of a non-parameterized class or with a raw dst type of |
| 540 // a parameterized class. | 542 // a parameterized class. |
| 541 if (type_class.IsSignatureClass() || (type_class.NumTypeArguments() > 0)) { | 543 if (type.IsFunctionType() || (type_class.NumTypeArguments() > 0)) { |
| 542 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, | 544 return GenerateInstantiatedTypeWithArgumentsTest(token_pos, |
| 543 type, | 545 type, |
| 544 is_instance_lbl, | 546 is_instance_lbl, |
| 545 is_not_instance_lbl); | 547 is_not_instance_lbl); |
| 546 // Fall through to runtime call. | 548 // Fall through to runtime call. |
| 547 } | 549 } |
| 548 const bool has_fall_through = | 550 const bool has_fall_through = |
| 549 GenerateInstantiatedTypeNoArgumentsTest(token_pos, | 551 GenerateInstantiatedTypeNoArgumentsTest(token_pos, |
| 550 type, | 552 type, |
| 551 is_instance_lbl, | 553 is_instance_lbl, |
| (...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 __ AddImmediate(SP, kDoubleSize); | 1898 __ AddImmediate(SP, kDoubleSize); |
| 1897 } | 1899 } |
| 1898 | 1900 |
| 1899 | 1901 |
| 1900 #undef __ | 1902 #undef __ |
| 1901 | 1903 |
| 1902 | 1904 |
| 1903 } // namespace dart | 1905 } // namespace dart |
| 1904 | 1906 |
| 1905 #endif // defined TARGET_ARCH_MIPS | 1907 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |