| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Keep a list of expected inputs of the current "expression" being | 85 // Keep a list of expected inputs of the current "expression" being |
| 86 // merged. If instructions occur in the expected order, they are | 86 // merged. If instructions occur in the expected order, they are |
| 87 // included in the expression. | 87 // included in the expression. |
| 88 | 88 |
| 89 // The expectedInputs list holds non-trivial instructions that may | 89 // The expectedInputs list holds non-trivial instructions that may |
| 90 // be generated at their use site, if they occur in the correct order. | 90 // be generated at their use site, if they occur in the correct order. |
| 91 if (expectedInputs === null) expectedInputs = new List<HInstruction>(); | 91 if (expectedInputs === null) expectedInputs = new List<HInstruction>(); |
| 92 | 92 |
| 93 // Pop instructions from expectedInputs until instruction is found. | 93 // Pop instructions from expectedInputs until instruction is found. |
| 94 // Return true if it is found, or false if not. | 94 // Return true if it is found, or false if not. |
| 95 bool findInInputs(HInstruction instruction) { | 95 bool findInInputsAndPopNonMatching(HInstruction instruction) { |
| 96 while (!expectedInputs.isEmpty()) { | 96 while (!expectedInputs.isEmpty()) { |
| 97 HInstruction nextInput = expectedInputs.removeLast(); | 97 HInstruction nextInput = expectedInputs.removeLast(); |
| 98 assert(!generateAtUseSite.contains(nextInput)); | 98 assert(!generateAtUseSite.contains(nextInput)); |
| 99 assert(nextInput.usedBy.length == 1); | 99 assert(nextInput.usedBy.length == 1); |
| 100 if (nextInput === instruction) { | 100 if (nextInput === instruction) { |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 127 for (HInstruction instruction = block.last.previous; | 127 for (HInstruction instruction = block.last.previous; |
| 128 instruction !== null; | 128 instruction !== null; |
| 129 instruction = instruction.previous) { | 129 instruction = instruction.previous) { |
| 130 if (generateAtUseSite.contains(instruction)) { | 130 if (generateAtUseSite.contains(instruction)) { |
| 131 continue; | 131 continue; |
| 132 } | 132 } |
| 133 if (instruction.isCodeMotionInvariant()) { | 133 if (instruction.isCodeMotionInvariant()) { |
| 134 generateAtUseSite.add(instruction); | 134 generateAtUseSite.add(instruction); |
| 135 continue; | 135 continue; |
| 136 } | 136 } |
| 137 bool foundInInputs = false; | |
| 138 // See if the current instruction is the next non-trivial | 137 // See if the current instruction is the next non-trivial |
| 139 // expected input. If not, drop the expectedInputs and | 138 // expected input. |
| 140 // start over. | 139 if (findInInputsAndPopNonMatching(instruction)) { |
| 141 if (findInInputs(instruction)) { | |
| 142 foundInInputs = true; | |
| 143 tryGenerateAtUseSite(instruction); | 140 tryGenerateAtUseSite(instruction); |
| 144 } else { | 141 } else { |
| 145 assert(expectedInputs.isEmpty()); | 142 assert(expectedInputs.isEmpty()); |
| 146 } | 143 } |
| 147 if (foundInInputs || usedOnlyByPhis(instruction)) { | 144 instruction.accept(this); |
| 148 // Try merging all non-trivial inputs. | |
| 149 instruction.accept(this); | |
| 150 } | |
| 151 } | 145 } |
| 152 | 146 |
| 153 if (block.predecessors.length === 1 | 147 if (block.predecessors.length === 1 |
| 154 && isBlockSinglePredecessor(block.predecessors[0])) { | 148 && isBlockSinglePredecessor(block.predecessors[0])) { |
| 155 assert(block.phis.isEmpty()); | 149 assert(block.phis.isEmpty()); |
| 156 tryMergingExpressions(block.predecessors[0]); | 150 tryMergingExpressions(block.predecessors[0]); |
| 157 } else { | 151 } else { |
| 158 expectedInputs = null; | 152 expectedInputs = null; |
| 159 } | 153 } |
| 160 } | 154 } |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // improving the performance of future lookups. | 425 // improving the performance of future lookups. |
| 432 T root = getRepresentative(parent); | 426 T root = getRepresentative(parent); |
| 433 if (root !== parent) representative[element] = root; | 427 if (root !== parent) representative[element] = root; |
| 434 return root; | 428 return root; |
| 435 } | 429 } |
| 436 | 430 |
| 437 bool areEquivalent(T a, T b) { | 431 bool areEquivalent(T a, T b) { |
| 438 return getRepresentative(a) === getRepresentative(b); | 432 return getRepresentative(a) === getRepresentative(b); |
| 439 } | 433 } |
| 440 } | 434 } |
| OLD | NEW |