| 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 class SsaCodeGeneratorTask extends CompilerTask { | 5 class SsaCodeGeneratorTask extends CompilerTask { |
| 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); | 6 SsaCodeGeneratorTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA code generator'; | 7 String get name() => 'SSA code generator'; |
| 8 | 8 |
| 9 | 9 |
| 10 String generateMethod(WorkItem work, HGraph graph) { | 10 String generateMethod(WorkItem work, HGraph graph) { |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 visitBasicBlock(node.finallyBlock); | 895 visitBasicBlock(node.finallyBlock); |
| 896 indent--; | 896 indent--; |
| 897 } | 897 } |
| 898 addIndentation(); | 898 addIndentation(); |
| 899 buffer.add('}\n'); | 899 buffer.add('}\n'); |
| 900 | 900 |
| 901 visitBasicBlock(node.joinBlock); | 901 visitBasicBlock(node.joinBlock); |
| 902 } | 902 } |
| 903 | 903 |
| 904 visitIf(HIf node) { | 904 visitIf(HIf node) { |
| 905 HInstruction condition = node.inputs[0]; |
| 906 int preVisitedBlocks = 0; |
| 905 List<HBasicBlock> dominated = node.block.dominatedBlocks; | 907 List<HBasicBlock> dominated = node.block.dominatedBlocks; |
| 906 HIfBlockInformation info = node.blockInformation; | 908 HIfBlockInformation info = node.blockInformation; |
| 907 startIf(node); | 909 if (condition.isConstant()) { |
| 908 assert(!isGenerateAtUseSite(node)); | 910 HConstant constant = condition; |
| 909 startThen(node); | 911 if (constant.constant.isTrue()) { |
| 910 assert(node.thenBlock === dominated[0]); | 912 visitSubGraph(info.thenGraph); |
| 911 visitSubGraph(info.thenGraph); | 913 } else if (node.hasElse) { |
| 912 int preVisitedBlocks = 1; | 914 visitSubGraph(info.elseGraph); |
| 913 endThen(node); | 915 } |
| 914 if (node.hasElse) { | 916 // We ignore the other branch, even if it isn't visited. |
| 915 startElse(node); | 917 preVisitedBlocks = node.hasElse ? 2 : 1; |
| 916 assert(node.elseBlock === dominated[1]); | 918 } else { |
| 917 visitSubGraph(info.elseGraph); | 919 startIf(node); |
| 918 preVisitedBlocks = 2; | 920 assert(!isGenerateAtUseSite(node)); |
| 919 endElse(node); | 921 startThen(node); |
| 922 assert(node.thenBlock === dominated[0]); |
| 923 visitSubGraph(info.thenGraph); |
| 924 preVisitedBlocks++; |
| 925 endThen(node); |
| 926 if (node.hasElse) { |
| 927 startElse(node); |
| 928 assert(node.elseBlock === dominated[1]); |
| 929 visitSubGraph(info.elseGraph); |
| 930 preVisitedBlocks++; |
| 931 endElse(node); |
| 932 } |
| 933 endIf(node); |
| 920 } | 934 } |
| 921 endIf(node); | |
| 922 if (info.joinBlock !== null && info.joinBlock.dominator !== node.block) { | 935 if (info.joinBlock !== null && info.joinBlock.dominator !== node.block) { |
| 923 // The join block is dominated by a block in one of the branches. | 936 // The join block is dominated by a block in one of the branches. |
| 924 // The subgraph traversal never reached it, so we visit it here | 937 // The subgraph traversal never reached it, so we visit it here |
| 925 // instead. | 938 // instead. |
| 926 visitBasicBlock(info.joinBlock); | 939 visitBasicBlock(info.joinBlock); |
| 927 } | 940 } |
| 928 | 941 |
| 929 // Visit all the dominated blocks that are not part of the then or else | 942 // Visit all the dominated blocks that are not part of the then or else |
| 930 // branches, and is not the join block. | 943 // branches, and is not the join block. |
| 931 // Depending on how the then/else branches terminate | 944 // Depending on how the then/else branches terminate |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 startBailoutSwitch(); | 1867 startBailoutSwitch(); |
| 1855 } | 1868 } |
| 1856 } | 1869 } |
| 1857 | 1870 |
| 1858 void endElse(HIf node) { | 1871 void endElse(HIf node) { |
| 1859 if (node.elseBlock.hasGuards()) { | 1872 if (node.elseBlock.hasGuards()) { |
| 1860 endBailoutSwitch(); | 1873 endBailoutSwitch(); |
| 1861 } | 1874 } |
| 1862 } | 1875 } |
| 1863 } | 1876 } |
| OLD | NEW |