Chromium Code Reviews| Index: pkg/compiler/lib/src/ssa/optimize.dart |
| diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart |
| index 07611f654a3292066d02ec241076f47e28dc7c3b..b904d3252455afe66cf0cf05745216383a180c97 100644 |
| --- a/pkg/compiler/lib/src/ssa/optimize.dart |
| +++ b/pkg/compiler/lib/src/ssa/optimize.dart |
| @@ -200,6 +200,45 @@ class SsaInstructionSimplifier extends HBaseVisitor |
| return node; |
| } |
| + ConstantValue getConstantFromType(HInstruction node) { |
| + if (node.isValue() && !node.canBeNull()) { |
| + ValueTypeMask valueMask = node.instructionType; |
| + if (valueMask.value.isBool) { |
| + return valueMask.value; |
| + } |
| + // TODO(het): consider supporting other values (short strings?) |
| + } |
| + return null; |
| + } |
| + |
| + void propagateConstantValueToUses(HInstruction known) { |
|
sra1
2015/10/01 01:48:00
Maybe call it 'node'.
It is not known until we tes
Harry Terkelsen
2015/10/01 21:06:36
Done.
|
| + if (known.usedBy.isEmpty) return; |
| + ConstantValue value = getConstantFromType(known); |
| + if (value != null) { |
| + // If this instruction is ever assigned to, then do not propagate the |
| + // value since it may |
|
sra1
2015/10/01 01:48:00
Not needed.
Only parameters (and Locals) can be as
Harry Terkelsen
2015/10/01 21:06:36
Done.
|
| + if (known.usedBy.any( |
| + (user) => user is HLocalSet && identical(user.local, known))) { |
| + return; |
| + } |
| + for (HInstruction user in known.usedBy.toList()) { |
| + user.changeUse(known, graph.addConstant(value, compiler)); |
|
sra1
2015/10/01 01:48:00
You can lift this out of the loop:
HInstruction c
Harry Terkelsen
2015/10/01 21:06:36
Done.
|
| + } |
| + } |
| + } |
| + |
| + HInstruction visitParameterValue(HParameterValue node) { |
| + // It is possible for the parameter value to be assigned to in the function |
| + // body. If that happens then we should not forward the constant value to |
| + // its uses since they are shadowed by the assignment. |
|
sra1
2015/10/01 01:48:00
"since the uses reachable from the assignment may
Harry Terkelsen
2015/10/01 21:06:36
I just tried out this program. The p is not recogn
|
| + if (node.usedBy.any((user) => |
| + user is HLocalSet && identical(user.local, node))) { |
| + return node; |
| + } |
| + propagateConstantValueToUses(node); |
| + return node; |
| + } |
| + |
| HInstruction visitBoolify(HBoolify node) { |
| List<HInstruction> inputs = node.inputs; |
| assert(inputs.length == 1); |
| @@ -372,6 +411,7 @@ class SsaInstructionSimplifier extends HBaseVisitor |
| } |
| HInstruction visitInvokeDynamicMethod(HInvokeDynamicMethod node) { |
| + propagateConstantValueToUses(node); |
| if (node.isInterceptedCall) { |
| HInstruction folded = handleInterceptedCall(node); |
| if (folded != node) return folded; |
| @@ -806,6 +846,7 @@ class SsaInstructionSimplifier extends HBaseVisitor |
| } |
| HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { |
| + propagateConstantValueToUses(node); |
| if (node.isInterceptedCall) { |
| HInstruction folded = handleInterceptedCall(node); |
| if (folded != node) return folded; |
| @@ -867,6 +908,7 @@ class SsaInstructionSimplifier extends HBaseVisitor |
| } |
| HInstruction visitInvokeStatic(HInvokeStatic node) { |
| + propagateConstantValueToUses(node); |
| if (node.element == backend.getCheckConcurrentModificationError()) { |
| if (node.inputs.length == 2) { |
| HInstruction firstArgument = node.inputs[0]; |
| @@ -1306,13 +1348,6 @@ class SsaLiveBlockAnalyzer extends HBaseVisitor { |
| } else { |
| markBlockLive(instruction.elseBlock); |
| } |
| - } else if (condition.isValue()) { |
| - ValueTypeMask valueType = condition.instructionType; |
| - if (valueType.value == true) { |
| - markBlockLive(instruction.thenBlock); |
| - } else { |
| - markBlockLive(instruction.elseBlock); |
| - } |
| } else { |
| visitControlFlow(instruction); |
| } |