OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.cps_ir.type_propagation; | 4 library dart2js.cps_ir.type_propagation; |
5 | 5 |
6 import 'optimizers.dart'; | 6 import 'optimizers.dart'; |
7 | 7 |
8 import '../closure.dart' show | 8 import '../closure.dart' show |
9 ClosureClassElement; | 9 ClosureClassElement; |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 if (prim.hasNoUses && prim.isSafeForElimination) { | 839 if (prim.hasNoUses && prim.isSafeForElimination) { |
840 push(node.body); | 840 push(node.body); |
841 prim.destroy(); | 841 prim.destroy(); |
842 node.remove(); | 842 node.remove(); |
843 return; | 843 return; |
844 } | 844 } |
845 | 845 |
846 // Try to constant-fold the primitive. | 846 // Try to constant-fold the primitive. |
847 if (prim is! Constant && prim is! Refinement && prim.isSafeForElimination) { | 847 if (prim is! Constant && prim is! Refinement && prim.isSafeForElimination) { |
848 AbstractConstantValue value = getValue(prim); | 848 AbstractConstantValue value = getValue(prim); |
849 if (value.isConstant) { | 849 if (value.isConstant) { |
asgerf
2015/12/11 12:27:12
I think we should just do the check here.
sra1
2015/12/11 19:13:26
Done.
| |
850 prim.replaceWith(makeConstantPrimitive(value.constant)); | 850 prim.replaceWith(makeConstantPrimitive(value.constant)); |
851 push(node.body); | 851 push(node.body); |
852 return; | 852 return; |
853 } | 853 } |
854 } | 854 } |
855 | 855 |
856 // Try to specialize the primitive. | 856 // Try to specialize the primitive. |
857 var replacement = visit(prim); | 857 var replacement = visit(prim); |
858 if (replacement is CpsFragment) { | 858 if (replacement is CpsFragment) { |
859 reanalyzeFragment(replacement); | 859 reanalyzeFragment(replacement); |
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2534 | 2534 |
2535 /// Sets the type of the given primitive. | 2535 /// Sets the type of the given primitive. |
2536 /// | 2536 /// |
2537 /// If [updateValue] is a constant and [canReplace] is true, the primitive | 2537 /// If [updateValue] is a constant and [canReplace] is true, the primitive |
2538 /// is also marked as safe for elimination, so it can be constant-folded. | 2538 /// is also marked as safe for elimination, so it can be constant-folded. |
2539 void setResult(UnsafePrimitive prim, | 2539 void setResult(UnsafePrimitive prim, |
2540 AbstractConstantValue updateValue, | 2540 AbstractConstantValue updateValue, |
2541 {bool canReplace: false}) { | 2541 {bool canReplace: false}) { |
2542 // TODO(asgerf): Separate constant folding from side effect analysis. | 2542 // TODO(asgerf): Separate constant folding from side effect analysis. |
2543 setValue(prim, updateValue); | 2543 setValue(prim, updateValue); |
2544 prim.isSafeForElimination = canReplace && updateValue.isConstant; | 2544 prim.isSafeForElimination = canReplace && |
2545 updateValue.isConstant && | |
2546 constantIsSafeToCopy(updateValue.constant); | |
2547 } | |
2548 | |
2549 bool constantIsSafeToCopy(ConstantValue constant) { | |
2550 // TODO(25230, 25231): Refer to large shared strings by name. | |
2551 // This number is chosen to prevent huge strings being copied. Don't make | |
2552 // this too small, otherwise it will suppress otherwise harmless constant | |
2553 // folding. | |
2554 const int MAXIMUM_LENGTH_OF_DUPLICATED_STRING = 500; | |
asgerf
2015/12/11 12:27:12
I think the better place to do this is in visitLet
sra1
2015/12/11 19:13:26
Done.
| |
2555 return constant is StringConstantValue | |
2556 ? constant.length < MAXIMUM_LENGTH_OF_DUPLICATED_STRING | |
2557 : true; | |
2545 } | 2558 } |
2546 | 2559 |
2547 bool isInterceptedSelector(Selector selector) { | 2560 bool isInterceptedSelector(Selector selector) { |
2548 return backend.isInterceptedSelector(selector); | 2561 return backend.isInterceptedSelector(selector); |
2549 } | 2562 } |
2550 | 2563 |
2551 // -------------------------- Visitor overrides ------------------------------ | 2564 // -------------------------- Visitor overrides ------------------------------ |
2552 void visit(Node node) { node.accept(this); } | 2565 void visit(Node node) { node.accept(this); } |
2553 | 2566 |
2554 void visitFunctionDefinition(FunctionDefinition node) { | 2567 void visitFunctionDefinition(FunctionDefinition node) { |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3289 processLetPrim(LetPrim node) { | 3302 processLetPrim(LetPrim node) { |
3290 node.primitive.type = null; | 3303 node.primitive.type = null; |
3291 values[node.primitive] = null; | 3304 values[node.primitive] = null; |
3292 } | 3305 } |
3293 | 3306 |
3294 processLetMutable(LetMutable node) { | 3307 processLetMutable(LetMutable node) { |
3295 node.variable.type = null; | 3308 node.variable.type = null; |
3296 values[node.variable] = null; | 3309 values[node.variable] = null; |
3297 } | 3310 } |
3298 } | 3311 } |
OLD | NEW |