OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library dart2js.cps_ir.share_interceptors; |
| 6 |
| 7 import 'cps_ir_nodes.dart'; |
| 8 import 'optimizers.dart'; |
| 9 |
| 10 /// Merges calls to `getInterceptor` when one call dominates the other. |
| 11 /// |
| 12 /// Should run after [LoopInvariantCodeMotion] so interceptors lifted out from |
| 13 /// loops can be merged. |
| 14 class ShareInterceptors extends RecursiveVisitor implements Pass { |
| 15 String get passName => 'Share interceptors'; |
| 16 |
| 17 final Map<Primitive, Interceptor> interceptorFor = |
| 18 <Primitive, Interceptor>{}; |
| 19 |
| 20 void rewrite(FunctionDefinition node) { |
| 21 visit(node.body); |
| 22 } |
| 23 |
| 24 @override |
| 25 Expression traverseLetPrim(LetPrim node) { |
| 26 if (node.primitive is Interceptor) { |
| 27 Interceptor interceptor = node.primitive; |
| 28 Primitive input = interceptor.input.definition; |
| 29 Interceptor existing = interceptorFor[input]; |
| 30 if (existing != null) { |
| 31 existing.interceptedClasses.addAll(interceptor.interceptedClasses); |
| 32 existing.substituteFor(interceptor); |
| 33 } else { |
| 34 interceptorFor[input] = interceptor; |
| 35 pushAction(() { |
| 36 interceptorFor.remove(input); |
| 37 }); |
| 38 } |
| 39 } |
| 40 return node.body; |
| 41 } |
| 42 } |
OLD | NEW |