| 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 import '../common/codegen.dart' show CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenWorkItem; |
| 6 import '../common/tasks.dart' show CompilerTask; | 6 import '../common/tasks.dart' show CompilerTask; |
| 7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../core_types.dart' show CoreClasses; | 10 import '../core_types.dart' show CoreClasses; |
| (...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 if (use is HFieldSet) { | 1216 if (use is HFieldSet) { |
| 1217 // The use must be the receiver. Even if the use is also the argument, | 1217 // The use must be the receiver. Even if the use is also the argument, |
| 1218 // i.e. a.x = a, the store is still dead if all other uses are dead. | 1218 // i.e. a.x = a, the store is still dead if all other uses are dead. |
| 1219 if (use.getDartReceiver(compiler) == instruction) return true; | 1219 if (use.getDartReceiver(compiler) == instruction) return true; |
| 1220 } else if (use is HFieldGet) { | 1220 } else if (use is HFieldGet) { |
| 1221 assert(use.getDartReceiver(compiler) == instruction); | 1221 assert(use.getDartReceiver(compiler) == instruction); |
| 1222 if (isDeadCode(use)) return true; | 1222 if (isDeadCode(use)) return true; |
| 1223 } | 1223 } |
| 1224 return false; | 1224 return false; |
| 1225 } | 1225 } |
| 1226 |
| 1226 return instruction.isAllocation && | 1227 return instruction.isAllocation && |
| 1227 instruction.isPure() && | 1228 instruction.isPure() && |
| 1228 trivialDeadStoreReceivers.putIfAbsent( | 1229 trivialDeadStoreReceivers.putIfAbsent( |
| 1229 instruction, () => instruction.usedBy.every(isDeadUse)); | 1230 instruction, () => instruction.usedBy.every(isDeadUse)); |
| 1230 } | 1231 } |
| 1231 | 1232 |
| 1232 bool isTrivialDeadStore(HInstruction instruction) { | 1233 bool isTrivialDeadStore(HInstruction instruction) { |
| 1233 return instruction is HFieldSet && | 1234 return instruction is HFieldSet && |
| 1234 isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler)); | 1235 isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler)); |
| 1235 } | 1236 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 removeUsers(instruction); | 1269 removeUsers(instruction); |
| 1269 block.remove(instruction); | 1270 block.remove(instruction); |
| 1270 } else if (isDeadCode(instruction)) { | 1271 } else if (isDeadCode(instruction)) { |
| 1271 block.remove(instruction); | 1272 block.remove(instruction); |
| 1272 } | 1273 } |
| 1273 instruction = previous; | 1274 instruction = previous; |
| 1274 } | 1275 } |
| 1275 } | 1276 } |
| 1276 | 1277 |
| 1277 void cleanPhis(HGraph graph) { | 1278 void cleanPhis(HGraph graph) { |
| 1278 L: for (HBasicBlock block in graph.blocks) { | 1279 L: |
| 1280 for (HBasicBlock block in graph.blocks) { |
| 1279 List<HBasicBlock> predecessors = block.predecessors; | 1281 List<HBasicBlock> predecessors = block.predecessors; |
| 1280 // Zap all inputs to phis that correspond to dead blocks. | 1282 // Zap all inputs to phis that correspond to dead blocks. |
| 1281 block.forEachPhi((HPhi phi) { | 1283 block.forEachPhi((HPhi phi) { |
| 1282 for (int i = 0; i < phi.inputs.length; ++i) { | 1284 for (int i = 0; i < phi.inputs.length; ++i) { |
| 1283 if (!predecessors[i].isLive && phi.inputs[i] != zapInstruction) { | 1285 if (!predecessors[i].isLive && phi.inputs[i] != zapInstruction) { |
| 1284 replaceInput(i, phi, zapInstruction); | 1286 replaceInput(i, phi, zapInstruction); |
| 1285 } | 1287 } |
| 1286 } | 1288 } |
| 1287 }); | 1289 }); |
| 1288 if (predecessors.length < 2) continue L; | 1290 if (predecessors.length < 2) continue L; |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 HBasicBlock block, HBasicBlock loopHeader, int changesFlags) { | 1564 HBasicBlock block, HBasicBlock loopHeader, int changesFlags) { |
| 1563 assert(block.parentLoopHeader == loopHeader || block == loopHeader); | 1565 assert(block.parentLoopHeader == loopHeader || block == loopHeader); |
| 1564 HBasicBlock preheader = loopHeader.predecessors[0]; | 1566 HBasicBlock preheader = loopHeader.predecessors[0]; |
| 1565 int dependsFlags = SideEffects.computeDependsOnFlags(changesFlags); | 1567 int dependsFlags = SideEffects.computeDependsOnFlags(changesFlags); |
| 1566 HInstruction instruction = block.first; | 1568 HInstruction instruction = block.first; |
| 1567 bool isLoopAlwaysTaken() { | 1569 bool isLoopAlwaysTaken() { |
| 1568 HInstruction instruction = loopHeader.last; | 1570 HInstruction instruction = loopHeader.last; |
| 1569 assert(instruction is HGoto || instruction is HLoopBranch); | 1571 assert(instruction is HGoto || instruction is HLoopBranch); |
| 1570 return instruction is HGoto || instruction.inputs[0].isConstantTrue(); | 1572 return instruction is HGoto || instruction.inputs[0].isConstantTrue(); |
| 1571 } | 1573 } |
| 1574 |
| 1572 bool firstInstructionInLoop = block == loopHeader | 1575 bool firstInstructionInLoop = block == loopHeader |
| 1573 // Compensate for lack of code motion. | 1576 // Compensate for lack of code motion. |
| 1574 || | 1577 || |
| 1575 (blockChangesFlags[loopHeader.id] == 0 && | 1578 (blockChangesFlags[loopHeader.id] == 0 && |
| 1576 isLoopAlwaysTaken() && | 1579 isLoopAlwaysTaken() && |
| 1577 loopHeader.successors[0] == block); | 1580 loopHeader.successors[0] == block); |
| 1578 while (instruction != null) { | 1581 while (instruction != null) { |
| 1579 HInstruction next = instruction.next; | 1582 HInstruction next = instruction.next; |
| 1580 if (instruction.useGvn() && | 1583 if (instruction.useGvn() && |
| 1581 instruction.isMovable && | 1584 instruction.isMovable && |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 | 2410 |
| 2408 keyedValues.forEach((receiver, values) { | 2411 keyedValues.forEach((receiver, values) { |
| 2409 result.keyedValues[receiver] = | 2412 result.keyedValues[receiver] = |
| 2410 new Map<HInstruction, HInstruction>.from(values); | 2413 new Map<HInstruction, HInstruction>.from(values); |
| 2411 }); | 2414 }); |
| 2412 | 2415 |
| 2413 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2416 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 2414 return result; | 2417 return result; |
| 2415 } | 2418 } |
| 2416 } | 2419 } |
| OLD | NEW |