| 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/entities.dart'; | 9 import '../elements/entities.dart'; |
| 10 import '../js_backend/backend.dart'; | 10 import '../js_backend/backend.dart'; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 user.inputs.where((input) => input == used).length; | 217 user.inputs.where((input) => input == used).length; |
| 218 | 218 |
| 219 Set<ClassEntity> interceptedClasses; | 219 Set<ClassEntity> interceptedClasses; |
| 220 HInstruction dominator = findDominator(node.usedBy); | 220 HInstruction dominator = findDominator(node.usedBy); |
| 221 // If there is a call that dominates all other uses, we can use just the | 221 // If there is a call that dominates all other uses, we can use just the |
| 222 // selector of that instruction. | 222 // selector of that instruction. |
| 223 if (dominator is HInvokeDynamic && | 223 if (dominator is HInvokeDynamic && |
| 224 dominator.isCallOnInterceptor(closedWorld) && | 224 dominator.isCallOnInterceptor(closedWorld) && |
| 225 node == dominator.receiver && | 225 node == dominator.receiver && |
| 226 useCount(dominator, node) == 1) { | 226 useCount(dominator, node) == 1) { |
| 227 interceptedClasses = | 227 interceptedClasses = backend.interceptorData |
| 228 backend.getInterceptedClassesOn(dominator.selector.name); | 228 .getInterceptedClassesOn(dominator.selector.name); |
| 229 | 229 |
| 230 // If we found that we need number, we must still go through all | 230 // If we found that we need number, we must still go through all |
| 231 // uses to check if they require int, or double. | 231 // uses to check if they require int, or double. |
| 232 if (interceptedClasses.contains(backendClasses.numClass) && | 232 if (interceptedClasses.contains(backendClasses.numClass) && |
| 233 !(interceptedClasses.contains(backendClasses.doubleClass) || | 233 !(interceptedClasses.contains(backendClasses.doubleClass) || |
| 234 interceptedClasses.contains(backendClasses.intClass))) { | 234 interceptedClasses.contains(backendClasses.intClass))) { |
| 235 Set<ClassEntity> required; | 235 Set<ClassEntity> required; |
| 236 for (HInstruction user in node.usedBy) { | 236 for (HInstruction user in node.usedBy) { |
| 237 if (user is! HInvoke) continue; | 237 if (user is! HInvoke) continue; |
| 238 Set<ClassEntity> intercepted = | 238 Set<ClassEntity> intercepted = backend.interceptorData |
| 239 backend.getInterceptedClassesOn(user.selector.name); | 239 .getInterceptedClassesOn(user.selector.name); |
| 240 if (intercepted.contains(backendClasses.intClass)) { | 240 if (intercepted.contains(backendClasses.intClass)) { |
| 241 // TODO(johnniwinther): Use type argument when all uses of | 241 // TODO(johnniwinther): Use type argument when all uses of |
| 242 // intercepted classes expect entities instead of elements. | 242 // intercepted classes expect entities instead of elements. |
| 243 required ??= new Set/*<ClassEntity>*/(); | 243 required ??= new Set/*<ClassEntity>*/(); |
| 244 required.add(backendClasses.intClass); | 244 required.add(backendClasses.intClass); |
| 245 } | 245 } |
| 246 if (intercepted.contains(backendClasses.doubleClass)) { | 246 if (intercepted.contains(backendClasses.doubleClass)) { |
| 247 // TODO(johnniwinther): Use type argument when all uses of | 247 // TODO(johnniwinther): Use type argument when all uses of |
| 248 // intercepted classes expect entities instead of elements. | 248 // intercepted classes expect entities instead of elements. |
| 249 required ??= new Set/*<ClassEntity>*/(); | 249 required ??= new Set/*<ClassEntity>*/(); |
| 250 required.add(backendClasses.doubleClass); | 250 required.add(backendClasses.doubleClass); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 // Don't modify the result of [backend.getInterceptedClassesOn]. | 253 // Don't modify the result of [backend.getInterceptedClassesOn]. |
| 254 if (required != null) { | 254 if (required != null) { |
| 255 interceptedClasses = interceptedClasses.union(required); | 255 interceptedClasses = interceptedClasses.union(required); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } else { | 258 } else { |
| 259 // TODO(johnniwinther): Use type argument when all uses of intercepted | 259 // TODO(johnniwinther): Use type argument when all uses of intercepted |
| 260 // classes expect entities instead of elements. | 260 // classes expect entities instead of elements. |
| 261 interceptedClasses = new Set/*<ClassEntity>*/(); | 261 interceptedClasses = new Set/*<ClassEntity>*/(); |
| 262 for (HInstruction user in node.usedBy) { | 262 for (HInstruction user in node.usedBy) { |
| 263 if (user is HInvokeDynamic && | 263 if (user is HInvokeDynamic && |
| 264 user.isCallOnInterceptor(closedWorld) && | 264 user.isCallOnInterceptor(closedWorld) && |
| 265 node == user.receiver && | 265 node == user.receiver && |
| 266 useCount(user, node) == 1) { | 266 useCount(user, node) == 1) { |
| 267 interceptedClasses | 267 interceptedClasses.addAll(backend.interceptorData |
| 268 .addAll(backend.getInterceptedClassesOn(user.selector.name)); | 268 .getInterceptedClassesOn(user.selector.name)); |
| 269 } else if (user is HInvokeSuper && | 269 } else if (user is HInvokeSuper && |
| 270 user.isCallOnInterceptor(closedWorld) && | 270 user.isCallOnInterceptor(closedWorld) && |
| 271 node == user.receiver && | 271 node == user.receiver && |
| 272 useCount(user, node) == 1) { | 272 useCount(user, node) == 1) { |
| 273 interceptedClasses | 273 interceptedClasses.addAll(backend.interceptorData |
| 274 .addAll(backend.getInterceptedClassesOn(user.selector.name)); | 274 .getInterceptedClassesOn(user.selector.name)); |
| 275 } else { | 275 } else { |
| 276 // Use a most general interceptor for other instructions, example, | 276 // Use a most general interceptor for other instructions, example, |
| 277 // is-checks and escaping interceptors. | 277 // is-checks and escaping interceptors. |
| 278 interceptedClasses.addAll(backend.interceptedClasses); | 278 interceptedClasses.addAll(backend.interceptorData.interceptedClasses); |
| 279 break; | 279 break; |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 node.interceptedClasses = interceptedClasses; | 284 node.interceptedClasses = interceptedClasses; |
| 285 | 285 |
| 286 HInstruction receiver = node.receiver; | 286 HInstruction receiver = node.receiver; |
| 287 | 287 |
| 288 // TODO(sra): We should consider each use individually and then all uses | 288 // TODO(sra): We should consider each use individually and then all uses |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 instruction = new HInvokeDynamicMethod( | 422 instruction = new HInvokeDynamicMethod( |
| 423 selector, mask, inputs, node.instructionType, true); | 423 selector, mask, inputs, node.instructionType, true); |
| 424 } | 424 } |
| 425 | 425 |
| 426 HBasicBlock block = node.block; | 426 HBasicBlock block = node.block; |
| 427 block.addAfter(node, instruction); | 427 block.addAfter(node, instruction); |
| 428 block.rewrite(node, instruction); | 428 block.rewrite(node, instruction); |
| 429 return true; | 429 return true; |
| 430 } | 430 } |
| 431 } | 431 } |
| OLD | NEW |