| 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 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 6 import '../common/names.dart' show Selectors; | 6 import '../common/names.dart' show Selectors; |
| 7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| 11 import '../common_elements.dart' show CommonElements; | 11 import '../common_elements.dart' show CommonElements; |
| 12 import '../elements/elements.dart' | 12 import '../elements/elements.dart' |
| 13 show ClassElement, FieldElement, MethodElement; | 13 show ClassElement, FieldElement, MethodElement; |
| 14 import '../elements/entities.dart'; | 14 import '../elements/entities.dart'; |
| 15 import '../elements/resolution_types.dart'; | 15 import '../elements/resolution_types.dart'; |
| 16 import '../js/js.dart' as js; | 16 import '../js/js.dart' as js; |
| 17 import '../js_backend/js_backend.dart'; | 17 import '../js_backend/js_backend.dart'; |
| 18 import '../js_backend/interceptor_data.dart' show InterceptorData; | |
| 19 import '../js_backend/native_data.dart' show NativeData; | 18 import '../js_backend/native_data.dart' show NativeData; |
| 20 import '../native/native.dart' as native; | 19 import '../native/native.dart' as native; |
| 21 import '../options.dart'; | 20 import '../options.dart'; |
| 22 import '../tree/dartstring.dart' as ast; | 21 import '../tree/dartstring.dart' as ast; |
| 23 import '../types/types.dart'; | 22 import '../types/types.dart'; |
| 24 import '../universe/selector.dart' show Selector; | 23 import '../universe/selector.dart' show Selector; |
| 25 import '../universe/side_effects.dart' show SideEffects; | 24 import '../universe/side_effects.dart' show SideEffects; |
| 26 import '../util/util.dart'; | 25 import '../util/util.dart'; |
| 27 import '../world.dart' show ClosedWorld; | 26 import '../world.dart' show ClosedWorld; |
| 28 import 'interceptor_simplifier.dart'; | 27 import 'interceptor_simplifier.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 String get name => 'SSA optimizer'; | 46 String get name => 'SSA optimizer'; |
| 48 | 47 |
| 49 Compiler get _compiler => _backend.compiler; | 48 Compiler get _compiler => _backend.compiler; |
| 50 | 49 |
| 51 GlobalTypeInferenceResults get _results => _compiler.globalInference.results; | 50 GlobalTypeInferenceResults get _results => _compiler.globalInference.results; |
| 52 | 51 |
| 53 CompilerOptions get _options => _compiler.options; | 52 CompilerOptions get _options => _compiler.options; |
| 54 | 53 |
| 55 RuntimeTypesSubstitutions get _rtiSubstitutions => _backend.rtiSubstitutions; | 54 RuntimeTypesSubstitutions get _rtiSubstitutions => _backend.rtiSubstitutions; |
| 56 | 55 |
| 57 InterceptorData get _interceptorData => _backend.interceptorData; | |
| 58 | |
| 59 void optimize(CodegenWorkItem work, HGraph graph, ClosedWorld closedWorld) { | 56 void optimize(CodegenWorkItem work, HGraph graph, ClosedWorld closedWorld) { |
| 60 void runPhase(OptimizationPhase phase) { | 57 void runPhase(OptimizationPhase phase) { |
| 61 measureSubtask(phase.name, () => phase.visitGraph(graph)); | 58 measureSubtask(phase.name, () => phase.visitGraph(graph)); |
| 62 _backend.tracer.traceGraph(phase.name, graph); | 59 _backend.tracer.traceGraph(phase.name, graph); |
| 63 assert(graph.isValid(), 'Graph not valid after ${phase.name}'); | 60 assert(graph.isValid(), 'Graph not valid after ${phase.name}'); |
| 64 } | 61 } |
| 65 | 62 |
| 66 bool trustPrimitives = _options.trustPrimitives; | 63 bool trustPrimitives = _options.trustPrimitives; |
| 67 CodegenRegistry registry = work.registry; | 64 CodegenRegistry registry = work.registry; |
| 68 Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 65 Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 new SsaInstructionSimplifier( | 110 new SsaInstructionSimplifier( |
| 114 _results, _options, _rtiSubstitutions, closedWorld, registry), | 111 _results, _options, _rtiSubstitutions, closedWorld, registry), |
| 115 new SsaCheckInserter(trustPrimitives, closedWorld, boundsChecked), | 112 new SsaCheckInserter(trustPrimitives, closedWorld, boundsChecked), |
| 116 ]; | 113 ]; |
| 117 phases.forEach(runPhase); | 114 phases.forEach(runPhase); |
| 118 | 115 |
| 119 // Simplifying interceptors is not strictly just an optimization, it is | 116 // Simplifying interceptors is not strictly just an optimization, it is |
| 120 // required for implementation correctness because the code generator | 117 // required for implementation correctness because the code generator |
| 121 // assumes it is always performed. | 118 // assumes it is always performed. |
| 122 runPhase(new SsaSimplifyInterceptors( | 119 runPhase(new SsaSimplifyInterceptors( |
| 123 closedWorld, | 120 closedWorld, work.element.enclosingClass)); |
| 124 closedWorld.commonElements, | |
| 125 _interceptorData, | |
| 126 work.element.enclosingClass)); | |
| 127 | 121 |
| 128 SsaDeadCodeEliminator dce = new SsaDeadCodeEliminator(closedWorld, this); | 122 SsaDeadCodeEliminator dce = new SsaDeadCodeEliminator(closedWorld, this); |
| 129 runPhase(dce); | 123 runPhase(dce); |
| 130 if (codeMotion.movedCode || | 124 if (codeMotion.movedCode || |
| 131 dce.eliminatedSideEffects || | 125 dce.eliminatedSideEffects || |
| 132 loadElimination.newGvnCandidates) { | 126 loadElimination.newGvnCandidates) { |
| 133 phases = <OptimizationPhase>[ | 127 phases = <OptimizationPhase>[ |
| 134 new SsaTypePropagator( | 128 new SsaTypePropagator( |
| 135 _results, _options, closedWorld.commonElements, closedWorld), | 129 _results, _options, closedWorld.commonElements, closedWorld), |
| 136 new SsaGlobalValueNumberer(), | 130 new SsaGlobalValueNumberer(), |
| 137 new SsaCodeMotion(), | 131 new SsaCodeMotion(), |
| 138 new SsaValueRangeAnalyzer(closedWorld, this), | 132 new SsaValueRangeAnalyzer(closedWorld, this), |
| 139 new SsaInstructionSimplifier( | 133 new SsaInstructionSimplifier( |
| 140 _results, _options, _rtiSubstitutions, closedWorld, registry), | 134 _results, _options, _rtiSubstitutions, closedWorld, registry), |
| 141 new SsaCheckInserter(trustPrimitives, closedWorld, boundsChecked), | 135 new SsaCheckInserter(trustPrimitives, closedWorld, boundsChecked), |
| 142 new SsaSimplifyInterceptors(closedWorld, closedWorld.commonElements, | 136 new SsaSimplifyInterceptors(closedWorld, work.element.enclosingClass), |
| 143 _interceptorData, work.element.enclosingClass), | |
| 144 new SsaDeadCodeEliminator(closedWorld, this), | 137 new SsaDeadCodeEliminator(closedWorld, this), |
| 145 ]; | 138 ]; |
| 146 } else { | 139 } else { |
| 147 phases = <OptimizationPhase>[ | 140 phases = <OptimizationPhase>[ |
| 148 new SsaTypePropagator( | 141 new SsaTypePropagator( |
| 149 _results, _options, closedWorld.commonElements, closedWorld), | 142 _results, _options, closedWorld.commonElements, closedWorld), |
| 150 // Run the simplifier to remove unneeded type checks inserted by | 143 // Run the simplifier to remove unneeded type checks inserted by |
| 151 // type propagation. | 144 // type propagation. |
| 152 new SsaInstructionSimplifier( | 145 new SsaInstructionSimplifier( |
| 153 _results, _options, _rtiSubstitutions, closedWorld, registry), | 146 _results, _options, _rtiSubstitutions, closedWorld, registry), |
| (...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 | 2986 |
| 2994 keyedValues.forEach((receiver, values) { | 2987 keyedValues.forEach((receiver, values) { |
| 2995 result.keyedValues[receiver] = | 2988 result.keyedValues[receiver] = |
| 2996 new Map<HInstruction, HInstruction>.from(values); | 2989 new Map<HInstruction, HInstruction>.from(values); |
| 2997 }); | 2990 }); |
| 2998 | 2991 |
| 2999 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2992 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 3000 return result; | 2993 return result; |
| 3001 } | 2994 } |
| 3002 } | 2995 } |
| OLD | NEW |