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

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

Issue 10386086: RFC: Start refactoring to provide more than a single backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 List<HInstruction> users = instruction.usedBy; 323 List<HInstruction> users = instruction.usedBy;
324 int length = users.length; 324 int length = users.length;
325 for (int i = 0; i < length; i++) { 325 for (int i = 0; i < length; i++) {
326 if (users[i] is! HBoolify) return false; 326 if (users[i] is! HBoolify) return false;
327 } 327 }
328 return true; 328 return true;
329 } 329 }
330 330
331 HInstruction visitRelational(HRelational node) { 331 HInstruction visitRelational(HRelational node) {
332 if (allUsersAreBoolifies(node)) { 332 if (allUsersAreBoolifies(node)) {
333 Interceptors interceptors = compiler.builder.interceptors; 333 Interceptors interceptors = compiler.backend.builder.interceptors;
334 HStatic oldTarget = node.target; 334 HStatic oldTarget = node.target;
335 Element boolifiedInterceptor = 335 Element boolifiedInterceptor =
336 interceptors.getBoolifiedVersionOf(oldTarget.element); 336 interceptors.getBoolifiedVersionOf(oldTarget.element);
337 if (boolifiedInterceptor !== null) { 337 if (boolifiedInterceptor !== null) {
338 HStatic boolifiedTarget = new HStatic(boolifiedInterceptor); 338 HStatic boolifiedTarget = new HStatic(boolifiedInterceptor);
339 // We don't remove the [oldTarget] in case it is used by other 339 // We don't remove the [oldTarget] in case it is used by other
340 // instructions. If it is unused it will be treated as dead code and 340 // instructions. If it is unused it will be treated as dead code and
341 // discarded. 341 // discarded.
342 oldTarget.block.addAfter(oldTarget, boolifiedTarget); 342 oldTarget.block.addAfter(oldTarget, boolifiedTarget);
343 // Remove us as user from the [oldTarget]. 343 // Remove us as user from the [oldTarget].
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 HInstruction visitIdentity(HIdentity node) { 393 HInstruction visitIdentity(HIdentity node) {
394 HInstruction newInstruction = handleIdentityCheck(node); 394 HInstruction newInstruction = handleIdentityCheck(node);
395 return newInstruction === null ? super.visitIdentity(node) : newInstruction; 395 return newInstruction === null ? super.visitIdentity(node) : newInstruction;
396 } 396 }
397 397
398 HInstruction foldBuiltinEqualsCheck(HEquals node) { 398 HInstruction foldBuiltinEqualsCheck(HEquals node) {
399 // TODO(floitsch): cache interceptors. 399 // TODO(floitsch): cache interceptors.
400 HInstruction newInstruction = handleIdentityCheck(node); 400 HInstruction newInstruction = handleIdentityCheck(node);
401 if (newInstruction === null) { 401 if (newInstruction === null) {
402 HStatic target = new HStatic( 402 HStatic target = new HStatic(
403 compiler.builder.interceptors.getTripleEqualsInterceptor()); 403 compiler.backend.builder.interceptors.getTripleEqualsInterceptor());
404 node.block.addBefore(node, target); 404 node.block.addBefore(node, target);
405 return new HIdentity(target, node.left, node.right); 405 return new HIdentity(target, node.left, node.right);
406 } else { 406 } else {
407 return newInstruction; 407 return newInstruction;
408 } 408 }
409 } 409 }
410 410
411 HInstruction visitEquals(HEquals node) { 411 HInstruction visitEquals(HEquals node) {
412 HInstruction left = node.left; 412 HInstruction left = node.left;
413 HInstruction right = node.right; 413 HInstruction right = node.right;
(...skipping 21 matching lines...) Expand all
435 // not implement operator=. 435 // not implement operator=.
436 return foldBuiltinEqualsCheck(node); 436 return foldBuiltinEqualsCheck(node);
437 } 437 }
438 } 438 }
439 439
440 if (right.isConstantNull()) { 440 if (right.isConstantNull()) {
441 if (left.propagatedType.isPrimitive()) { 441 if (left.propagatedType.isPrimitive()) {
442 return graph.addConstantBool(false); 442 return graph.addConstantBool(false);
443 } else { 443 } else {
444 // TODO(floitsch): cache interceptors. 444 // TODO(floitsch): cache interceptors.
445 Interceptors interceptors = compiler.builder.interceptors; 445 Interceptors interceptors = compiler.backend.builder.interceptors;
446 Element equalsElement = interceptors.getEqualsInterceptor(); 446 Element equalsElement = interceptors.getEqualsInterceptor();
447 // If we have a different element than [equalsElement], we 447 // If we have a different element than [equalsElement], we
448 // don't need to optimize this instruction to use another 448 // don't need to optimize this instruction to use another
449 // element: we know the element is either eqNull or eqNullB. 449 // element: we know the element is either eqNull or eqNullB.
450 if (node.element === equalsElement) { 450 if (node.element === equalsElement) {
451 Element targetElement = interceptors.getEqualsNullInterceptor(); 451 Element targetElement = interceptors.getEqualsNullInterceptor();
452 bool onlyUsedInBoolify = allUsersAreBoolifies(node); 452 bool onlyUsedInBoolify = allUsersAreBoolifies(node);
453 if (onlyUsedInBoolify) { 453 if (onlyUsedInBoolify) {
454 targetElement = interceptors.getBoolifiedVersionOf(targetElement); 454 targetElement = interceptors.getBoolifiedVersionOf(targetElement);
455 } 455 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 } 573 }
574 } 574 }
575 575
576 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { 576 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
577 final String name = "SsaCheckInserter"; 577 final String name = "SsaCheckInserter";
578 Element lengthInterceptor; 578 Element lengthInterceptor;
579 579
580 SsaCheckInserter(Compiler compiler) { 580 SsaCheckInserter(Compiler compiler) {
581 SourceString lengthString = const SourceString('length'); 581 SourceString lengthString = const SourceString('length');
582 lengthInterceptor = 582 lengthInterceptor =
583 compiler.builder.interceptors.getStaticGetInterceptor(lengthString); 583 compiler.backend.builder.interceptors.getStaticGetInterceptor(lengthStri ng);
584 } 584 }
585 585
586 void visitGraph(HGraph graph) { 586 void visitGraph(HGraph graph) {
587 visitDominatorTree(graph); 587 visitDominatorTree(graph);
588 } 588 }
589 589
590 void visitBasicBlock(HBasicBlock block) { 590 void visitBasicBlock(HBasicBlock block) {
591 HInstruction instruction = block.first; 591 HInstruction instruction = block.first;
592 while (instruction !== null) { 592 while (instruction !== null) {
593 HInstruction next = instruction.next; 593 HInstruction next = instruction.next;
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 // the if block terminates. So any use of the instruction 1106 // the if block terminates. So any use of the instruction
1107 // after the join block should be changed to the new 1107 // after the join block should be changed to the new
1108 // instruction. 1108 // instruction.
1109 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); 1109 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType);
1110 } 1110 }
1111 // TODO(ngeoffray): Also change uses for the then block on a HType 1111 // TODO(ngeoffray): Also change uses for the then block on a HType
1112 // that knows it is not of a specific Type. 1112 // that knows it is not of a specific Type.
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
OLDNEW
« lib/compiler/implementation/ssa/builder.dart ('K') | « lib/compiler/implementation/ssa/codegen.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698