Chromium Code Reviews| 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/code_generator.h" | 10 #include "vm/code_generator.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 const Code& unoptimized_code = | 149 const Code& unoptimized_code = |
| 150 Code::Handle(parsed_function.function().unoptimized_code()); | 150 Code::Handle(parsed_function.function().unoptimized_code()); |
| 151 isolate->set_ic_data_array( | 151 isolate->set_ic_data_array( |
| 152 unoptimized_code.ExtractTypeFeedbackArray()); | 152 unoptimized_code.ExtractTypeFeedbackArray()); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 // Build the flow graph. | 156 // Build the flow graph. |
| 157 FlowGraphBuilder builder(parsed_function); | 157 FlowGraphBuilder builder(parsed_function); |
| 158 flow_graph = builder.BuildGraph(FlowGraphBuilder::kNotInlining); | 158 flow_graph = builder.BuildGraph(FlowGraphBuilder::kNotInlining); |
| 159 } | |
| 159 | 160 |
| 160 // Transform to SSA. | 161 // Transform to SSA. |
| 161 if (optimized) flow_graph->ComputeSSA(0); // Start at virtual register 0. | 162 if (optimized) { |
| 163 TimerScope timer(FLAG_compiler_stats, | |
| 164 &CompilerStats::graphssa_timer, | |
|
Kevin Millikin (Google)
2012/10/23 07:54:56
Needs to be graph_ssa_timer. Could it be just Com
| |
| 165 isolate); | |
| 166 flow_graph->ComputeSSA(0); // Start at virtual register 0. | |
| 167 } | |
| 168 | |
| 169 if (FLAG_print_flow_graph) { | |
| 170 OS::Print("Before Optimizations\n"); | |
| 171 FlowGraphPrinter printer(*flow_graph); | |
| 172 printer.PrintBlocks(); | |
| 173 } | |
| 174 | |
| 175 if (optimized) { | |
| 176 TimerScope timer(FLAG_compiler_stats, | |
| 177 &CompilerStats::graphoptimizer_timer, | |
| 178 isolate); | |
| 179 | |
| 180 flow_graph->ComputeUseLists(); | |
| 181 | |
| 182 FlowGraphOptimizer optimizer(flow_graph); | |
| 183 optimizer.ApplyICData(); | |
| 184 | |
| 185 // Compute the use lists. | |
| 186 flow_graph->ComputeUseLists(); | |
| 187 | |
| 188 // Inlining (mutates the flow graph) | |
| 189 if (FLAG_use_inlining) { | |
| 190 TimerScope timer(FLAG_compiler_stats, | |
| 191 &CompilerStats::graphinliner_timer); | |
| 192 FlowGraphInliner inliner(flow_graph); | |
| 193 inliner.Inline(); | |
| 194 // Use lists are maintained and validated by the inliner. | |
| 195 } | |
| 196 | |
| 197 // Propagate types and eliminate more type tests. | |
| 198 if (FLAG_propagate_types) { | |
| 199 FlowGraphTypePropagator propagator(flow_graph); | |
| 200 propagator.PropagateTypes(); | |
| 201 } | |
| 202 | |
| 203 // Verify that the use lists are still valid. | |
| 204 DEBUG_ASSERT(flow_graph->ValidateUseLists()); | |
| 205 | |
| 206 // Propagate sminess from CheckSmi to phis. | |
| 207 optimizer.PropagateSminess(); | |
| 208 | |
| 209 // Use propagated class-ids to optimize further. | |
| 210 optimizer.ApplyClassIds(); | |
| 211 | |
| 212 // Do optimizations that depend on the propagated type information. | |
| 213 // TODO(srdjan): Should this be called CanonicalizeComputations? | |
| 214 optimizer.OptimizeComputations(); | |
| 215 | |
| 216 // Unbox doubles. | |
| 217 flow_graph->ComputeUseLists(); | |
| 218 optimizer.SelectRepresentations(); | |
| 219 | |
| 220 if (FLAG_constant_propagation || | |
| 221 FLAG_common_subexpression_elimination) { | |
| 222 flow_graph->ComputeUseLists(); | |
| 223 } | |
| 224 if (FLAG_constant_propagation) { | |
| 225 ConstantPropagator::Optimize(flow_graph); | |
| 226 // A canonicalization pass to remove e.g. smi checks on smi constants. | |
| 227 optimizer.OptimizeComputations(); | |
| 228 } | |
| 229 if (FLAG_common_subexpression_elimination) { | |
| 230 if (DominatorBasedCSE::Optimize(flow_graph)) { | |
| 231 // Do another round of CSE to take secondary effects into account: | |
| 232 // e.g. when eliminating dependent loads (a.x[0] + a.x[0]) | |
| 233 // TODO(fschneider): Change to a one-pass optimization pass. | |
| 234 DominatorBasedCSE::Optimize(flow_graph); | |
| 235 } | |
| 236 } | |
| 237 if (FLAG_loop_invariant_code_motion && | |
| 238 (parsed_function.function().deoptimization_counter() < | |
| 239 (FLAG_deoptimization_counter_threshold - 1))) { | |
| 240 LICM::Optimize(flow_graph); | |
| 241 } | |
| 242 | |
| 243 if (FLAG_range_analysis) { | |
| 244 // We have to perform range analysis after LICM because it | |
| 245 // optimistically moves CheckSmi through phis into loop preheaders | |
| 246 // making some phis smi. | |
| 247 flow_graph->ComputeUseLists(); | |
| 248 optimizer.InferSmiRanges(); | |
| 249 } | |
| 250 | |
| 251 // Perform register allocation on the SSA graph. | |
| 252 FlowGraphAllocator allocator(*flow_graph); | |
| 253 allocator.AllocateRegisters(); | |
| 162 | 254 |
| 163 if (FLAG_print_flow_graph) { | 255 if (FLAG_print_flow_graph) { |
| 164 OS::Print("Before Optimizations\n"); | 256 OS::Print("After Optimizations:\n"); |
| 165 FlowGraphPrinter printer(*flow_graph); | 257 FlowGraphPrinter printer(*flow_graph); |
| 166 printer.PrintBlocks(); | 258 printer.PrintBlocks(); |
| 167 } | 259 } |
| 168 | |
| 169 if (optimized) { | |
| 170 flow_graph->ComputeUseLists(); | |
| 171 | |
| 172 FlowGraphOptimizer optimizer(flow_graph); | |
| 173 optimizer.ApplyICData(); | |
| 174 | |
| 175 // Compute the use lists. | |
| 176 flow_graph->ComputeUseLists(); | |
| 177 | |
| 178 // Inlining (mutates the flow graph) | |
| 179 if (FLAG_use_inlining) { | |
| 180 FlowGraphInliner inliner(flow_graph); | |
| 181 inliner.Inline(); | |
| 182 // Use lists are maintained and validated by the inliner. | |
| 183 } | |
| 184 | |
| 185 // Propagate types and eliminate more type tests. | |
| 186 if (FLAG_propagate_types) { | |
| 187 FlowGraphTypePropagator propagator(flow_graph); | |
| 188 propagator.PropagateTypes(); | |
| 189 } | |
| 190 | |
| 191 // Verify that the use lists are still valid. | |
| 192 DEBUG_ASSERT(flow_graph->ValidateUseLists()); | |
| 193 | |
| 194 // Propagate sminess from CheckSmi to phis. | |
| 195 optimizer.PropagateSminess(); | |
| 196 | |
| 197 // Use propagated class-ids to optimize further. | |
| 198 optimizer.ApplyClassIds(); | |
| 199 | |
| 200 // Do optimizations that depend on the propagated type information. | |
| 201 // TODO(srdjan): Should this be called CanonicalizeComputations? | |
| 202 optimizer.OptimizeComputations(); | |
| 203 | |
| 204 // Unbox doubles. | |
| 205 flow_graph->ComputeUseLists(); | |
| 206 optimizer.SelectRepresentations(); | |
| 207 | |
| 208 if (FLAG_constant_propagation || | |
| 209 FLAG_common_subexpression_elimination) { | |
| 210 flow_graph->ComputeUseLists(); | |
| 211 } | |
| 212 if (FLAG_constant_propagation) { | |
| 213 ConstantPropagator::Optimize(flow_graph); | |
| 214 // A canonicalization pass to remove e.g. smi checks on smi constants. | |
| 215 optimizer.OptimizeComputations(); | |
| 216 } | |
| 217 if (FLAG_common_subexpression_elimination) { | |
| 218 if (DominatorBasedCSE::Optimize(flow_graph)) { | |
| 219 // Do another round of CSE to take secondary effects into account: | |
| 220 // e.g. when eliminating dependent loads (a.x[0] + a.x[0]) | |
| 221 // TODO(fschneider): Change to a one-pass optimization pass. | |
| 222 DominatorBasedCSE::Optimize(flow_graph); | |
| 223 } | |
| 224 } | |
| 225 if (FLAG_loop_invariant_code_motion && | |
| 226 (parsed_function.function().deoptimization_counter() < | |
| 227 (FLAG_deoptimization_counter_threshold - 1))) { | |
| 228 LICM::Optimize(flow_graph); | |
| 229 } | |
| 230 | |
| 231 if (FLAG_range_analysis) { | |
| 232 // We have to perform range analysis after LICM because it | |
| 233 // optimistically moves CheckSmi through phis into loop preheaders | |
| 234 // making some phis smi. | |
| 235 flow_graph->ComputeUseLists(); | |
| 236 optimizer.InferSmiRanges(); | |
| 237 } | |
| 238 | |
| 239 // Perform register allocation on the SSA graph. | |
| 240 FlowGraphAllocator allocator(*flow_graph); | |
| 241 allocator.AllocateRegisters(); | |
| 242 | |
| 243 if (FLAG_print_flow_graph) { | |
| 244 OS::Print("After Optimizations:\n"); | |
| 245 FlowGraphPrinter printer(*flow_graph); | |
| 246 printer.PrintBlocks(); | |
| 247 } | |
| 248 } | |
| 249 } | 260 } |
| 250 | 261 |
| 251 Assembler assembler; | 262 Assembler assembler; |
| 252 FlowGraphCompiler graph_compiler(&assembler, | 263 FlowGraphCompiler graph_compiler(&assembler, |
| 253 *flow_graph, | 264 *flow_graph, |
| 254 optimized); | 265 optimized); |
| 255 { | 266 { |
| 256 TimerScope timer(FLAG_compiler_stats, | 267 TimerScope timer(FLAG_compiler_stats, |
| 257 &CompilerStats::graphcompiler_timer, | 268 &CompilerStats::graphcompiler_timer, |
| 258 isolate); | 269 isolate); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 result = isolate->object_store()->sticky_error(); | 605 result = isolate->object_store()->sticky_error(); |
| 595 isolate->object_store()->clear_sticky_error(); | 606 isolate->object_store()->clear_sticky_error(); |
| 596 isolate->set_long_jump_base(base); | 607 isolate->set_long_jump_base(base); |
| 597 return result.raw(); | 608 return result.raw(); |
| 598 } | 609 } |
| 599 UNREACHABLE(); | 610 UNREACHABLE(); |
| 600 return Object::null(); | 611 return Object::null(); |
| 601 } | 612 } |
| 602 | 613 |
| 603 } // namespace dart | 614 } // namespace dart |
| OLD | NEW |