Chromium Code Reviews| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 return result; | 166 return result; |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool visitInterceptor(HInterceptor node) { | 169 bool visitInterceptor(HInterceptor node) { |
| 170 if (node.isConstant()) return false; | 170 if (node.isConstant()) return false; |
| 171 | 171 |
| 172 // If the interceptor is used by multiple instructions, specialize | 172 // If the interceptor is used by multiple instructions, specialize |
| 173 // it with a set of classes it intercepts. | 173 // it with a set of classes it intercepts. |
| 174 Set<ClassElement> interceptedClasses; | 174 Set<ClassElement> interceptedClasses; |
| 175 JavaScriptBackend backend = compiler.backend; | 175 JavaScriptBackend backend = compiler.backend; |
| 176 HInstruction dominator = | 176 HInstruction dominator = findDominator(node.usedBy.where((i) { |
| 177 findDominator(node.usedBy.where((i) => i is HInvokeDynamic)); | 177 return i is HInvokeDynamic || i is HIs; |
|
floitsch
2014/03/11 17:07:06
Indent by two and the next line by 0.
| |
| 178 })); | |
| 178 // If there is an instruction that dominates all others, we can | 179 // If there is an instruction that dominates all others, we can |
| 179 // use only the selector of that instruction. | 180 // use only the selector of that instruction. |
| 180 if (dominator != null) { | 181 if (dominator != null) { |
| 181 interceptedClasses = | 182 if (dominator is HIs) { |
| 182 backend.getInterceptedClassesOn(dominator.selector.name); | 183 // Is checks do not constrain the set of intercepted classes. |
| 184 interceptedClasses = backend.interceptedClasses; | |
| 185 } else { | |
| 186 interceptedClasses = | |
| 187 backend.getInterceptedClassesOn(dominator.selector.name); | |
| 183 | 188 |
| 184 // If we found that we need number, we must still go through all | 189 // If we found that we need number, we must still go through all |
| 185 // uses to check if they require int, or double. | 190 // uses to check if they require int, or double. |
| 186 if (interceptedClasses.contains(backend.jsNumberClass) | 191 if (interceptedClasses.contains(backend.jsNumberClass) |
| 187 && !(interceptedClasses.contains(backend.jsDoubleClass) | 192 && !(interceptedClasses.contains(backend.jsDoubleClass) |
| 188 || interceptedClasses.contains(backend.jsIntClass))) { | 193 || interceptedClasses.contains(backend.jsIntClass))) { |
| 189 for (HInstruction user in node.usedBy) { | 194 for (HInstruction user in node.usedBy) { |
| 190 if (user is! HInvoke) continue; | 195 if (user is! HInvoke) continue; |
| 191 Set<ClassElement> intercepted = | 196 Set<ClassElement> intercepted = |
| 192 backend.getInterceptedClassesOn(user.selector.name); | 197 backend.getInterceptedClassesOn(user.selector.name); |
| 193 if (intercepted.contains(backend.jsIntClass)) { | 198 if (intercepted.contains(backend.jsIntClass)) { |
| 194 interceptedClasses.add(backend.jsIntClass); | 199 interceptedClasses.add(backend.jsIntClass); |
| 195 } | 200 } |
| 196 if (intercepted.contains(backend.jsDoubleClass)) { | 201 if (intercepted.contains(backend.jsDoubleClass)) { |
| 197 interceptedClasses.add(backend.jsDoubleClass); | 202 interceptedClasses.add(backend.jsDoubleClass); |
| 203 } | |
| 198 } | 204 } |
| 199 } | 205 } |
| 200 } | 206 } |
| 201 } else { | 207 } else { |
| 202 interceptedClasses = new Set<ClassElement>(); | 208 interceptedClasses = new Set<ClassElement>(); |
| 203 for (HInstruction user in node.usedBy) { | 209 for (HInstruction user in node.usedBy) { |
| 204 if (user is HIs) { | 210 if (user is HIs) { |
| 205 // Is-checks can be performed on any intercepted class. | 211 // Is-checks can be performed on any intercepted class. |
| 206 interceptedClasses.addAll(backend.interceptedClasses); | 212 interceptedClasses.addAll(backend.interceptedClasses); |
| 207 break; | 213 break; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 instruction = new HInvokeDynamicMethod( | 334 instruction = new HInvokeDynamicMethod( |
| 329 selector, inputs, node.instructionType, true); | 335 selector, inputs, node.instructionType, true); |
| 330 } | 336 } |
| 331 | 337 |
| 332 HBasicBlock block = node.block; | 338 HBasicBlock block = node.block; |
| 333 block.addAfter(node, instruction); | 339 block.addAfter(node, instruction); |
| 334 block.rewrite(node, instruction); | 340 block.rewrite(node, instruction); |
| 335 return true; | 341 return true; |
| 336 } | 342 } |
| 337 } | 343 } |
| OLD | NEW |