| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.cps_ir.share_interceptors; | 5 library dart2js.cps_ir.share_interceptors; |
| 6 | 6 |
| 7 import 'optimizers.dart'; | 7 import 'optimizers.dart'; |
| 8 import 'cps_ir_nodes.dart'; | 8 import 'cps_ir_nodes.dart'; |
| 9 import 'loop_hierarchy.dart'; | 9 import 'loop_hierarchy.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| 11 | 11 |
| 12 /// Removes redundant `getInterceptor` calls. | 12 /// Removes redundant `getInterceptor` calls. |
| 13 /// | 13 /// |
| 14 /// The pass performs three optimizations for interceptors: | 14 /// The pass performs three optimizations for interceptors: |
| 15 ///- pull interceptors out of loops | 15 ///- pull interceptors out of loops |
| 16 ///- replace interceptors with constants | 16 ///- replace interceptors with constants |
| 17 ///- share interceptors when one is in scope of the other | 17 ///- share interceptors when one is in scope of the other |
| 18 class ShareInterceptors extends RecursiveVisitor implements Pass { | 18 class ShareInterceptors extends TrampolineRecursiveVisitor implements Pass { |
| 19 String get passName => 'Share interceptors'; | 19 String get passName => 'Share interceptors'; |
| 20 | 20 |
| 21 /// The innermost loop containing a given primitive. | 21 /// The innermost loop containing a given primitive. |
| 22 final Map<Primitive, Continuation> loopHeaderFor = | 22 final Map<Primitive, Continuation> loopHeaderFor = |
| 23 <Primitive, Continuation>{}; | 23 <Primitive, Continuation>{}; |
| 24 | 24 |
| 25 /// An interceptor currently in scope for a given primitive. | 25 /// An interceptor currently in scope for a given primitive. |
| 26 final Map<Primitive, Primitive> interceptorFor = | 26 final Map<Primitive, Primitive> interceptorFor = |
| 27 <Primitive, Primitive>{}; | 27 <Primitive, Primitive>{}; |
| 28 | 28 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (existing != null) { | 108 if (existing != null) { |
| 109 existing.substituteFor(interceptor); | 109 existing.substituteFor(interceptor); |
| 110 interceptor.destroy(); | 110 interceptor.destroy(); |
| 111 node.remove(); | 111 node.remove(); |
| 112 return next; | 112 return next; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // The interceptor could not be shared. Replace it with a constant. | 115 // The interceptor could not be shared. Replace it with a constant. |
| 116 Constant constantPrim = new Constant(constant); | 116 Constant constantPrim = new Constant(constant); |
| 117 node.primitive = constantPrim; | 117 node.primitive = constantPrim; |
| 118 constantPrim.parent = node; |
| 118 constantPrim.hint = interceptor.hint; | 119 constantPrim.hint = interceptor.hint; |
| 119 constantPrim.type = interceptor.type; | 120 constantPrim.type = interceptor.type; |
| 120 constantPrim.substituteFor(interceptor); | 121 constantPrim.substituteFor(interceptor); |
| 121 interceptor.destroy(); | 122 interceptor.destroy(); |
| 122 sharedConstantFor[constant] = constantPrim; | 123 sharedConstantFor[constant] = constantPrim; |
| 123 } else { | 124 } else { |
| 124 interceptorFor[input] = interceptor; | 125 interceptorFor[input] = interceptor; |
| 125 } | 126 } |
| 126 | 127 |
| 127 // Determine the outermost loop where the input to the interceptor call | 128 // Determine the outermost loop where the input to the interceptor call |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 return c1; | 189 return c1; |
| 189 } | 190 } |
| 190 | 191 |
| 191 int getDepth(Continuation loop) { | 192 int getDepth(Continuation loop) { |
| 192 if (loop == null) return -1; | 193 if (loop == null) return -1; |
| 193 return loopHierarchy.loopDepth[loop]; | 194 return loopHierarchy.loopDepth[loop]; |
| 194 } | 195 } |
| 195 } | 196 } |
| OLD | NEW |