Chromium Code Reviews| Index: lib/compiler/implementation/ssa/optimize.dart |
| diff --git a/lib/compiler/implementation/ssa/optimize.dart b/lib/compiler/implementation/ssa/optimize.dart |
| index a1562b535c79efae6f852115688d6281c8b531fc..17ae1297e0b7cacd47b6fcfd205f802be8d149ff 100644 |
| --- a/lib/compiler/implementation/ssa/optimize.dart |
| +++ b/lib/compiler/implementation/ssa/optimize.dart |
| @@ -241,6 +241,45 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { |
| return node; |
| } |
| + HInstruction visitRelational(HRelational node) { |
| + if (node.usedBy.length == 1 && node.usedBy[0] is HBoolify) { |
|
ngeoffray
2012/04/25 11:48:08
I'd check if all the users are HBoolify instead.
floitsch
2012/04/25 16:01:49
Done.
|
| + Interceptors interceptors = compiler.builder.interceptors; |
| + HStatic oldTarget = node.target; |
| + Element boolifiedInterceptor = |
| + interceptors.getBoolifiedVersionOfInterceptor(oldTarget.element); |
| + if (boolifiedInterceptor !== null) { |
| + HStatic boolifiedTarget = new HStatic(boolifiedInterceptor); |
| + // We don't remove the [oldTarget] in case it is used by other |
| + // instructions. If it is unused it will be treated as dead code and |
| + // discarded. |
| + oldTarget.block.addAfter(oldTarget, boolifiedTarget); |
| + // Remove us from the usedBy list of the old target. |
|
ngeoffray
2012/04/25 11:48:08
Please move that code into the HInstruction class.
floitsch
2012/04/25 16:01:49
Moved into HBasicBlock class.
|
| + if (oldTarget.usedBy.length == 1) { |
| + oldTarget.usedBy.clear(); |
| + } else { |
| + List<HInstruction> users = oldTarget.usedBy; |
| + int length = users.length; |
| + for (int i = 0; i < length; i++) { |
| + if (users[i] === node) { |
| + users[i] = users[length - 1]; |
| + users.length = length - 1; |
| + } |
| + } |
| + } |
| + // Replace old target with boolified target. |
| + assert(node.target == node.inputs[0]); |
| + node.inputs[0] = boolifiedTarget; |
| + boolifiedTarget.usedBy.add(node); |
| + node.usesBoolifiedInterceptor = true; |
| + node.propagatedType = HType.BOOLEAN; |
| + } |
| + } |
| + // This node stays the same, but the Boolify node will go away. |
|
ngeoffray
2012/04/25 11:48:08
Move that comment one line up (in the if clause).
floitsch
2012/04/25 16:01:49
Done.
|
| + // Note that we still have to call [super] to make sure that we end up |
| + // in the remaining optimizations. |
| + return super.visitRelational(node); |
| + } |
| + |
| HInstruction visitEquals(HEquals node) { |
| HInstruction left = node.left; |
| HInstruction right = node.right; |
| @@ -283,8 +322,10 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { |
| } |
| } |
| - // All other cases are dealt with by the [visitInvokeBinary]. |
| - return visitInvokeBinary(node); |
| + // All other cases are dealt with by the [visitRelational] and |
| + // [visitInvokeBinary], which are visited by invoking the [super]'s |
| + // visit method. |
| + return super.visitEquals(node); |
| } |
| HInstruction visitTypeGuard(HTypeGuard node) { |