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

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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 List<HInstruction> users = instruction.usedBy; 326 List<HInstruction> users = instruction.usedBy;
327 int length = users.length; 327 int length = users.length;
328 for (int i = 0; i < length; i++) { 328 for (int i = 0; i < length; i++) {
329 if (users[i] is! HBoolify) return false; 329 if (users[i] is! HBoolify) return false;
330 } 330 }
331 return true; 331 return true;
332 } 332 }
333 333
334 HInstruction visitRelational(HRelational node) { 334 HInstruction visitRelational(HRelational node) {
335 if (allUsersAreBoolifies(node)) { 335 if (allUsersAreBoolifies(node)) {
336 Interceptors interceptors = compiler.builder.interceptors; 336 Interceptors interceptors = compiler.backend.builder.interceptors;
337 HStatic oldTarget = node.target; 337 HStatic oldTarget = node.target;
338 Element boolifiedInterceptor = 338 Element boolifiedInterceptor =
339 interceptors.getBoolifiedVersionOf(oldTarget.element); 339 interceptors.getBoolifiedVersionOf(oldTarget.element);
340 if (boolifiedInterceptor !== null) { 340 if (boolifiedInterceptor !== null) {
341 HStatic boolifiedTarget = new HStatic(boolifiedInterceptor); 341 HStatic boolifiedTarget = new HStatic(boolifiedInterceptor);
342 // We don't remove the [oldTarget] in case it is used by other 342 // We don't remove the [oldTarget] in case it is used by other
343 // instructions. If it is unused it will be treated as dead code and 343 // instructions. If it is unused it will be treated as dead code and
344 // discarded. 344 // discarded.
345 oldTarget.block.addAfter(oldTarget, boolifiedTarget); 345 oldTarget.block.addAfter(oldTarget, boolifiedTarget);
346 // Remove us as user from the [oldTarget]. 346 // Remove us as user from the [oldTarget].
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 HInstruction visitIdentity(HIdentity node) { 396 HInstruction visitIdentity(HIdentity node) {
397 HInstruction newInstruction = handleIdentityCheck(node); 397 HInstruction newInstruction = handleIdentityCheck(node);
398 return newInstruction === null ? super.visitIdentity(node) : newInstruction; 398 return newInstruction === null ? super.visitIdentity(node) : newInstruction;
399 } 399 }
400 400
401 HInstruction foldBuiltinEqualsCheck(HEquals node) { 401 HInstruction foldBuiltinEqualsCheck(HEquals node) {
402 // TODO(floitsch): cache interceptors. 402 // TODO(floitsch): cache interceptors.
403 HInstruction newInstruction = handleIdentityCheck(node); 403 HInstruction newInstruction = handleIdentityCheck(node);
404 if (newInstruction === null) { 404 if (newInstruction === null) {
405 HStatic target = new HStatic( 405 HStatic target = new HStatic(
406 compiler.builder.interceptors.getTripleEqualsInterceptor()); 406 compiler.backend.builder.interceptors.getTripleEqualsInterceptor());
407 node.block.addBefore(node, target); 407 node.block.addBefore(node, target);
408 return new HIdentity(target, node.left, node.right); 408 return new HIdentity(target, node.left, node.right);
409 } else { 409 } else {
410 return newInstruction; 410 return newInstruction;
411 } 411 }
412 } 412 }
413 413
414 HInstruction visitEquals(HEquals node) { 414 HInstruction visitEquals(HEquals node) {
415 HInstruction left = node.left; 415 HInstruction left = node.left;
416 HInstruction right = node.right; 416 HInstruction right = node.right;
(...skipping 21 matching lines...) Expand all
438 // not implement operator=. 438 // not implement operator=.
439 return foldBuiltinEqualsCheck(node); 439 return foldBuiltinEqualsCheck(node);
440 } 440 }
441 } 441 }
442 442
443 if (right.isConstantNull()) { 443 if (right.isConstantNull()) {
444 if (left.propagatedType.isPrimitive()) { 444 if (left.propagatedType.isPrimitive()) {
445 return graph.addConstantBool(false); 445 return graph.addConstantBool(false);
446 } else { 446 } else {
447 // TODO(floitsch): cache interceptors. 447 // TODO(floitsch): cache interceptors.
448 Interceptors interceptors = compiler.builder.interceptors; 448 Interceptors interceptors = compiler.backend.builder.interceptors;
449 Element equalsElement = interceptors.getEqualsInterceptor(); 449 Element equalsElement = interceptors.getEqualsInterceptor();
450 // If we have a different element than [equalsElement], we 450 // If we have a different element than [equalsElement], we
451 // don't need to optimize this instruction to use another 451 // don't need to optimize this instruction to use another
452 // element: we know the element is either eqNull or eqNullB. 452 // element: we know the element is either eqNull or eqNullB.
453 if (node.element === equalsElement) { 453 if (node.element === equalsElement) {
454 Element targetElement = interceptors.getEqualsNullInterceptor(); 454 Element targetElement = interceptors.getEqualsNullInterceptor();
455 bool onlyUsedInBoolify = allUsersAreBoolifies(node); 455 bool onlyUsedInBoolify = allUsersAreBoolifies(node);
456 if (onlyUsedInBoolify) { 456 if (onlyUsedInBoolify) {
457 targetElement = interceptors.getBoolifiedVersionOf(targetElement); 457 targetElement = interceptors.getBoolifiedVersionOf(targetElement);
458 } 458 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 } 580 }
581 } 581 }
582 582
583 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { 583 class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
584 final String name = "SsaCheckInserter"; 584 final String name = "SsaCheckInserter";
585 Element lengthInterceptor; 585 Element lengthInterceptor;
586 586
587 SsaCheckInserter(Compiler compiler) { 587 SsaCheckInserter(Compiler compiler) {
588 SourceString lengthString = const SourceString('length'); 588 SourceString lengthString = const SourceString('length');
589 lengthInterceptor = 589 lengthInterceptor =
590 compiler.builder.interceptors.getStaticGetInterceptor(lengthString); 590 compiler.backend.builder.interceptors.getStaticGetInterceptor(lengthStri ng);
591 } 591 }
592 592
593 void visitGraph(HGraph graph) { 593 void visitGraph(HGraph graph) {
594 visitDominatorTree(graph); 594 visitDominatorTree(graph);
595 } 595 }
596 596
597 void visitBasicBlock(HBasicBlock block) { 597 void visitBasicBlock(HBasicBlock block) {
598 HInstruction instruction = block.first; 598 HInstruction instruction = block.first;
599 while (instruction !== null) { 599 while (instruction !== null) {
600 HInstruction next = instruction.next; 600 HInstruction next = instruction.next;
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 // the if block terminates. So any use of the instruction 1112 // the if block terminates. So any use of the instruction
1113 // after the join block should be changed to the new 1113 // after the join block should be changed to the new
1114 // instruction. 1114 // instruction.
1115 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); 1115 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType);
1116 } 1116 }
1117 // TODO(ngeoffray): Also change uses for the then block on a HType 1117 // TODO(ngeoffray): Also change uses for the then block on a HType
1118 // that knows it is not of a specific Type. 1118 // that knows it is not of a specific Type.
1119 } 1119 }
1120 } 1120 }
1121 } 1121 }
OLDNEW
« lib/compiler/implementation/compiler.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