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 CodegenRegistry, CodegenWorkItem; | 5 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
6 import '../common/names.dart' show Selectors; | 6 import '../common/names.dart' show Selectors; |
7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // If we can replace [instruction] with [replacement], then | 228 // If we can replace [instruction] with [replacement], then |
229 // [replacement]'s type can be narrowed. | 229 // [replacement]'s type can be narrowed. |
230 TypeMask newType = replacement.instructionType | 230 TypeMask newType = replacement.instructionType |
231 .intersection(instruction.instructionType, _closedWorld); | 231 .intersection(instruction.instructionType, _closedWorld); |
232 replacement.instructionType = newType; | 232 replacement.instructionType = newType; |
233 } | 233 } |
234 | 234 |
235 // If the replacement instruction does not know its | 235 // If the replacement instruction does not know its |
236 // source element, use the source element of the | 236 // source element, use the source element of the |
237 // instruction. | 237 // instruction. |
238 if (replacement.sourceElement == null) { | 238 replacement.sourceElement ??= instruction.sourceElement; |
239 replacement.sourceElement = instruction.sourceElement; | 239 replacement.sourceInformation ??= instruction.sourceInformation; |
240 } | |
241 if (replacement.sourceInformation == null) { | |
242 replacement.sourceInformation = instruction.sourceInformation; | |
243 } | |
244 if (!replacement.isInBasicBlock()) { | 240 if (!replacement.isInBasicBlock()) { |
245 // The constant folding can return an instruction that is already | 241 // The constant folding can return an instruction that is already |
246 // part of the graph (like an input), so we only add the replacement | 242 // part of the graph (like an input), so we only add the replacement |
247 // if necessary. | 243 // if necessary. |
248 block.addAfter(instruction, replacement); | 244 block.addAfter(instruction, replacement); |
249 // Visit the replacement as the next instruction in case it | 245 // Visit the replacement as the next instruction in case it |
250 // can also be constant folded away. | 246 // can also be constant folded away. |
251 next = replacement; | 247 next = replacement; |
252 } | 248 } |
253 block.remove(instruction); | 249 block.remove(instruction); |
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 // | 1749 // |
1754 // TODO(sra): If the input is directly in the only live predecessor, it | 1750 // TODO(sra): If the input is directly in the only live predecessor, it |
1755 // might be possible to move it into [block] (e.g. all its inputs are | 1751 // might be possible to move it into [block] (e.g. all its inputs are |
1756 // dominating.) | 1752 // dominating.) |
1757 block.forEachPhi((HPhi phi) { | 1753 block.forEachPhi((HPhi phi) { |
1758 HInstruction replacement = | 1754 HInstruction replacement = |
1759 (indexOfLive >= 0) ? phi.inputs[indexOfLive] : zapInstruction; | 1755 (indexOfLive >= 0) ? phi.inputs[indexOfLive] : zapInstruction; |
1760 if (replacement.dominates(phi)) { | 1756 if (replacement.dominates(phi)) { |
1761 block.rewrite(phi, replacement); | 1757 block.rewrite(phi, replacement); |
1762 block.removePhi(phi); | 1758 block.removePhi(phi); |
| 1759 if (replacement.sourceElement == null && |
| 1760 phi.sourceElement != null && |
| 1761 replacement is! HThis) { |
| 1762 replacement.sourceElement = phi.sourceElement; |
| 1763 } |
1763 } | 1764 } |
1764 }); | 1765 }); |
1765 } | 1766 } |
1766 } | 1767 } |
1767 | 1768 |
1768 void replaceInput(int i, HInstruction from, HInstruction by) { | 1769 void replaceInput(int i, HInstruction from, HInstruction by) { |
1769 from.inputs[i].usedBy.remove(from); | 1770 from.inputs[i].usedBy.remove(from); |
1770 from.inputs[i] = by; | 1771 from.inputs[i] = by; |
1771 by.usedBy.add(from); | 1772 by.usedBy.add(from); |
1772 } | 1773 } |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 if (candidate == null) continue; | 1959 if (candidate == null) continue; |
1959 | 1960 |
1960 // Because we're updating the users of this phi, we may have new | 1961 // Because we're updating the users of this phi, we may have new |
1961 // phis candidate for elimination. Add phis that used this phi | 1962 // phis candidate for elimination. Add phis that used this phi |
1962 // to the worklist. | 1963 // to the worklist. |
1963 for (final user in phi.usedBy) { | 1964 for (final user in phi.usedBy) { |
1964 if (user is HPhi) worklist.add(user); | 1965 if (user is HPhi) worklist.add(user); |
1965 } | 1966 } |
1966 phi.block.rewrite(phi, candidate); | 1967 phi.block.rewrite(phi, candidate); |
1967 phi.block.removePhi(phi); | 1968 phi.block.removePhi(phi); |
| 1969 if (candidate.sourceElement == null && |
| 1970 phi.sourceElement != null && |
| 1971 candidate is! HThis) { |
| 1972 candidate.sourceElement = phi.sourceElement; |
| 1973 } |
1968 } | 1974 } |
1969 } | 1975 } |
1970 } | 1976 } |
1971 | 1977 |
1972 class GvnWorkItem { | 1978 class GvnWorkItem { |
1973 final HBasicBlock block; | 1979 final HBasicBlock block; |
1974 final ValueSet valueSet; | 1980 final ValueSet valueSet; |
1975 GvnWorkItem(this.block, this.valueSet); | 1981 GvnWorkItem(this.block, this.valueSet); |
1976 } | 1982 } |
1977 | 1983 |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2976 | 2982 |
2977 keyedValues.forEach((receiver, values) { | 2983 keyedValues.forEach((receiver, values) { |
2978 result.keyedValues[receiver] = | 2984 result.keyedValues[receiver] = |
2979 new Map<HInstruction, HInstruction>.from(values); | 2985 new Map<HInstruction, HInstruction>.from(values); |
2980 }); | 2986 }); |
2981 | 2987 |
2982 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 2988 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
2983 return result; | 2989 return result; |
2984 } | 2990 } |
2985 } | 2991 } |
OLD | NEW |