| 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 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 void runPhase(HGraph graph, OptimizationPhase phase) { | 27 void runPhase(HGraph graph, OptimizationPhase phase) { |
| 28 phase.visitGraph(graph); | 28 phase.visitGraph(graph); |
| 29 compiler.tracer.traceGraph(phase.name, graph); | 29 compiler.tracer.traceGraph(phase.name, graph); |
| 30 assert(graph.isValid()); | 30 assert(graph.isValid()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void optimize(CodegenWorkItem work, HGraph graph) { | 33 void optimize(CodegenWorkItem work, HGraph graph) { |
| 34 ConstantSystem constantSystem = compiler.backend.constantSystem; | 34 ConstantSystem constantSystem = compiler.backend.constantSystem; |
| 35 JavaScriptItemCompilationContext context = work.compilationContext; | 35 JavaScriptItemCompilationContext context = work.compilationContext; |
| 36 bool trustPrimitives = compiler.trustPrimitives; |
| 36 measure(() { | 37 measure(() { |
| 37 SsaDeadCodeEliminator dce; | 38 SsaDeadCodeEliminator dce; |
| 38 List<OptimizationPhase> phases = <OptimizationPhase>[ | 39 List<OptimizationPhase> phases = <OptimizationPhase>[ |
| 39 // Run trivial instruction simplification first to optimize | 40 // Run trivial instruction simplification first to optimize |
| 40 // some patterns useful for type conversion. | 41 // some patterns useful for type conversion. |
| 41 new SsaInstructionSimplifier(constantSystem, backend, work), | 42 new SsaInstructionSimplifier(constantSystem, backend, work), |
| 42 new SsaTypeConversionInserter(compiler), | 43 new SsaTypeConversionInserter(compiler), |
| 43 new SsaRedundantPhiEliminator(), | 44 new SsaRedundantPhiEliminator(), |
| 44 new SsaDeadPhiEliminator(), | 45 new SsaDeadPhiEliminator(), |
| 45 new SsaTypePropagator(compiler), | 46 new SsaTypePropagator(compiler), |
| 46 // After type propagation, more instructions can be | 47 // After type propagation, more instructions can be |
| 47 // simplified. | 48 // simplified. |
| 48 new SsaInstructionSimplifier(constantSystem, backend, work), | 49 new SsaInstructionSimplifier(constantSystem, backend, work), |
| 49 new SsaCheckInserter(backend, work, context.boundsChecked), | 50 new SsaCheckInserter( |
| 51 trustPrimitives, backend, work, context.boundsChecked), |
| 50 new SsaInstructionSimplifier(constantSystem, backend, work), | 52 new SsaInstructionSimplifier(constantSystem, backend, work), |
| 51 new SsaCheckInserter(backend, work, context.boundsChecked), | 53 new SsaCheckInserter( |
| 54 trustPrimitives, backend, work, context.boundsChecked), |
| 52 new SsaTypePropagator(compiler), | 55 new SsaTypePropagator(compiler), |
| 53 // Run a dead code eliminator before LICM because dead | 56 // Run a dead code eliminator before LICM because dead |
| 54 // interceptors are often in the way of LICM'able instructions. | 57 // interceptors are often in the way of LICM'able instructions. |
| 55 new SsaDeadCodeEliminator(compiler), | 58 new SsaDeadCodeEliminator(compiler), |
| 56 new SsaGlobalValueNumberer(compiler), | 59 new SsaGlobalValueNumberer(compiler), |
| 57 // After GVN, some instructions might need their type to be | 60 // After GVN, some instructions might need their type to be |
| 58 // updated because they now have different inputs. | 61 // updated because they now have different inputs. |
| 59 new SsaTypePropagator(compiler), | 62 new SsaTypePropagator(compiler), |
| 60 new SsaCodeMotion(), | 63 new SsaCodeMotion(), |
| 61 new SsaLoadElimination(compiler), | 64 new SsaLoadElimination(compiler), |
| 62 new SsaDeadPhiEliminator(), | 65 new SsaDeadPhiEliminator(), |
| 63 new SsaTypePropagator(compiler), | 66 new SsaTypePropagator(compiler), |
| 64 new SsaValueRangeAnalyzer(compiler, constantSystem, work), | 67 new SsaValueRangeAnalyzer(compiler, constantSystem, work), |
| 65 // Previous optimizations may have generated new | 68 // Previous optimizations may have generated new |
| 66 // opportunities for instruction simplification. | 69 // opportunities for instruction simplification. |
| 67 new SsaInstructionSimplifier(constantSystem, backend, work), | 70 new SsaInstructionSimplifier(constantSystem, backend, work), |
| 68 new SsaCheckInserter(backend, work, context.boundsChecked), | 71 new SsaCheckInserter( |
| 72 trustPrimitives, backend, work, context.boundsChecked), |
| 69 new SsaSimplifyInterceptors(compiler, constantSystem, work), | 73 new SsaSimplifyInterceptors(compiler, constantSystem, work), |
| 70 dce = new SsaDeadCodeEliminator(compiler), | 74 dce = new SsaDeadCodeEliminator(compiler), |
| 71 new SsaTypePropagator(compiler)]; | 75 new SsaTypePropagator(compiler)]; |
| 72 runPhases(graph, phases); | 76 runPhases(graph, phases); |
| 73 if (dce.eliminatedSideEffects) { | 77 if (dce.eliminatedSideEffects) { |
| 74 phases = <OptimizationPhase>[ | 78 phases = <OptimizationPhase>[ |
| 75 new SsaGlobalValueNumberer(compiler), | 79 new SsaGlobalValueNumberer(compiler), |
| 76 new SsaCodeMotion(), | 80 new SsaCodeMotion(), |
| 77 new SsaValueRangeAnalyzer(compiler, constantSystem, work), | 81 new SsaValueRangeAnalyzer(compiler, constantSystem, work), |
| 78 new SsaInstructionSimplifier(constantSystem, backend, work), | 82 new SsaInstructionSimplifier(constantSystem, backend, work), |
| 79 new SsaCheckInserter(backend, work, context.boundsChecked), | 83 new SsaCheckInserter( |
| 84 trustPrimitives, backend, work, context.boundsChecked), |
| 80 new SsaSimplifyInterceptors(compiler, constantSystem, work), | 85 new SsaSimplifyInterceptors(compiler, constantSystem, work), |
| 81 new SsaDeadCodeEliminator(compiler)]; | 86 new SsaDeadCodeEliminator(compiler)]; |
| 82 } else { | 87 } else { |
| 83 phases = <OptimizationPhase>[ | 88 phases = <OptimizationPhase>[ |
| 84 // Run the simplifier to remove unneeded type checks inserted | 89 // Run the simplifier to remove unneeded type checks inserted |
| 85 // by type propagation. | 90 // by type propagation. |
| 86 new SsaInstructionSimplifier(constantSystem, backend, work)]; | 91 new SsaInstructionSimplifier(constantSystem, backend, work)]; |
| 87 } | 92 } |
| 88 runPhases(graph, phases); | 93 runPhases(graph, phases); |
| 89 }); | 94 }); |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 } | 884 } |
| 880 | 885 |
| 881 HInstruction visitOneShotInterceptor(HOneShotInterceptor node) { | 886 HInstruction visitOneShotInterceptor(HOneShotInterceptor node) { |
| 882 return handleInterceptedCall(node); | 887 return handleInterceptedCall(node); |
| 883 } | 888 } |
| 884 } | 889 } |
| 885 | 890 |
| 886 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { | 891 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { |
| 887 final Set<HInstruction> boundsChecked; | 892 final Set<HInstruction> boundsChecked; |
| 888 final CodegenWorkItem work; | 893 final CodegenWorkItem work; |
| 894 final bool trustPrimitives; |
| 889 final JavaScriptBackend backend; | 895 final JavaScriptBackend backend; |
| 890 final String name = "SsaCheckInserter"; | 896 final String name = "SsaCheckInserter"; |
| 891 HGraph graph; | 897 HGraph graph; |
| 892 | 898 |
| 893 SsaCheckInserter(this.backend, | 899 SsaCheckInserter(this.trustPrimitives, |
| 900 this.backend, |
| 894 this.work, | 901 this.work, |
| 895 this.boundsChecked); | 902 this.boundsChecked); |
| 896 | 903 |
| 897 void visitGraph(HGraph graph) { | 904 void visitGraph(HGraph graph) { |
| 898 this.graph = graph; | 905 this.graph = graph; |
| 906 |
| 907 // In --trust-primitives mode we don't add bounds checks. This is better |
| 908 // than trying to remove them later as the limit expression would become |
| 909 // dead and require DCE. |
| 910 if (trustPrimitives) return; |
| 911 |
| 899 visitDominatorTree(graph); | 912 visitDominatorTree(graph); |
| 900 } | 913 } |
| 901 | 914 |
| 902 void visitBasicBlock(HBasicBlock block) { | 915 void visitBasicBlock(HBasicBlock block) { |
| 903 HInstruction instruction = block.first; | 916 HInstruction instruction = block.first; |
| 904 while (instruction != null) { | 917 while (instruction != null) { |
| 905 HInstruction next = instruction.next; | 918 HInstruction next = instruction.next; |
| 906 instruction = instruction.accept(this); | 919 instruction = instruction.accept(this); |
| 907 instruction = next; | 920 instruction = next; |
| 908 } | 921 } |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2142 | 2155 |
| 2143 keyedValues.forEach((receiver, values) { | 2156 keyedValues.forEach((receiver, values) { |
| 2144 result.keyedValues[receiver] = | 2157 result.keyedValues[receiver] = |
| 2145 new Map<HInstruction, HInstruction>.from(values); | 2158 new Map<HInstruction, HInstruction>.from(values); |
| 2146 }); | 2159 }); |
| 2147 | 2160 |
| 2148 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2161 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 2149 return result; | 2162 return result; |
| 2150 } | 2163 } |
| 2151 } | 2164 } |
| OLD | NEW |