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

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

Issue 12042003: Move relational operators to the new interceptors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 part of ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 visit(instruction); 1256 visit(instruction);
1257 } 1257 }
1258 1258
1259 visitInvokeBinary(HInvokeBinary node, String op) { 1259 visitInvokeBinary(HInvokeBinary node, String op) {
1260 use(node.left); 1260 use(node.left);
1261 js.Expression jsLeft = pop(); 1261 js.Expression jsLeft = pop();
1262 use(node.right); 1262 use(node.right);
1263 push(new js.Binary(op, jsLeft, pop()), node); 1263 push(new js.Binary(op, jsLeft, pop()), node);
1264 } 1264 }
1265 1265
1266 visitRelational(HRelational node, String op) { 1266 visitRelational(HRelational node, String op) => visitInvokeBinary(node, op);
1267 if (node.isBuiltin(types)) {
1268 use(node.left);
1269 js.Expression jsLeft = pop();
1270 use(node.right);
1271 push(new js.Binary(op, jsLeft, pop()), node);
1272 } else {
1273 visitInvokeStatic(node);
1274 }
1275 }
1276 1267
1277 // We want the outcome of bit-operations to be positive. We use the unsigned 1268 // We want the outcome of bit-operations to be positive. We use the unsigned
1278 // shift operator to achieve this. 1269 // shift operator to achieve this.
1279 visitBitInvokeBinary(HBinaryBitOp node, String op) { 1270 visitBitInvokeBinary(HBinaryBitOp node, String op) {
1280 visitInvokeBinary(node, op); 1271 visitInvokeBinary(node, op);
1281 if (requiresUintConversion(node)) { 1272 if (requiresUintConversion(node)) {
1282 push(new js.Binary(">>>", pop(), new js.LiteralNumber("0")), node); 1273 push(new js.Binary(">>>", pop(), new js.LiteralNumber("0")), node);
1283 } 1274 }
1284 } 1275 }
1285 1276
(...skipping 27 matching lines...) Expand all
1313 js.Binary rightEqualsNull = 1304 js.Binary rightEqualsNull =
1314 new js.Binary("==", pop(), new js.LiteralNull()); 1305 new js.Binary("==", pop(), new js.LiteralNull());
1315 use(right); 1306 use(right);
1316 use(left); 1307 use(left);
1317 js.Binary tripleEq = new js.Binary("===", pop(), pop()); 1308 js.Binary tripleEq = new js.Binary("===", pop(), pop());
1318 1309
1319 push(new js.Conditional(leftEqualsNull, rightEqualsNull, tripleEq)); 1310 push(new js.Conditional(leftEqualsNull, rightEqualsNull, tripleEq));
1320 } 1311 }
1321 } 1312 }
1322 1313
1323 visitEquals(HEquals node) {
1324 if (node.isBuiltin(types)) {
1325 emitIdentityComparison(node.left, node.right);
1326 } else {
1327 visitInvokeStatic(node);
1328 }
1329 }
1330
1331 visitIdentity(HIdentity node) { 1314 visitIdentity(HIdentity node) {
1332 assert(node.isBuiltin(types));
1333 emitIdentityComparison(node.left, node.right); 1315 emitIdentityComparison(node.left, node.right);
1334 } 1316 }
1335 1317
1336 visitAdd(HAdd node) => visitInvokeBinary(node, '+'); 1318 visitAdd(HAdd node) => visitInvokeBinary(node, '+');
1337 visitDivide(HDivide node) => visitInvokeBinary(node, '/'); 1319 visitDivide(HDivide node) => visitInvokeBinary(node, '/');
1338 visitMultiply(HMultiply node) => visitInvokeBinary(node, '*'); 1320 visitMultiply(HMultiply node) => visitInvokeBinary(node, '*');
1339 visitSubtract(HSubtract node) => visitInvokeBinary(node, '-'); 1321 visitSubtract(HSubtract node) => visitInvokeBinary(node, '-');
1340 visitBitAnd(HBitAnd node) => visitBitInvokeBinary(node, '&'); 1322 visitBitAnd(HBitAnd node) => visitBitInvokeBinary(node, '&');
1341 visitBitNot(HBitNot node) => visitBitInvokeUnary(node, '~'); 1323 visitBitNot(HBitNot node) => visitBitInvokeUnary(node, '~');
1342 visitBitOr(HBitOr node) => visitBitInvokeBinary(node, '|'); 1324 visitBitOr(HBitOr node) => visitBitInvokeBinary(node, '|');
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 } 1830 }
1849 } 1831 }
1850 } 1832 }
1851 1833
1852 visitNot(HNot node) { 1834 visitNot(HNot node) {
1853 assert(node.inputs.length == 1); 1835 assert(node.inputs.length == 1);
1854 generateNot(node.inputs[0]); 1836 generateNot(node.inputs[0]);
1855 attachLocationToLast(node); 1837 attachLocationToLast(node);
1856 } 1838 }
1857 1839
1858
1859 void generateNot(HInstruction input) { 1840 void generateNot(HInstruction input) {
1860 bool canGenerateOptimizedComparison(HInstruction instruction) { 1841 bool canGenerateOptimizedComparison(HInstruction instruction) {
1861 if (instruction is !HRelational) return false; 1842 if (instruction is !HRelational) return false;
1862 HRelational relational = instruction; 1843 HRelational relational = instruction;
1863 HInstruction left = relational.left; 1844 HInstruction left = relational.left;
1864 HInstruction right = relational.right; 1845 HInstruction right = relational.right;
1865 // This optimization doesn't work for NaN, so we only do it if the 1846 // This optimization doesn't work for NaN, so we only do it if the
1866 // type is known to be an integer. 1847 // type is known to be an integer.
1867 return relational.isBuiltin(types) 1848 return types[left].isUseful() && left.isInteger(types)
1868 && types[left].isUseful() && left.isInteger(types)
1869 && types[right].isUseful() && right.isInteger(types); 1849 && types[right].isUseful() && right.isInteger(types);
1870 } 1850 }
1871 1851
1872 if (input is HBoolify && isGenerateAtUseSite(input)) { 1852 if (input is HBoolify && isGenerateAtUseSite(input)) {
1873 use(input.inputs[0]); 1853 use(input.inputs[0]);
1874 push(new js.Binary("!==", pop(), newLiteralBool(true)), input); 1854 push(new js.Binary("!==", pop(), newLiteralBool(true)), input);
1875 } else if (canGenerateOptimizedComparison(input) && 1855 } else if (canGenerateOptimizedComparison(input) &&
1876 isGenerateAtUseSite(input)) { 1856 isGenerateAtUseSite(input)) {
1877 Map<String, String> inverseOperator = const <String, String>{ 1857 Map<String, String> inverseOperator = const <String, String>{
1878 "==" : "!=", 1858 "==" : "!=",
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
3018 if (leftType.canBeNull() && rightType.canBeNull()) { 2998 if (leftType.canBeNull() && rightType.canBeNull()) {
3019 if (left.isConstantNull() || right.isConstantNull() || 2999 if (left.isConstantNull() || right.isConstantNull() ||
3020 (leftType.isPrimitive() && leftType == rightType)) { 3000 (leftType.isPrimitive() && leftType == rightType)) {
3021 return '=='; 3001 return '==';
3022 } 3002 }
3023 return null; 3003 return null;
3024 } else { 3004 } else {
3025 return '==='; 3005 return '===';
3026 } 3006 }
3027 } 3007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698