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_XXX. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX. |
6 | 6 |
7 #include "vm/flow_graph_compiler.h" | 7 #include "vm/flow_graph_compiler.h" |
8 | 8 |
9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
10 #include "vm/cha.h" | 10 #include "vm/cha.h" |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } else if (instr->MayThrow() && | 437 } else if (instr->MayThrow() && |
438 (CurrentTryIndex() != CatchClauseNode::kInvalidTryIndex)) { | 438 (CurrentTryIndex() != CatchClauseNode::kInvalidTryIndex)) { |
439 // Optimized try-block: Sync locals to fixed stack locations. | 439 // Optimized try-block: Sync locals to fixed stack locations. |
440 EmitTrySync(instr, CurrentTryIndex()); | 440 EmitTrySync(instr, CurrentTryIndex()); |
441 } | 441 } |
442 } | 442 } |
443 | 443 |
444 | 444 |
445 | 445 |
446 void FlowGraphCompiler::EmitSourceLine(Instruction* instr) { | 446 void FlowGraphCompiler::EmitSourceLine(Instruction* instr) { |
447 if ((instr->token_pos() < 0) || (instr->env() == NULL)) { | 447 if (!instr->token_pos().IsReal() || (instr->env() == NULL)) { |
448 return; | 448 return; |
449 } | 449 } |
450 const Script& script = | 450 const Script& script = |
451 Script::Handle(zone(), instr->env()->function().script()); | 451 Script::Handle(zone(), instr->env()->function().script()); |
452 intptr_t line_nr; | 452 intptr_t line_nr; |
453 intptr_t column_nr; | 453 intptr_t column_nr; |
454 script.GetTokenLocation(instr->token_pos(), &line_nr, &column_nr); | 454 script.GetTokenLocation(instr->token_pos(), &line_nr, &column_nr); |
455 const String& line = String::Handle(zone(), script.GetLine(line_nr)); | 455 const String& line = String::Handle(zone(), script.GetLine(line_nr)); |
456 assembler()->Comment("Line %" Pd " in '%s':\n %s", | 456 assembler()->Comment("Line %" Pd " in '%s':\n %s", |
457 line_nr, | 457 line_nr, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 | 752 |
753 | 753 |
754 void FlowGraphCompiler::SetNeedsStacktrace(intptr_t try_index) { | 754 void FlowGraphCompiler::SetNeedsStacktrace(intptr_t try_index) { |
755 exception_handlers_list_->SetNeedsStacktrace(try_index); | 755 exception_handlers_list_->SetNeedsStacktrace(try_index); |
756 } | 756 } |
757 | 757 |
758 | 758 |
759 // Uses current pc position and try-index. | 759 // Uses current pc position and try-index. |
760 void FlowGraphCompiler::AddCurrentDescriptor(RawPcDescriptors::Kind kind, | 760 void FlowGraphCompiler::AddCurrentDescriptor(RawPcDescriptors::Kind kind, |
761 intptr_t deopt_id, | 761 intptr_t deopt_id, |
762 intptr_t token_pos) { | 762 TokenPosition token_pos) { |
763 // When running with optimizations disabled, don't emit deopt-descriptors. | 763 // When running with optimizations disabled, don't emit deopt-descriptors. |
764 if (!CanOptimize() && (kind == RawPcDescriptors::kDeopt)) return; | 764 if (!CanOptimize() && (kind == RawPcDescriptors::kDeopt)) return; |
765 pc_descriptors_list()->AddDescriptor(kind, | 765 pc_descriptors_list()->AddDescriptor(kind, |
766 assembler()->CodeSize(), | 766 assembler()->CodeSize(), |
767 deopt_id, | 767 deopt_id, |
768 token_pos, | 768 token_pos, |
769 CurrentTryIndex()); | 769 CurrentTryIndex()); |
770 } | 770 } |
771 | 771 |
772 | 772 |
773 void FlowGraphCompiler::AddStaticCallTarget(const Function& func) { | 773 void FlowGraphCompiler::AddStaticCallTarget(const Function& func) { |
774 ASSERT(func.IsZoneHandle()); | 774 ASSERT(func.IsZoneHandle()); |
775 static_calls_target_table_.Add( | 775 static_calls_target_table_.Add( |
776 new(zone()) StaticCallsStruct(assembler()->CodeSize(), &func, NULL)); | 776 new(zone()) StaticCallsStruct(assembler()->CodeSize(), &func, NULL)); |
777 } | 777 } |
778 | 778 |
779 | 779 |
780 void FlowGraphCompiler::AddStubCallTarget(const Code& code) { | 780 void FlowGraphCompiler::AddStubCallTarget(const Code& code) { |
781 ASSERT(code.IsZoneHandle()); | 781 ASSERT(code.IsZoneHandle()); |
782 static_calls_target_table_.Add( | 782 static_calls_target_table_.Add( |
783 new(zone()) StaticCallsStruct(assembler()->CodeSize(), NULL, &code)); | 783 new(zone()) StaticCallsStruct(assembler()->CodeSize(), NULL, &code)); |
784 } | 784 } |
785 | 785 |
786 | 786 |
787 void FlowGraphCompiler::AddDeoptIndexAtCall(intptr_t deopt_id, | 787 void FlowGraphCompiler::AddDeoptIndexAtCall(intptr_t deopt_id, |
788 intptr_t token_pos) { | 788 TokenPosition token_pos) { |
789 ASSERT(is_optimizing()); | 789 ASSERT(is_optimizing()); |
790 ASSERT(!intrinsic_mode()); | 790 ASSERT(!intrinsic_mode()); |
791 CompilerDeoptInfo* info = | 791 CompilerDeoptInfo* info = |
792 new(zone()) CompilerDeoptInfo(deopt_id, | 792 new(zone()) CompilerDeoptInfo(deopt_id, |
793 ICData::kDeoptAtCall, | 793 ICData::kDeoptAtCall, |
794 0, // No flags. | 794 0, // No flags. |
795 pending_deoptimization_env_); | 795 pending_deoptimization_env_); |
796 info->set_pc_offset(assembler()->CodeSize()); | 796 info->set_pc_offset(assembler()->CodeSize()); |
797 deopt_infos_.Add(info); | 797 deopt_infos_.Add(info); |
798 } | 798 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 if (parsed_function().node_sequence() == NULL) { | 1037 if (parsed_function().node_sequence() == NULL) { |
1038 // Eager local var descriptors computation for Irregexp function as it is | 1038 // Eager local var descriptors computation for Irregexp function as it is |
1039 // complicated to factor out. | 1039 // complicated to factor out. |
1040 // TODO(srdjan): Consider canonicalizing and reusing the local var | 1040 // TODO(srdjan): Consider canonicalizing and reusing the local var |
1041 // descriptor for IrregexpFunction. | 1041 // descriptor for IrregexpFunction. |
1042 ASSERT(flow_graph().IsIrregexpFunction()); | 1042 ASSERT(flow_graph().IsIrregexpFunction()); |
1043 var_descs = LocalVarDescriptors::New(1); | 1043 var_descs = LocalVarDescriptors::New(1); |
1044 RawLocalVarDescriptors::VarInfo info; | 1044 RawLocalVarDescriptors::VarInfo info; |
1045 info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); | 1045 info.set_kind(RawLocalVarDescriptors::kSavedCurrentContext); |
1046 info.scope_id = 0; | 1046 info.scope_id = 0; |
1047 info.begin_pos = 0; | 1047 info.begin_pos = TokenPosition::kMinSource; |
1048 info.end_pos = 0; | 1048 info.end_pos = TokenPosition::kMinSource; |
1049 info.set_index(parsed_function().current_context_var()->index()); | 1049 info.set_index(parsed_function().current_context_var()->index()); |
1050 var_descs.SetVar(0, Symbols::CurrentContextVar(), &info); | 1050 var_descs.SetVar(0, Symbols::CurrentContextVar(), &info); |
1051 } | 1051 } |
1052 code.set_var_descriptors(var_descs); | 1052 code.set_var_descriptors(var_descs); |
1053 } | 1053 } |
1054 | 1054 |
1055 | 1055 |
1056 void FlowGraphCompiler::FinalizeStaticCallTargetsTable(const Code& code) { | 1056 void FlowGraphCompiler::FinalizeStaticCallTargetsTable(const Code& code) { |
1057 ASSERT(code.static_calls_target_table() == Array::null()); | 1057 ASSERT(code.static_calls_target_table() == Array::null()); |
1058 const Array& targets = Array::Handle(zone(), Array::New( | 1058 const Array& targets = Array::Handle(zone(), Array::New( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 // This means that there must not be any side-effects in intrinsic code | 1128 // This means that there must not be any side-effects in intrinsic code |
1129 // before any deoptimization point. | 1129 // before any deoptimization point. |
1130 ASSERT(!intrinsic_slow_path_label_.IsBound()); | 1130 ASSERT(!intrinsic_slow_path_label_.IsBound()); |
1131 assembler()->Bind(&intrinsic_slow_path_label_); | 1131 assembler()->Bind(&intrinsic_slow_path_label_); |
1132 return false; | 1132 return false; |
1133 } | 1133 } |
1134 | 1134 |
1135 | 1135 |
1136 void FlowGraphCompiler::GenerateInstanceCall( | 1136 void FlowGraphCompiler::GenerateInstanceCall( |
1137 intptr_t deopt_id, | 1137 intptr_t deopt_id, |
1138 intptr_t token_pos, | 1138 TokenPosition token_pos, |
1139 intptr_t argument_count, | 1139 intptr_t argument_count, |
1140 LocationSummary* locs, | 1140 LocationSummary* locs, |
1141 const ICData& ic_data_in) { | 1141 const ICData& ic_data_in) { |
1142 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); | 1142 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); |
1143 if (FLAG_precompilation) { | 1143 if (FLAG_precompilation) { |
1144 EmitSwitchableInstanceCall(ic_data, argument_count, | 1144 EmitSwitchableInstanceCall(ic_data, argument_count, |
1145 deopt_id, token_pos, locs); | 1145 deopt_id, token_pos, locs); |
1146 return; | 1146 return; |
1147 } | 1147 } |
1148 if (FLAG_always_megamorphic_calls) { | 1148 if (FLAG_always_megamorphic_calls) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 *StubCode::TwoArgsCheckInlineCache_entry(), ic_data, argument_count, | 1194 *StubCode::TwoArgsCheckInlineCache_entry(), ic_data, argument_count, |
1195 deopt_id, token_pos, locs); | 1195 deopt_id, token_pos, locs); |
1196 break; | 1196 break; |
1197 default: | 1197 default: |
1198 UNIMPLEMENTED(); | 1198 UNIMPLEMENTED(); |
1199 } | 1199 } |
1200 } | 1200 } |
1201 | 1201 |
1202 | 1202 |
1203 void FlowGraphCompiler::GenerateStaticCall(intptr_t deopt_id, | 1203 void FlowGraphCompiler::GenerateStaticCall(intptr_t deopt_id, |
1204 intptr_t token_pos, | 1204 TokenPosition token_pos, |
1205 const Function& function, | 1205 const Function& function, |
1206 intptr_t argument_count, | 1206 intptr_t argument_count, |
1207 const Array& argument_names, | 1207 const Array& argument_names, |
1208 LocationSummary* locs, | 1208 LocationSummary* locs, |
1209 const ICData& ic_data_in) { | 1209 const ICData& ic_data_in) { |
1210 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); | 1210 const ICData& ic_data = ICData::ZoneHandle(ic_data_in.Original()); |
1211 const Array& arguments_descriptor = Array::ZoneHandle( | 1211 const Array& arguments_descriptor = Array::ZoneHandle( |
1212 ic_data.IsNull() ? ArgumentsDescriptor::New(argument_count, | 1212 ic_data.IsNull() ? ArgumentsDescriptor::New(argument_count, |
1213 argument_names) | 1213 argument_names) |
1214 : ic_data.arguments_descriptor()); | 1214 : ic_data.arguments_descriptor()); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 } | 1773 } |
1774 return res.raw(); | 1774 return res.raw(); |
1775 } | 1775 } |
1776 | 1776 |
1777 | 1777 |
1778 void FlowGraphCompiler::EmitPolymorphicInstanceCall( | 1778 void FlowGraphCompiler::EmitPolymorphicInstanceCall( |
1779 const ICData& ic_data, | 1779 const ICData& ic_data, |
1780 intptr_t argument_count, | 1780 intptr_t argument_count, |
1781 const Array& argument_names, | 1781 const Array& argument_names, |
1782 intptr_t deopt_id, | 1782 intptr_t deopt_id, |
1783 intptr_t token_pos, | 1783 TokenPosition token_pos, |
1784 LocationSummary* locs) { | 1784 LocationSummary* locs) { |
1785 if (FLAG_polymorphic_with_deopt) { | 1785 if (FLAG_polymorphic_with_deopt) { |
1786 Label* deopt = AddDeoptStub(deopt_id, | 1786 Label* deopt = AddDeoptStub(deopt_id, |
1787 ICData::kDeoptPolymorphicInstanceCallTestFail); | 1787 ICData::kDeoptPolymorphicInstanceCallTestFail); |
1788 Label ok; | 1788 Label ok; |
1789 EmitTestAndCall(ic_data, argument_count, argument_names, | 1789 EmitTestAndCall(ic_data, argument_count, argument_names, |
1790 deopt, // No cid match. | 1790 deopt, // No cid match. |
1791 &ok, // Found cid. | 1791 &ok, // Found cid. |
1792 deopt_id, token_pos, locs); | 1792 deopt_id, token_pos, locs); |
1793 assembler()->Bind(&ok); | 1793 assembler()->Bind(&ok); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1878 | 1878 |
1879 | 1879 |
1880 void FlowGraphCompiler::FrameStateClear() { | 1880 void FlowGraphCompiler::FrameStateClear() { |
1881 ASSERT(!is_optimizing()); | 1881 ASSERT(!is_optimizing()); |
1882 frame_state_.TruncateTo(0); | 1882 frame_state_.TruncateTo(0); |
1883 } | 1883 } |
1884 #endif | 1884 #endif |
1885 | 1885 |
1886 | 1886 |
1887 } // namespace dart | 1887 } // namespace dart |
OLD | NEW |