| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 value); | 819 value); |
| 820 } | 820 } |
| 821 | 821 |
| 822 | 822 |
| 823 Definition* EffectGraphVisitor::BuildLoadExprTemp() { | 823 Definition* EffectGraphVisitor::BuildLoadExprTemp() { |
| 824 return BuildLoadLocal(*owner()->parsed_function().expression_temp_var()); | 824 return BuildLoadLocal(*owner()->parsed_function().expression_temp_var()); |
| 825 } | 825 } |
| 826 | 826 |
| 827 | 827 |
| 828 Definition* EffectGraphVisitor::BuildStoreLocal(const LocalVariable& local, | 828 Definition* EffectGraphVisitor::BuildStoreLocal(const LocalVariable& local, |
| 829 Value* value) { | 829 Value* value, |
| 830 intptr_t token_pos) { |
| 830 if (local.is_captured()) { | 831 if (local.is_captured()) { |
| 831 LocalVariable* tmp_var = EnterTempLocalScope(value); | 832 LocalVariable* tmp_var = EnterTempLocalScope(value); |
| 832 intptr_t delta = | 833 intptr_t delta = |
| 833 owner()->context_level() - local.owner()->context_level(); | 834 owner()->context_level() - local.owner()->context_level(); |
| 834 ASSERT(delta >= 0); | 835 ASSERT(delta >= 0); |
| 835 Value* context = Bind(BuildCurrentContext()); | 836 Value* context = Bind(BuildCurrentContext()); |
| 836 while (delta-- > 0) { | 837 while (delta-- > 0) { |
| 837 context = Bind(new(Z) LoadFieldInstr( | 838 context = Bind(new(Z) LoadFieldInstr( |
| 838 context, Context::parent_offset(), Type::ZoneHandle(Z, Type::null()), | 839 context, Context::parent_offset(), Type::ZoneHandle(Z, Type::null()), |
| 839 Scanner::kNoSourcePos)); | 840 token_pos)); |
| 840 } | 841 } |
| 841 Value* tmp_val = Bind(new(Z) LoadLocalInstr(*tmp_var)); | 842 Value* tmp_val = Bind(new(Z) LoadLocalInstr(*tmp_var)); |
| 842 StoreInstanceFieldInstr* store = | 843 StoreInstanceFieldInstr* store = |
| 843 new(Z) StoreInstanceFieldInstr(Context::variable_offset(local.index()), | 844 new(Z) StoreInstanceFieldInstr(Context::variable_offset(local.index()), |
| 844 context, | 845 context, |
| 845 tmp_val, | 846 tmp_val, |
| 846 kEmitStoreBarrier, | 847 kEmitStoreBarrier, |
| 847 Scanner::kNoSourcePos); | 848 token_pos); |
| 848 Do(store); | 849 Do(store); |
| 849 return ExitTempLocalScope(tmp_var); | 850 return ExitTempLocalScope(tmp_var); |
| 850 } else { | 851 } else { |
| 851 return new(Z) StoreLocalInstr(local, value); | 852 return new(Z) StoreLocalInstr(local, value, token_pos); |
| 852 } | 853 } |
| 853 } | 854 } |
| 854 | 855 |
| 855 | 856 |
| 856 Definition* EffectGraphVisitor::BuildLoadLocal(const LocalVariable& local) { | 857 Definition* EffectGraphVisitor::BuildLoadLocal(const LocalVariable& local, |
| 858 intptr_t token_pos) { |
| 857 if (local.IsConst()) { | 859 if (local.IsConst()) { |
| 858 return new(Z) ConstantInstr(*local.ConstValue(), local.token_pos()); | 860 return new(Z) ConstantInstr(*local.ConstValue(), token_pos); |
| 859 } else if (local.is_captured()) { | 861 } else if (local.is_captured()) { |
| 860 intptr_t delta = | 862 intptr_t delta = |
| 861 owner()->context_level() - local.owner()->context_level(); | 863 owner()->context_level() - local.owner()->context_level(); |
| 862 ASSERT(delta >= 0); | 864 ASSERT(delta >= 0); |
| 863 Value* context = Bind(BuildCurrentContext()); | 865 Value* context = Bind(BuildCurrentContext()); |
| 864 while (delta-- > 0) { | 866 while (delta-- > 0) { |
| 865 context = Bind(new(Z) LoadFieldInstr( | 867 context = Bind(new(Z) LoadFieldInstr( |
| 866 context, Context::parent_offset(), Type::ZoneHandle(Z, Type::null()), | 868 context, Context::parent_offset(), Type::ZoneHandle(Z, Type::null()), |
| 867 Scanner::kNoSourcePos)); | 869 token_pos)); |
| 868 } | 870 } |
| 869 return new(Z) LoadFieldInstr(context, | 871 return new(Z) LoadFieldInstr(context, |
| 870 Context::variable_offset(local.index()), | 872 Context::variable_offset(local.index()), |
| 871 local.type(), | 873 local.type(), |
| 872 Scanner::kNoSourcePos); | 874 token_pos); |
| 873 } else { | 875 } else { |
| 874 return new(Z) LoadLocalInstr(local); | 876 return new(Z) LoadLocalInstr(local, token_pos); |
| 875 } | 877 } |
| 876 } | 878 } |
| 877 | 879 |
| 878 | 880 |
| 879 // Stores current context into the 'variable' | 881 // Stores current context into the 'variable' |
| 880 void EffectGraphVisitor::BuildSaveContext(const LocalVariable& variable) { | 882 void EffectGraphVisitor::BuildSaveContext(const LocalVariable& variable) { |
| 881 Value* context = Bind(BuildCurrentContext()); | 883 Value* context = Bind(BuildCurrentContext()); |
| 882 Do(BuildStoreLocal(variable, context)); | 884 Do(BuildStoreLocal(variable, context)); |
| 883 } | 885 } |
| 884 | 886 |
| (...skipping 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3576 } | 3578 } |
| 3577 | 3579 |
| 3578 | 3580 |
| 3579 // <Expression> ::= LoadLocal { local: LocalVariable } | 3581 // <Expression> ::= LoadLocal { local: LocalVariable } |
| 3580 void EffectGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { | 3582 void EffectGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { |
| 3581 // Nothing to do. | 3583 // Nothing to do. |
| 3582 } | 3584 } |
| 3583 | 3585 |
| 3584 | 3586 |
| 3585 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { | 3587 void ValueGraphVisitor::VisitLoadLocalNode(LoadLocalNode* node) { |
| 3586 Definition* load = BuildLoadLocal(node->local()); | 3588 Definition* load = BuildLoadLocal(node->local(), node->token_pos()); |
| 3587 ReturnDefinition(load); | 3589 ReturnDefinition(load); |
| 3588 } | 3590 } |
| 3589 | 3591 |
| 3590 | 3592 |
| 3591 // <Expression> ::= StoreLocal { local: LocalVariable | 3593 // <Expression> ::= StoreLocal { local: LocalVariable |
| 3592 // value: <Expression> } | 3594 // value: <Expression> } |
| 3593 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) { | 3595 void EffectGraphVisitor::VisitStoreLocalNode(StoreLocalNode* node) { |
| 3594 // If the right hand side is an expression that does not contain | 3596 // If the right hand side is an expression that does not contain |
| 3595 // a safe point for the debugger to stop, add an explicit stub | 3597 // a safe point for the debugger to stop, add an explicit stub |
| 3596 // call. Exception: don't do this when assigning to or from internal | 3598 // call. Exception: don't do this when assigning to or from internal |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3610 ValueGraphVisitor for_value(owner()); | 3612 ValueGraphVisitor for_value(owner()); |
| 3611 node->value()->Visit(&for_value); | 3613 node->value()->Visit(&for_value); |
| 3612 Append(for_value); | 3614 Append(for_value); |
| 3613 Value* store_value = for_value.value(); | 3615 Value* store_value = for_value.value(); |
| 3614 if (Isolate::Current()->flags().type_checks()) { | 3616 if (Isolate::Current()->flags().type_checks()) { |
| 3615 store_value = BuildAssignableValue(node->value()->token_pos(), | 3617 store_value = BuildAssignableValue(node->value()->token_pos(), |
| 3616 store_value, | 3618 store_value, |
| 3617 node->local().type(), | 3619 node->local().type(), |
| 3618 node->local().name()); | 3620 node->local().name()); |
| 3619 } | 3621 } |
| 3620 Definition* store = BuildStoreLocal(node->local(), store_value); | 3622 Definition* store = BuildStoreLocal(node->local(), |
| 3623 store_value, |
| 3624 node->token_pos()); |
| 3621 ReturnDefinition(store); | 3625 ReturnDefinition(store); |
| 3622 } | 3626 } |
| 3623 | 3627 |
| 3624 | 3628 |
| 3625 void EffectGraphVisitor::VisitLoadInstanceFieldNode( | 3629 void EffectGraphVisitor::VisitLoadInstanceFieldNode( |
| 3626 LoadInstanceFieldNode* node) { | 3630 LoadInstanceFieldNode* node) { |
| 3627 ValueGraphVisitor for_instance(owner()); | 3631 ValueGraphVisitor for_instance(owner()); |
| 3628 node->instance()->Visit(&for_instance); | 3632 node->instance()->Visit(&for_instance); |
| 3629 Append(for_instance); | 3633 Append(for_instance); |
| 3630 LoadFieldInstr* load = new(Z) LoadFieldInstr( | 3634 LoadFieldInstr* load = new(Z) LoadFieldInstr( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3683 store_value, | 3687 store_value, |
| 3684 kEmitStoreBarrier, | 3688 kEmitStoreBarrier, |
| 3685 node->token_pos()); | 3689 node->token_pos()); |
| 3686 // Maybe initializing unboxed store. | 3690 // Maybe initializing unboxed store. |
| 3687 store->set_is_potential_unboxed_initialization(true); | 3691 store->set_is_potential_unboxed_initialization(true); |
| 3688 ReturnDefinition(store); | 3692 ReturnDefinition(store); |
| 3689 } | 3693 } |
| 3690 | 3694 |
| 3691 | 3695 |
| 3692 void EffectGraphVisitor::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { | 3696 void EffectGraphVisitor::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { |
| 3697 const intptr_t token_pos = node->token_pos(); |
| 3693 if (node->field().is_const()) { | 3698 if (node->field().is_const()) { |
| 3694 ASSERT(node->field().StaticValue() != Object::sentinel().raw()); | 3699 ASSERT(node->field().StaticValue() != Object::sentinel().raw()); |
| 3695 ASSERT(node->field().StaticValue() != | 3700 ASSERT(node->field().StaticValue() != |
| 3696 Object::transition_sentinel().raw()); | 3701 Object::transition_sentinel().raw()); |
| 3697 Definition* result = new(Z) ConstantInstr( | 3702 Definition* result = new(Z) ConstantInstr( |
| 3698 Instance::ZoneHandle(Z, node->field().StaticValue())); | 3703 Instance::ZoneHandle(Z, node->field().StaticValue()), token_pos); |
| 3699 return ReturnDefinition(result); | 3704 return ReturnDefinition(result); |
| 3700 } | 3705 } |
| 3701 Value* field_value = Bind(new(Z) ConstantInstr(node->field())); | 3706 Value* field_value = Bind(new(Z) ConstantInstr(node->field(), token_pos)); |
| 3702 LoadStaticFieldInstr* load = new(Z) LoadStaticFieldInstr(field_value); | 3707 LoadStaticFieldInstr* load = |
| 3708 new(Z) LoadStaticFieldInstr(field_value, token_pos); |
| 3703 ReturnDefinition(load); | 3709 ReturnDefinition(load); |
| 3704 } | 3710 } |
| 3705 | 3711 |
| 3706 | 3712 |
| 3707 Definition* EffectGraphVisitor::BuildStoreStaticField( | 3713 Definition* EffectGraphVisitor::BuildStoreStaticField( |
| 3708 StoreStaticFieldNode* node, bool result_is_needed) { | 3714 StoreStaticFieldNode* node, bool result_is_needed) { |
| 3709 ValueGraphVisitor for_value(owner()); | 3715 ValueGraphVisitor for_value(owner()); |
| 3710 node->value()->Visit(&for_value); | 3716 node->value()->Visit(&for_value); |
| 3711 Append(for_value); | 3717 Append(for_value); |
| 3712 Value* store_value = NULL; | 3718 Value* store_value = NULL; |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4582 Report::MessageF(Report::kBailout, | 4588 Report::MessageF(Report::kBailout, |
| 4583 Script::Handle(function.script()), | 4589 Script::Handle(function.script()), |
| 4584 function.token_pos(), | 4590 function.token_pos(), |
| 4585 "FlowGraphBuilder Bailout: %s %s", | 4591 "FlowGraphBuilder Bailout: %s %s", |
| 4586 String::Handle(function.name()).ToCString(), | 4592 String::Handle(function.name()).ToCString(), |
| 4587 reason); | 4593 reason); |
| 4588 UNREACHABLE(); | 4594 UNREACHABLE(); |
| 4589 } | 4595 } |
| 4590 | 4596 |
| 4591 } // namespace dart | 4597 } // namespace dart |
| OLD | NEW |