Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class HValidator extends HInstructionVisitor { | 5 class HValidator extends HInstructionVisitor { |
| 6 bool isValid = true; | 6 bool isValid = true; |
| 7 HGraph graph; | 7 HGraph graph; |
| 8 | 8 |
| 9 void visitGraph(HGraph visitee) { | 9 void visitGraph(HGraph visitee) { |
| 10 graph = visitee; | 10 graph = visitee; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 markInvalid("dominated block not pointing back"); | 75 markInvalid("dominated block not pointing back"); |
| 76 } | 76 } |
| 77 if (dominated.id === null || dominated.id <= lastId) { | 77 if (dominated.id === null || dominated.id <= lastId) { |
| 78 markInvalid("dominated.id === null or dominated has <= id"); | 78 markInvalid("dominated.id === null or dominated has <= id"); |
| 79 } | 79 } |
| 80 lastId = dominated.id; | 80 lastId = dominated.id; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (!isValid) return; | 83 if (!isValid) return; |
| 84 block.forEachPhi(visitInstruction); | 84 block.forEachPhi(visitInstruction); |
| 85 | |
| 86 // Make sure the parameters of a phi are dominating the | |
| 87 // corresponding predecessor block. | |
|
Lasse Reichstein Nielsen
2012/05/30 09:35:14
We usually use "dominating" about blocks, not inst
ngeoffray
2012/05/30 10:19:07
Done.
| |
| 88 block.forEachPhi((HPhi phi) { | |
| 89 for (int i = 0; i < phi.inputs.length; i++) { | |
| 90 HInstruction input = phi.inputs[i]; | |
| 91 if (!input.block.dominates(block.predecessors[i])) { | |
| 92 markInvalid("Definition does not dominate use"); | |
| 93 } | |
| 94 } | |
| 95 }); | |
| 96 | |
| 97 // Make sure the inputs of an instruction dominate the | |
| 98 // instruction. | |
| 99 block.forEachInstruction((HInstruction instruction) { | |
| 100 for (HInstruction input in instruction.inputs) { | |
|
Lasse Reichstein Nielsen
2012/05/30 09:35:14
This is an un-pretty combination of functional for
ngeoffray
2012/05/30 10:19:07
As discussed, it doesn't look un-pretty to me, as
| |
| 101 if (!input.block.dominates(block)) { | |
| 102 markInvalid("Definition does not dominate use"); | |
| 103 } | |
| 104 } | |
| 105 }); | |
| 106 | |
| 85 super.visitBasicBlock(block); | 107 super.visitBasicBlock(block); |
| 86 } | 108 } |
| 87 | 109 |
| 88 /** Returns how often [instruction] is contained in [instructions]. */ | 110 /** Returns how often [instruction] is contained in [instructions]. */ |
| 89 static int countInstruction(List<HInstruction> instructions, | 111 static int countInstruction(List<HInstruction> instructions, |
| 90 HInstruction instruction) { | 112 HInstruction instruction) { |
| 91 int result = 0; | 113 int result = 0; |
| 92 for (int i = 0; i < instructions.length; i++) { | 114 for (int i = 0; i < instructions.length; i++) { |
| 93 if (instructions[i] === instruction) result++; | 115 if (instructions[i] === instruction) result++; |
| 94 } | 116 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 markInvalid("Instruction in wrong block"); | 166 markInvalid("Instruction in wrong block"); |
| 145 } | 167 } |
| 146 if (!hasCorrectInputs()) { | 168 if (!hasCorrectInputs()) { |
| 147 markInvalid("Incorrect inputs"); | 169 markInvalid("Incorrect inputs"); |
| 148 } | 170 } |
| 149 if (!hasCorrectUses()) { | 171 if (!hasCorrectUses()) { |
| 150 markInvalid("Incorrect uses"); | 172 markInvalid("Incorrect uses"); |
| 151 } | 173 } |
| 152 } | 174 } |
| 153 } | 175 } |
| OLD | NEW |