| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Instead of emitting each SSA instruction with a temporary variable | 8 * Instead of emitting each SSA instruction with a temporary variable |
| 9 * mark instructions that can be emitted at their use-site. | 9 * mark instructions that can be emitted at their use-site. |
| 10 * For example, in: | 10 * For example, in: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 assert(!instruction.isJsStatement()); | 33 assert(!instruction.isJsStatement()); |
| 34 generateAtUseSite.add(instruction); | 34 generateAtUseSite.add(instruction); |
| 35 } | 35 } |
| 36 | 36 |
| 37 SsaInstructionMerger(this.types, this.generateAtUseSite); | 37 SsaInstructionMerger(this.types, this.generateAtUseSite); |
| 38 | 38 |
| 39 void visitGraph(HGraph graph) { | 39 void visitGraph(HGraph graph) { |
| 40 visitDominatorTree(graph); | 40 visitDominatorTree(graph); |
| 41 } | 41 } |
| 42 | 42 |
| 43 /** | |
| 44 * Return whether the instructions do not belong to a loop or | |
| 45 * belong to the same loop. | |
| 46 */ | |
| 47 bool notInLoopOrInSameLoop(HInstruction one, HInstruction two) { | |
| 48 return one.block.enclosingLoopHeader == two.block.enclosingLoopHeader; | |
| 49 } | |
| 50 | |
| 51 void analyzeInputs(HInstruction user, int start) { | 43 void analyzeInputs(HInstruction user, int start) { |
| 52 List<HInstruction> inputs = user.inputs; | 44 List<HInstruction> inputs = user.inputs; |
| 53 for (int i = start; i < inputs.length; i++) { | 45 for (int i = start; i < inputs.length; i++) { |
| 54 HInstruction input = inputs[i]; | 46 HInstruction input = inputs[i]; |
| 55 if (!generateAtUseSite.contains(input) | 47 if (!generateAtUseSite.contains(input) |
| 56 && !input.isCodeMotionInvariant() | 48 && !input.isCodeMotionInvariant() |
| 57 && input.usedBy.length == 1 | 49 && input.usedBy.length == 1 |
| 58 && input is !HPhi | 50 && input is !HPhi |
| 59 && input is !HLocalValue | 51 && input is !HLocalValue |
| 60 && !input.isJsStatement()) { | 52 && !input.isJsStatement()) { |
| 61 if (input.isPure()) { | 53 if (input.isPure()) { |
| 62 // Only consider a pure input if it is in the same loop. | 54 // Only consider a pure input if it is in the same loop. |
| 63 // Otherwise, we might move GVN'ed instruction back into the | 55 // Otherwise, we might move GVN'ed instruction back into the |
| 64 // loop. | 56 // loop. |
| 65 if (notInLoopOrInSameLoop(user, input)) { | 57 if (user.hasSameLoopHeaderAs(input)) { |
| 66 // Move it closer to [user], so that instructions in | 58 // Move it closer to [user], so that instructions in |
| 67 // between do not prevent making it generate at use site. | 59 // between do not prevent making it generate at use site. |
| 68 input.moveBefore(user); | 60 input.moveBefore(user); |
| 69 pureInputs.add(input); | 61 pureInputs.add(input); |
| 70 // Visit the pure input now so that the expected inputs | 62 // Visit the pure input now so that the expected inputs |
| 71 // are after the expected inputs of [user]. | 63 // are after the expected inputs of [user]. |
| 72 input.accept(this); | 64 input.accept(this); |
| 73 } | 65 } |
| 74 } else { | 66 } else { |
| 75 expectedInputs.add(input); | 67 expectedInputs.add(input); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 371 } |
| 380 | 372 |
| 381 // If [thenInput] is defined in the first predecessor, then it is only used | 373 // If [thenInput] is defined in the first predecessor, then it is only used |
| 382 // by [phi] and can be generated at use site. | 374 // by [phi] and can be generated at use site. |
| 383 if (identical(thenInput.block, end.predecessors[0])) { | 375 if (identical(thenInput.block, end.predecessors[0])) { |
| 384 assert(thenInput.usedBy.length == 1); | 376 assert(thenInput.usedBy.length == 1); |
| 385 markAsGenerateAtUseSite(thenInput); | 377 markAsGenerateAtUseSite(thenInput); |
| 386 } | 378 } |
| 387 } | 379 } |
| 388 } | 380 } |
| OLD | NEW |