| 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 /** | 619 /** |
| 620 * Returns whether [instruction] dies at the instruction [at]. | 620 * Returns whether [instruction] dies at the instruction [at]. |
| 621 */ | 621 */ |
| 622 bool diesAt(HInstruction instruction, HInstruction at) { | 622 bool diesAt(HInstruction instruction, HInstruction at) { |
| 623 LiveInterval atInterval = liveIntervals[at]; | 623 LiveInterval atInterval = liveIntervals[at]; |
| 624 LiveInterval instructionInterval = liveIntervals[instruction]; | 624 LiveInterval instructionInterval = liveIntervals[instruction]; |
| 625 int start = atInterval.start; | 625 int start = atInterval.start; |
| 626 return instructionInterval.diesAt(start); | 626 return instructionInterval.diesAt(start); |
| 627 } | 627 } |
| 628 | 628 |
| 629 void handleInstruction(HInstruction instruction, VariableNamer namer) { | 629 void freeUsedNamesAt(HInstruction instruction, |
| 630 HInstruction at, |
| 631 VariableNamer namer) { |
| 630 // TODO(ager): We cannot perform this check to free names for | 632 // TODO(ager): We cannot perform this check to free names for |
| 631 // HCheck instructions because they are special cased to have the | 633 // HCheck instructions because they are special cased to have the |
| 632 // same live intervals as the instruction they are checking. This | 634 // same live intervals as the instruction they are checking. This |
| 633 // includes sharing the start id with the checked | 635 // includes sharing the start id with the checked |
| 634 // input. Therefore, for HCheck(checkedInput, otherInput) we would | 636 // input. Therefore, for HCheck(checkedInput, otherInput) we would |
| 635 // end up checking that otherInput dies not here, but at the | 637 // end up checking that otherInput dies not here, but at the |
| 636 // location of checkedInput. We should preserve the start id for | 638 // location of checkedInput. We should preserve the start id for |
| 637 // the check instruction. | 639 // the check instruction. |
| 638 if (instruction is! HCheck) { | 640 if (at is HCheck) return; |
| 641 if (needsName(instruction)) { |
| 642 if (diesAt(instruction, at)) { |
| 643 namer.freeName(instruction); |
| 644 } |
| 645 } else if (generateAtUseSite.contains(instruction)) { |
| 646 // If the instruction is generated at use site, then all its |
| 647 // inputs may also die at [at]. |
| 639 for (int i = 0, len = instruction.inputs.length; i < len; i++) { | 648 for (int i = 0, len = instruction.inputs.length; i < len; i++) { |
| 640 HInstruction input = instruction.inputs[i]; | 649 HInstruction input = instruction.inputs[i]; |
| 641 // If [input] has a name, and its use here is the last use, free | 650 freeUsedNamesAt(input, at, namer); |
| 642 // its name. | |
| 643 if (needsName(input) && diesAt(input, instruction)) { | |
| 644 namer.freeName(input); | |
| 645 } | |
| 646 } | 651 } |
| 647 } | 652 } |
| 653 } |
| 654 |
| 655 void handleInstruction(HInstruction instruction, VariableNamer namer) { |
| 656 for (int i = 0, len = instruction.inputs.length; i < len; i++) { |
| 657 HInstruction input = instruction.inputs[i]; |
| 658 freeUsedNamesAt(input, instruction, namer); |
| 659 } |
| 648 | 660 |
| 649 if (needsName(instruction)) { | 661 if (needsName(instruction)) { |
| 650 namer.allocateName(instruction); | 662 namer.allocateName(instruction); |
| 651 } | 663 } |
| 652 } | 664 } |
| 653 | 665 |
| 654 void handlePhi(HPhi phi, VariableNamer namer) { | 666 void handlePhi(HPhi phi, VariableNamer namer) { |
| 655 if (!needsName(phi)) return; | 667 if (!needsName(phi)) return; |
| 656 | 668 |
| 657 for (int i = 0; i < phi.inputs.length; i++) { | 669 for (int i = 0; i < phi.inputs.length; i++) { |
| 658 HInstruction input = phi.inputs[i]; | 670 HInstruction input = phi.inputs[i]; |
| 659 HBasicBlock predecessor = phi.block.predecessors[i]; | 671 HBasicBlock predecessor = phi.block.predecessors[i]; |
| 660 if (!needsName(input)) { | 672 if (!needsName(input)) { |
| 661 names.addAssignment(predecessor, input, phi); | 673 names.addAssignment(predecessor, input, phi); |
| 662 } else { | 674 } else { |
| 663 names.addCopy(predecessor, input, phi); | 675 names.addCopy(predecessor, input, phi); |
| 664 } | 676 } |
| 665 } | 677 } |
| 666 | 678 |
| 667 namer.allocateName(phi); | 679 namer.allocateName(phi); |
| 668 } | 680 } |
| 669 } | 681 } |
| OLD | NEW |