| 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 /** | 5 /** |
| 6 * Instead of emitting each SSA instruction with a temporary variable | 6 * Instead of emitting each SSA instruction with a temporary variable |
| 7 * mark instructions that can be emitted at their use-site. | 7 * mark instructions that can be emitted at their use-site. |
| 8 * For example, in: | 8 * For example, in: |
| 9 * t0 = 4; | 9 * t0 = 4; |
| 10 * t1 = 3; | 10 * t1 = 3; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 && input is !HPhi) { | 32 && input is !HPhi) { |
| 33 expectedInputs.add(input); | 33 expectedInputs.add(input); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 // The codegen might use the input multiple times, so it must not be | 38 // The codegen might use the input multiple times, so it must not be |
| 39 // set generate at use site. | 39 // set generate at use site. |
| 40 void visitIs(HIs instruction) {} | 40 void visitIs(HIs instruction) {} |
| 41 | 41 |
| 42 // A check method must not have its input generate at use site, | 42 // A check method must not have its input generated at use site, |
| 43 // because it's using it multiple times. | 43 // because it's using it multiple times. |
| 44 void visitCheck(HCheck instruction) {} | 44 void visitCheck(HCheck instruction) {} |
| 45 | 45 |
| 46 // A type guard should not generate its input at use site, otherwise | 46 // A type guard should not generate its input at use site, otherwise |
| 47 // they would not be alive. | 47 // they would not be alive. |
| 48 void visitTypeGuard(HTypeGuard instruction) {} | 48 void visitTypeGuard(HTypeGuard instruction) {} |
| 49 | 49 |
| 50 // If an equality operation is builtin it must not have its input generated at |
| 51 // use site, because it's using it multiple times (because of null/undefined). |
| 52 void visitEquals(HEquals instruction) { |
| 53 if (!instruction.builtin) super.visitEquals(instruction); |
| 54 // Otherwise do nothing. |
| 55 } |
| 56 |
| 57 // Identity operations must not have its input generated at use site, because |
| 58 // it's using it multiple times (because of null/undefined). |
| 59 void visitIdentity(HIdentity instruction) {} |
| 60 |
| 50 void visitTypeConversion(HTypeConversion instruction) { | 61 void visitTypeConversion(HTypeConversion instruction) { |
| 51 if (!instruction.isChecked()) { | 62 if (!instruction.isChecked()) { |
| 52 generateAtUseSite.add(instruction); | 63 generateAtUseSite.add(instruction); |
| 53 } else if (instruction.isCheckedModeCheck()) { | 64 } else if (instruction.isCheckedModeCheck()) { |
| 54 // Checked mode checks compile to code that only use their input | 65 // Checked mode checks compile to code that only use their input |
| 55 // once, so we can safely visit them and try to merge the input. | 66 // once, so we can safely visit them and try to merge the input. |
| 56 visitInstruction(instruction); | 67 visitInstruction(instruction); |
| 57 } | 68 } |
| 58 } | 69 } |
| 59 | 70 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 225 |
| 215 if (hasAnyStatement(elseBlock, elseInput)) return; | 226 if (hasAnyStatement(elseBlock, elseInput)) return; |
| 216 assert(elseBlock.successors.length == 1); | 227 assert(elseBlock.successors.length == 1); |
| 217 assert(end.predecessors.length == 2); | 228 assert(end.predecessors.length == 2); |
| 218 | 229 |
| 219 HBasicBlock thenBlock = startIf.thenBlock; | 230 HBasicBlock thenBlock = startIf.thenBlock; |
| 220 // Skip trivial goto blocks. | 231 // Skip trivial goto blocks. |
| 221 while (thenBlock.successors[0] != end && thenBlock.first is HGoto) { | 232 while (thenBlock.successors[0] != end && thenBlock.first is HGoto) { |
| 222 thenBlock = thenBlock.successors[0]; | 233 thenBlock = thenBlock.successors[0]; |
| 223 } | 234 } |
| 224 | 235 |
| 225 // If the [thenBlock] is already a control flow operation, and does not | 236 // If the [thenBlock] is already a control flow operation, and does not |
| 226 // have any statement and its join block is [end], we can emit a | 237 // have any statement and its join block is [end], we can emit a |
| 227 // sequence of control flow operation. | 238 // sequence of control flow operation. |
| 228 if (controlFlowOperators.contains(thenBlock.last)) { | 239 if (controlFlowOperators.contains(thenBlock.last)) { |
| 229 HIf otherIf = thenBlock.last; | 240 HIf otherIf = thenBlock.last; |
| 230 if (otherIf.joinBlock !== end) return; | 241 if (otherIf.joinBlock !== end) return; |
| 231 if (hasAnyStatement(thenBlock, otherIf)) return; | 242 if (hasAnyStatement(thenBlock, otherIf)) return; |
| 232 } else { | 243 } else { |
| 233 if (end.predecessors[0] !== thenBlock) return; | 244 if (end.predecessors[0] !== thenBlock) return; |
| 234 if (hasAnyStatement(thenBlock, thenInput)) return; | 245 if (hasAnyStatement(thenBlock, thenInput)) return; |
| 235 assert(thenBlock.successors.length == 1); | 246 assert(thenBlock.successors.length == 1); |
| 236 } | 247 } |
| 237 | 248 |
| 238 // From now on, we have recognized a control flow operation built from | 249 // From now on, we have recognized a control flow operation built from |
| 239 // the builder. Mark the if instruction as such. | 250 // the builder. Mark the if instruction as such. |
| 240 controlFlowOperators.add(startIf); | 251 controlFlowOperators.add(startIf); |
| 241 | 252 |
| 242 // If the operation is only used by the first instruction | 253 // If the operation is only used by the first instruction |
| 243 // of its block and is safe to be generated at use sute, mark it | 254 // of its block and is safe to be generated at use sute, mark it |
| 244 // so. | 255 // so. |
| 245 if (phi.usedBy.length == 1 | 256 if (phi.usedBy.length == 1 |
| 246 && phi.usedBy[0] === phi.block.first | 257 && phi.usedBy[0] === phi.block.first |
| 247 && isSafeToGenerateAtUseSite(phi.usedBy[0], phi)) { | 258 && isSafeToGenerateAtUseSite(phi.usedBy[0], phi)) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 }; | 346 }; |
| 336 } | 347 } |
| 337 | 348 |
| 338 class JSBinaryOperatorPrecedence { | 349 class JSBinaryOperatorPrecedence { |
| 339 final int left; | 350 final int left; |
| 340 final int right; | 351 final int right; |
| 341 const JSBinaryOperatorPrecedence(this.left, this.right); | 352 const JSBinaryOperatorPrecedence(this.left, this.right); |
| 342 // All binary operators (excluding assignment) are left associative. | 353 // All binary operators (excluding assignment) are left associative. |
| 343 int get precedence() => left; | 354 int get precedence() => left; |
| 344 } | 355 } |
| OLD | NEW |