Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: lib/compiler/implementation/ssa/optimize.dart

Issue 10544026: Simplify generated code for string interpolation by delaying the constant folding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 interface OptimizationPhase { 5 interface OptimizationPhase {
6 String get name(); 6 String get name();
7 void visitGraph(HGraph graph); 7 void visitGraph(HGraph graph);
8 } 8 }
9 9
10 class SsaOptimizerTask extends CompilerTask { 10 class SsaOptimizerTask extends CompilerTask {
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 583
584 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { 584 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) {
585 HInstruction receiver = node.inputs[0]; 585 HInstruction receiver = node.inputs[0];
586 if (!receiver.propagatedType.isUseful()) return node; 586 if (!receiver.propagatedType.isUseful()) return node;
587 Type type = receiver.propagatedType.computeType(compiler); 587 Type type = receiver.propagatedType.computeType(compiler);
588 if (type === null) return node; 588 if (type === null) return node;
589 Element field = compiler.world.locateSingleField(type, node.name); 589 Element field = compiler.world.locateSingleField(type, node.name);
590 if (field === null) return node; 590 if (field === null) return node;
591 return new HFieldSet(field, node.inputs[0], node.inputs[1]); 591 return new HFieldSet(field, node.inputs[0], node.inputs[1]);
592 } 592 }
593
594 bool isEmptyString(HInstruction node) {
595 if (!node.isConstantString()) return false;
596 HConstant constant = node;
597 StringConstant string = constant.constant;
598 return string.value.length == 0;
599 }
600
601 HInstruction visitStringConcat(HStringConcat node) {
602 if (isEmptyString(node.inputs[0])) return node.inputs[1];
603 if (isEmptyString(node.inputs[1])) return node.inputs[0];
604 DartString folded = const LiteralDartString("");
605 for (int i = 0; i < node.inputs.length; i++) {
Lasse Reichstein Nielsen 2012/06/06 12:11:40 This seems to assume more than two inputs. Intenti
606 HInstruction part = node.inputs[i];
607 if (!part.isConstant()) return node;
608 HConstant constant = part;
609 if (!constant.constant.isPrimitive()) return node;
610 PrimitiveConstant primitive = constant.constant;
611 folded = new DartString.concat(folded, primitive.toDartString());
612 }
613 return graph.addConstantString(folded, node);
614 }
593 } 615 }
594 616
595 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { 617 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
596 final String name = "SsaCheckInserter"; 618 final String name = "SsaCheckInserter";
597 Element lengthInterceptor; 619 Element lengthInterceptor;
598 620
599 SsaCheckInserter(JavaScriptBackend backend) { 621 SsaCheckInserter(JavaScriptBackend backend) {
600 SourceString lengthString = const SourceString('length'); 622 SourceString lengthString = const SourceString('length');
601 lengthInterceptor = 623 lengthInterceptor =
602 backend.builder.interceptors.getStaticGetInterceptor(lengthString); 624 backend.builder.interceptors.getStaticGetInterceptor(lengthString);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 // the if block terminates. So any use of the instruction 1146 // the if block terminates. So any use of the instruction
1125 // after the join block should be changed to the new 1147 // after the join block should be changed to the new
1126 // instruction. 1148 // instruction.
1127 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); 1149 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType);
1128 } 1150 }
1129 // TODO(ngeoffray): Also change uses for the then block on a HType 1151 // TODO(ngeoffray): Also change uses for the then block on a HType
1130 // that knows it is not of a specific Type. 1152 // that knows it is not of a specific Type.
1131 } 1153 }
1132 } 1154 }
1133 } 1155 }
OLDNEW
« lib/compiler/implementation/ssa/nodes.dart ('K') | « lib/compiler/implementation/ssa/nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698