| 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/backend_api.dart' show BackendClasses; | 5 import '../common/backend_api.dart' show BackendClasses; |
| 6 import '../compiler.dart' show Compiler; | 6 import '../compiler.dart' show Compiler; |
| 7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../js_backend/backend.dart'; | 10 import '../js_backend/backend.dart'; |
| (...skipping 20 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 ConstantSystem constantSystem; | |
| 42 final Compiler compiler; | 41 final Compiler compiler; |
| 43 final Element element; | 42 final Element element; |
| 44 HGraph graph; | 43 HGraph graph; |
| 45 | 44 |
| 46 SsaSimplifyInterceptors( | 45 SsaSimplifyInterceptors(this.compiler, this.closedWorld, this.element); |
| 47 this.compiler, this.closedWorld, this.constantSystem, this.element); | |
| 48 | 46 |
| 49 JavaScriptBackend get backend => compiler.backend; | 47 JavaScriptBackend get backend => compiler.backend; |
| 50 | 48 |
| 51 BackendClasses get backendClasses => closedWorld.backendClasses; | 49 BackendClasses get backendClasses => closedWorld.backendClasses; |
| 52 | 50 |
| 51 ConstantSystem get constantSystem => closedWorld.constantSystem; |
| 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 |
| 58 void visitBasicBlock(HBasicBlock node) { | 58 void visitBasicBlock(HBasicBlock node) { |
| 59 currentBlock = node; | 59 currentBlock = node; |
| 60 | 60 |
| 61 HInstruction instruction = node.first; | 61 HInstruction instruction = node.first; |
| 62 while (instruction != null) { | 62 while (instruction != null) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 // If we just happen to be in an instance method of the constant | 130 // If we just happen to be in an instance method of the constant |
| 131 // interceptor, `this` is a shorter alias. | 131 // interceptor, `this` is a shorter alias. |
| 132 if (constantInterceptor == element.enclosingClass && | 132 if (constantInterceptor == element.enclosingClass && |
| 133 graph.thisInstruction != null) { | 133 graph.thisInstruction != null) { |
| 134 return graph.thisInstruction; | 134 return graph.thisInstruction; |
| 135 } | 135 } |
| 136 | 136 |
| 137 ConstantValue constant = | 137 ConstantValue constant = |
| 138 new InterceptorConstantValue(constantInterceptor.thisType); | 138 new InterceptorConstantValue(constantInterceptor.thisType); |
| 139 return graph.addConstant(constant, compiler); | 139 return graph.addConstant(constant, closedWorld); |
| 140 } | 140 } |
| 141 | 141 |
| 142 ClassElement tryComputeConstantInterceptorFromType( | 142 ClassElement tryComputeConstantInterceptorFromType( |
| 143 TypeMask type, Set<ClassElement> interceptedClasses) { | 143 TypeMask type, Set<ClassElement> interceptedClasses) { |
| 144 if (type.isNullable) { | 144 if (type.isNullable) { |
| 145 if (type.isNull) { | 145 if (type.isNull) { |
| 146 return backendClasses.nullImplementation; | 146 return backendClasses.nullImplementation; |
| 147 } | 147 } |
| 148 } else if (type.containsOnlyInt(closedWorld)) { | 148 } else if (type.containsOnlyInt(closedWorld)) { |
| 149 return backendClasses.intImplementation; | 149 return backendClasses.intImplementation; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (!interceptedClasses.contains(backendClasses.nullImplementation)) { | 313 if (!interceptedClasses.contains(backendClasses.nullImplementation)) { |
| 314 // Can use `(receiver && C)` only if receiver is either null or truthy. | 314 // Can use `(receiver && C)` only if receiver is either null or truthy. |
| 315 if (!(receiver.canBePrimitiveNumber(closedWorld) || | 315 if (!(receiver.canBePrimitiveNumber(closedWorld) || |
| 316 receiver.canBePrimitiveBoolean(closedWorld) || | 316 receiver.canBePrimitiveBoolean(closedWorld) || |
| 317 receiver.canBePrimitiveString(closedWorld))) { | 317 receiver.canBePrimitiveString(closedWorld))) { |
| 318 ClassElement interceptorClass = tryComputeConstantInterceptorFromType( | 318 ClassElement interceptorClass = tryComputeConstantInterceptorFromType( |
| 319 receiver.instructionType.nonNullable(), interceptedClasses); | 319 receiver.instructionType.nonNullable(), interceptedClasses); |
| 320 if (interceptorClass != null) { | 320 if (interceptorClass != null) { |
| 321 HInstruction constantInstruction = graph.addConstant( | 321 HInstruction constantInstruction = graph.addConstant( |
| 322 new InterceptorConstantValue(interceptorClass.thisType), | 322 new InterceptorConstantValue(interceptorClass.thisType), |
| 323 compiler); | 323 closedWorld); |
| 324 node.conditionalConstantInterceptor = constantInstruction; | 324 node.conditionalConstantInterceptor = constantInstruction; |
| 325 constantInstruction.usedBy.add(node); | 325 constantInstruction.usedBy.add(node); |
| 326 return false; | 326 return false; |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Try creating a one-shot interceptor or optimized is-check | 332 // Try creating a one-shot interceptor or optimized is-check |
| 333 if (compiler.options.hasIncrementalSupport) return false; | 333 if (compiler.options.hasIncrementalSupport) return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 353 HInstruction instanceofCheck = new HIs.instanceOf( | 353 HInstruction instanceofCheck = new HIs.instanceOf( |
| 354 user.typeExpression, user.expression, user.instructionType); | 354 user.typeExpression, user.expression, user.instructionType); |
| 355 instanceofCheck.sourceInformation = user.sourceInformation; | 355 instanceofCheck.sourceInformation = user.sourceInformation; |
| 356 instanceofCheck.sourceElement = user.sourceElement; | 356 instanceofCheck.sourceElement = user.sourceElement; |
| 357 return replaceUserWith(instanceofCheck); | 357 return replaceUserWith(instanceofCheck); |
| 358 } | 358 } |
| 359 } | 359 } |
| 360 } else if (user is HInvokeDynamic) { | 360 } else if (user is HInvokeDynamic) { |
| 361 if (node == user.inputs[0]) { | 361 if (node == user.inputs[0]) { |
| 362 // Replace the user with a [HOneShotInterceptor]. | 362 // Replace the user with a [HOneShotInterceptor]. |
| 363 HConstant nullConstant = graph.addConstantNull(compiler); | 363 HConstant nullConstant = graph.addConstantNull(closedWorld); |
| 364 List<HInstruction> inputs = new List<HInstruction>.from(user.inputs); | 364 List<HInstruction> inputs = new List<HInstruction>.from(user.inputs); |
| 365 inputs[0] = nullConstant; | 365 inputs[0] = nullConstant; |
| 366 HOneShotInterceptor oneShotInterceptor = new HOneShotInterceptor( | 366 HOneShotInterceptor oneShotInterceptor = new HOneShotInterceptor( |
| 367 user.selector, | 367 user.selector, |
| 368 user.mask, | 368 user.mask, |
| 369 inputs, | 369 inputs, |
| 370 user.instructionType, | 370 user.instructionType, |
| 371 interceptedClasses); | 371 interceptedClasses); |
| 372 oneShotInterceptor.sourceInformation = user.sourceInformation; | 372 oneShotInterceptor.sourceInformation = user.sourceInformation; |
| 373 oneShotInterceptor.sourceElement = user.sourceElement; | 373 oneShotInterceptor.sourceElement = user.sourceElement; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 instruction = new HInvokeDynamicMethod( | 419 instruction = new HInvokeDynamicMethod( |
| 420 selector, mask, inputs, node.instructionType, true); | 420 selector, mask, inputs, node.instructionType, true); |
| 421 } | 421 } |
| 422 | 422 |
| 423 HBasicBlock block = node.block; | 423 HBasicBlock block = node.block; |
| 424 block.addAfter(node, instruction); | 424 block.addAfter(node, instruction); |
| 425 block.rewrite(node, instruction); | 425 block.rewrite(node, instruction); |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 } | 428 } |
| OLD | NEW |