| 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 /** | 5 /** |
| 6 * The [LiveRange] class covers a range where an instruction is live. | 6 * The [LiveRange] class covers a range where an instruction is live. |
| 7 */ | 7 */ |
| 8 class LiveRange { | 8 class LiveRange { |
| 9 final int start; | 9 final int start; |
| 10 // [end] is not final because it can be updated due to loops. | 10 // [end] is not final because it can be updated due to loops. |
| 11 int end; | 11 int end; |
| 12 LiveRange(this.start, this.end) { | 12 LiveRange(this.start, this.end) { |
| 13 assert(start <= end); | 13 assert(start <= end); |
| 14 } | 14 } |
| 15 | 15 |
| 16 String toString() => '[$start $end['; | 16 String toString() => '[$start $end['; |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * The [LiveInterval] class contains the list of ranges where an | 20 * The [LiveInterval] class contains the list of ranges where an |
| 21 * instruction is live. | 21 * instruction is live. |
| 22 */ | 22 */ |
| 23 class LiveInterval { | 23 class LiveInterval { |
| 24 /** | 24 /** |
| 25 * The id where the instruction is defined. | 25 * The id where there instruction is defined. |
| 26 */ | 26 */ |
| 27 int start; | 27 int start; |
| 28 final List<LiveRange> ranges; | 28 final List<LiveRange> ranges; |
| 29 LiveInterval() : ranges = <LiveRange>[]; | 29 LiveInterval() : ranges = <LiveRange>[]; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Update all ranges that are contained in [from, to[ to | 32 * Update all ranges that are contained in [from, to[ to |
| 33 * die at [to]. | 33 * die at [to]. |
| 34 */ | 34 */ |
| 35 void loopUpdate(int from, int to) { | 35 void loopUpdate(int from, int to) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 range.start = id; | 131 range.start = id; |
| 132 } | 132 } |
| 133 liveInstructions.remove(instruction); | 133 liveInstructions.remove(instruction); |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * Add [instruction] to the liveIn set. If the instruction is not | 137 * Add [instruction] to the liveIn set. If the instruction is not |
| 138 * already in the set, we save the id where it dies. | 138 * already in the set, we save the id where it dies. |
| 139 */ | 139 */ |
| 140 void add(HInstruction instruction, int userId) { | 140 void add(HInstruction instruction, int userId) { |
| 141 // Note that we are visiting the graph in post-dominator order, so | 141 // Note that we are visiting the grap in post-dominator order, so |
| 142 // the first time we see a variable is when it dies. | 142 // the first time we see a variable is when it dies. |
| 143 liveInstructions.putIfAbsent(instruction, () => userId); | 143 liveInstructions.putIfAbsent(instruction, () => userId); |
| 144 if (instruction is HCheck) { | 144 if (instruction is HCheck) { |
| 145 // Special case the HCheck instruction to mark the actual | 145 // Special case the HCheck instruction to mark the actual |
| 146 // checked instruction live. | 146 // checked instruction live. |
| 147 var input = instruction.checkedInput; | 147 var input = instruction.checkedInput; |
| 148 while (input is HCheck) input = input.checkedInput; | 148 while (input is HCheck) input = input.checkedInput; |
| 149 liveInstructions.putIfAbsent(input, () => userId); | 149 liveInstructions.putIfAbsent(input, () => userId); |
| 150 } | 150 } |
| 151 } | 151 } |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 * Returns whether [instruction] dies at the instruction [at]. | 582 * Returns whether [instruction] dies at the instruction [at]. |
| 583 */ | 583 */ |
| 584 bool diesAt(HInstruction instruction, HInstruction at) { | 584 bool diesAt(HInstruction instruction, HInstruction at) { |
| 585 LiveInterval atInterval = liveIntervals[at]; | 585 LiveInterval atInterval = liveIntervals[at]; |
| 586 LiveInterval instructionInterval = liveIntervals[instruction]; | 586 LiveInterval instructionInterval = liveIntervals[instruction]; |
| 587 int start = atInterval.start; | 587 int start = atInterval.start; |
| 588 return instructionInterval.diesAt(start); | 588 return instructionInterval.diesAt(start); |
| 589 } | 589 } |
| 590 | 590 |
| 591 void handleInstruction(HInstruction instruction, VariableNamer namer) { | 591 void handleInstruction(HInstruction instruction, VariableNamer namer) { |
| 592 // TODO(ager): We cannot perform this check to free names for | 592 for (int i = 0, len = instruction.inputs.length; i < len; i++) { |
| 593 // HCheck instructions because they are special cased to have the | 593 HInstruction input = instruction.inputs[i]; |
| 594 // same live intervals as the instruction they are checking. This | 594 // If [input] has a name, and its use here is the last use, free |
| 595 // includes sharing the start id with the checked | 595 // its name. |
| 596 // input. Therefore, for HCheck(checkedInput, otherInput) we would | 596 if (needsName(input) && diesAt(input, instruction)) { |
| 597 // end up checking that otherInput dies not here, but at the | 597 namer.freeName(input); |
| 598 // location of checkedInput. We should preserve the start id for | |
| 599 // the check instruction. | |
| 600 if (instruction is! HCheck) { | |
| 601 for (int i = 0, len = instruction.inputs.length; i < len; i++) { | |
| 602 HInstruction input = instruction.inputs[i]; | |
| 603 // If [input] has a name, and its use here is the last use, free | |
| 604 // its name. | |
| 605 if (needsName(input) && diesAt(input, instruction)) { | |
| 606 namer.freeName(input); | |
| 607 } | |
| 608 } | 598 } |
| 609 } | 599 } |
| 610 | 600 |
| 611 if (needsName(instruction)) { | 601 if (needsName(instruction)) { |
| 612 namer.allocateName(instruction); | 602 namer.allocateName(instruction); |
| 613 } | 603 } |
| 614 } | 604 } |
| 615 | 605 |
| 616 void handlePhi(HPhi phi, VariableNamer namer) { | 606 void handlePhi(HPhi phi, VariableNamer namer) { |
| 617 if (!needsName(phi)) return; | 607 if (!needsName(phi)) return; |
| 618 | 608 |
| 619 for (int i = 0; i < phi.inputs.length; i++) { | 609 for (int i = 0; i < phi.inputs.length; i++) { |
| 620 HInstruction input = phi.inputs[i]; | 610 HInstruction input = phi.inputs[i]; |
| 621 HBasicBlock predecessor = phi.block.predecessors[i]; | 611 HBasicBlock predecessor = phi.block.predecessors[i]; |
| 622 if (!needsName(input)) { | 612 if (!needsName(input)) { |
| 623 names.addAssignment(predecessor, input, phi); | 613 names.addAssignment(predecessor, input, phi); |
| 624 } else { | 614 } else { |
| 625 names.addCopy(predecessor, input, phi); | 615 names.addCopy(predecessor, input, phi); |
| 626 } | 616 } |
| 627 } | 617 } |
| 628 | 618 |
| 629 namer.allocateName(phi); | 619 namer.allocateName(phi); |
| 630 } | 620 } |
| 631 } | 621 } |
| OLD | NEW |