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_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" |
11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/deopt_instructions.h" | 13 #include "vm/deopt_instructions.h" |
14 #include "vm/il_printer.h" | 14 #include "vm/il_printer.h" |
15 #include "vm/instructions.h" | 15 #include "vm/instructions.h" |
16 #include "vm/locations.h" | 16 #include "vm/locations.h" |
17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
18 #include "vm/parser.h" | 18 #include "vm/parser.h" |
19 #include "vm/stack_frame.h" | 19 #include "vm/stack_frame.h" |
20 #include "vm/stub_code.h" | 20 #include "vm/stub_code.h" |
21 #include "vm/symbols.h" | 21 #include "vm/symbols.h" |
| 22 #include "vm/code_statistics.h" |
22 | 23 |
23 namespace dart { | 24 namespace dart { |
24 | 25 |
25 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); | 26 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); |
26 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); | 27 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); |
27 DECLARE_FLAG(bool, enable_simd_inline); | 28 DECLARE_FLAG(bool, enable_simd_inline); |
28 | 29 |
29 | 30 |
30 FlowGraphCompiler::~FlowGraphCompiler() { | 31 FlowGraphCompiler::~FlowGraphCompiler() { |
31 // BlockInfos are zone-allocated, so their destructors are not called. | 32 // BlockInfos are zone-allocated, so their destructors are not called. |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 } | 976 } |
976 } | 977 } |
977 | 978 |
978 | 979 |
979 void FlowGraphCompiler::CompileGraph() { | 980 void FlowGraphCompiler::CompileGraph() { |
980 InitCompiler(); | 981 InitCompiler(); |
981 const Function& function = parsed_function().function(); | 982 const Function& function = parsed_function().function(); |
982 | 983 |
983 #ifdef DART_PRECOMPILER | 984 #ifdef DART_PRECOMPILER |
984 if (function.IsDynamicFunction()) { | 985 if (function.IsDynamicFunction()) { |
| 986 SpecialStatsBegin(CombinedCodeStatistics::kTagCheckedEntry); |
985 __ MonomorphicCheckedEntry(); | 987 __ MonomorphicCheckedEntry(); |
| 988 SpecialStatsEnd(CombinedCodeStatistics::kTagCheckedEntry); |
986 } | 989 } |
987 #endif // DART_PRECOMPILER | 990 #endif // DART_PRECOMPILER |
988 | 991 |
989 if (TryIntrinsify()) { | 992 if (TryIntrinsify()) { |
990 // Skip regular code generation. | 993 // Skip regular code generation. |
991 return; | 994 return; |
992 } | 995 } |
993 | 996 |
| 997 SpecialStatsBegin(CombinedCodeStatistics::kTagFrameEntry); |
994 EmitFrameEntry(); | 998 EmitFrameEntry(); |
| 999 SpecialStatsEnd(CombinedCodeStatistics::kTagFrameEntry); |
995 ASSERT(assembler()->constant_pool_allowed()); | 1000 ASSERT(assembler()->constant_pool_allowed()); |
996 | 1001 |
997 const int num_fixed_params = function.num_fixed_parameters(); | 1002 const int num_fixed_params = function.num_fixed_parameters(); |
998 const int num_copied_params = parsed_function().num_copied_params(); | 1003 const int num_copied_params = parsed_function().num_copied_params(); |
999 const int num_locals = parsed_function().num_stack_locals(); | 1004 const int num_locals = parsed_function().num_stack_locals(); |
1000 | 1005 |
1001 // We check the number of passed arguments when we have to copy them due to | 1006 // We check the number of passed arguments when we have to copy them due to |
1002 // the presence of optional parameters. | 1007 // the presence of optional parameters. |
1003 // No such checking code is generated if only fixed parameters are declared, | 1008 // No such checking code is generated if only fixed parameters are declared, |
1004 // unless we are in debug mode or unless we are compiling a closure. | 1009 // unless we are in debug mode or unless we are compiling a closure. |
1005 if (num_copied_params == 0) { | 1010 if (num_copied_params == 0) { |
1006 const bool check_arguments = | 1011 const bool check_arguments = |
1007 function.IsClosureFunction() && !flow_graph().IsCompiledForOsr(); | 1012 function.IsClosureFunction() && !flow_graph().IsCompiledForOsr(); |
1008 if (check_arguments) { | 1013 if (check_arguments) { |
1009 __ Comment("Check argument count"); | 1014 __ Comment("Check argument count"); |
| 1015 SpecialStatsBegin(CombinedCodeStatistics::kTagCheckArgumentCount); |
1010 // Check that exactly num_fixed arguments are passed in. | 1016 // Check that exactly num_fixed arguments are passed in. |
1011 Label correct_num_arguments, wrong_num_arguments; | 1017 Label correct_num_arguments, wrong_num_arguments; |
1012 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); | 1018 __ movq(RAX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); |
1013 __ CompareImmediate(RAX, Immediate(Smi::RawValue(num_fixed_params))); | 1019 __ CompareImmediate(RAX, Immediate(Smi::RawValue(num_fixed_params))); |
1014 __ j(NOT_EQUAL, &wrong_num_arguments, Assembler::kNearJump); | 1020 __ j(NOT_EQUAL, &wrong_num_arguments, Assembler::kNearJump); |
1015 __ cmpq(RAX, FieldAddress( | 1021 __ cmpq(RAX, FieldAddress( |
1016 R10, ArgumentsDescriptor::positional_count_offset())); | 1022 R10, ArgumentsDescriptor::positional_count_offset())); |
1017 __ j(EQUAL, &correct_num_arguments, Assembler::kNearJump); | 1023 __ j(EQUAL, &correct_num_arguments, Assembler::kNearJump); |
1018 | 1024 |
1019 __ Bind(&wrong_num_arguments); | 1025 __ Bind(&wrong_num_arguments); |
1020 __ LeaveDartFrame(kKeepCalleePP); // Leave arguments on the stack. | 1026 __ LeaveDartFrame(kKeepCalleePP); // Leave arguments on the stack. |
1021 __ Jmp(*StubCode::CallClosureNoSuchMethod_entry()); | 1027 __ Jmp(*StubCode::CallClosureNoSuchMethod_entry()); |
1022 // The noSuchMethod call may return to the caller, but not here. | 1028 // The noSuchMethod call may return to the caller, but not here. |
1023 __ Bind(&correct_num_arguments); | 1029 __ Bind(&correct_num_arguments); |
| 1030 SpecialStatsEnd(CombinedCodeStatistics::kTagCheckArgumentCount); |
1024 } | 1031 } |
1025 } else if (!flow_graph().IsCompiledForOsr()) { | 1032 } else if (!flow_graph().IsCompiledForOsr()) { |
| 1033 SpecialStatsBegin(CombinedCodeStatistics::kTagCopyParameters); |
1026 CopyParameters(); | 1034 CopyParameters(); |
| 1035 SpecialStatsEnd(CombinedCodeStatistics::kTagCopyParameters); |
1027 } | 1036 } |
1028 | 1037 |
1029 if (function.IsClosureFunction() && !flow_graph().IsCompiledForOsr()) { | 1038 if (function.IsClosureFunction() && !flow_graph().IsCompiledForOsr()) { |
| 1039 SpecialStatsBegin(CombinedCodeStatistics::kTagLoadClosureContext); |
1030 // Load context from the closure object (first argument). | 1040 // Load context from the closure object (first argument). |
1031 LocalScope* scope = parsed_function().node_sequence()->scope(); | 1041 LocalScope* scope = parsed_function().node_sequence()->scope(); |
1032 LocalVariable* closure_parameter = scope->VariableAt(0); | 1042 LocalVariable* closure_parameter = scope->VariableAt(0); |
1033 __ movq(CTX, Address(RBP, closure_parameter->index() * kWordSize)); | 1043 __ movq(CTX, Address(RBP, closure_parameter->index() * kWordSize)); |
1034 __ movq(CTX, FieldAddress(CTX, Closure::context_offset())); | 1044 __ movq(CTX, FieldAddress(CTX, Closure::context_offset())); |
1035 #ifdef DEBUG | 1045 #ifdef DEBUG |
1036 Label ok; | 1046 Label ok; |
1037 __ LoadClassId(RAX, CTX); | 1047 __ LoadClassId(RAX, CTX); |
1038 __ cmpq(RAX, Immediate(kContextCid)); | 1048 __ cmpq(RAX, Immediate(kContextCid)); |
1039 __ j(EQUAL, &ok, Assembler::kNearJump); | 1049 __ j(EQUAL, &ok, Assembler::kNearJump); |
1040 __ Stop("Incorrect context at entry"); | 1050 __ Stop("Incorrect context at entry"); |
1041 __ Bind(&ok); | 1051 __ Bind(&ok); |
1042 #endif | 1052 #endif |
| 1053 SpecialStatsEnd(CombinedCodeStatistics::kTagLoadClosureContext); |
1043 } | 1054 } |
1044 | 1055 |
1045 // In unoptimized code, initialize (non-argument) stack allocated slots to | 1056 // In unoptimized code, initialize (non-argument) stack allocated slots to |
1046 // null. | 1057 // null. |
1047 if (!is_optimizing()) { | 1058 if (!is_optimizing()) { |
1048 ASSERT(num_locals > 0); // There is always at least context_var. | 1059 ASSERT(num_locals > 0); // There is always at least context_var. |
1049 __ Comment("Initialize spill slots"); | 1060 __ Comment("Initialize spill slots"); |
1050 const intptr_t slot_base = parsed_function().first_stack_local_index(); | 1061 const intptr_t slot_base = parsed_function().first_stack_local_index(); |
1051 const intptr_t context_index = | 1062 const intptr_t context_index = |
1052 parsed_function().current_context_var()->index(); | 1063 parsed_function().current_context_var()->index(); |
(...skipping 15 matching lines...) Expand all Loading... |
1068 ASSERT(num_locals > 1); | 1079 ASSERT(num_locals > 1); |
1069 __ movq(Address(RBP, (slot_base - i) * kWordSize), RAX); | 1080 __ movq(Address(RBP, (slot_base - i) * kWordSize), RAX); |
1070 } | 1081 } |
1071 } | 1082 } |
1072 } | 1083 } |
1073 | 1084 |
1074 EndCodeSourceRange(TokenPosition::kDartCodePrologue); | 1085 EndCodeSourceRange(TokenPosition::kDartCodePrologue); |
1075 ASSERT(!block_order().is_empty()); | 1086 ASSERT(!block_order().is_empty()); |
1076 VisitBlocks(); | 1087 VisitBlocks(); |
1077 | 1088 |
| 1089 SpecialStatsBegin(CombinedCodeStatistics::kDebugAfterBody); |
1078 __ int3(); | 1090 __ int3(); |
| 1091 SpecialStatsEnd(CombinedCodeStatistics::kDebugAfterBody); |
| 1092 |
1079 ASSERT(assembler()->constant_pool_allowed()); | 1093 ASSERT(assembler()->constant_pool_allowed()); |
1080 GenerateDeferredCode(); | 1094 GenerateDeferredCode(); |
1081 } | 1095 } |
1082 | 1096 |
1083 | 1097 |
1084 void FlowGraphCompiler::GenerateCall(TokenPosition token_pos, | 1098 void FlowGraphCompiler::GenerateCall(TokenPosition token_pos, |
1085 const StubEntry& stub_entry, | 1099 const StubEntry& stub_entry, |
1086 RawPcDescriptors::Kind kind, | 1100 RawPcDescriptors::Kind kind, |
1087 LocationSummary* locs) { | 1101 LocationSummary* locs) { |
1088 __ Call(stub_entry); | 1102 __ Call(stub_entry); |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 __ movups(reg, Address(RSP, 0)); | 1791 __ movups(reg, Address(RSP, 0)); |
1778 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); | 1792 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); |
1779 } | 1793 } |
1780 | 1794 |
1781 | 1795 |
1782 #undef __ | 1796 #undef __ |
1783 | 1797 |
1784 } // namespace dart | 1798 } // namespace dart |
1785 | 1799 |
1786 #endif // defined TARGET_ARCH_X64 | 1800 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |