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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // position of the inlined call until later. A side effect of this | 831 // position of the inlined call until later. A side effect of this |
832 // is that the length of |inline_id_to_function| is always larger | 832 // is that the length of |inline_id_to_function| is always larger |
833 // than the length of |inline_id_to_token_pos| by one. | 833 // than the length of |inline_id_to_token_pos| by one. |
834 // Top scope function has no caller (-1). We do this because we expect | 834 // Top scope function has no caller (-1). We do this because we expect |
835 // all token positions to be at an inlined call. | 835 // all token positions to be at an inlined call. |
836 caller_inline_id.Add(-1); | 836 caller_inline_id.Add(-1); |
837 CSTAT_TIMER_SCOPE(thread(), graphoptimizer_timer); | 837 CSTAT_TIMER_SCOPE(thread(), graphoptimizer_timer); |
838 | 838 |
839 JitOptimizer optimizer(flow_graph); | 839 JitOptimizer optimizer(flow_graph); |
840 | 840 |
841 optimizer.ApplyICData(); | 841 { |
| 842 NOT_IN_PRODUCT(TimelineDurationScope tds(thread(), compiler_timeline, |
| 843 "ApplyICData")); |
| 844 optimizer.ApplyICData(); |
| 845 thread()->CheckForSafepoint(); |
| 846 } |
842 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 847 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
843 | 848 |
844 // Optimize (a << b) & c patterns, merge operations. | 849 // Optimize (a << b) & c patterns, merge operations. |
845 // Run early in order to have more opportunity to optimize left shifts. | 850 // Run early in order to have more opportunity to optimize left shifts. |
846 flow_graph->TryOptimizePatterns(); | 851 flow_graph->TryOptimizePatterns(); |
847 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 852 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
848 | 853 |
849 FlowGraphInliner::SetInliningId(flow_graph, 0); | 854 FlowGraphInliner::SetInliningId(flow_graph, 0); |
850 | 855 |
851 // Inlining (mutates the flow graph) | 856 // Inlining (mutates the flow graph) |
(...skipping 10 matching lines...) Expand all Loading... |
862 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 867 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
863 | 868 |
864 FlowGraphInliner inliner(flow_graph, &inline_id_to_function, | 869 FlowGraphInliner inliner(flow_graph, &inline_id_to_function, |
865 &inline_id_to_token_pos, &caller_inline_id, | 870 &inline_id_to_token_pos, &caller_inline_id, |
866 use_speculative_inlining, | 871 use_speculative_inlining, |
867 /*inlining_black_list=*/NULL, | 872 /*inlining_black_list=*/NULL, |
868 /*precompiler=*/NULL); | 873 /*precompiler=*/NULL); |
869 inliner.Inline(); | 874 inliner.Inline(); |
870 // Use lists are maintained and validated by the inliner. | 875 // Use lists are maintained and validated by the inliner. |
871 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 876 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 877 thread()->CheckForSafepoint(); |
872 } | 878 } |
873 | 879 |
874 // Propagate types and eliminate more type tests. | 880 // Propagate types and eliminate more type tests. |
875 FlowGraphTypePropagator::Propagate(flow_graph); | 881 FlowGraphTypePropagator::Propagate(flow_graph); |
876 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 882 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
877 | 883 |
878 { | 884 { |
879 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, | 885 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, |
880 "ApplyClassIds")); | 886 "ApplyClassIds")); |
881 // Use propagated class-ids to optimize further. | 887 // Use propagated class-ids to optimize further. |
(...skipping 29 matching lines...) Expand all Loading... |
911 "ConstantPropagation"); | 917 "ConstantPropagation"); |
912 ConstantPropagator::Optimize(flow_graph)); | 918 ConstantPropagator::Optimize(flow_graph)); |
913 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 919 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
914 // A canonicalization pass to remove e.g. smi checks on smi constants. | 920 // A canonicalization pass to remove e.g. smi checks on smi constants. |
915 flow_graph->Canonicalize(); | 921 flow_graph->Canonicalize(); |
916 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 922 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
917 // Canonicalization introduced more opportunities for constant | 923 // Canonicalization introduced more opportunities for constant |
918 // propagation. | 924 // propagation. |
919 ConstantPropagator::Optimize(flow_graph); | 925 ConstantPropagator::Optimize(flow_graph); |
920 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 926 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
| 927 thread()->CheckForSafepoint(); |
921 } | 928 } |
922 | 929 |
923 // Optimistically convert loop phis that have a single non-smi input | 930 // Optimistically convert loop phis that have a single non-smi input |
924 // coming from the loop pre-header into smi-phis. | 931 // coming from the loop pre-header into smi-phis. |
925 if (FLAG_loop_invariant_code_motion) { | 932 if (FLAG_loop_invariant_code_motion) { |
926 LICM licm(flow_graph); | 933 LICM licm(flow_graph); |
927 licm.OptimisticallySpecializeSmiPhis(); | 934 licm.OptimisticallySpecializeSmiPhis(); |
928 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 935 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
929 } | 936 } |
930 | 937 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 // it depends on the numbering of loads from the previous | 981 // it depends on the numbering of loads from the previous |
975 // load-elimination. | 982 // load-elimination. |
976 if (FLAG_loop_invariant_code_motion) { | 983 if (FLAG_loop_invariant_code_motion) { |
977 flow_graph->RenameUsesDominatedByRedefinitions(); | 984 flow_graph->RenameUsesDominatedByRedefinitions(); |
978 DEBUG_ASSERT(flow_graph->VerifyRedefinitions()); | 985 DEBUG_ASSERT(flow_graph->VerifyRedefinitions()); |
979 LICM licm(flow_graph); | 986 LICM licm(flow_graph); |
980 licm.Optimize(); | 987 licm.Optimize(); |
981 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 988 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
982 } | 989 } |
983 flow_graph->RemoveRedefinitions(); | 990 flow_graph->RemoveRedefinitions(); |
| 991 thread()->CheckForSafepoint(); |
984 } | 992 } |
985 | 993 |
986 // Optimize (a << b) & c patterns, merge operations. | 994 // Optimize (a << b) & c patterns, merge operations. |
987 // Run after CSE in order to have more opportunity to merge | 995 // Run after CSE in order to have more opportunity to merge |
988 // instructions that have same inputs. | 996 // instructions that have same inputs. |
989 flow_graph->TryOptimizePatterns(); | 997 flow_graph->TryOptimizePatterns(); |
990 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 998 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
991 | 999 |
992 { | 1000 { |
993 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, | 1001 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 // Attempt to sink allocations of temporary non-escaping objects to | 1061 // Attempt to sink allocations of temporary non-escaping objects to |
1054 // the deoptimization path. | 1062 // the deoptimization path. |
1055 AllocationSinking* sinking = NULL; | 1063 AllocationSinking* sinking = NULL; |
1056 if (FLAG_allocation_sinking && | 1064 if (FLAG_allocation_sinking && |
1057 (flow_graph->graph_entry()->SuccessorCount() == 1)) { | 1065 (flow_graph->graph_entry()->SuccessorCount() == 1)) { |
1058 NOT_IN_PRODUCT(TimelineDurationScope tds2( | 1066 NOT_IN_PRODUCT(TimelineDurationScope tds2( |
1059 thread(), compiler_timeline, "AllocationSinking::Optimize")); | 1067 thread(), compiler_timeline, "AllocationSinking::Optimize")); |
1060 // TODO(fschneider): Support allocation sinking with try-catch. | 1068 // TODO(fschneider): Support allocation sinking with try-catch. |
1061 sinking = new AllocationSinking(flow_graph); | 1069 sinking = new AllocationSinking(flow_graph); |
1062 sinking->Optimize(); | 1070 sinking->Optimize(); |
| 1071 thread()->CheckForSafepoint(); |
1063 } | 1072 } |
1064 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 1073 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
1065 | 1074 |
1066 DeadCodeElimination::EliminateDeadPhis(flow_graph); | 1075 DeadCodeElimination::EliminateDeadPhis(flow_graph); |
1067 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 1076 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
1068 | 1077 |
1069 FlowGraphTypePropagator::Propagate(flow_graph); | 1078 FlowGraphTypePropagator::Propagate(flow_graph); |
1070 DEBUG_ASSERT(flow_graph->VerifyUseLists()); | 1079 DEBUG_ASSERT(flow_graph->VerifyUseLists()); |
1071 | 1080 |
1072 { | 1081 { |
(...skipping 29 matching lines...) Expand all Loading... |
1102 // to be later used by the inliner. | 1111 // to be later used by the inliner. |
1103 FlowGraphInliner::CollectGraphInfo(flow_graph, true); | 1112 FlowGraphInliner::CollectGraphInfo(flow_graph, true); |
1104 | 1113 |
1105 flow_graph->RemoveRedefinitions(); | 1114 flow_graph->RemoveRedefinitions(); |
1106 { | 1115 { |
1107 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, | 1116 NOT_IN_PRODUCT(TimelineDurationScope tds2(thread(), compiler_timeline, |
1108 "AllocateRegisters")); | 1117 "AllocateRegisters")); |
1109 // Perform register allocation on the SSA graph. | 1118 // Perform register allocation on the SSA graph. |
1110 FlowGraphAllocator allocator(*flow_graph); | 1119 FlowGraphAllocator allocator(*flow_graph); |
1111 allocator.AllocateRegisters(); | 1120 allocator.AllocateRegisters(); |
| 1121 thread()->CheckForSafepoint(); |
1112 } | 1122 } |
1113 | 1123 |
1114 if (reorder_blocks) { | 1124 if (reorder_blocks) { |
1115 NOT_IN_PRODUCT(TimelineDurationScope tds( | 1125 NOT_IN_PRODUCT(TimelineDurationScope tds( |
1116 thread(), compiler_timeline, "BlockScheduler::ReorderBlocks")); | 1126 thread(), compiler_timeline, "BlockScheduler::ReorderBlocks")); |
1117 block_scheduler.ReorderBlocks(); | 1127 block_scheduler.ReorderBlocks(); |
1118 } | 1128 } |
1119 | 1129 |
1120 if (print_flow_graph) { | 1130 if (print_flow_graph) { |
1121 FlowGraphPrinter::PrintGraph("After Optimizations", flow_graph); | 1131 FlowGraphPrinter::PrintGraph("After Optimizations", flow_graph); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 | 2313 |
2304 | 2314 |
2305 bool BackgroundCompiler::IsDisabled() { | 2315 bool BackgroundCompiler::IsDisabled() { |
2306 UNREACHABLE(); | 2316 UNREACHABLE(); |
2307 return true; | 2317 return true; |
2308 } | 2318 } |
2309 | 2319 |
2310 #endif // DART_PRECOMPILED_RUNTIME | 2320 #endif // DART_PRECOMPILED_RUNTIME |
2311 | 2321 |
2312 } // namespace dart | 2322 } // namespace dart |
OLD | NEW |