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 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
8 String get name; | 8 String get name; |
9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
10 } | 10 } |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 if (use is HFieldSet) { | 1135 if (use is HFieldSet) { |
1136 // The use must be the receiver. Even if the use is also the argument, | 1136 // The use must be the receiver. Even if the use is also the argument, |
1137 // i.e. a.x = a, the store is still dead if all other uses are dead. | 1137 // i.e. a.x = a, the store is still dead if all other uses are dead. |
1138 if (use.getDartReceiver(compiler) == instruction) return true; | 1138 if (use.getDartReceiver(compiler) == instruction) return true; |
1139 } else if (use is HFieldGet) { | 1139 } else if (use is HFieldGet) { |
1140 assert(use.getDartReceiver(compiler) == instruction); | 1140 assert(use.getDartReceiver(compiler) == instruction); |
1141 if (isDeadCode(use)) return true; | 1141 if (isDeadCode(use)) return true; |
1142 } | 1142 } |
1143 return false; | 1143 return false; |
1144 } | 1144 } |
1145 return instruction is HForeignNew | 1145 return instruction.isAllocation |
| 1146 && instruction.isPure() |
1146 && trivialDeadStoreReceivers.putIfAbsent(instruction, | 1147 && trivialDeadStoreReceivers.putIfAbsent(instruction, |
1147 () => instruction.usedBy.every(isDeadUse)); | 1148 () => instruction.usedBy.every(isDeadUse)); |
1148 } | 1149 } |
1149 | 1150 |
1150 bool isTrivialDeadStore(HInstruction instruction) { | 1151 bool isTrivialDeadStore(HInstruction instruction) { |
1151 return instruction is HFieldSet | 1152 return instruction is HFieldSet |
1152 && isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler)); | 1153 && isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler)); |
1153 } | 1154 } |
1154 | 1155 |
1155 bool isDeadCode(HInstruction instruction) { | 1156 bool isDeadCode(HInstruction instruction) { |
1156 if (!instruction.usedBy.isEmpty) return false; | 1157 if (!instruction.usedBy.isEmpty) return false; |
1157 if (isTrivialDeadStore(instruction)) return true; | 1158 if (isTrivialDeadStore(instruction)) return true; |
1158 if (instruction.sideEffects.hasSideEffects()) return false; | 1159 if (instruction.sideEffects.hasSideEffects()) return false; |
1159 if (instruction.canThrow() | 1160 if (instruction.canThrow() && |
1160 && instruction.onlyThrowsNSM() | 1161 instruction.onlyThrowsNSM() && |
1161 && hasFollowingThrowingNSM(instruction)) { | 1162 hasFollowingThrowingNSM(instruction)) { |
1162 return true; | 1163 return true; |
1163 } | 1164 } |
1164 return !instruction.canThrow() | 1165 return !instruction.canThrow() |
1165 && instruction is !HParameterValue | 1166 && instruction is !HParameterValue |
1166 && instruction is !HLocalSet; | 1167 && instruction is !HLocalSet; |
1167 } | 1168 } |
1168 | 1169 |
1169 void visitGraph(HGraph graph) { | 1170 void visitGraph(HGraph graph) { |
1170 analyzer = new SsaLiveBlockAnalyzer(graph, compiler, optimizer); | 1171 analyzer = new SsaLiveBlockAnalyzer(graph, compiler, optimizer); |
1171 analyzer.analyze(); | 1172 analyzer.analyze(); |
1172 visitPostDominatorTree(graph); | 1173 visitPostDominatorTree(graph); |
1173 cleanPhis(graph); | 1174 cleanPhis(graph); |
1174 } | 1175 } |
1175 | 1176 |
1176 void visitBasicBlock(HBasicBlock block) { | 1177 void visitBasicBlock(HBasicBlock block) { |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2295 | 2296 |
2296 keyedValues.forEach((receiver, values) { | 2297 keyedValues.forEach((receiver, values) { |
2297 result.keyedValues[receiver] = | 2298 result.keyedValues[receiver] = |
2298 new Map<HInstruction, HInstruction>.from(values); | 2299 new Map<HInstruction, HInstruction>.from(values); |
2299 }); | 2300 }); |
2300 | 2301 |
2301 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2302 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2302 return result; | 2303 return result; |
2303 } | 2304 } |
2304 } | 2305 } |
OLD | NEW |