Chromium Code Reviews| Index: frog/leg/ssa/types.dart |
| =================================================================== |
| --- frog/leg/ssa/types.dart (revision 5905) |
| +++ frog/leg/ssa/types.dart (working copy) |
| @@ -7,12 +7,36 @@ |
| final Map<int, HInstruction> workmap; |
| final List<int> worklist; |
| final Compiler compiler; |
| + final bool speculative; |
| final String name = 'type propagator'; |
| - SsaTypePropagator(Compiler this.compiler) |
| + SsaTypePropagator(Compiler this.compiler, bool this.speculative) |
|
floitsch
2012/03/27 22:38:33
I prefer not to type 'this.X' parameters, but your
ngeoffray
2012/03/28 07:23:22
I will keep it with the types since that's what wa
|
| : workmap = new Map<int, HInstruction>(), |
| worklist = new List<int>(); |
| + // Re-compute and update the type of the instruction. Returns |
| + // whether or not the type was changed. |
| + bool updateType(HInstruction instruction) { |
| + if (instruction.type.isConflicting()) return false; |
| + HType newType = instruction.computeType(); |
| + |
| + if (speculative) { |
| + HType desiredType = instruction.computeDesiredType(); |
| + HType combined = newType.combine(desiredType); |
| + if (combined.isKnown()) newType = combined; |
| + } |
| + |
| + bool changed = (instruction.type != newType); |
| + if (instruction.type.isUnknown()) { |
| + instruction.type = newType; |
| + return changed; |
| + } else if (changed) { |
| + instruction.type = instruction.type.combine(newType); |
| + return changed; |
| + } |
| + return false; |
| + } |
| + |
| void visitGraph(HGraph graph) { |
| visitDominatorTree(graph); |
| processWorklist(); |
| @@ -21,18 +45,19 @@ |
| visitBasicBlock(HBasicBlock block) { |
| if (block.isLoopHeader()) { |
| block.forEachPhi((HPhi phi) { |
| - phi.setInitialTypeForLoopPhi(); |
| + // Set the initial type for the phi. |
| + phi.type = phi.inputs[0].type; |
| addToWorkList(phi); |
| }); |
| } else { |
| block.forEachPhi((HPhi phi) { |
| - if (phi.updateType()) addUsersAndInputsToWorklist(phi); |
| + if (updateType(phi)) addUsersAndInputsToWorklist(phi); |
| }); |
| } |
| HInstruction instruction = block.first; |
| while (instruction !== null) { |
| - if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); |
| + if (updateType(instruction)) addUsersAndInputsToWorklist(instruction); |
| instruction = instruction.next; |
| } |
| } |
| @@ -43,7 +68,7 @@ |
| HInstruction instruction = workmap[id]; |
| assert(instruction !== null); |
| workmap.remove(id); |
| - if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); |
| + if (updateType(instruction)) addUsersAndInputsToWorklist(instruction); |
| } |
| } |