Chromium Code Reviews| 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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 if (node->kind() == Token::kAND) { | 552 if (node->kind() == Token::kAND) { |
| 553 Join(for_left, for_right, empty); | 553 Join(for_left, for_right, empty); |
| 554 } else { | 554 } else { |
| 555 Join(for_left, empty, for_right); | 555 Join(for_left, empty, for_right); |
| 556 } | 556 } |
| 557 return; | 557 return; |
| 558 } | 558 } |
| 559 ValueGraphVisitor for_left_value(owner(), temp_index()); | 559 ValueGraphVisitor for_left_value(owner(), temp_index()); |
| 560 node->left()->Visit(&for_left_value); | 560 node->left()->Visit(&for_left_value); |
| 561 Append(for_left_value); | 561 Append(for_left_value); |
| 562 PushArgumentInstr* push_left = PushArgument(for_left_value.value()); | |
| 563 | |
| 562 ValueGraphVisitor for_right_value(owner(), temp_index()); | 564 ValueGraphVisitor for_right_value(owner(), temp_index()); |
| 563 node->right()->Visit(&for_right_value); | 565 node->right()->Visit(&for_right_value); |
| 564 Append(for_right_value); | 566 Append(for_right_value); |
| 565 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(2); | 567 PushArgumentInstr* push_right = PushArgument(for_right_value.value()); |
| 566 arguments->Add(for_left_value.value()); | 568 |
| 567 arguments->Add(for_right_value.value()); | 569 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 570 new ZoneGrowableArray<PushArgumentInstr*>(2); | |
| 571 arguments->Add(push_left); | |
| 572 arguments->Add(push_right); | |
| 568 const String& name = String::ZoneHandle(Symbols::New(node->Name())); | 573 const String& name = String::ZoneHandle(Symbols::New(node->Name())); |
| 569 InstanceCallComp* call = new InstanceCallComp(node->token_pos(), | 574 InstanceCallComp* call = new InstanceCallComp(node->token_pos(), |
| 570 owner()->try_index(), | 575 owner()->try_index(), |
| 571 name, | 576 name, |
| 572 node->kind(), | 577 node->kind(), |
| 573 arguments, | 578 arguments, |
| 574 Array::ZoneHandle(), | 579 Array::ZoneHandle(), |
| 575 2); | 580 2); |
| 576 ReturnComputation(call); | 581 ReturnComputation(call); |
| 577 } | 582 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 owner()->try_index(), | 906 owner()->try_index(), |
| 902 value)); | 907 value)); |
| 903 } | 908 } |
| 904 BooleanNegateComp* negate = new BooleanNegateComp(value); | 909 BooleanNegateComp* negate = new BooleanNegateComp(value); |
| 905 ReturnComputation(negate); | 910 ReturnComputation(negate); |
| 906 return; | 911 return; |
| 907 } | 912 } |
| 908 ValueGraphVisitor for_value(owner(), temp_index()); | 913 ValueGraphVisitor for_value(owner(), temp_index()); |
| 909 node->operand()->Visit(&for_value); | 914 node->operand()->Visit(&for_value); |
| 910 Append(for_value); | 915 Append(for_value); |
| 911 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); | 916 PushArgumentInstr* push_value = PushArgument(for_value.value()); |
| 912 arguments->Add(for_value.value()); | 917 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 918 new ZoneGrowableArray<PushArgumentInstr*>(1); | |
| 919 arguments->Add(push_value); | |
| 913 Token::Kind token_kind = | 920 Token::Kind token_kind = |
| 914 (node->kind() == Token::kSUB) ? Token::kNEGATE : node->kind(); | 921 (node->kind() == Token::kSUB) ? Token::kNEGATE : node->kind(); |
| 915 | |
| 916 const String& name = | 922 const String& name = |
| 917 String::ZoneHandle(Symbols::New(Token::Str(token_kind))); | 923 String::ZoneHandle(Symbols::New(Token::Str(token_kind))); |
| 918 InstanceCallComp* call = new InstanceCallComp( | 924 InstanceCallComp* call = new InstanceCallComp( |
| 919 node->token_pos(), owner()->try_index(), name, token_kind, | 925 node->token_pos(), owner()->try_index(), name, token_kind, |
| 920 arguments, Array::ZoneHandle(), 1); | 926 arguments, Array::ZoneHandle(), 1); |
| 921 ReturnComputation(call); | 927 ReturnComputation(call); |
| 922 } | 928 } |
| 923 | 929 |
| 924 | 930 |
| 925 void EffectGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { | 931 void EffectGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1419 ValueGraphVisitor for_argument(owner(), temp_index()); | 1425 ValueGraphVisitor for_argument(owner(), temp_index()); |
| 1420 node.NodeAt(i)->Visit(&for_argument); | 1426 node.NodeAt(i)->Visit(&for_argument); |
| 1421 Append(for_argument); | 1427 Append(for_argument); |
| 1422 PushArgumentInstr* push_arg = PushArgument(for_argument.value()); | 1428 PushArgumentInstr* push_arg = PushArgument(for_argument.value()); |
| 1423 values->Add(push_arg); | 1429 values->Add(push_arg); |
| 1424 } | 1430 } |
| 1425 } | 1431 } |
| 1426 | 1432 |
| 1427 | 1433 |
| 1428 void EffectGraphVisitor::VisitInstanceCallNode(InstanceCallNode* node) { | 1434 void EffectGraphVisitor::VisitInstanceCallNode(InstanceCallNode* node) { |
| 1429 ArgumentListNode* arguments = node->arguments(); | 1435 int length = node->arguments()->length(); |
|
Vyacheslav Egorov (Google)
2012/07/30 13:17:58
const int length
Florian Schneider
2012/07/30 13:26:14
Done.
| |
| 1430 int length = arguments->length(); | |
| 1431 ZoneGrowableArray<Value*>* values = new ZoneGrowableArray<Value*>(length + 1); | |
| 1432 | 1436 |
| 1433 ValueGraphVisitor for_receiver(owner(), temp_index()); | 1437 ValueGraphVisitor for_receiver(owner(), temp_index()); |
| 1434 node->receiver()->Visit(&for_receiver); | 1438 node->receiver()->Visit(&for_receiver); |
| 1435 Append(for_receiver); | 1439 Append(for_receiver); |
| 1436 values->Add(for_receiver.value()); | 1440 PushArgumentInstr* push_receiver = PushArgument(for_receiver.value()); |
| 1441 ZoneGrowableArray<PushArgumentInstr*>* arguments = | |
| 1442 new ZoneGrowableArray<PushArgumentInstr*>(length + 1); | |
| 1443 arguments->Add(push_receiver); | |
| 1437 | 1444 |
| 1438 TranslateArgumentList(*arguments, values); | 1445 BuildPushArguments(*node->arguments(), arguments); |
| 1439 InstanceCallComp* call = new InstanceCallComp( | 1446 InstanceCallComp* call = new InstanceCallComp( |
| 1440 node->token_pos(), owner()->try_index(), | 1447 node->token_pos(), owner()->try_index(), |
| 1441 node->function_name(), Token::kILLEGAL, values, | 1448 node->function_name(), Token::kILLEGAL, arguments, |
| 1442 arguments->names(), 1); | 1449 node->arguments()->names(), 1); |
| 1443 ReturnComputation(call); | 1450 ReturnComputation(call); |
| 1444 } | 1451 } |
| 1445 | 1452 |
| 1446 | 1453 |
| 1447 // <Expression> ::= StaticCall { function: Function | 1454 // <Expression> ::= StaticCall { function: Function |
| 1448 // arguments: <ArgumentList> } | 1455 // arguments: <ArgumentList> } |
| 1449 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { | 1456 void EffectGraphVisitor::VisitStaticCallNode(StaticCallNode* node) { |
| 1450 int length = node->arguments()->length(); | 1457 int length = node->arguments()->length(); |
| 1451 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 1458 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 1452 new ZoneGrowableArray<PushArgumentInstr*>(length); | 1459 new ZoneGrowableArray<PushArgumentInstr*>(length); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1763 node->allocated_object_var()); | 1770 node->allocated_object_var()); |
| 1764 allocated_value = Bind(load_allocated); | 1771 allocated_value = Bind(load_allocated); |
| 1765 ReturnValue(allocated_value); | 1772 ReturnValue(allocated_value); |
| 1766 } | 1773 } |
| 1767 | 1774 |
| 1768 | 1775 |
| 1769 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { | 1776 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 1770 ValueGraphVisitor for_receiver(owner(), temp_index()); | 1777 ValueGraphVisitor for_receiver(owner(), temp_index()); |
| 1771 node->receiver()->Visit(&for_receiver); | 1778 node->receiver()->Visit(&for_receiver); |
| 1772 Append(for_receiver); | 1779 Append(for_receiver); |
| 1773 ZoneGrowableArray<Value*>* arguments = new ZoneGrowableArray<Value*>(1); | 1780 PushArgumentInstr* push_receiver = PushArgument(for_receiver.value()); |
| 1774 arguments->Add(for_receiver.value()); | 1781 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 1782 new ZoneGrowableArray<PushArgumentInstr*>(1); | |
| 1783 arguments->Add(push_receiver); | |
| 1775 const String& name = | 1784 const String& name = |
| 1776 String::ZoneHandle(Field::GetterSymbol(node->field_name())); | 1785 String::ZoneHandle(Field::GetterSymbol(node->field_name())); |
| 1777 InstanceCallComp* call = new InstanceCallComp( | 1786 InstanceCallComp* call = new InstanceCallComp( |
| 1778 node->token_pos(), owner()->try_index(), name, Token::kGET, | 1787 node->token_pos(), owner()->try_index(), name, Token::kGET, |
| 1779 arguments, Array::ZoneHandle(), 1); | 1788 arguments, Array::ZoneHandle(), 1); |
| 1780 ReturnComputation(call); | 1789 ReturnComputation(call); |
| 1781 } | 1790 } |
| 1782 | 1791 |
| 1783 | 1792 |
| 1784 void EffectGraphVisitor::BuildInstanceSetterValues( | 1793 void EffectGraphVisitor::BuildInstanceSetterValues( |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2651 if ((as_bind != NULL) && as_bind->computation()->IsStoreLocal()) { | 2660 if ((as_bind != NULL) && as_bind->computation()->IsStoreLocal()) { |
| 2652 // For each use of a StoreLocal: Replace it with the value from the | 2661 // For each use of a StoreLocal: Replace it with the value from the |
| 2653 // environment. | 2662 // environment. |
| 2654 Computation* comp = as_bind->computation(); | 2663 Computation* comp = as_bind->computation(); |
| 2655 intptr_t index = | 2664 intptr_t index = |
| 2656 comp->AsStoreLocal()->local().BitIndexIn(fixed_parameter_count); | 2665 comp->AsStoreLocal()->local().BitIndexIn(fixed_parameter_count); |
| 2657 current->SetInputAt(i, CopyValue((*env)[index])); | 2666 current->SetInputAt(i, CopyValue((*env)[index])); |
| 2658 } | 2667 } |
| 2659 } | 2668 } |
| 2660 | 2669 |
| 2670 // Drop pushed arguments for calls. | |
| 2671 for (intptr_t j = 0; j < current->ArgumentCount(); j++) { | |
| 2672 env->RemoveLast(); | |
| 2673 } | |
| 2674 | |
| 2661 // 2b. Handle LoadLocal and StoreLocal. | 2675 // 2b. Handle LoadLocal and StoreLocal. |
| 2662 // For each LoadLocal: Remove it from the graph. | 2676 // For each LoadLocal: Remove it from the graph. |
| 2663 // For each StoreLocal: Remove it from the graph and update the environment. | 2677 // For each StoreLocal: Remove it from the graph and update the environment. |
| 2664 BindInstr* bind = current->AsBind(); | 2678 BindInstr* bind = current->AsBind(); |
| 2665 if (bind != NULL) { | 2679 if (bind != NULL) { |
| 2666 LoadLocalComp* load = bind->computation()->AsLoadLocal(); | 2680 LoadLocalComp* load = bind->computation()->AsLoadLocal(); |
| 2667 StoreLocalComp* store = bind->computation()->AsStoreLocal(); | 2681 StoreLocalComp* store = bind->computation()->AsStoreLocal(); |
| 2668 if ((load != NULL) || (store != NULL)) { | 2682 if ((load != NULL) || (store != NULL)) { |
| 2669 intptr_t index; | 2683 intptr_t index; |
| 2670 if (store != NULL) { | 2684 if (store != NULL) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2684 it.RemoveCurrentFromGraph(); | 2698 it.RemoveCurrentFromGraph(); |
| 2685 } else { | 2699 } else { |
| 2686 // Not a load or store. | 2700 // Not a load or store. |
| 2687 if (bind->is_used()) { | 2701 if (bind->is_used()) { |
| 2688 // Assign fresh SSA temporary and update expression stack. | 2702 // Assign fresh SSA temporary and update expression stack. |
| 2689 bind->set_ssa_temp_index(alloc_ssa_temp_index()); | 2703 bind->set_ssa_temp_index(alloc_ssa_temp_index()); |
| 2690 env->Add(new UseVal(bind)); | 2704 env->Add(new UseVal(bind)); |
| 2691 } | 2705 } |
| 2692 } | 2706 } |
| 2693 } | 2707 } |
| 2708 | |
| 2709 // 2c. Handle pushed argument. | |
| 2710 PushArgumentInstr* push = current->AsPushArgument(); | |
| 2711 if (push != NULL) { | |
| 2712 env->Add(push->value()); | |
| 2713 } | |
| 2694 } | 2714 } |
| 2695 | 2715 |
| 2696 // 3. Process dominated blocks. | 2716 // 3. Process dominated blocks. |
| 2697 for (intptr_t i = 0; i < block_entry->dominated_blocks().length(); ++i) { | 2717 for (intptr_t i = 0; i < block_entry->dominated_blocks().length(); ++i) { |
| 2698 BlockEntryInstr* block = block_entry->dominated_blocks()[i]; | 2718 BlockEntryInstr* block = block_entry->dominated_blocks()[i]; |
| 2699 GrowableArray<Value*> new_env(env->length()); | 2719 GrowableArray<Value*> new_env(env->length()); |
| 2700 new_env.AddArray(*env); | 2720 new_env.AddArray(*env); |
| 2701 RenameRecursive(block, &new_env, var_count, fixed_parameter_count); | 2721 RenameRecursive(block, &new_env, var_count, fixed_parameter_count); |
| 2702 } | 2722 } |
| 2703 | 2723 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 2732 char* chars = reinterpret_cast<char*>( | 2752 char* chars = reinterpret_cast<char*>( |
| 2733 Isolate::Current()->current_zone()->Allocate(len)); | 2753 Isolate::Current()->current_zone()->Allocate(len)); |
| 2734 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2754 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2735 const Error& error = Error::Handle( | 2755 const Error& error = Error::Handle( |
| 2736 LanguageError::New(String::Handle(String::New(chars)))); | 2756 LanguageError::New(String::Handle(String::New(chars)))); |
| 2737 Isolate::Current()->long_jump_base()->Jump(1, error); | 2757 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2738 } | 2758 } |
| 2739 | 2759 |
| 2740 | 2760 |
| 2741 } // namespace dart | 2761 } // namespace dart |
| OLD | NEW |