| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Builds the live intervals of each instruction. The algorithm visits | 180 * Builds the live intervals of each instruction. The algorithm visits |
| 181 * the graph post-dominator tree to find the last uses of an | 181 * the graph post-dominator tree to find the last uses of an |
| 182 * instruction, and computes the liveIns of each basic block. | 182 * instruction, and computes the liveIns of each basic block. |
| 183 */ | 183 */ |
| 184 class SsaLiveIntervalBuilder extends HBaseVisitor { | 184 class SsaLiveIntervalBuilder extends HBaseVisitor { |
| 185 final Compiler compiler; | 185 final Compiler compiler; |
| 186 final Set<HInstruction> generateAtUseSite; | 186 final Set<HInstruction> generateAtUseSite; |
| 187 final Set<HInstruction> controlFlowOperators; |
| 187 | 188 |
| 188 /** | 189 /** |
| 189 * A counter to assign start and end ids to live ranges. The initial | 190 * A counter to assign start and end ids to live ranges. The initial |
| 190 * value is not relevant. Note that instructionId goes downward to ease | 191 * value is not relevant. Note that instructionId goes downward to ease |
| 191 * reasoning about live ranges (the first instruction of a graph has | 192 * reasoning about live ranges (the first instruction of a graph has |
| 192 * the lowest id). | 193 * the lowest id). |
| 193 */ | 194 */ |
| 194 int instructionId = 0; | 195 int instructionId = 0; |
| 195 | 196 |
| 196 /** | 197 /** |
| 197 * The liveIns of basic blocks. | 198 * The liveIns of basic blocks. |
| 198 */ | 199 */ |
| 199 final Map<HBasicBlock, LiveEnvironment> liveInstructions; | 200 final Map<HBasicBlock, LiveEnvironment> liveInstructions; |
| 200 | 201 |
| 201 /** | 202 /** |
| 202 * The live intervals of instructions. | 203 * The live intervals of instructions. |
| 203 */ | 204 */ |
| 204 final Map<HInstruction, LiveInterval> liveIntervals; | 205 final Map<HInstruction, LiveInterval> liveIntervals; |
| 205 | 206 |
| 206 SsaLiveIntervalBuilder(this.compiler, this.generateAtUseSite) | 207 SsaLiveIntervalBuilder( |
| 208 this.compiler, this.generateAtUseSite, this.controlFlowOperators) |
| 207 : liveInstructions = new Map<HBasicBlock, LiveEnvironment>(), | 209 : liveInstructions = new Map<HBasicBlock, LiveEnvironment>(), |
| 208 liveIntervals = new Map<HInstruction, LiveInterval>(); | 210 liveIntervals = new Map<HInstruction, LiveInterval>(); |
| 209 | 211 |
| 210 void visitGraph(HGraph graph) { | 212 void visitGraph(HGraph graph) { |
| 211 visitPostDominatorTree(graph); | 213 visitPostDominatorTree(graph); |
| 212 if (!liveInstructions[graph.entry].isEmpty) { | 214 if (!liveInstructions[graph.entry].isEmpty) { |
| 213 compiler.internalError('LiveIntervalBuilder', | 215 compiler.internalError('LiveIntervalBuilder', |
| 214 node: compiler.currentElement.parseNode(compiler)); | 216 node: compiler.currentElement.parseNode(compiler)); |
| 215 } | 217 } |
| 216 } | 218 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 liveIntervals[instruction] = | 258 liveIntervals[instruction] = |
| 257 new LiveInterval.forCheck(instructionId, liveIntervals[checked]); | 259 new LiveInterval.forCheck(instructionId, liveIntervals[checked]); |
| 258 } | 260 } |
| 259 } | 261 } |
| 260 } | 262 } |
| 261 | 263 |
| 262 void visitBasicBlock(HBasicBlock block) { | 264 void visitBasicBlock(HBasicBlock block) { |
| 263 LiveEnvironment environment = | 265 LiveEnvironment environment = |
| 264 new LiveEnvironment(liveIntervals, instructionId); | 266 new LiveEnvironment(liveIntervals, instructionId); |
| 265 | 267 |
| 268 // If the control flow instruction in this block will actually be |
| 269 // inlined in the codegen in the join block, we need to make |
| 270 // whatever is used by that control flow instruction as live in |
| 271 // the join block. |
| 272 if (controlFlowOperators.contains(block.last)) { |
| 273 HIf ifInstruction = block.last; |
| 274 HBasicBlock joinBlock = ifInstruction.joinBlock; |
| 275 if (generateAtUseSite.contains(joinBlock.phis.first)) { |
| 276 markInputsAsLiveInEnvironment( |
| 277 ifInstruction, liveInstructions[joinBlock]); |
| 278 } |
| 279 } |
| 280 |
| 266 // Add to the environment the liveIn of its successor, as well as | 281 // Add to the environment the liveIn of its successor, as well as |
| 267 // the inputs of the phis of the successor that flow from this block. | 282 // the inputs of the phis of the successor that flow from this block. |
| 268 for (int i = 0; i < block.successors.length; i++) { | 283 for (int i = 0; i < block.successors.length; i++) { |
| 269 HBasicBlock successor = block.successors[i]; | 284 HBasicBlock successor = block.successors[i]; |
| 270 LiveEnvironment successorEnv = liveInstructions[successor]; | 285 LiveEnvironment successorEnv = liveInstructions[successor]; |
| 271 if (successorEnv != null) { | 286 if (successorEnv != null) { |
| 272 environment.mergeWith(successorEnv); | 287 environment.mergeWith(successorEnv); |
| 273 } else { | 288 } else { |
| 274 environment.addLoopMarker(successor, instructionId); | 289 environment.addLoopMarker(successor, instructionId); |
| 275 } | 290 } |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 if (!needsName(input)) { | 695 if (!needsName(input)) { |
| 681 names.addAssignment(predecessor, input, phi); | 696 names.addAssignment(predecessor, input, phi); |
| 682 } else { | 697 } else { |
| 683 names.addCopy(predecessor, input, phi); | 698 names.addCopy(predecessor, input, phi); |
| 684 } | 699 } |
| 685 } | 700 } |
| 686 | 701 |
| 687 namer.allocateName(phi); | 702 namer.allocateName(phi); |
| 688 } | 703 } |
| 689 } | 704 } |
| OLD | NEW |