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/compiler.h" | 5 #include "vm/compiler.h" |
6 | 6 |
7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
8 | 8 |
9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 } | 888 } |
889 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 889 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
890 | 890 |
891 // Optimize (a << b) & c patterns, merge operations. | 891 // Optimize (a << b) & c patterns, merge operations. |
892 // Run early in order to have more opportunity to optimize left shifts. | 892 // Run early in order to have more opportunity to optimize left shifts. |
893 flow_graph->TryOptimizePatterns(); | 893 flow_graph->TryOptimizePatterns(); |
894 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 894 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
895 | 895 |
896 FlowGraphInliner::SetInliningId(flow_graph, 0); | 896 FlowGraphInliner::SetInliningId(flow_graph, 0); |
897 | 897 |
| 898 int inlining_depth = 0; |
| 899 |
898 // Inlining (mutates the flow graph) | 900 // Inlining (mutates the flow graph) |
899 if (FLAG_use_inlining) { | 901 if (FLAG_use_inlining) { |
900 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, | 902 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, |
901 "Inlining")); | 903 "Inlining")); |
902 CSTAT_TIMER_SCOPE(thread(), graphinliner_timer); | 904 CSTAT_TIMER_SCOPE(thread(), graphinliner_timer); |
903 // Propagate types to create more inlining opportunities. | 905 // Propagate types to create more inlining opportunities. |
904 FlowGraphTypePropagator::Propagate(flow_graph); | 906 FlowGraphTypePropagator::Propagate(flow_graph); |
905 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 907 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
906 | 908 |
907 // Use propagated class-ids to create more inlining opportunities. | 909 // Use propagated class-ids to create more inlining opportunities. |
908 optimizer.ApplyClassIds(); | 910 optimizer.ApplyClassIds(); |
909 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 911 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
910 | 912 |
911 FlowGraphInliner inliner(flow_graph, &inline_id_to_function, | 913 FlowGraphInliner inliner(flow_graph, &inline_id_to_function, |
912 &inline_id_to_token_pos, &caller_inline_id, | 914 &inline_id_to_token_pos, &caller_inline_id, |
913 use_speculative_inlining, | 915 use_speculative_inlining, |
914 /*inlining_black_list=*/NULL, | 916 /*inlining_black_list=*/NULL, |
915 /*precompiler=*/NULL); | 917 /*precompiler=*/NULL); |
916 inliner.Inline(); | 918 inlining_depth = inliner.Inline(); |
917 // Use lists are maintained and validated by the inliner. | 919 // Use lists are maintained and validated by the inliner. |
918 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 920 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
919 thread()->CheckForSafepoint(); | 921 thread()->CheckForSafepoint(); |
920 } | 922 } |
921 | 923 |
922 // Propagate types and eliminate more type tests. | 924 // Propagate types and eliminate more type tests. |
923 FlowGraphTypePropagator::Propagate(flow_graph); | 925 FlowGraphTypePropagator::Propagate(flow_graph); |
924 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 926 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
925 | 927 |
926 { | 928 { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // Remove all MaterializeObject instructions inserted by allocation | 1147 // Remove all MaterializeObject instructions inserted by allocation |
1146 // sinking from the flow graph and let them float on the side | 1148 // sinking from the flow graph and let them float on the side |
1147 // referenced only from environments. Register allocator will consider | 1149 // referenced only from environments. Register allocator will consider |
1148 // them as part of a deoptimization environment. | 1150 // them as part of a deoptimization environment. |
1149 sinking->DetachMaterializations(); | 1151 sinking->DetachMaterializations(); |
1150 } | 1152 } |
1151 | 1153 |
1152 // Compute and store graph informations (call & instruction counts) | 1154 // Compute and store graph informations (call & instruction counts) |
1153 // to be later used by the inliner. | 1155 // to be later used by the inliner. |
1154 FlowGraphInliner::CollectGraphInfo(flow_graph, true); | 1156 FlowGraphInliner::CollectGraphInfo(flow_graph, true); |
| 1157 function.set_inlining_depth(inlining_depth); |
1155 | 1158 |
1156 flow_graph->RemoveRedefinitions(); | 1159 flow_graph->RemoveRedefinitions(); |
1157 { | 1160 { |
1158 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, | 1161 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, |
1159 "AllocateRegisters")); | 1162 "AllocateRegisters")); |
1160 // Perform register allocation on the SSA graph. | 1163 // Perform register allocation on the SSA graph. |
1161 FlowGraphAllocator allocator(*flow_graph); | 1164 FlowGraphAllocator allocator(*flow_graph); |
1162 allocator.AllocateRegisters(); | 1165 allocator.AllocateRegisters(); |
1163 thread()->CheckForSafepoint(); | 1166 thread()->CheckForSafepoint(); |
1164 } | 1167 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 thread()->set_deopt_id(prev_deopt_id); | 1257 thread()->set_deopt_id(prev_deopt_id); |
1255 } | 1258 } |
1256 return result->raw(); | 1259 return result->raw(); |
1257 } | 1260 } |
1258 | 1261 |
1259 static RawObject* CompileFunctionHelper(CompilationPipeline* pipeline, | 1262 static RawObject* CompileFunctionHelper(CompilationPipeline* pipeline, |
1260 const Function& function, | 1263 const Function& function, |
1261 bool optimized, | 1264 bool optimized, |
1262 intptr_t osr_id) { | 1265 intptr_t osr_id) { |
1263 ASSERT(!FLAG_precompiled_mode); | 1266 ASSERT(!FLAG_precompiled_mode); |
1264 ASSERT(!optimized || function.was_compiled()); | 1267 ASSERT(!optimized || function.WasCompiled()); |
1265 LongJumpScope jump; | 1268 LongJumpScope jump; |
1266 if (setjmp(*jump.Set()) == 0) { | 1269 if (setjmp(*jump.Set()) == 0) { |
1267 Thread* const thread = Thread::Current(); | 1270 Thread* const thread = Thread::Current(); |
1268 Isolate* const isolate = thread->isolate(); | 1271 Isolate* const isolate = thread->isolate(); |
1269 StackZone stack_zone(thread); | 1272 StackZone stack_zone(thread); |
1270 Zone* const zone = stack_zone.GetZone(); | 1273 Zone* const zone = stack_zone.GetZone(); |
1271 const bool trace_compiler = | 1274 const bool trace_compiler = |
1272 FLAG_trace_compiler || (FLAG_trace_optimizing_compiler && optimized); | 1275 FLAG_trace_compiler || (FLAG_trace_optimizing_compiler && optimized); |
1273 Timer per_compile_timer(trace_compiler, "Compilation time"); | 1276 Timer per_compile_timer(trace_compiler, "Compilation time"); |
1274 per_compile_timer.Start(); | 1277 per_compile_timer.Start(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 // changed while compiling. | 1314 // changed while compiling. |
1312 Compiler::AbortBackgroundCompilation( | 1315 Compiler::AbortBackgroundCompilation( |
1313 Thread::kNoDeoptId, | 1316 Thread::kNoDeoptId, |
1314 "Invalidated state during parsing because of script loading"); | 1317 "Invalidated state during parsing because of script loading"); |
1315 } | 1318 } |
1316 } | 1319 } |
1317 | 1320 |
1318 const Code& result = Code::Handle(helper.Compile(pipeline)); | 1321 const Code& result = Code::Handle(helper.Compile(pipeline)); |
1319 if (!result.IsNull()) { | 1322 if (!result.IsNull()) { |
1320 if (!optimized) { | 1323 if (!optimized) { |
1321 function.set_was_compiled(true); | 1324 function.SetWasCompiled(true); |
1322 } | 1325 } |
1323 } else { | 1326 } else { |
1324 if (optimized) { | 1327 if (optimized) { |
1325 if (Compiler::IsBackgroundCompilation()) { | 1328 if (Compiler::IsBackgroundCompilation()) { |
1326 // Try again later, background compilation may abort because of | 1329 // Try again later, background compilation may abort because of |
1327 // state change during compilation. | 1330 // state change during compilation. |
1328 if (FLAG_trace_compiler) { | 1331 if (FLAG_trace_compiler) { |
1329 THR_Print("Aborted background compilation: %s\n", | 1332 THR_Print("Aborted background compilation: %s\n", |
1330 function.ToFullyQualifiedCString()); | 1333 function.ToFullyQualifiedCString()); |
1331 } | 1334 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 } | 1422 } |
1420 UNREACHABLE(); | 1423 UNREACHABLE(); |
1421 return Object::null(); | 1424 return Object::null(); |
1422 } | 1425 } |
1423 | 1426 |
1424 static RawError* ParseFunctionHelper(CompilationPipeline* pipeline, | 1427 static RawError* ParseFunctionHelper(CompilationPipeline* pipeline, |
1425 const Function& function, | 1428 const Function& function, |
1426 bool optimized, | 1429 bool optimized, |
1427 intptr_t osr_id) { | 1430 intptr_t osr_id) { |
1428 ASSERT(!FLAG_precompiled_mode); | 1431 ASSERT(!FLAG_precompiled_mode); |
1429 ASSERT(!optimized || function.was_compiled()); | 1432 ASSERT(!optimized || function.WasCompiled()); |
1430 LongJumpScope jump; | 1433 LongJumpScope jump; |
1431 if (setjmp(*jump.Set()) == 0) { | 1434 if (setjmp(*jump.Set()) == 0) { |
1432 Thread* const thread = Thread::Current(); | 1435 Thread* const thread = Thread::Current(); |
1433 StackZone stack_zone(thread); | 1436 StackZone stack_zone(thread); |
1434 Zone* const zone = stack_zone.GetZone(); | 1437 Zone* const zone = stack_zone.GetZone(); |
1435 const bool trace_compiler = | 1438 const bool trace_compiler = |
1436 FLAG_trace_compiler || (FLAG_trace_optimizing_compiler && optimized); | 1439 FLAG_trace_compiler || (FLAG_trace_optimizing_compiler && optimized); |
1437 | 1440 |
1438 if (trace_compiler) { | 1441 if (trace_compiler) { |
1439 const intptr_t token_size = | 1442 const intptr_t token_size = |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2320 } | 2323 } |
2321 | 2324 |
2322 bool BackgroundCompiler::IsDisabled() { | 2325 bool BackgroundCompiler::IsDisabled() { |
2323 UNREACHABLE(); | 2326 UNREACHABLE(); |
2324 return true; | 2327 return true; |
2325 } | 2328 } |
2326 | 2329 |
2327 #endif // DART_PRECOMPILED_RUNTIME | 2330 #endif // DART_PRECOMPILED_RUNTIME |
2328 | 2331 |
2329 } // namespace dart | 2332 } // namespace dart |
OLD | NEW |