Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: runtime/vm/flow_graph_compiler_x64.cc

Issue 10051011: Eliminate type checks that can successfully be performed at compile time. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "vm/ast_printer.h" 10 #include "vm/ast_printer.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 442 }
443 443
444 444
445 void FlowGraphCompiler::GenerateInstantiatorTypeArguments( 445 void FlowGraphCompiler::GenerateInstantiatorTypeArguments(
446 intptr_t token_index) { 446 intptr_t token_index) {
447 Bailout("FlowGraphCompiler::GenerateInstantiatorTypeArguments"); 447 Bailout("FlowGraphCompiler::GenerateInstantiatorTypeArguments");
448 } 448 }
449 449
450 450
451 // Copied from CodeGenerator. 451 // Copied from CodeGenerator.
452 // Optimize instanceof type test by adding inlined tests for: 452 // If instanceof type test cannot be performed successfully at compile time and
453 // therefore eliminated, optimize it by adding inlined tests for:
453 // - NULL -> return false. 454 // - NULL -> return false.
454 // - Smi -> compile time subtype check (only if dst class is not parameterized). 455 // - Smi -> compile time subtype check (only if dst class is not parameterized).
455 // - Class equality (only if class is not parameterized). 456 // - Class equality (only if class is not parameterized).
456 // Inputs: 457 // Inputs:
457 // - RAX: object. 458 // - RAX: object.
458 // Destroys RCX. 459 // Destroys RCX.
459 // Returns: 460 // Returns:
460 // - true or false in RAX. 461 // - true or false in RAX.
461 void FlowGraphCompiler::GenerateInstanceOf(intptr_t node_id, 462 void FlowGraphCompiler::GenerateInstanceOf(intptr_t node_id,
462 intptr_t token_index, 463 intptr_t token_index,
463 intptr_t try_index, 464 intptr_t try_index,
465 Value* value,
464 const AbstractType& type, 466 const AbstractType& type,
465 bool negate_result) { 467 bool negate_result) {
466 ASSERT(type.IsFinalized() && !type.IsMalformed()); 468 ASSERT(type.IsFinalized() && !type.IsMalformed());
467 const Bool& bool_true = Bool::ZoneHandle(Bool::True()); 469 const Bool& bool_true = Bool::ZoneHandle(Bool::True());
468 const Bool& bool_false = Bool::ZoneHandle(Bool::False()); 470 const Bool& bool_false = Bool::ZoneHandle(Bool::False());
469 471
470 // All instances are of a subtype of the Object type. 472 // All objects are instances of type T if Object type is a subtype of type T.
471 const Type& object_type = 473 const Type& object_type =
472 Type::Handle(Isolate::Current()->object_store()->object_type()); 474 Type::Handle(Isolate::Current()->object_store()->object_type());
473 Error& malformed_error = Error::Handle(); 475 Error& malformed_error = Error::Handle();
474 if (type.IsInstantiated() && 476 if (type.IsInstantiated() &&
475 object_type.IsSubtypeOf(type, &malformed_error)) { 477 object_type.IsSubtypeOf(type, &malformed_error)) {
476 __ LoadObject(RAX, negate_result ? bool_false : bool_true); 478 __ LoadObject(RAX, negate_result ? bool_false : bool_true);
477 return; 479 return;
478 } 480 }
479 481
482 // Eliminate the test if it can be performed successfully at compile time.
483 if ((value != NULL) && value->IsConstant() && type.IsInstantiated()) {
484 // TODO(regis): A constant value should be an instance, not an object.
485 Instance& literal_value = Instance::Handle();
486 literal_value ^= value->AsConstant()->value().raw();
487 const Class& cls = Class::Handle(literal_value.clazz());
488 if (cls.IsNullClass()) {
489 ASSERT(literal_value.IsNull() ||
490 (literal_value.raw() == Object::sentinel()) ||
491 (literal_value.raw() == Object::transition_sentinel()));
492 // A null object is only an instance of Object and Dynamic, which has
493 // already been checked above (if the type is instantiated). So we can
494 // return false here if the instance is null (and if the type is
495 // instantiated).
496 __ PushObject(negate_result ? bool_true : bool_false);
497 return;
498 }
499 Error& malformed_error = Error::Handle();
500 if (literal_value.IsInstanceOf(type,
501 TypeArguments::Handle(),
502 &malformed_error)) {
503 __ PushObject(negate_result ? bool_false : bool_true);
504 return;
505 }
srdjan 2012/04/11 17:25:08 ditto (missing an else)
regis 2012/04/11 17:42:12 Done.
506 }
507
480 const Immediate raw_null = 508 const Immediate raw_null =
481 Immediate(reinterpret_cast<intptr_t>(Object::null())); 509 Immediate(reinterpret_cast<intptr_t>(Object::null()));
482 Label done; 510 Label done;
483 // If type is instantiated and non-parameterized, we can inline code 511 // If type is instantiated and non-parameterized, we can inline code
484 // checking whether the tested instance is a Smi. 512 // checking whether the tested instance is a Smi.
485 if (type.IsInstantiated()) { 513 if (type.IsInstantiated()) {
486 // A null object is only an instance of Object and Dynamic, which has 514 // A null object is only an instance of Object and Dynamic, which has
487 // already been checked above (if the type is instantiated). So we can 515 // already been checked above (if the type is instantiated). So we can
488 // return false here if the instance is null (and if the type is 516 // return false here if the instance is null (and if the type is
489 // instantiated). 517 // instantiated).
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 __ movq(RCX, FieldAddress(RAX, Object::class_offset())); 556 __ movq(RCX, FieldAddress(RAX, Object::class_offset()));
529 __ CompareObject(RCX, type_class); 557 __ CompareObject(RCX, type_class);
530 __ j(NOT_EQUAL, &runtime_call, Assembler::kNearJump); 558 __ j(NOT_EQUAL, &runtime_call, Assembler::kNearJump);
531 __ PushObject(negate_result ? bool_false : bool_true); 559 __ PushObject(negate_result ? bool_false : bool_true);
532 __ jmp(&done); 560 __ jmp(&done);
533 } 561 }
534 } 562 }
535 __ Bind(&runtime_call); 563 __ Bind(&runtime_call);
536 // Fall through to runtime call. 564 // Fall through to runtime call.
537 } else { 565 } else {
566 ASSERT(!requires_type_arguments);
567 // Test if object is Smi and for a couple known test-classes.
538 Label compare_classes; 568 Label compare_classes;
539 __ testq(RAX, Immediate(kSmiTagMask)); 569 __ testq(RAX, Immediate(kSmiTagMask));
540 __ j(NOT_ZERO, &compare_classes, Assembler::kNearJump); 570 __ j(NOT_ZERO, &compare_classes, Assembler::kNearJump);
541 // Object is Smi. 571 // Object is Smi.
542 const Class& smi_class = Class::Handle(Smi::Class()); 572 const Class& smi_class = Class::Handle(Smi::Class());
543 // TODO(regis): We should introduce a SmiType. 573 // TODO(regis): We should introduce a SmiType.
544 Error& malformed_error = Error::Handle(); 574 Error& malformed_error = Error::Handle();
545 if (smi_class.IsSubtypeOf(TypeArguments::Handle(), 575 if (smi_class.IsSubtypeOf(TypeArguments::Handle(),
546 type_class, 576 type_class,
547 TypeArguments::Handle(), 577 TypeArguments::Handle(),
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 __ Bind(&done); 636 __ Bind(&done);
607 __ popq(RAX); 637 __ popq(RAX);
608 } 638 }
609 639
610 640
611 void FlowGraphCompiler::VisitInstanceOf(InstanceOfComp* comp) { 641 void FlowGraphCompiler::VisitInstanceOf(InstanceOfComp* comp) {
612 __ popq(RAX); 642 __ popq(RAX);
613 GenerateInstanceOf(comp->node_id(), 643 GenerateInstanceOf(comp->node_id(),
614 comp->token_index(), 644 comp->token_index(),
615 comp->try_index(), 645 comp->try_index(),
646 comp->value(),
616 comp->type(), 647 comp->type(),
617 comp->negate_result()); 648 comp->negate_result());
618 } 649 }
619 650
620 651
621 void FlowGraphCompiler::VisitAllocateObject(AllocateObjectComp* comp) { 652 void FlowGraphCompiler::VisitAllocateObject(AllocateObjectComp* comp) {
622 const Class& cls = Class::ZoneHandle(comp->constructor().owner()); 653 const Class& cls = Class::ZoneHandle(comp->constructor().owner());
623 const Code& stub = Code::Handle(StubCode::GetAllocationStubForClass(cls)); 654 const Code& stub = Code::Handle(StubCode::GetAllocationStubForClass(cls));
624 const ExternalLabel label(cls.ToCString(), stub.EntryPoint()); 655 const ExternalLabel label(cls.ToCString(), stub.EntryPoint());
625 GenerateCall(comp->token_index(), comp->try_index(), &label, 656 GenerateCall(comp->token_index(), comp->try_index(), &label,
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 ASSERT(exception_handlers_list_ != NULL); 1392 ASSERT(exception_handlers_list_ != NULL);
1362 const ExceptionHandlers& handlers = ExceptionHandlers::Handle( 1393 const ExceptionHandlers& handlers = ExceptionHandlers::Handle(
1363 exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint())); 1394 exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint()));
1364 code.set_exception_handlers(handlers); 1395 code.set_exception_handlers(handlers);
1365 } 1396 }
1366 1397
1367 1398
1368 } // namespace dart 1399 } // namespace dart
1369 1400
1370 #endif // defined TARGET_ARCH_X64 1401 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698