Chromium Code Reviews| 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; |
| 11 * t2 = add(t0, t1); | 11 * t2 = add(t0, t1); |
| 12 * t0 and t1 would be marked and the resulting code would then be: | 12 * t0 and t1 would be marked and the resulting code would then be: |
| 13 * t2 = add(4, 3); | 13 * t2 = add(4, 3); |
| 14 */ | 14 */ |
| 15 class SsaInstructionMerger extends HGraphVisitor { | 15 class SsaInstructionMerger extends HBaseVisitor { |
| 16 List<HInstruction> expectedInputs; | |
| 17 | |
| 16 void visitGraph(HGraph graph) { | 18 void visitGraph(HGraph graph) { |
| 17 visitDominatorTree(graph); | 19 visitDominatorTree(graph); |
| 18 } | 20 } |
| 19 | 21 |
| 20 bool usedOnlyByPhis(instruction) { | 22 bool usedOnlyByPhis(instruction) { |
| 21 for (HInstruction user in instruction.usedBy) { | 23 for (HInstruction user in instruction.usedBy) { |
| 22 if (user is !HPhi) return false; | 24 if (user is !HPhi) return false; |
| 23 } | 25 } |
| 24 return true; | 26 return true; |
| 25 } | 27 } |
| 26 | 28 |
| 29 void visitInstruction(HInstruction instruction) { | |
| 30 for (HInstruction input in instruction.inputs) { | |
| 31 if (!input.generateAtUseSite() && input.usedBy.length == 1) { | |
| 32 expectedInputs.add(input); | |
| 33 } | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void visitIs(HIs instruction) {} | |
|
floitsch
2012/02/10 09:38:17
add comment why this is empty.
ngeoffray
2012/02/10 09:40:48
Done.
| |
| 38 | |
| 27 void visitBasicBlock(HBasicBlock block) { | 39 void visitBasicBlock(HBasicBlock block) { |
| 28 // Visit each instruction of the basic block in last-to-first order. | 40 // Visit each instruction of the basic block in last-to-first order. |
| 29 // Keep a list of expected inputs of the current "expression" being | 41 // Keep a list of expected inputs of the current "expression" being |
| 30 // merged. If instructions occur in the expected order, they are | 42 // merged. If instructions occur in the expected order, they are |
| 31 // included in the expression. | 43 // included in the expression. |
| 32 | 44 |
| 33 // The expectedInputs list holds non-trivial instructions that may | 45 // The expectedInputs list holds non-trivial instructions that may |
| 34 // be generated at their use site, if they occur in the correct order. | 46 // be generated at their use site, if they occur in the correct order. |
| 35 List<HInstruction> expectedInputs = new List<HInstruction>(); | 47 expectedInputs = new List<HInstruction>(); |
| 36 // Add non-trivial inputs of instruction to expectedInputs, in | 48 // Add non-trivial inputs of instruction to expectedInputs, in |
| 37 // evaluation order. | 49 // evaluation order. |
| 38 void addInputs(HInstruction instruction) { | 50 void addInputs(HInstruction instruction) { |
| 39 for (HInstruction input in instruction.inputs) { | 51 instruction.accept(this); |
| 40 if (!input.generateAtUseSite() && input.usedBy.length == 1) { | |
| 41 expectedInputs.add(input); | |
| 42 } | |
| 43 } | |
| 44 } | 52 } |
| 45 // Pop instructions from expectedInputs until instruction is found. | 53 // Pop instructions from expectedInputs until instruction is found. |
| 46 // Return true if it is found, or false if not. | 54 // Return true if it is found, or false if not. |
| 47 bool findInInputs(HInstruction instruction) { | 55 bool findInInputs(HInstruction instruction) { |
| 48 while (!expectedInputs.isEmpty()) { | 56 while (!expectedInputs.isEmpty()) { |
| 49 HInstruction nextInput = expectedInputs.removeLast(); | 57 HInstruction nextInput = expectedInputs.removeLast(); |
| 50 assert(!nextInput.generateAtUseSite()); | 58 assert(!nextInput.generateAtUseSite()); |
| 51 assert(nextInput.usedBy.length == 1); | 59 assert(nextInput.usedBy.length == 1); |
| 52 if (nextInput == instruction) { | 60 if (nextInput == instruction) { |
| 53 return true; | 61 return true; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 73 } | 81 } |
| 74 if (instruction is HForeign) { | 82 if (instruction is HForeign) { |
| 75 // Never try to merge inputs to HForeign. | 83 // Never try to merge inputs to HForeign. |
| 76 continue; | 84 continue; |
| 77 } else if (instruction.generateAtUseSite() || | 85 } else if (instruction.generateAtUseSite() || |
| 78 usedOnlyByPhis(instruction)) { | 86 usedOnlyByPhis(instruction)) { |
| 79 // In all other cases, try merging all non-trivial inputs. | 87 // In all other cases, try merging all non-trivial inputs. |
| 80 addInputs(instruction); | 88 addInputs(instruction); |
| 81 } | 89 } |
| 82 } | 90 } |
| 91 expectedInputs = null; | |
| 83 } | 92 } |
| 84 } | 93 } |
| 85 | 94 |
| 86 /** | 95 /** |
| 87 * In order to generate efficient code that works with bailouts, we | 96 * In order to generate efficient code that works with bailouts, we |
| 88 * rewrite users of check instruction to use the input of the | 97 * rewrite users of check instruction to use the input of the |
| 89 * instruction instead of the check itself. | 98 * instruction instead of the check itself. |
| 90 */ | 99 */ |
| 91 class SsaCheckInstructionUnuser extends HBaseVisitor { | 100 class SsaCheckInstructionUnuser extends HBaseVisitor { |
| 92 void visitGraph(HGraph graph) { | 101 void visitGraph(HGraph graph) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 secondBlock.last.tryGenerateAtUseSite(); | 255 secondBlock.last.tryGenerateAtUseSite(); |
| 247 } | 256 } |
| 248 | 257 |
| 249 void visitBasicBlock(HBasicBlock block) { | 258 void visitBasicBlock(HBasicBlock block) { |
| 250 if (!block.phis.isEmpty() && | 259 if (!block.phis.isEmpty() && |
| 251 block.phis.first == block.phis.last) { | 260 block.phis.first == block.phis.last) { |
| 252 detectLogicControlFlow(block.phis.first); | 261 detectLogicControlFlow(block.phis.first); |
| 253 } | 262 } |
| 254 } | 263 } |
| 255 } | 264 } |
| OLD | NEW |