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

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

Issue 10078008: Fix folding of == when a type defines operator=. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 238 }
239 239
240 HInstruction visitEquals(HEquals node) { 240 HInstruction visitEquals(HEquals node) {
241 HInstruction left = node.left; 241 HInstruction left = node.left;
242 HInstruction right = node.right; 242 HInstruction right = node.right;
243 243
244 if (left.isConstant() && right.isConstant()) { 244 if (left.isConstant() && right.isConstant()) {
245 return visitInvokeBinary(node); 245 return visitInvokeBinary(node);
246 } 246 }
247 247
248 if (left.isNonPrimitive()) {
249 HNonPrimitiveType type = left.propagatedType;
250 Element element = type.lookupMember(Namer.OPERATOR_EQUALS);
251 if (element !== null) {
252 // If the left-hand side is guaranteed to be a non-primitive
253 // type and and it defines operator==, we emit a call to that
254 // operator.
255 return visitInvokeBinary(node);
256 } else if (right.isConstantNull()) {
257 return graph.addConstantBool(false);
258 } else {
259 // We can just emit an identity check because the type does
260 // not implement operator=.
261 // TODO(floitsch): cache interceptors.
262 HStatic target = new HStatic(
263 compiler.builder.interceptors.getTripleEqualsInterceptor());
264 return new HIdentity(target, left, right);
265 }
266 }
267
268
248 if (right.isConstantNull()) { 269 if (right.isConstantNull()) {
249 if (left.propagatedType.isUseful()) { 270 if (left.propagatedType.isUseful()) {
250 return graph.addConstantBool(false); 271 return graph.addConstantBool(false);
251 } else { 272 } else {
252 // TODO(floitsch): cache interceptors. 273 // TODO(floitsch): cache interceptors.
253 HStatic target = new HStatic( 274 HStatic target = new HStatic(
254 compiler.builder.interceptors.getEqualsNullInterceptor()); 275 compiler.builder.interceptors.getEqualsNullInterceptor());
255 node.block.addBefore(node,target); 276 node.block.addBefore(node,target);
256 return new HEquals(target, node.left, node.right); 277 return new HEquals(target, node.left, node.right);
257 } 278 }
258 } 279 }
259 280
260 if (left.isNonPrimitive()) {
261 // If the left-hand side is guaranteed to be a non-primitive
262 // type and and it does not define operator==, we can just emit
263 // an identity check.
264 HNonPrimitiveType type = left.propagatedType;
265 Element element = type.lookupMember(Namer.OPERATOR_EQUALS);
266 if (element === null) {
267 // TODO(floitsch): cache interceptors.
268 HStatic target = new HStatic(
269 compiler.builder.interceptors.getTripleEqualsInterceptor());
270 return new HIdentity(target, left, right);
271 }
272 }
273
274 // All other cases are dealt with by the [visitInvokeBinary]. 281 // All other cases are dealt with by the [visitInvokeBinary].
275 return visitInvokeBinary(node); 282 return visitInvokeBinary(node);
276 } 283 }
277 284
278 HInstruction visitTypeGuard(HTypeGuard node) { 285 HInstruction visitTypeGuard(HTypeGuard node) {
279 HInstruction value = node.guarded; 286 HInstruction value = node.guarded;
280 HType combinedType = value.propagatedType.combine(node.propagatedType); 287 HType combinedType = value.propagatedType.combine(node.propagatedType);
281 return (combinedType == value.propagatedType) ? value : node; 288 return (combinedType == value.propagatedType) ? value : node;
282 } 289 }
283 290
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 811 }
805 } 812 }
806 if (!canBeMoved) continue; 813 if (!canBeMoved) continue;
807 814
808 // This is safe because we are running after GVN. 815 // This is safe because we are running after GVN.
809 // TODO(ngeoffray): ensure GVN has been run. 816 // TODO(ngeoffray): ensure GVN has been run.
810 set_.add(current); 817 set_.add(current);
811 } 818 }
812 } 819 }
813 } 820 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698