| 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 /** | 7 /** |
| 8 * The [LiveRange] class covers a range where an instruction is live. | 8 * The [LiveRange] class covers a range where an instruction is live. |
| 9 */ | 9 */ |
| 10 class LiveRange { | 10 class LiveRange { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 LiveEnvironment environment) { | 226 LiveEnvironment environment) { |
| 227 if (generateAtUseSite.contains(instruction)) { | 227 if (generateAtUseSite.contains(instruction)) { |
| 228 markInputsAsLiveInEnvironment(instruction, environment); | 228 markInputsAsLiveInEnvironment(instruction, environment); |
| 229 } else { | 229 } else { |
| 230 environment.add(instruction, instructionId); | 230 environment.add(instruction, instructionId); |
| 231 // Special case the HCheck instruction to mark the actual | 231 // Special case the HCheck instruction to mark the actual |
| 232 // checked instruction live. The checked instruction and the | 232 // checked instruction live. The checked instruction and the |
| 233 // [HCheck] will share the same live ranges. | 233 // [HCheck] will share the same live ranges. |
| 234 if (instruction is HCheck) { | 234 if (instruction is HCheck) { |
| 235 HCheck check = instruction; | 235 HCheck check = instruction; |
| 236 HInstruction checked = check.unwrap(); | 236 HInstruction checked = check.nonCheck(); |
| 237 if (!generateAtUseSite.contains(checked)) { | 237 if (!generateAtUseSite.contains(checked)) { |
| 238 environment.add(checked, instructionId); | 238 environment.add(checked, instructionId); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 void removeFromEnvironment(HInstruction instruction, | 244 void removeFromEnvironment(HInstruction instruction, |
| 245 LiveEnvironment environment) { | 245 LiveEnvironment environment) { |
| 246 environment.remove(instruction, instructionId); | 246 environment.remove(instruction, instructionId); |
| 247 // Special case the HCheck instruction to have the same live | 247 // Special case the HCheck instruction to have the same live |
| 248 // interval as the instruction it is checking. | 248 // interval as the instruction it is checking. |
| 249 if (instruction is HCheck) { | 249 if (instruction is HCheck) { |
| 250 HCheck check = instruction; | 250 HCheck check = instruction; |
| 251 HInstruction checked = check.unwrap(); | 251 HInstruction checked = check.nonCheck(); |
| 252 if (!generateAtUseSite.contains(checked)) { | 252 if (!generateAtUseSite.contains(checked)) { |
| 253 liveIntervals.putIfAbsent(checked, () => new LiveInterval()); | 253 liveIntervals.putIfAbsent(checked, () => new LiveInterval()); |
| 254 // Unconditionally force the live ranges of the HCheck to | 254 // Unconditionally force the live ranges of the HCheck to |
| 255 // be the live ranges of the instruction it is checking. | 255 // be the live ranges of the instruction it is checking. |
| 256 liveIntervals[instruction] = | 256 liveIntervals[instruction] = |
| 257 new LiveInterval.forCheck(instructionId, liveIntervals[checked]); | 257 new LiveInterval.forCheck(instructionId, liveIntervals[checked]); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 618 |
| 619 /** | 619 /** |
| 620 * Returns whether [instruction] needs a name. Instructions that | 620 * Returns whether [instruction] needs a name. Instructions that |
| 621 * have no users or that are generated at use site do not need a name. | 621 * have no users or that are generated at use site do not need a name. |
| 622 */ | 622 */ |
| 623 bool needsName(instruction) { | 623 bool needsName(instruction) { |
| 624 if (instruction is HThis) return false; | 624 if (instruction is HThis) return false; |
| 625 if (instruction is HParameterValue) return true; | 625 if (instruction is HParameterValue) return true; |
| 626 if (instruction.usedBy.isEmpty) return false; | 626 if (instruction.usedBy.isEmpty) return false; |
| 627 if (generateAtUseSite.contains(instruction)) return false; | 627 if (generateAtUseSite.contains(instruction)) return false; |
| 628 // A [HCheck] instruction needs a name only if its | 628 return !instruction.nonCheck().isCodeMotionInvariant(); |
| 629 // checked input does not have a fixed name or value. | |
| 630 if (instruction is HCheck) { | |
| 631 return !instruction.unwrap().isCodeMotionInvariant(); | |
| 632 } | |
| 633 return true; | |
| 634 } | 629 } |
| 635 | 630 |
| 636 /** | 631 /** |
| 637 * Returns whether [instruction] dies at the instruction [at]. | 632 * Returns whether [instruction] dies at the instruction [at]. |
| 638 */ | 633 */ |
| 639 bool diesAt(HInstruction instruction, HInstruction at) { | 634 bool diesAt(HInstruction instruction, HInstruction at) { |
| 640 LiveInterval atInterval = liveIntervals[at]; | 635 LiveInterval atInterval = liveIntervals[at]; |
| 641 LiveInterval instructionInterval = liveIntervals[instruction]; | 636 LiveInterval instructionInterval = liveIntervals[instruction]; |
| 642 int start = atInterval.start; | 637 int start = atInterval.start; |
| 643 return instructionInterval.diesAt(start); | 638 return instructionInterval.diesAt(start); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 if (!needsName(input)) { | 680 if (!needsName(input)) { |
| 686 names.addAssignment(predecessor, input, phi); | 681 names.addAssignment(predecessor, input, phi); |
| 687 } else { | 682 } else { |
| 688 names.addCopy(predecessor, input, phi); | 683 names.addCopy(predecessor, input, phi); |
| 689 } | 684 } |
| 690 } | 685 } |
| 691 | 686 |
| 692 namer.allocateName(phi); | 687 namer.allocateName(phi); |
| 693 } | 688 } |
| 694 } | 689 } |
| OLD | NEW |