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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
| 8 String get name; | 8 String get name; |
| 9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
| 10 } | 10 } |
| 11 | 11 |
| 12 class SsaOptimizerTask extends CompilerTask { | 12 class SsaOptimizerTask extends CompilerTask { |
| 13 final JavaScriptBackend backend; | 13 final JavaScriptBackend backend; |
| 14 SsaOptimizerTask(JavaScriptBackend backend) | 14 SsaOptimizerTask(JavaScriptBackend backend) |
| 15 : this.backend = backend, | 15 : this.backend = backend, |
| 16 super(backend.compiler); | 16 super(backend.compiler); |
| 17 String get name => 'SSA optimizer'; | 17 String get name => 'SSA optimizer'; |
| 18 Compiler get compiler => backend.compiler; | 18 Compiler get compiler => backend.compiler; |
| 19 Map<HInstruction, Range> ranges = <HInstruction, Range>{}; | 19 Map<HInstruction, Range> ranges = <HInstruction, Range>{}; |
| 20 | 20 |
| 21 void runPhases(HGraph graph, List<OptimizationPhase> phases) { | 21 void optimize(CodegenWorkItem work, HGraph graph) { |
| 22 for (OptimizationPhase phase in phases) { | 22 void runPhase(OptimizationPhase phase) { |
| 23 runPhase(graph, phase); | 23 phase.visitGraph(graph); |
| 24 compiler.tracer.traceGraph(phase.name, graph); | |
| 25 assert(graph.isValid()); | |
| 24 } | 26 } |
| 25 } | |
| 26 | 27 |
| 27 void runPhase(HGraph graph, OptimizationPhase phase) { | |
| 28 phase.visitGraph(graph); | |
| 29 compiler.tracer.traceGraph(phase.name, graph); | |
| 30 assert(graph.isValid()); | |
| 31 } | |
| 32 | |
| 33 void optimize(CodegenWorkItem work, HGraph graph) { | |
| 34 ConstantSystem constantSystem = compiler.backend.constantSystem; | 28 ConstantSystem constantSystem = compiler.backend.constantSystem; |
| 35 JavaScriptItemCompilationContext context = work.compilationContext; | 29 JavaScriptItemCompilationContext context = work.compilationContext; |
| 36 bool trustPrimitives = compiler.trustPrimitives; | 30 bool trustPrimitives = compiler.trustPrimitives; |
| 37 measure(() { | 31 measure(() { |
| 38 SsaDeadCodeEliminator dce; | |
| 39 List<OptimizationPhase> phases = <OptimizationPhase>[ | 32 List<OptimizationPhase> phases = <OptimizationPhase>[ |
| 40 // Run trivial instruction simplification first to optimize | 33 // Run trivial instruction simplification first to optimize |
| 41 // some patterns useful for type conversion. | 34 // some patterns useful for type conversion. |
| 42 new SsaInstructionSimplifier(constantSystem, backend, this, work), | 35 new SsaInstructionSimplifier(constantSystem, backend, this, work), |
| 43 new SsaTypeConversionInserter(compiler), | 36 new SsaTypeConversionInserter(compiler), |
| 44 new SsaRedundantPhiEliminator(), | 37 new SsaRedundantPhiEliminator(), |
| 45 new SsaDeadPhiEliminator(), | 38 new SsaDeadPhiEliminator(), |
| 46 new SsaTypePropagator(compiler), | 39 new SsaTypePropagator(compiler), |
| 47 // After type propagation, more instructions can be | 40 // After type propagation, more instructions can be |
| 48 // simplified. | 41 // simplified. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 63 new SsaCodeMotion(), | 56 new SsaCodeMotion(), |
| 64 new SsaLoadElimination(compiler), | 57 new SsaLoadElimination(compiler), |
| 65 new SsaDeadPhiEliminator(), | 58 new SsaDeadPhiEliminator(), |
| 66 new SsaTypePropagator(compiler), | 59 new SsaTypePropagator(compiler), |
| 67 new SsaValueRangeAnalyzer(compiler, constantSystem, this, work), | 60 new SsaValueRangeAnalyzer(compiler, constantSystem, this, work), |
| 68 // Previous optimizations may have generated new | 61 // Previous optimizations may have generated new |
| 69 // opportunities for instruction simplification. | 62 // opportunities for instruction simplification. |
| 70 new SsaInstructionSimplifier(constantSystem, backend, this, work), | 63 new SsaInstructionSimplifier(constantSystem, backend, this, work), |
| 71 new SsaCheckInserter( | 64 new SsaCheckInserter( |
| 72 trustPrimitives, backend, work, context.boundsChecked), | 65 trustPrimitives, backend, work, context.boundsChecked), |
| 73 new SsaSimplifyInterceptors(compiler, constantSystem, work), | 66 ]; |
| 74 dce = new SsaDeadCodeEliminator(compiler, this), | 67 phases.forEach(runPhase); |
| 75 new SsaTypePropagator(compiler)]; | 68 |
| 76 runPhases(graph, phases); | 69 // Simplifying interceptors is not strictly just an optimization, it is |
| 70 // required for implementation correctness because the code generator | |
| 71 // assumes it is always performed. | |
|
Kevin Millikin (Google)
2015/03/13 10:18:04
If this refactoring seems too aggressive, I could
| |
| 72 runPhase(new SsaSimplifyInterceptors(compiler, constantSystem, work)); | |
| 73 | |
| 74 SsaDeadCodeEliminator dce = new SsaDeadCodeEliminator(compiler, this); | |
| 75 runPhase(dce); | |
| 77 if (dce.eliminatedSideEffects) { | 76 if (dce.eliminatedSideEffects) { |
| 78 phases = <OptimizationPhase>[ | 77 phases = <OptimizationPhase>[ |
| 78 new SsaTypePropagator(compiler), | |
| 79 new SsaGlobalValueNumberer(compiler), | 79 new SsaGlobalValueNumberer(compiler), |
| 80 new SsaCodeMotion(), | 80 new SsaCodeMotion(), |
| 81 new SsaValueRangeAnalyzer(compiler, constantSystem, this, work), | 81 new SsaValueRangeAnalyzer(compiler, constantSystem, this, work), |
| 82 new SsaInstructionSimplifier(constantSystem, backend, this, work), | 82 new SsaInstructionSimplifier(constantSystem, backend, this, work), |
| 83 new SsaCheckInserter( | 83 new SsaCheckInserter( |
| 84 trustPrimitives, backend, work, context.boundsChecked), | 84 trustPrimitives, backend, work, context.boundsChecked), |
| 85 new SsaSimplifyInterceptors(compiler, constantSystem, work), | 85 new SsaSimplifyInterceptors(compiler, constantSystem, work), |
| 86 new SsaDeadCodeEliminator(compiler, this)]; | 86 new SsaDeadCodeEliminator(compiler, this), |
| 87 ]; | |
| 87 } else { | 88 } else { |
| 88 phases = <OptimizationPhase>[ | 89 phases = <OptimizationPhase>[ |
| 89 // Run the simplifier to remove unneeded type checks inserted | 90 new SsaTypePropagator(compiler), |
| 90 // by type propagation. | 91 // Run the simplifier to remove unneeded type checks inserted by |
| 91 new SsaInstructionSimplifier(constantSystem, backend, this, work)]; | 92 // type propagation. |
| 93 new SsaInstructionSimplifier(constantSystem, backend, this, work), | |
| 94 ]; | |
| 92 } | 95 } |
| 93 runPhases(graph, phases); | 96 phases.forEach(runPhase); |
| 94 }); | 97 }); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 | 100 |
| 98 bool isFixedLength(mask, Compiler compiler) { | 101 bool isFixedLength(mask, Compiler compiler) { |
| 99 ClassWorld classWorld = compiler.world; | 102 ClassWorld classWorld = compiler.world; |
| 100 JavaScriptBackend backend = compiler.backend; | 103 JavaScriptBackend backend = compiler.backend; |
| 101 if (mask.isContainer && mask.length != null) { | 104 if (mask.isContainer && mask.length != null) { |
| 102 // A container on which we have inferred the length. | 105 // A container on which we have inferred the length. |
| 103 return true; | 106 return true; |
| (...skipping 2098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2202 | 2205 |
| 2203 keyedValues.forEach((receiver, values) { | 2206 keyedValues.forEach((receiver, values) { |
| 2204 result.keyedValues[receiver] = | 2207 result.keyedValues[receiver] = |
| 2205 new Map<HInstruction, HInstruction>.from(values); | 2208 new Map<HInstruction, HInstruction>.from(values); |
| 2206 }); | 2209 }); |
| 2207 | 2210 |
| 2208 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2211 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 2209 return result; | 2212 return result; |
| 2210 } | 2213 } |
| 2211 } | 2214 } |
| OLD | NEW |