| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This phase simplifies interceptors in multiple ways: | 8 * This phase simplifies interceptors in multiple ways: |
| 9 * | 9 * |
| 10 * 1) If the interceptor is for an object whose type is known, it | 10 * 1) If the interceptor is for an object whose type is known, it |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // use only the selector of that instruction. | 179 // use only the selector of that instruction. |
| 180 if (dominator != null) { | 180 if (dominator != null) { |
| 181 interceptedClasses = | 181 interceptedClasses = |
| 182 backend.getInterceptedClassesOn(dominator.selector.name); | 182 backend.getInterceptedClassesOn(dominator.selector.name); |
| 183 | 183 |
| 184 // If we found that we need number, we must still go through all | 184 // If we found that we need number, we must still go through all |
| 185 // uses to check if they require int, or double. | 185 // uses to check if they require int, or double. |
| 186 if (interceptedClasses.contains(backend.jsNumberClass) | 186 if (interceptedClasses.contains(backend.jsNumberClass) |
| 187 && !(interceptedClasses.contains(backend.jsDoubleClass) | 187 && !(interceptedClasses.contains(backend.jsDoubleClass) |
| 188 || interceptedClasses.contains(backend.jsIntClass))) { | 188 || interceptedClasses.contains(backend.jsIntClass))) { |
| 189 for (var user in node.usedBy) { | 189 for (HInstruction user in node.usedBy) { |
| 190 if (user is! HInvoke) continue; | 190 if (user is! HInvoke) continue; |
| 191 Set<ClassElement> intercepted = | 191 Set<ClassElement> intercepted = |
| 192 backend.getInterceptedClassesOn(user.selector.name); | 192 backend.getInterceptedClassesOn(user.selector.name); |
| 193 if (intercepted.contains(backend.jsIntClass)) { | 193 if (intercepted.contains(backend.jsIntClass)) { |
| 194 interceptedClasses.add(backend.jsIntClass); | 194 interceptedClasses.add(backend.jsIntClass); |
| 195 } | 195 } |
| 196 if (intercepted.contains(backend.jsDoubleClass)) { | 196 if (intercepted.contains(backend.jsDoubleClass)) { |
| 197 interceptedClasses.add(backend.jsDoubleClass); | 197 interceptedClasses.add(backend.jsDoubleClass); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 } else { | 201 } else { |
| 202 interceptedClasses = new Set<ClassElement>(); | 202 interceptedClasses = new Set<ClassElement>(); |
| 203 for (var user in node.usedBy) { | 203 for (HInstruction user in node.usedBy) { |
| 204 if (user is HIs) { | 204 if (user is HIs) { |
| 205 // Is-checks can be performed on any intercepted class. | 205 // Is-checks can be performed on any intercepted class. |
| 206 interceptedClasses.addAll(backend.interceptedClasses); | 206 interceptedClasses.addAll(backend.interceptedClasses); |
| 207 break; | 207 break; |
| 208 } | 208 } |
| 209 if (user is! HInvoke) continue; | 209 if (user is! HInvoke) continue; |
| 210 // We don't handle escaping interceptors yet. | 210 // We don't handle escaping interceptors yet. |
| 211 interceptedClasses.addAll( | 211 interceptedClasses.addAll( |
| 212 backend.getInterceptedClassesOn(user.selector.name)); | 212 backend.getInterceptedClassesOn(user.selector.name)); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 HInstruction receiver = node.receiver; | 216 HInstruction receiver = node.receiver; |
| 217 if (canUseSelfForInterceptor(receiver, interceptedClasses)) { | 217 if (canUseSelfForInterceptor(receiver, interceptedClasses)) { |
| 218 List<HInstruction> users = node.usedBy.toList(); |
| 218 node.block.rewrite(node, receiver); | 219 node.block.rewrite(node, receiver); |
| 220 |
| 221 // Replace occurences of the receiver in invocations with a dummy receiver |
| 222 // if the selector matches only methods that ignore the receiver. |
| 223 JavaScriptBackend backend = compiler.backend; |
| 224 for (HInstruction user in users) { |
| 225 if (user is HInvokeDynamic) { |
| 226 HInvokeDynamic invoke = user; |
| 227 if (invoke.getDartReceiver(compiler) == receiver |
| 228 && !backend.isInterceptedMixinSelector(invoke.selector)) { |
| 229 // [receiver] might not be the direct input since `node.receiver` |
| 230 // looks through type conversion nodes like [TypeKnown]. |
| 231 HInstruction immediateReceiver = invoke.inputs[1]; |
| 232 Constant constant = new DummyReceiverConstant( |
| 233 immediateReceiver.instructionType); |
| 234 HConstant dummy = graph.addConstant(constant, compiler); |
| 235 immediateReceiver.usedBy.remove(invoke); |
| 236 invoke.inputs[1] = dummy; |
| 237 dummy.usedBy.add(invoke); |
| 238 } |
| 239 } |
| 240 } |
| 219 return false; | 241 return false; |
| 220 } | 242 } |
| 221 | 243 |
| 222 // Try computing a constant interceptor. | 244 // Try computing a constant interceptor. |
| 223 HInstruction constantInterceptor = | 245 HInstruction constantInterceptor = |
| 224 tryComputeConstantInterceptor(receiver, interceptedClasses); | 246 tryComputeConstantInterceptor(receiver, interceptedClasses); |
| 225 if (constantInterceptor != null) { | 247 if (constantInterceptor != null) { |
| 226 node.block.rewrite(node, constantInterceptor); | 248 node.block.rewrite(node, constantInterceptor); |
| 227 return false; | 249 return false; |
| 228 } | 250 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 instruction = new HInvokeDynamicMethod( | 302 instruction = new HInvokeDynamicMethod( |
| 281 selector, inputs, node.instructionType, true); | 303 selector, inputs, node.instructionType, true); |
| 282 } | 304 } |
| 283 | 305 |
| 284 HBasicBlock block = node.block; | 306 HBasicBlock block = node.block; |
| 285 block.addAfter(node, instruction); | 307 block.addAfter(node, instruction); |
| 286 block.rewrite(node, instruction); | 308 block.rewrite(node, instruction); |
| 287 return true; | 309 return true; |
| 288 } | 310 } |
| 289 } | 311 } |
| OLD | NEW |