| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_elements.dart' show CommonElements; |
| 5 import '../common/backend_api.dart' show BackendClasses; | 6 import '../common/backend_api.dart' show BackendClasses; |
| 6 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 7 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 8 import '../elements/entities.dart'; | 9 import '../elements/entities.dart'; |
| 9 import '../js_backend/backend_helpers.dart'; | |
| 10 import '../js_backend/interceptor_data.dart'; | 10 import '../js_backend/interceptor_data.dart'; |
| 11 import '../types/types.dart'; | 11 import '../types/types.dart'; |
| 12 import '../universe/selector.dart' show Selector; | 12 import '../universe/selector.dart' show Selector; |
| 13 import '../world.dart' show ClosedWorld; | 13 import '../world.dart' show ClosedWorld; |
| 14 import 'nodes.dart'; | 14 import 'nodes.dart'; |
| 15 import 'optimize.dart'; | 15 import 'optimize.dart'; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * This phase simplifies interceptors in multiple ways: | 18 * This phase simplifies interceptors in multiple ways: |
| 19 * | 19 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 * receiver of an intercepted call a candidate for being generated at use site. | 31 * receiver of an intercepted call a candidate for being generated at use site. |
| 32 * | 32 * |
| 33 * 5) Some HIs operations on an interceptor are replaced with a HIs version that | 33 * 5) Some HIs operations on an interceptor are replaced with a HIs version that |
| 34 * uses 'instanceof' rather than testing a type flag. | 34 * uses 'instanceof' rather than testing a type flag. |
| 35 * | 35 * |
| 36 */ | 36 */ |
| 37 class SsaSimplifyInterceptors extends HBaseVisitor | 37 class SsaSimplifyInterceptors extends HBaseVisitor |
| 38 implements OptimizationPhase { | 38 implements OptimizationPhase { |
| 39 final String name = "SsaSimplifyInterceptors"; | 39 final String name = "SsaSimplifyInterceptors"; |
| 40 final ClosedWorld closedWorld; | 40 final ClosedWorld closedWorld; |
| 41 final BackendHelpers helpers; | |
| 42 final InterceptorData interceptorData; | 41 final InterceptorData interceptorData; |
| 42 final CommonElements _commonElements; |
| 43 final ClassEntity enclosingClass; | 43 final ClassEntity enclosingClass; |
| 44 HGraph graph; | 44 HGraph graph; |
| 45 | 45 |
| 46 SsaSimplifyInterceptors(this.closedWorld, this.helpers, this.interceptorData, | 46 SsaSimplifyInterceptors(this.closedWorld, this._commonElements, |
| 47 this.enclosingClass); | 47 this.interceptorData, this.enclosingClass); |
| 48 | 48 |
| 49 BackendClasses get backendClasses => closedWorld.backendClasses; | 49 BackendClasses get backendClasses => closedWorld.backendClasses; |
| 50 | 50 |
| 51 ConstantSystem get constantSystem => closedWorld.constantSystem; | 51 ConstantSystem get constantSystem => closedWorld.constantSystem; |
| 52 | 52 |
| 53 void visitGraph(HGraph graph) { | 53 void visitGraph(HGraph graph) { |
| 54 this.graph = graph; | 54 this.graph = graph; |
| 55 visitDominatorTree(graph); | 55 visitDominatorTree(graph); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 if (receiver.canBeNull() && | 103 if (receiver.canBeNull() && |
| 104 interceptedClasses.contains(backendClasses.nullClass)) { | 104 interceptedClasses.contains(backendClasses.nullClass)) { |
| 105 // Need the JSNull interceptor. | 105 // Need the JSNull interceptor. |
| 106 return false; | 106 return false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 // All intercepted classes extend `Interceptor`, so if the receiver can't be | 109 // All intercepted classes extend `Interceptor`, so if the receiver can't be |
| 110 // a class extending `Interceptor` then it can be called directly. | 110 // a class extending `Interceptor` then it can be called directly. |
| 111 return new TypeMask.nonNullSubclass(helpers.jsInterceptorClass, closedWorld) | 111 return new TypeMask.nonNullSubclass( |
| 112 _commonElements.jsInterceptorClass, closedWorld) |
| 112 .isDisjoint(receiver.instructionType, closedWorld); | 113 .isDisjoint(receiver.instructionType, closedWorld); |
| 113 } | 114 } |
| 114 | 115 |
| 115 HInstruction tryComputeConstantInterceptor( | 116 HInstruction tryComputeConstantInterceptor( |
| 116 HInstruction input, Set<ClassEntity> interceptedClasses) { | 117 HInstruction input, Set<ClassEntity> interceptedClasses) { |
| 117 if (input == graph.explicitReceiverParameter) { | 118 if (input == graph.explicitReceiverParameter) { |
| 118 // If `explicitReceiverParameter` is set it means the current method is an | 119 // If `explicitReceiverParameter` is set it means the current method is an |
| 119 // interceptor method, and `this` is the interceptor. The caller just did | 120 // interceptor method, and `this` is the interceptor. The caller just did |
| 120 // `getInterceptor(foo).currentMethod(foo)` to enter the current method. | 121 // `getInterceptor(foo).currentMethod(foo)` to enter the current method. |
| 121 return graph.thisInstruction; | 122 return graph.thisInstruction; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 instruction = new HInvokeDynamicMethod( | 422 instruction = new HInvokeDynamicMethod( |
| 422 selector, mask, inputs, node.instructionType, true); | 423 selector, mask, inputs, node.instructionType, true); |
| 423 } | 424 } |
| 424 | 425 |
| 425 HBasicBlock block = node.block; | 426 HBasicBlock block = node.block; |
| 426 block.addAfter(node, instruction); | 427 block.addAfter(node, instruction); |
| 427 block.rewrite(node, instruction); | 428 block.rewrite(node, instruction); |
| 428 return true; | 429 return true; |
| 429 } | 430 } |
| 430 } | 431 } |
| OLD | NEW |