OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/pipeline.h" | 5 #include "src/compiler/pipeline.h" |
6 | 6 |
7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/base/adapters.h" | 10 #include "src/base/adapters.h" |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 EscapeAnalysisReducer escape_reducer(&graph_reducer, data->jsgraph(), | 764 EscapeAnalysisReducer escape_reducer(&graph_reducer, data->jsgraph(), |
765 &escape_analysis, temp_zone); | 765 &escape_analysis, temp_zone); |
766 escape_reducer.SetExistsVirtualAllocate( | 766 escape_reducer.SetExistsVirtualAllocate( |
767 escape_analysis.ExistsVirtualAllocate()); | 767 escape_analysis.ExistsVirtualAllocate()); |
768 AddReducer(data, &graph_reducer, &escape_reducer); | 768 AddReducer(data, &graph_reducer, &escape_reducer); |
769 graph_reducer.ReduceGraph(); | 769 graph_reducer.ReduceGraph(); |
770 escape_reducer.VerifyReplacement(); | 770 escape_reducer.VerifyReplacement(); |
771 } | 771 } |
772 }; | 772 }; |
773 | 773 |
774 | 774 struct RepresentationSelectionPhase { |
775 struct SimplifiedLoweringPhase { | 775 static const char* phase_name() { return "representation selection"; } |
776 static const char* phase_name() { return "simplified lowering"; } | |
777 | 776 |
778 void Run(PipelineData* data, Zone* temp_zone) { | 777 void Run(PipelineData* data, Zone* temp_zone) { |
779 SimplifiedLowering lowering(data->jsgraph(), temp_zone, | 778 SimplifiedLowering lowering(data->jsgraph(), temp_zone, |
780 data->source_positions()); | 779 data->source_positions()); |
781 lowering.LowerAllNodes(); | 780 lowering.LowerAllNodes(); |
| 781 } |
| 782 }; |
782 | 783 |
| 784 struct EarlyOptimizationPhase { |
| 785 static const char* phase_name() { return "early optimization"; } |
| 786 |
| 787 void Run(PipelineData* data, Zone* temp_zone) { |
783 JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); | 788 JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
| 789 JSGenericLowering generic_lowering(data->jsgraph()); |
784 DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), | 790 DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
785 data->common()); | 791 data->common()); |
786 SimplifiedOperatorReducer simple_reducer(data->jsgraph()); | 792 SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
787 ValueNumberingReducer value_numbering(temp_zone); | 793 ValueNumberingReducer value_numbering(temp_zone); |
788 MachineOperatorReducer machine_reducer(data->jsgraph()); | 794 MachineOperatorReducer machine_reducer(data->jsgraph()); |
789 CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), | 795 CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
790 data->common(), data->machine()); | 796 data->common(), data->machine()); |
791 AddReducer(data, &graph_reducer, &dead_code_elimination); | 797 AddReducer(data, &graph_reducer, &dead_code_elimination); |
792 AddReducer(data, &graph_reducer, &simple_reducer); | 798 AddReducer(data, &graph_reducer, &simple_reducer); |
| 799 AddReducer(data, &graph_reducer, &generic_lowering); |
793 AddReducer(data, &graph_reducer, &value_numbering); | 800 AddReducer(data, &graph_reducer, &value_numbering); |
794 AddReducer(data, &graph_reducer, &machine_reducer); | 801 AddReducer(data, &graph_reducer, &machine_reducer); |
795 AddReducer(data, &graph_reducer, &common_reducer); | 802 AddReducer(data, &graph_reducer, &common_reducer); |
796 graph_reducer.ReduceGraph(); | 803 graph_reducer.ReduceGraph(); |
797 } | 804 } |
798 }; | 805 }; |
799 | 806 |
800 | |
801 struct ControlFlowOptimizationPhase { | 807 struct ControlFlowOptimizationPhase { |
802 static const char* phase_name() { return "control flow optimization"; } | 808 static const char* phase_name() { return "control flow optimization"; } |
803 | 809 |
804 void Run(PipelineData* data, Zone* temp_zone) { | 810 void Run(PipelineData* data, Zone* temp_zone) { |
805 ControlFlowOptimizer optimizer(data->graph(), data->common(), | 811 ControlFlowOptimizer optimizer(data->graph(), data->common(), |
806 data->machine(), temp_zone); | 812 data->machine(), temp_zone); |
807 optimizer.Optimize(); | 813 optimizer.Optimize(); |
808 } | 814 } |
809 }; | 815 }; |
810 | 816 |
(...skipping 20 matching lines...) Expand all Loading... |
831 // Post-pass for wiring the control/effects | 837 // Post-pass for wiring the control/effects |
832 // - connect allocating representation changes into the control&effect | 838 // - connect allocating representation changes into the control&effect |
833 // chains and lower them, | 839 // chains and lower them, |
834 // - get rid of the region markers, | 840 // - get rid of the region markers, |
835 // - introduce effect phis and rewire effects to get SSA again. | 841 // - introduce effect phis and rewire effects to get SSA again. |
836 EffectControlLinearizer introducer(data->jsgraph(), schedule, temp_zone); | 842 EffectControlLinearizer introducer(data->jsgraph(), schedule, temp_zone); |
837 introducer.Run(); | 843 introducer.Run(); |
838 } | 844 } |
839 }; | 845 }; |
840 | 846 |
841 struct ChangeLoweringPhase { | 847 struct LateOptimizationPhase { |
842 static const char* phase_name() { return "change lowering"; } | 848 static const char* phase_name() { return "late optimization"; } |
843 | 849 |
844 void Run(PipelineData* data, Zone* temp_zone) { | 850 void Run(PipelineData* data, Zone* temp_zone) { |
845 JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); | 851 JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); |
846 DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), | 852 DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), |
847 data->common()); | 853 data->common()); |
848 SimplifiedOperatorReducer simple_reducer(data->jsgraph()); | 854 SimplifiedOperatorReducer simple_reducer(data->jsgraph()); |
849 ValueNumberingReducer value_numbering(temp_zone); | 855 ValueNumberingReducer value_numbering(temp_zone); |
850 ChangeLowering lowering(data->jsgraph()); | 856 ChangeLowering lowering(data->jsgraph()); |
851 MachineOperatorReducer machine_reducer(data->jsgraph()); | 857 MachineOperatorReducer machine_reducer(data->jsgraph()); |
852 CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), | 858 CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), |
853 data->common(), data->machine()); | 859 data->common(), data->machine()); |
| 860 SelectLowering select_lowering(data->jsgraph()->graph(), |
| 861 data->jsgraph()->common()); |
| 862 TailCallOptimization tco(data->common(), data->graph()); |
854 AddReducer(data, &graph_reducer, &dead_code_elimination); | 863 AddReducer(data, &graph_reducer, &dead_code_elimination); |
855 AddReducer(data, &graph_reducer, &simple_reducer); | 864 AddReducer(data, &graph_reducer, &simple_reducer); |
856 AddReducer(data, &graph_reducer, &value_numbering); | 865 AddReducer(data, &graph_reducer, &value_numbering); |
857 AddReducer(data, &graph_reducer, &lowering); | 866 AddReducer(data, &graph_reducer, &lowering); |
858 AddReducer(data, &graph_reducer, &machine_reducer); | 867 AddReducer(data, &graph_reducer, &machine_reducer); |
859 AddReducer(data, &graph_reducer, &common_reducer); | 868 AddReducer(data, &graph_reducer, &common_reducer); |
| 869 AddReducer(data, &graph_reducer, &select_lowering); |
| 870 AddReducer(data, &graph_reducer, &tco); |
860 graph_reducer.ReduceGraph(); | 871 graph_reducer.ReduceGraph(); |
861 } | 872 } |
862 }; | 873 }; |
863 | 874 |
864 struct EarlyGraphTrimmingPhase { | 875 struct EarlyGraphTrimmingPhase { |
865 static const char* phase_name() { return "early graph trimming"; } | 876 static const char* phase_name() { return "early graph trimming"; } |
866 void Run(PipelineData* data, Zone* temp_zone) { | 877 void Run(PipelineData* data, Zone* temp_zone) { |
867 GraphTrimmer trimmer(temp_zone, data->graph()); | 878 GraphTrimmer trimmer(temp_zone, data->graph()); |
868 NodeVector roots(temp_zone); | 879 NodeVector roots(temp_zone); |
869 data->jsgraph()->GetCachedNodes(&roots); | 880 data->jsgraph()->GetCachedNodes(&roots); |
(...skipping 21 matching lines...) Expand all Loading... |
891 // TODO(titzer): peel all loops? the N'th loop? Innermost loops? | 902 // TODO(titzer): peel all loops? the N'th loop? Innermost loops? |
892 LoopTree* loop_tree = LoopFinder::BuildLoopTree(data->graph(), temp_zone); | 903 LoopTree* loop_tree = LoopFinder::BuildLoopTree(data->graph(), temp_zone); |
893 if (loop_tree != nullptr && loop_tree->outer_loops().size() > 0) { | 904 if (loop_tree != nullptr && loop_tree->outer_loops().size() > 0) { |
894 LoopPeeler::Peel(data->graph(), data->common(), loop_tree, | 905 LoopPeeler::Peel(data->graph(), data->common(), loop_tree, |
895 loop_tree->outer_loops()[0], temp_zone); | 906 loop_tree->outer_loops()[0], temp_zone); |
896 } | 907 } |
897 } | 908 } |
898 }; | 909 }; |
899 | 910 |
900 | 911 |
901 struct GenericLoweringPhase { | |
902 static const char* phase_name() { return "generic lowering"; } | |
903 | |
904 void Run(PipelineData* data, Zone* temp_zone) { | |
905 JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); | |
906 DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), | |
907 data->common()); | |
908 CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), | |
909 data->common(), data->machine()); | |
910 JSGenericLowering generic_lowering(data->jsgraph()); | |
911 SelectLowering select_lowering(data->jsgraph()->graph(), | |
912 data->jsgraph()->common()); | |
913 TailCallOptimization tco(data->common(), data->graph()); | |
914 AddReducer(data, &graph_reducer, &dead_code_elimination); | |
915 AddReducer(data, &graph_reducer, &common_reducer); | |
916 AddReducer(data, &graph_reducer, &generic_lowering); | |
917 AddReducer(data, &graph_reducer, &select_lowering); | |
918 AddReducer(data, &graph_reducer, &tco); | |
919 graph_reducer.ReduceGraph(); | |
920 } | |
921 }; | |
922 | |
923 | |
924 struct ComputeSchedulePhase { | 912 struct ComputeSchedulePhase { |
925 static const char* phase_name() { return "scheduling"; } | 913 static const char* phase_name() { return "scheduling"; } |
926 | 914 |
927 void Run(PipelineData* data, Zone* temp_zone) { | 915 void Run(PipelineData* data, Zone* temp_zone) { |
928 Schedule* schedule = Scheduler::ComputeSchedule( | 916 Schedule* schedule = Scheduler::ComputeSchedule( |
929 temp_zone, data->graph(), data->info()->is_splitting_enabled() | 917 temp_zone, data->graph(), data->info()->is_splitting_enabled() |
930 ? Scheduler::kSplitNodes | 918 ? Scheduler::kSplitNodes |
931 : Scheduler::kNoFlags); | 919 : Scheduler::kNoFlags); |
932 if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); | 920 if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); |
933 data->set_schedule(schedule); | 921 data->set_schedule(schedule); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 if (FLAG_turbo_stress_loop_peeling) { | 1265 if (FLAG_turbo_stress_loop_peeling) { |
1278 Run<StressLoopPeelingPhase>(); | 1266 Run<StressLoopPeelingPhase>(); |
1279 RunPrintAndVerify("Loop peeled"); | 1267 RunPrintAndVerify("Loop peeled"); |
1280 } | 1268 } |
1281 | 1269 |
1282 if (FLAG_experimental_turbo_escape) { | 1270 if (FLAG_experimental_turbo_escape) { |
1283 Run<EscapeAnalysisPhase>(); | 1271 Run<EscapeAnalysisPhase>(); |
1284 RunPrintAndVerify("Escape Analysed"); | 1272 RunPrintAndVerify("Escape Analysed"); |
1285 } | 1273 } |
1286 | 1274 |
1287 // Lower simplified operators and insert changes. | 1275 // Select representations. |
1288 Run<SimplifiedLoweringPhase>(); | 1276 Run<RepresentationSelectionPhase>(); |
1289 RunPrintAndVerify("Lowered simplified"); | 1277 RunPrintAndVerify("Representations selected"); |
| 1278 |
| 1279 // Run early optimization pass. |
| 1280 Run<EarlyOptimizationPhase>(); |
| 1281 RunPrintAndVerify("Early optimized"); |
1290 | 1282 |
1291 if (info()->is_effect_scheduling_enabled()) { | 1283 if (info()->is_effect_scheduling_enabled()) { |
1292 // TODO(jarin) Run value numbering for the representation changes. | 1284 // TODO(jarin) Run value numbering for the representation changes. |
1293 Run<EffectControlLinearizationPhase>(); | 1285 Run<EffectControlLinearizationPhase>(); |
1294 RunPrintAndVerify("Effect and control linearized"); | 1286 RunPrintAndVerify("Effect and control linearized"); |
1295 } | 1287 } |
1296 | 1288 |
1297 Run<BranchEliminationPhase>(); | 1289 Run<BranchEliminationPhase>(); |
1298 RunPrintAndVerify("Branch conditions eliminated"); | 1290 RunPrintAndVerify("Branch conditions eliminated"); |
1299 | 1291 |
1300 // Optimize control flow. | 1292 // Optimize control flow. |
1301 if (FLAG_turbo_cf_optimization) { | 1293 if (FLAG_turbo_cf_optimization) { |
1302 Run<ControlFlowOptimizationPhase>(); | 1294 Run<ControlFlowOptimizationPhase>(); |
1303 RunPrintAndVerify("Control flow optimized"); | 1295 RunPrintAndVerify("Control flow optimized"); |
1304 } | 1296 } |
1305 | 1297 |
1306 // Lower changes that have been inserted before. | 1298 // Lower changes that have been inserted before. |
1307 Run<ChangeLoweringPhase>(); | 1299 Run<LateOptimizationPhase>(); |
1308 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1300 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1309 RunPrintAndVerify("Lowered changes", true); | 1301 RunPrintAndVerify("Late optimized", true); |
1310 | |
1311 // Lower any remaining generic JSOperators. | |
1312 Run<GenericLoweringPhase>(); | |
1313 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | |
1314 RunPrintAndVerify("Lowered generic", true); | |
1315 | 1302 |
1316 Run<LateGraphTrimmingPhase>(); | 1303 Run<LateGraphTrimmingPhase>(); |
1317 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1304 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1318 RunPrintAndVerify("Late trimmed", true); | 1305 RunPrintAndVerify("Late trimmed", true); |
1319 | 1306 |
1320 BeginPhaseKind("block building"); | 1307 BeginPhaseKind("block building"); |
1321 | 1308 |
1322 data.source_positions()->RemoveDecorator(); | 1309 data.source_positions()->RemoveDecorator(); |
1323 | 1310 |
1324 // Kill the Typer and thereby uninstall the decorator (if any). | 1311 // Kill the Typer and thereby uninstall the decorator (if any). |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 } | 1594 } |
1608 | 1595 |
1609 data->DeleteRegisterAllocationZone(); | 1596 data->DeleteRegisterAllocationZone(); |
1610 } | 1597 } |
1611 | 1598 |
1612 Isolate* Pipeline::isolate() const { return info()->isolate(); } | 1599 Isolate* Pipeline::isolate() const { return info()->isolate(); } |
1613 | 1600 |
1614 } // namespace compiler | 1601 } // namespace compiler |
1615 } // namespace internal | 1602 } // namespace internal |
1616 } // namespace v8 | 1603 } // namespace v8 |
OLD | NEW |