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

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

Issue 10695106: Allow === and == to generate inputs at the use site when compiling to a single comparison (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 8 years, 5 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 SsaCodeGeneratorTask extends CompilerTask { 5 class SsaCodeGeneratorTask extends CompilerTask {
6 final JavaScriptBackend backend; 6 final JavaScriptBackend backend;
7 SsaCodeGeneratorTask(JavaScriptBackend backend) 7 SsaCodeGeneratorTask(JavaScriptBackend backend)
8 : this.backend = backend, 8 : this.backend = backend,
9 super(backend.compiler); 9 super(backend.compiler);
10 String get name() => 'SSA code generator'; 10 String get name() => 'SSA code generator';
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 visitInvokeUnary(node, op); 1224 visitInvokeUnary(node, op);
1225 buffer.add(' >>> 0'); 1225 buffer.add(' >>> 0');
1226 this.expectedPrecedence = oldPrecedence; 1226 this.expectedPrecedence = oldPrecedence;
1227 endExpression(unsignedShiftPrecedences.precedence); 1227 endExpression(unsignedShiftPrecedences.precedence);
1228 } else { 1228 } else {
1229 visitInvokeUnary(node, op); 1229 visitInvokeUnary(node, op);
1230 } 1230 }
1231 } 1231 }
1232 1232
1233 void emitIdentityComparison(HInstruction left, HInstruction right) { 1233 void emitIdentityComparison(HInstruction left, HInstruction right) {
1234 HType leftType = left.propagatedType; 1234 String op = singleIdentityComparison(left, right);
1235 HType rightType = right.propagatedType; 1235 if (op != null) {
1236 if (leftType.canBeNull() && rightType.canBeNull()) { 1236 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1237 if (left.isConstantNull() || right.isConstantNull() || 1237 use(left, JSPrecedence.EQUALITY_PRECEDENCE);
1238 (leftType.isPrimitive() && leftType == rightType)) { 1238 buffer.add(' $op ');
1239 use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
1240 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1241 } else {
1242 assert(NullConstant.JsNull == 'null');
1243 withPrecedence(JSPrecedence.CONDITIONAL_PRECEDENCE, () {
1239 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1244 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1240 use(left, JSPrecedence.EQUALITY_PRECEDENCE); 1245 use(left, JSPrecedence.EQUALITY_PRECEDENCE);
1241 buffer.add(' == '); 1246 buffer.add(' == null');
1242 use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
1243 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1247 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1244 } else { 1248 buffer.add(' ? ');
1245 assert(NullConstant.JsNull == 'null'); 1249 this.expectedPrecedence = JSPrecedence.ASSIGNMENT_PRECEDENCE;
1246 withPrecedence(JSPrecedence.CONDITIONAL_PRECEDENCE, () { 1250 withPrecedence(JSPrecedence.LOGICAL_AND_PRECEDENCE, () {
1251 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1252 use(right, JSPrecedence.EQUALITY_PRECEDENCE);
1253 buffer.add(' == null');
1254 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1255 buffer.add(" : ");
1247 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1256 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1248 use(left, JSPrecedence.EQUALITY_PRECEDENCE); 1257 use(left, JSPrecedence.EQUALITY_PRECEDENCE);
1249 buffer.add(' == null'); 1258 buffer.add(' === ');
1259 use(right, JSPrecedence.EQUALITY_PRECEDENCE);
1250 endExpression(JSPrecedence.EQUALITY_PRECEDENCE); 1260 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1251 buffer.add(' ? ');
1252 this.expectedPrecedence = JSPrecedence.ASSIGNMENT_PRECEDENCE;
1253 withPrecedence(JSPrecedence.LOGICAL_AND_PRECEDENCE, () {
1254 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1255 use(right, JSPrecedence.EQUALITY_PRECEDENCE);
1256 buffer.add(' == null');
1257 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1258 buffer.add(" : ");
1259 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1260 use(left, JSPrecedence.EQUALITY_PRECEDENCE);
1261 buffer.add(' === ');
1262 use(right, JSPrecedence.EQUALITY_PRECEDENCE);
1263 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1264 });
1265 }); 1261 });
1266 } 1262 });
1267 } else {
1268 beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1269 use(left, JSPrecedence.EQUALITY_PRECEDENCE);
1270 buffer.add(' === ');
1271 use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
1272 endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
1273 } 1263 }
1274 } 1264 }
1275 1265
1276 visitEquals(HEquals node) { 1266 visitEquals(HEquals node) {
1277 if (node.builtin) { 1267 if (node.builtin) {
1278 emitIdentityComparison(node.left, node.right); 1268 emitIdentityComparison(node.left, node.right);
1279 } else { 1269 } else {
1280 visitInvokeStatic(node); 1270 visitInvokeStatic(node);
1281 } 1271 }
1282 } 1272 }
(...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after
3108 startBailoutSwitch(); 3098 startBailoutSwitch();
3109 } 3099 }
3110 } 3100 }
3111 3101
3112 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) { 3102 void endLabeledBlock(HLabeledBlockInformation labeledBlockInfo) {
3113 if (labeledBlockInfo.body.start.hasGuards()) { 3103 if (labeledBlockInfo.body.start.hasGuards()) {
3114 endBailoutSwitch(); 3104 endBailoutSwitch();
3115 } 3105 }
3116 } 3106 }
3117 } 3107 }
3108
3109 String singleIdentityComparison(HInstruction left, HInstruction right) {
3110 // Returns the single identity comparison (== or ===) or null if a more
3111 // complex expression is required.
3112 HType leftType = left.propagatedType;
3113 HType rightType = right.propagatedType;
3114 if (leftType.canBeNull() && rightType.canBeNull()) {
3115 if (left.isConstantNull() || right.isConstantNull() ||
3116 (leftType.isPrimitive() && leftType == rightType)) {
3117 return '==';
3118 }
3119 return null;
3120 } else {
3121 return '===';
3122 }
3123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698