| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 '../compiler.dart' show Compiler; | 5 import '../compiler.dart' show Compiler; |
| 6 import '../constants/values.dart'; | 6 import '../constants/values.dart'; |
| 7 import '../elements/elements.dart'; | 7 import '../elements/elements.dart'; |
| 8 import '../js_backend/js_backend.dart'; | 8 import '../js_backend/js_backend.dart'; |
| 9 import '../types/types.dart'; | 9 import '../types/types.dart'; |
| 10 import '../universe/selector.dart' show Selector; | 10 import '../universe/selector.dart' show Selector; |
| 11 import '../world.dart' show ClosedWorld; |
| 11 import 'nodes.dart'; | 12 import 'nodes.dart'; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Replaces some instructions with specialized versions to make codegen easier. | 15 * Replaces some instructions with specialized versions to make codegen easier. |
| 15 * Caches codegen information on nodes. | 16 * Caches codegen information on nodes. |
| 16 */ | 17 */ |
| 17 class SsaInstructionSelection extends HBaseVisitor { | 18 class SsaInstructionSelection extends HBaseVisitor { |
| 18 final Compiler compiler; | 19 final Compiler compiler; |
| 19 HGraph graph; | 20 HGraph graph; |
| 20 | 21 |
| 21 SsaInstructionSelection(this.compiler); | 22 SsaInstructionSelection(this.compiler); |
| 22 | 23 |
| 23 JavaScriptBackend get backend => compiler.backend; | 24 JavaScriptBackend get backend => compiler.backend; |
| 24 | 25 |
| 26 ClosedWorld get closedWorld => compiler.closedWorld; |
| 27 |
| 25 void visitGraph(HGraph graph) { | 28 void visitGraph(HGraph graph) { |
| 26 this.graph = graph; | 29 this.graph = graph; |
| 27 visitDominatorTree(graph); | 30 visitDominatorTree(graph); |
| 28 } | 31 } |
| 29 | 32 |
| 30 visitBasicBlock(HBasicBlock block) { | 33 visitBasicBlock(HBasicBlock block) { |
| 31 HInstruction instruction = block.first; | 34 HInstruction instruction = block.first; |
| 32 while (instruction != null) { | 35 while (instruction != null) { |
| 33 HInstruction next = instruction.next; | 36 HInstruction next = instruction.next; |
| 34 HInstruction replacement = instruction.accept(this); | 37 HInstruction replacement = instruction.accept(this); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 60 | 63 |
| 61 HInstruction visitInstruction(HInstruction node) { | 64 HInstruction visitInstruction(HInstruction node) { |
| 62 return node; | 65 return node; |
| 63 } | 66 } |
| 64 | 67 |
| 65 HInstruction visitIs(HIs node) { | 68 HInstruction visitIs(HIs node) { |
| 66 if (node.kind == HIs.RAW_CHECK) { | 69 if (node.kind == HIs.RAW_CHECK) { |
| 67 HInstruction interceptor = node.interceptor; | 70 HInstruction interceptor = node.interceptor; |
| 68 if (interceptor != null) { | 71 if (interceptor != null) { |
| 69 return new HIsViaInterceptor( | 72 return new HIsViaInterceptor( |
| 70 node.typeExpression, interceptor, backend.boolType); | 73 node.typeExpression, interceptor, closedWorld.commonMasks.boolType); |
| 71 } | 74 } |
| 72 } | 75 } |
| 73 return node; | 76 return node; |
| 74 } | 77 } |
| 75 | 78 |
| 76 HInstruction visitIdentity(HIdentity node) { | 79 HInstruction visitIdentity(HIdentity node) { |
| 77 node.singleComparisonOp = simpleOp(node.left, node.right); | 80 node.singleComparisonOp = simpleOp(node.left, node.right); |
| 78 return node; | 81 return node; |
| 79 } | 82 } |
| 80 | 83 |
| 81 String simpleOp(HInstruction left, HInstruction right) { | 84 String simpleOp(HInstruction left, HInstruction right) { |
| 82 // Returns the single identity comparison (== or ===) or null if a more | 85 // Returns the single identity comparison (== or ===) or null if a more |
| 83 // complex expression is required. | 86 // complex expression is required. |
| 84 TypeMask leftType = left.instructionType; | 87 TypeMask leftType = left.instructionType; |
| 85 TypeMask rightType = right.instructionType; | 88 TypeMask rightType = right.instructionType; |
| 86 if (leftType.isNullable && rightType.isNullable) { | 89 if (leftType.isNullable && rightType.isNullable) { |
| 87 if (left.isConstantNull() || | 90 if (left.isConstantNull() || |
| 88 right.isConstantNull() || | 91 right.isConstantNull() || |
| 89 (left.isPrimitive(compiler) && leftType == rightType)) { | 92 (left.isPrimitive(closedWorld) && leftType == rightType)) { |
| 90 return '=='; | 93 return '=='; |
| 91 } | 94 } |
| 92 return null; | 95 return null; |
| 93 } | 96 } |
| 94 return '==='; | 97 return '==='; |
| 95 } | 98 } |
| 96 | 99 |
| 97 HInstruction visitInvokeDynamic(HInvokeDynamic node) { | 100 HInstruction visitInvokeDynamic(HInvokeDynamic node) { |
| 98 if (node.isInterceptedCall) { | 101 if (node.isInterceptedCall) { |
| 99 tryReplaceInterceptorWithDummy(node, node.selector, node.mask); | 102 tryReplaceInterceptorWithDummy(node, node.selector, node.mask); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 238 } |
| 236 | 239 |
| 237 HInstruction simpleBinary(String assignOp) { | 240 HInstruction simpleBinary(String assignOp) { |
| 238 HInvokeBinary binary = op; | 241 HInvokeBinary binary = op; |
| 239 return simple(assignOp, binary.left, binary.right); | 242 return simple(assignOp, binary.left, binary.right); |
| 240 } | 243 } |
| 241 | 244 |
| 242 HInstruction bitop(String assignOp) { | 245 HInstruction bitop(String assignOp) { |
| 243 // HBitAnd, HBitOr etc. are more difficult because HBitAnd(a.x, y) | 246 // HBitAnd, HBitOr etc. are more difficult because HBitAnd(a.x, y) |
| 244 // sometimes needs to be forced to unsigned: a.x = (a.x & y) >>> 0. | 247 // sometimes needs to be forced to unsigned: a.x = (a.x & y) >>> 0. |
| 245 if (op.isUInt31(compiler)) return simpleBinary(assignOp); | 248 if (op.isUInt31(closedWorld)) return simpleBinary(assignOp); |
| 246 return noMatchingRead(); | 249 return noMatchingRead(); |
| 247 } | 250 } |
| 248 | 251 |
| 249 if (op is HAdd) return plusOrMinus('+', '++'); | 252 if (op is HAdd) return plusOrMinus('+', '++'); |
| 250 if (op is HSubtract) return plusOrMinus('-', '--'); | 253 if (op is HSubtract) return plusOrMinus('-', '--'); |
| 251 | 254 |
| 252 if (op is HStringConcat) return simple('+', op.left, op.right); | 255 if (op is HStringConcat) return simple('+', op.left, op.right); |
| 253 | 256 |
| 254 if (op is HMultiply) return simpleBinary('*'); | 257 if (op is HMultiply) return simpleBinary('*'); |
| 255 if (op is HDivide) return simpleBinary('/'); | 258 if (op is HDivide) return simpleBinary('/'); |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 } | 798 } |
| 796 | 799 |
| 797 // If [thenInput] is defined in the first predecessor, then it is only used | 800 // If [thenInput] is defined in the first predecessor, then it is only used |
| 798 // by [phi] and can be generated at use site. | 801 // by [phi] and can be generated at use site. |
| 799 if (identical(thenInput.block, end.predecessors[0])) { | 802 if (identical(thenInput.block, end.predecessors[0])) { |
| 800 assert(thenInput.usedBy.length == 1); | 803 assert(thenInput.usedBy.length == 1); |
| 801 markAsGenerateAtUseSite(thenInput); | 804 markAsGenerateAtUseSite(thenInput); |
| 802 } | 805 } |
| 803 } | 806 } |
| 804 } | 807 } |
| OLD | NEW |