| 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/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 join->SetSuccessor(test_fragment.entry()); | 137 join->SetSuccessor(test_fragment.entry()); |
| 138 body_exit->SetSuccessor(join); | 138 body_exit->SetSuccessor(join); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // 3. Set the exit to the graph to be the false successor of the test, a | 141 // 3. Set the exit to the graph to be the false successor of the test, a |
| 142 // fresh target node | 142 // fresh target node |
| 143 exit_ = *test_fragment.false_successor_address() = new TargetEntryInstr(); | 143 exit_ = *test_fragment.false_successor_address() = new TargetEntryInstr(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 | 146 |
| 147 Computation* EffectGraphVisitor::BuildStoreLocal( |
| 148 const LocalVariable& local, Value* value) { |
| 149 if (local.is_captured()) { |
| 150 intptr_t delta = owner()->context_level() - |
| 151 local.owner()->context_level(); |
| 152 ASSERT(delta >= 0); |
| 153 BindInstr* context = new BindInstr(new CurrentContextComp()); |
| 154 AddInstruction(context); |
| 155 Value* context_value = new UseVal(context); |
| 156 while (delta-- > 0) { |
| 157 BindInstr* load = new BindInstr(new NativeLoadFieldComp( |
| 158 context_value, Context::parent_offset())); |
| 159 AddInstruction(load); |
| 160 context_value = new UseVal(load); |
| 161 } |
| 162 Computation* store = new NativeStoreFieldComp( |
| 163 context_value, Context::variable_offset(local.index()), value); |
| 164 return store; |
| 165 } else { |
| 166 return new StoreLocalComp(local, value, owner()->context_level()); |
| 167 } |
| 168 } |
| 169 |
| 170 |
| 171 Computation* EffectGraphVisitor::BuildLoadLocal(const LocalVariable& local) { |
| 172 if (local.is_captured()) { |
| 173 intptr_t delta = owner()->context_level() - |
| 174 local.owner()->context_level(); |
| 175 ASSERT(delta >= 0); |
| 176 BindInstr* context = new BindInstr(new CurrentContextComp()); |
| 177 AddInstruction(context); |
| 178 Value* context_value = new UseVal(context); |
| 179 while (delta-- > 0) { |
| 180 BindInstr* load = new BindInstr(new NativeLoadFieldComp( |
| 181 context_value, Context::parent_offset())); |
| 182 AddInstruction(load); |
| 183 context_value = new UseVal(load); |
| 184 } |
| 185 Computation* store = new NativeLoadFieldComp( |
| 186 context_value, Context::variable_offset(local.index())); |
| 187 return store; |
| 188 } else { |
| 189 return new LoadLocalComp(local, owner()->context_level()); |
| 190 } |
| 191 } |
| 192 |
| 193 |
| 147 // Stores current context into the 'variable' | 194 // Stores current context into the 'variable' |
| 148 void EffectGraphVisitor::BuildStoreContext(const LocalVariable& variable) { | 195 void EffectGraphVisitor::BuildStoreContext(const LocalVariable& variable) { |
| 149 BindInstr* context = new BindInstr(new CurrentContextComp()); | 196 BindInstr* context = new BindInstr(new CurrentContextComp()); |
| 150 AddInstruction(context); | 197 AddInstruction(context); |
| 151 StoreLocalComp* store_context = | 198 Computation* store_context = BuildStoreLocal(variable, new UseVal(context)); |
| 152 new StoreLocalComp(variable, new UseVal(context), | |
| 153 owner()->context_level()); | |
| 154 AddInstruction(new DoInstr(store_context)); | 199 AddInstruction(new DoInstr(store_context)); |
| 155 } | 200 } |
| 156 | 201 |
| 157 | 202 |
| 158 // Loads context saved in 'context_variable' into the current context. | 203 // Loads context saved in 'context_variable' into the current context. |
| 159 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) { | 204 void EffectGraphVisitor::BuildLoadContext(const LocalVariable& variable) { |
| 160 BindInstr* load_saved_context = | 205 BindInstr* load_saved_context = new BindInstr(BuildLoadLocal(variable)); |
| 161 new BindInstr(new LoadLocalComp(variable, owner()->context_level())); | |
| 162 AddInstruction(load_saved_context); | 206 AddInstruction(load_saved_context); |
| 163 DoInstr* store_context = | 207 DoInstr* store_context = |
| 164 new DoInstr(new StoreContextComp(new UseVal(load_saved_context))); | 208 new DoInstr(new StoreContextComp(new UseVal(load_saved_context))); |
| 165 AddInstruction(store_context); | 209 AddInstruction(store_context); |
| 166 } | 210 } |
| 167 | 211 |
| 168 | 212 |
| 169 | 213 |
| 170 void TestGraphVisitor::ReturnValue(Value* value) { | 214 void TestGraphVisitor::ReturnValue(Value* value) { |
| 171 if (FLAG_enable_type_checks) { | 215 if (FLAG_enable_type_checks) { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 right_value = new UseVal(assert_boolean); | 444 right_value = new UseVal(assert_boolean); |
| 401 } | 445 } |
| 402 BindInstr* constant_true = new BindInstr(new ConstantVal(bool_true)); | 446 BindInstr* constant_true = new BindInstr(new ConstantVal(bool_true)); |
| 403 for_right.AddInstruction(constant_true); | 447 for_right.AddInstruction(constant_true); |
| 404 BindInstr* comp = | 448 BindInstr* comp = |
| 405 new BindInstr(new StrictCompareComp(Token::kEQ_STRICT, | 449 new BindInstr(new StrictCompareComp(Token::kEQ_STRICT, |
| 406 right_value, | 450 right_value, |
| 407 new UseVal(constant_true))); | 451 new UseVal(constant_true))); |
| 408 for_right.AddInstruction(comp); | 452 for_right.AddInstruction(comp); |
| 409 for_right.AddInstruction( | 453 for_right.AddInstruction( |
| 410 new DoInstr(new StoreLocalComp( | 454 new DoInstr(BuildStoreLocal( |
| 411 *owner()->parsed_function().expression_temp_var(), | 455 *owner()->parsed_function().expression_temp_var(), |
| 412 new UseVal(comp), | 456 new UseVal(comp)))); |
| 413 owner()->context_level()))); | |
| 414 | 457 |
| 415 if (node->kind() == Token::kAND) { | 458 if (node->kind() == Token::kAND) { |
| 416 ValueGraphVisitor for_false(owner(), temp_index()); | 459 ValueGraphVisitor for_false(owner(), temp_index()); |
| 417 BindInstr* constant_false = new BindInstr(new ConstantVal(bool_false)); | 460 BindInstr* constant_false = new BindInstr(new ConstantVal(bool_false)); |
| 418 for_false.AddInstruction(constant_false); | 461 for_false.AddInstruction(constant_false); |
| 419 for_false.AddInstruction( | 462 for_false.AddInstruction( |
| 420 new DoInstr(new StoreLocalComp( | 463 new DoInstr(BuildStoreLocal( |
| 421 *owner()->parsed_function().expression_temp_var(), | 464 *owner()->parsed_function().expression_temp_var(), |
| 422 new UseVal(constant_false), | 465 new UseVal(constant_false)))); |
| 423 owner()->context_level()))); | |
| 424 Join(for_test, for_right, for_false); | 466 Join(for_test, for_right, for_false); |
| 425 } else { | 467 } else { |
| 426 ASSERT(node->kind() == Token::kOR); | 468 ASSERT(node->kind() == Token::kOR); |
| 427 ValueGraphVisitor for_true(owner(), temp_index()); | 469 ValueGraphVisitor for_true(owner(), temp_index()); |
| 428 BindInstr* constant_true = new BindInstr(new ConstantVal(bool_true)); | 470 BindInstr* constant_true = new BindInstr(new ConstantVal(bool_true)); |
| 429 for_true.AddInstruction(constant_true); | 471 for_true.AddInstruction(constant_true); |
| 430 for_true.AddInstruction( | 472 for_true.AddInstruction( |
| 431 new DoInstr(new StoreLocalComp( | 473 new DoInstr(BuildStoreLocal( |
| 432 *owner()->parsed_function().expression_temp_var(), | 474 *owner()->parsed_function().expression_temp_var(), |
| 433 new UseVal(constant_true), | 475 new UseVal(constant_true)))); |
| 434 owner()->context_level()))); | |
| 435 Join(for_test, for_true, for_right); | 476 Join(for_test, for_true, for_right); |
| 436 } | 477 } |
| 437 ReturnComputation( | 478 ReturnComputation( |
| 438 new LoadLocalComp(*owner()->parsed_function().expression_temp_var(), | 479 BuildLoadLocal(*owner()->parsed_function().expression_temp_var())); |
| 439 owner()->context_level())); | |
| 440 return; | 480 return; |
| 441 } | 481 } |
| 442 EffectGraphVisitor::VisitBinaryOpNode(node); | 482 EffectGraphVisitor::VisitBinaryOpNode(node); |
| 443 } | 483 } |
| 444 | 484 |
| 445 | 485 |
| 446 void EffectGraphVisitor::CompiletimeStringInterpolation( | 486 void EffectGraphVisitor::CompiletimeStringInterpolation( |
| 447 const Function& interpol_func, const Array& literals) { | 487 const Function& interpol_func, const Array& literals) { |
| 448 // Do nothing. | 488 // Do nothing. |
| 449 } | 489 } |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 | 804 |
| 765 void ValueGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { | 805 void ValueGraphVisitor::VisitConditionalExprNode(ConditionalExprNode* node) { |
| 766 TestGraphVisitor for_test(owner(), | 806 TestGraphVisitor for_test(owner(), |
| 767 temp_index(), | 807 temp_index(), |
| 768 node->condition()->token_index()); | 808 node->condition()->token_index()); |
| 769 node->condition()->Visit(&for_test); | 809 node->condition()->Visit(&for_test); |
| 770 | 810 |
| 771 ValueGraphVisitor for_true(owner(), temp_index()); | 811 ValueGraphVisitor for_true(owner(), temp_index()); |
| 772 node->true_expr()->Visit(&for_true); | 812 node->true_expr()->Visit(&for_true); |
| 773 ASSERT(for_true.is_open()); | 813 ASSERT(for_true.is_open()); |
| 774 for_true.AddInstruction( | 814 for_true.AddInstruction(new DoInstr(BuildStoreLocal( |
| 775 new DoInstr( | 815 *owner()->parsed_function().expression_temp_var(), for_true.value()))); |
| 776 new StoreLocalComp(*owner()->parsed_function().expression_temp_var(), | |
| 777 for_true.value(), | |
| 778 owner()->context_level()))); | |
| 779 | 816 |
| 780 ValueGraphVisitor for_false(owner(), temp_index()); | 817 ValueGraphVisitor for_false(owner(), temp_index()); |
| 781 node->false_expr()->Visit(&for_false); | 818 node->false_expr()->Visit(&for_false); |
| 782 ASSERT(for_false.is_open()); | 819 ASSERT(for_false.is_open()); |
| 783 for_false.AddInstruction( | 820 for_false.AddInstruction(new DoInstr(BuildStoreLocal( |
| 784 new DoInstr( | 821 *owner()->parsed_function().expression_temp_var(), for_false.value()))); |
| 785 new StoreLocalComp(*owner()->parsed_function().expression_temp_var(), | |
| 786 for_false.value(), | |
| 787 owner()->context_level()))); | |
| 788 | 822 |
| 789 Join(for_test, for_true, for_false); | 823 Join(for_test, for_true, for_false); |
| 790 ReturnComputation( | 824 ReturnComputation( |
| 791 new LoadLocalComp(*owner()->parsed_function().expression_temp_var(), | 825 BuildLoadLocal(*owner()->parsed_function().expression_temp_var())); |
| 792 owner()->context_level())); | |
| 793 } | 826 } |
| 794 | 827 |
| 795 | 828 |
| 796 // <Statement> ::= If { condition: <Expression> | 829 // <Statement> ::= If { condition: <Expression> |
| 797 // true_branch: <Sequence> | 830 // true_branch: <Sequence> |
| 798 // false_branch: <Sequence> } | 831 // false_branch: <Sequence> } |
| 799 void EffectGraphVisitor::VisitIfNode(IfNode* node) { | 832 void EffectGraphVisitor::VisitIfNode(IfNode* node) { |
| 800 TestGraphVisitor for_test(owner(), | 833 TestGraphVisitor for_test(owner(), |
| 801 temp_index(), | 834 temp_index(), |
| 802 node->condition()->token_index()); | 835 node->condition()->token_index()); |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 args->Add(new UseVal(type_args)); | 1539 args->Add(new UseVal(type_args)); |
| 1507 args->Add(new UseVal(no_instantiator)); | 1540 args->Add(new UseVal(no_instantiator)); |
| 1508 return; | 1541 return; |
| 1509 } | 1542 } |
| 1510 // The type arguments are uninstantiated. The generated pseudo code: | 1543 // The type arguments are uninstantiated. The generated pseudo code: |
| 1511 // t1 = InstantiatorTypeArguments(); | 1544 // t1 = InstantiatorTypeArguments(); |
| 1512 // t2 = ExtractConstructorTypeArguments(t1); | 1545 // t2 = ExtractConstructorTypeArguments(t1); |
| 1513 // t1 = ExtractConstructorInstantiator(t1, t2); | 1546 // t1 = ExtractConstructorInstantiator(t1, t2); |
| 1514 // t_n <- t2 | 1547 // t_n <- t2 |
| 1515 // t_n+1 <- t1 | 1548 // t_n+1 <- t1 |
| 1516 const intptr_t context_level = owner()->context_level(); | |
| 1517 // Use expression_temp_var and node->allocated_object_var() locals to keep | 1549 // Use expression_temp_var and node->allocated_object_var() locals to keep |
| 1518 // intermediate results around (t1 and t2 above). | 1550 // intermediate results around (t1 and t2 above). |
| 1519 ASSERT(owner()->parsed_function().expression_temp_var() != NULL); | 1551 ASSERT(owner()->parsed_function().expression_temp_var() != NULL); |
| 1520 const LocalVariable& t1 = *owner()->parsed_function().expression_temp_var(); | 1552 const LocalVariable& t1 = *owner()->parsed_function().expression_temp_var(); |
| 1521 const LocalVariable& t2 = node->allocated_object_var(); | 1553 const LocalVariable& t2 = node->allocated_object_var(); |
| 1522 | |
| 1523 Value* instantiator = BuildInstantiatorTypeArguments(node->token_index()); | 1554 Value* instantiator = BuildInstantiatorTypeArguments(node->token_index()); |
| 1524 ASSERT(instantiator->IsUse()); | 1555 ASSERT(instantiator->IsUse()); |
| 1525 Definition* stored_instantiator = new BindInstr(new StoreLocalComp( | 1556 Definition* stored_instantiator = new BindInstr( |
| 1526 t1, instantiator, context_level)); | 1557 BuildStoreLocal(t1, instantiator)); |
| 1527 AddInstruction(stored_instantiator); | 1558 AddInstruction(stored_instantiator); |
| 1528 // t1: instantiator type arguments. | 1559 // t1: instantiator type arguments. |
| 1529 | 1560 |
| 1530 BindInstr* extract_type_arguments = new BindInstr( | 1561 BindInstr* extract_type_arguments = new BindInstr( |
| 1531 new ExtractConstructorTypeArgumentsComp( | 1562 new ExtractConstructorTypeArgumentsComp( |
| 1532 node->token_index(), | 1563 node->token_index(), |
| 1533 owner()->try_index(), | 1564 owner()->try_index(), |
| 1534 node->type_arguments(), | 1565 node->type_arguments(), |
| 1535 new UseVal(stored_instantiator))); | 1566 new UseVal(stored_instantiator))); |
| 1536 AddInstruction(extract_type_arguments); | 1567 AddInstruction(extract_type_arguments); |
| 1537 | 1568 |
| 1538 Instruction* stored_type_arguments = new DoInstr(new StoreLocalComp( | 1569 Instruction* stored_type_arguments = new DoInstr( |
| 1539 t2, new UseVal(extract_type_arguments), context_level)); | 1570 BuildStoreLocal(t2, new UseVal(extract_type_arguments))); |
| 1540 AddInstruction(stored_type_arguments); | 1571 AddInstruction(stored_type_arguments); |
| 1541 // t2: extracted constructor type arguments. | 1572 // t2: extracted constructor type arguments. |
| 1542 Definition* load_instantiator = new BindInstr( | 1573 Definition* load_instantiator = new BindInstr(BuildLoadLocal(t1)); |
| 1543 new LoadLocalComp(t1, context_level)); | |
| 1544 AddInstruction(load_instantiator); | 1574 AddInstruction(load_instantiator); |
| 1545 Definition* load_type_arguments = new BindInstr( | 1575 Definition* load_type_arguments = new BindInstr(BuildLoadLocal(t2)); |
| 1546 new LoadLocalComp(t2, context_level)); | |
| 1547 AddInstruction(load_type_arguments); | 1576 AddInstruction(load_type_arguments); |
| 1548 | 1577 |
| 1549 BindInstr* extract_instantiator = | 1578 BindInstr* extract_instantiator = |
| 1550 new BindInstr(new ExtractConstructorInstantiatorComp( | 1579 new BindInstr(new ExtractConstructorInstantiatorComp( |
| 1551 node, | 1580 node, |
| 1552 new UseVal(load_instantiator), | 1581 new UseVal(load_instantiator), |
| 1553 new UseVal(load_type_arguments))); | 1582 new UseVal(load_type_arguments))); |
| 1554 AddInstruction(extract_instantiator); | 1583 AddInstruction(extract_instantiator); |
| 1555 AddInstruction(new DoInstr(new StoreLocalComp( | 1584 AddInstruction(new DoInstr( |
| 1556 t1, new UseVal(extract_instantiator), context_level))); | 1585 BuildStoreLocal(t1, new UseVal(extract_instantiator)))); |
| 1557 // t2: extracted constructor type arguments. | 1586 // t2: extracted constructor type arguments. |
| 1558 // t1: extracted constructor instantiator. | 1587 // t1: extracted constructor instantiator. |
| 1559 Definition* load_0 = new BindInstr(new LoadLocalComp(t2, context_level)); | 1588 Definition* load_0 = new BindInstr(BuildLoadLocal(t2)); |
| 1560 AddInstruction(load_0); | 1589 AddInstruction(load_0); |
| 1561 Definition* load_1 = new BindInstr(new LoadLocalComp(t1, context_level)); | 1590 Definition* load_1 = new BindInstr(BuildLoadLocal(t1)); |
| 1562 AddInstruction(load_1); | 1591 AddInstruction(load_1); |
| 1563 args->Add(new UseVal(load_0)); | 1592 args->Add(new UseVal(load_0)); |
| 1564 args->Add(new UseVal(load_1)); | 1593 args->Add(new UseVal(load_1)); |
| 1565 } | 1594 } |
| 1566 | 1595 |
| 1567 | 1596 |
| 1568 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { | 1597 void ValueGraphVisitor::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 1569 if (node->constructor().IsFactory()) { | 1598 if (node->constructor().IsFactory()) { |
| 1570 EffectGraphVisitor::VisitConstructorCallNode(node); | 1599 EffectGraphVisitor::VisitConstructorCallNode(node); |
| 1571 return; | 1600 return; |
| 1572 } | 1601 } |
| 1573 | 1602 |
| 1574 // t_n contains the allocated and initialized object. | 1603 // t_n contains the allocated and initialized object. |
| 1575 // t_n <- AllocateObject(class) | 1604 // t_n <- AllocateObject(class) |
| 1576 // t_n <- StoreLocal(temp, t_n); | 1605 // t_n <- StoreLocal(temp, t_n); |
| 1577 // t_n+1 <- ctor-arg | 1606 // t_n+1 <- ctor-arg |
| 1578 // t_n+2... <- constructor arguments start here | 1607 // t_n+2... <- constructor arguments start here |
| 1579 // StaticCall(constructor, t_n, t_n+1, ...) | 1608 // StaticCall(constructor, t_n, t_n+1, ...) |
| 1580 // tn <- LoadLocal(temp) | 1609 // tn <- LoadLocal(temp) |
| 1581 | 1610 |
| 1582 Definition* allocate = BuildObjectAllocation(node); | 1611 Definition* allocate = BuildObjectAllocation(node); |
| 1583 StoreLocalComp* store_allocated = new StoreLocalComp( | 1612 Computation* store_allocated = BuildStoreLocal( |
| 1584 node->allocated_object_var(), | 1613 node->allocated_object_var(), |
| 1585 new UseVal(allocate), | 1614 new UseVal(allocate)); |
| 1586 owner()->context_level()); | |
| 1587 Definition* allocated_value = new BindInstr(store_allocated); | 1615 Definition* allocated_value = new BindInstr(store_allocated); |
| 1588 AddInstruction(allocated_value); | 1616 AddInstruction(allocated_value); |
| 1589 BuildConstructorCall(node, new UseVal(allocated_value)); | 1617 BuildConstructorCall(node, new UseVal(allocated_value)); |
| 1590 LoadLocalComp* load_allocated = new LoadLocalComp( | 1618 Computation* load_allocated = BuildLoadLocal( |
| 1591 node->allocated_object_var(), | 1619 node->allocated_object_var()); |
| 1592 owner()->context_level()); | |
| 1593 allocated_value = new BindInstr(load_allocated); | 1620 allocated_value = new BindInstr(load_allocated); |
| 1594 AddInstruction(allocated_value); | 1621 AddInstruction(allocated_value); |
| 1595 ReturnValue(new UseVal(allocated_value)); | 1622 ReturnValue(new UseVal(allocated_value)); |
| 1596 } | 1623 } |
| 1597 | 1624 |
| 1598 | 1625 |
| 1599 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { | 1626 void EffectGraphVisitor::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 1600 ValueGraphVisitor for_receiver(owner(), temp_index()); | 1627 ValueGraphVisitor for_receiver(owner(), temp_index()); |
| 1601 node->receiver()->Visit(&for_receiver); | 1628 node->receiver()->Visit(&for_receiver); |
| 1602 Append(for_receiver); | 1629 Append(for_receiver); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 if (node->HasPseudo()) { | 1706 if (node->HasPseudo()) { |
| 1680 EffectGraphVisitor for_pseudo(owner(), temp_index()); | 1707 EffectGraphVisitor for_pseudo(owner(), temp_index()); |
| 1681 node->pseudo()->Visit(&for_pseudo); | 1708 node->pseudo()->Visit(&for_pseudo); |
| 1682 Append(for_pseudo); | 1709 Append(for_pseudo); |
| 1683 } | 1710 } |
| 1684 } | 1711 } |
| 1685 | 1712 |
| 1686 | 1713 |
| 1687 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { | 1714 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { |
| 1688 EffectGraphVisitor::VisitLoadLocalNode(node); | 1715 EffectGraphVisitor::VisitLoadLocalNode(node); |
| 1689 LoadLocalComp* load = new LoadLocalComp(node->local(), | 1716 Computation* load = BuildLoadLocal(node->local()); |
| 1690 owner()->context_level()); | |
| 1691 ReturnComputation(load); | 1717 ReturnComputation(load); |
| 1692 } | 1718 } |
| 1693 | 1719 |
| 1694 | 1720 |
| 1695 // <Expression> ::= StoreLocal { local: LocalVariable | 1721 // <Expression> ::= StoreLocal { local: LocalVariable |
| 1696 // value: <Expression> } | 1722 // value: <Expression> } |
| 1697 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) { | 1723 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) { |
| 1698 ValueGraphVisitor for_value(owner(), temp_index()); | 1724 ValueGraphVisitor for_value(owner(), temp_index()); |
| 1699 node->value()->Visit(&for_value); | 1725 node->value()->Visit(&for_value); |
| 1700 Append(for_value); | 1726 Append(for_value); |
| 1701 Value* store_value = for_value.value(); | 1727 Value* store_value = for_value.value(); |
| 1702 if (FLAG_enable_type_checks) { | 1728 if (FLAG_enable_type_checks) { |
| 1703 store_value = BuildAssignableValue(node->value(), | 1729 store_value = BuildAssignableValue(node->value(), |
| 1704 store_value, | 1730 store_value, |
| 1705 node->local().type(), | 1731 node->local().type(), |
| 1706 node->local().name()); | 1732 node->local().name()); |
| 1707 } | 1733 } |
| 1708 StoreLocalComp* store = | 1734 Computation* store = BuildStoreLocal(node->local(), store_value); |
| 1709 new StoreLocalComp(node->local(), store_value, owner()->context_level()); | |
| 1710 ReturnComputation(store); | 1735 ReturnComputation(store); |
| 1711 } | 1736 } |
| 1712 | 1737 |
| 1713 | 1738 |
| 1714 void EffectGraphVisitor::VisitLoadInstanceFieldNode( | 1739 void EffectGraphVisitor::VisitLoadInstanceFieldNode( |
| 1715 LoadInstanceFieldNode* node) { | 1740 LoadInstanceFieldNode* node) { |
| 1716 ValueGraphVisitor for_instance(owner(), temp_index()); | 1741 ValueGraphVisitor for_instance(owner(), temp_index()); |
| 1717 node->instance()->Visit(&for_instance); | 1742 node->instance()->Visit(&for_instance); |
| 1718 Append(for_instance); | 1743 Append(for_instance); |
| 1719 LoadInstanceFieldComp* load = | 1744 LoadInstanceFieldComp* load = |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1843 num_context_variables)); | 1868 num_context_variables)); |
| 1844 AddInstruction(allocated_context); | 1869 AddInstruction(allocated_context); |
| 1845 | 1870 |
| 1846 // If this node_sequence is the body of the function being compiled, and if | 1871 // If this node_sequence is the body of the function being compiled, and if |
| 1847 // this function is not a closure, do not link the current context as the | 1872 // this function is not a closure, do not link the current context as the |
| 1848 // parent of the newly allocated context, as it is not accessible. Instead, | 1873 // parent of the newly allocated context, as it is not accessible. Instead, |
| 1849 // save it in a pre-allocated variable and restore it on exit. | 1874 // save it in a pre-allocated variable and restore it on exit. |
| 1850 if (MustSaveRestoreContext(node)) { | 1875 if (MustSaveRestoreContext(node)) { |
| 1851 BindInstr* current_context = new BindInstr(new CurrentContextComp()); | 1876 BindInstr* current_context = new BindInstr(new CurrentContextComp()); |
| 1852 AddInstruction(current_context); | 1877 AddInstruction(current_context); |
| 1853 StoreLocalComp* store_local = new StoreLocalComp( | 1878 Computation* store_local = BuildStoreLocal( |
| 1854 *owner()->parsed_function().saved_context_var(), | 1879 *owner()->parsed_function().saved_context_var(), |
| 1855 new UseVal(current_context), | 1880 new UseVal(current_context)); |
| 1856 0); | |
| 1857 AddInstruction(new DoInstr(store_local)); | 1881 AddInstruction(new DoInstr(store_local)); |
| 1858 BindInstr* null_context = | 1882 BindInstr* null_context = |
| 1859 new BindInstr(new ConstantVal(Object::ZoneHandle())); | 1883 new BindInstr(new ConstantVal(Object::ZoneHandle())); |
| 1860 AddInstruction(null_context); | 1884 AddInstruction(null_context); |
| 1861 StoreContextComp* store_context = | 1885 StoreContextComp* store_context = |
| 1862 new StoreContextComp(new UseVal(null_context)); | 1886 new StoreContextComp(new UseVal(null_context)); |
| 1863 AddInstruction(new DoInstr(store_context)); | 1887 AddInstruction(new DoInstr(store_context)); |
| 1864 } | 1888 } |
| 1865 | 1889 |
| 1866 ChainContextComp* chain_context = | 1890 ChainContextComp* chain_context = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1883 // Create a temporary local describing the original position. | 1907 // Create a temporary local describing the original position. |
| 1884 const String& temp_name = String::ZoneHandle(String::Concat( | 1908 const String& temp_name = String::ZoneHandle(String::Concat( |
| 1885 parameter.name(), String::Handle(String::NewSymbol("-orig")))); | 1909 parameter.name(), String::Handle(String::NewSymbol("-orig")))); |
| 1886 LocalVariable* temp_local = new LocalVariable( | 1910 LocalVariable* temp_local = new LocalVariable( |
| 1887 0, // Token index. | 1911 0, // Token index. |
| 1888 temp_name, | 1912 temp_name, |
| 1889 Type::ZoneHandle(Type::DynamicType())); // Type. | 1913 Type::ZoneHandle(Type::DynamicType())); // Type. |
| 1890 temp_local->set_index(param_frame_index); | 1914 temp_local->set_index(param_frame_index); |
| 1891 | 1915 |
| 1892 // Copy parameter from local frame to current context. | 1916 // Copy parameter from local frame to current context. |
| 1893 BindInstr* load = | 1917 BindInstr* load = new BindInstr(BuildLoadLocal(*temp_local)); |
| 1894 new BindInstr(new LoadLocalComp(*temp_local, | |
| 1895 owner()->context_level())); | |
| 1896 AddInstruction(load); | 1918 AddInstruction(load); |
| 1897 StoreLocalComp* store_local = new StoreLocalComp( | 1919 Computation* store_local = |
| 1898 parameter, | 1920 BuildStoreLocal(parameter, new UseVal(load)); |
| 1899 new UseVal(load), | |
| 1900 owner()->context_level()); | |
| 1901 AddInstruction(new DoInstr(store_local)); | 1921 AddInstruction(new DoInstr(store_local)); |
| 1902 // Write NULL to the source location to detect buggy accesses and | 1922 // Write NULL to the source location to detect buggy accesses and |
| 1903 // allow GC of passed value if it gets overwritten by a new value in | 1923 // allow GC of passed value if it gets overwritten by a new value in |
| 1904 // the function. | 1924 // the function. |
| 1905 BindInstr* null_constant = | 1925 BindInstr* null_constant = |
| 1906 new BindInstr(new ConstantVal(Object::ZoneHandle())); | 1926 new BindInstr(new ConstantVal(Object::ZoneHandle())); |
| 1907 AddInstruction(null_constant); | 1927 AddInstruction(null_constant); |
| 1908 StoreLocalComp* clear_local = new StoreLocalComp( | 1928 Computation* clear_local = |
| 1909 *temp_local, | 1929 BuildStoreLocal(*temp_local, new UseVal(null_constant)); |
| 1910 new UseVal(null_constant), | |
| 1911 owner()->context_level()); | |
| 1912 AddInstruction(new DoInstr(clear_local)); | 1930 AddInstruction(new DoInstr(clear_local)); |
| 1913 } | 1931 } |
| 1914 } | 1932 } |
| 1915 } | 1933 } |
| 1916 } | 1934 } |
| 1917 | 1935 |
| 1918 if (FLAG_enable_type_checks && | 1936 if (FLAG_enable_type_checks && |
| 1919 (node == owner()->parsed_function().node_sequence())) { | 1937 (node == owner()->parsed_function().node_sequence())) { |
| 1920 const int num_params = | 1938 const int num_params = |
| 1921 owner()->parsed_function().function().NumberOfParameters(); | 1939 owner()->parsed_function().function().NumberOfParameters(); |
| 1922 for (int pos = 0; pos < num_params; pos++) { | 1940 for (int pos = 0; pos < num_params; pos++) { |
| 1923 const LocalVariable& parameter = *scope->VariableAt(pos); | 1941 const LocalVariable& parameter = *scope->VariableAt(pos); |
| 1924 ASSERT(parameter.owner() == scope); | 1942 ASSERT(parameter.owner() == scope); |
| 1925 if (!CanSkipTypeCheck(NULL, parameter.type())) { | 1943 if (!CanSkipTypeCheck(NULL, parameter.type())) { |
| 1926 BindInstr* load = | 1944 BindInstr* load = new BindInstr(BuildLoadLocal(parameter)); |
| 1927 new BindInstr(new LoadLocalComp(parameter, | |
| 1928 owner()->context_level())); | |
| 1929 AddInstruction(load); | 1945 AddInstruction(load); |
| 1930 BuildAssertAssignable(parameter.token_index(), | 1946 BuildAssertAssignable(parameter.token_index(), |
| 1931 new UseVal(load), | 1947 new UseVal(load), |
| 1932 parameter.type(), | 1948 parameter.type(), |
| 1933 parameter.name()); | 1949 parameter.name()); |
| 1934 } | 1950 } |
| 1935 } | 1951 } |
| 1936 } | 1952 } |
| 1937 | 1953 |
| 1938 intptr_t i = 0; | 1954 intptr_t i = 0; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 char* chars = reinterpret_cast<char*>( | 2251 char* chars = reinterpret_cast<char*>( |
| 2236 Isolate::Current()->current_zone()->Allocate(len)); | 2252 Isolate::Current()->current_zone()->Allocate(len)); |
| 2237 OS::SNPrint(chars, len, kFormat, function_name, reason); | 2253 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 2238 const Error& error = Error::Handle( | 2254 const Error& error = Error::Handle( |
| 2239 LanguageError::New(String::Handle(String::New(chars)))); | 2255 LanguageError::New(String::Handle(String::New(chars)))); |
| 2240 Isolate::Current()->long_jump_base()->Jump(1, error); | 2256 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 2241 } | 2257 } |
| 2242 | 2258 |
| 2243 | 2259 |
| 2244 } // namespace dart | 2260 } // namespace dart |
| OLD | NEW |