Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 interface HVisitor<R> { | 5 interface HVisitor<R> { |
| 6 R visitAdd(HAdd node); | 6 R visitAdd(HAdd node); |
| 7 R visitBailoutTarget(HBailoutTarget node); | 7 R visitBailoutTarget(HBailoutTarget node); |
| 8 R visitBitAnd(HBitAnd node); | 8 R visitBitAnd(HBitAnd node); |
| 9 R visitBitNot(HBitNot node); | 9 R visitBitNot(HBitNot node); |
| 10 R visitBitOr(HBitOr node); | 10 R visitBitOr(HBitOr node); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 * instruction instead. | 597 * instruction instead. |
| 598 */ | 598 */ |
| 599 void rewrite(HInstruction from, HInstruction to) { | 599 void rewrite(HInstruction from, HInstruction to) { |
| 600 for (HInstruction use in from.usedBy) { | 600 for (HInstruction use in from.usedBy) { |
| 601 use.rewriteInput(from, to); | 601 use.rewriteInput(from, to); |
| 602 } | 602 } |
| 603 to.usedBy.addAll(from.usedBy); | 603 to.usedBy.addAll(from.usedBy); |
| 604 from.usedBy.clear(); | 604 from.usedBy.clear(); |
| 605 } | 605 } |
| 606 | 606 |
| 607 /** | |
| 608 * Rewrites all uses of the [from] instruction to using either the | |
| 609 * [to] instruction, or a [HCheck] instruction that has better type | |
| 610 * information on [to], and that dominates the user. | |
| 611 */ | |
| 612 void rewriteWithBetterUser(HInstruction from, HInstruction to) { | |
| 613 List<HCheck> better = <HCheck>[]; | |
|
kasperl
2012/08/21 10:37:41
Wouldn't a Link<HCheck> be more efficient here? Th
ngeoffray
2012/08/21 10:43:54
Done.
| |
| 614 for (HInstruction user in to.usedBy) { | |
| 615 if (user is HCheck && (user as HCheck).checkedInput == to) { | |
|
kasperl
2012/08/21 10:37:41
===
ngeoffray
2012/08/21 10:43:54
Done.
| |
| 616 better.add(user); | |
| 617 } | |
| 618 } | |
| 619 | |
| 620 if (better.isEmpty()) return rewrite(from, to); | |
| 621 | |
| 622 L1: for (HInstruction user in from.usedBy) { | |
| 623 for (HCheck check in better) { | |
| 624 if (check.dominates(user)) { | |
| 625 user.rewriteInput(from, check); | |
| 626 check.usedBy.add(user); | |
| 627 continue L1; | |
| 628 } | |
| 629 } | |
| 630 user.rewriteInput(from, to); | |
| 631 to.usedBy.add(user); | |
| 632 } | |
| 633 from.usedBy.clear(); | |
| 634 } | |
| 635 | |
| 607 bool isExitBlock() { | 636 bool isExitBlock() { |
| 608 return first === last && first is HExit; | 637 return first === last && first is HExit; |
| 609 } | 638 } |
| 610 | 639 |
| 611 void addDominatedBlock(HBasicBlock block) { | 640 void addDominatedBlock(HBasicBlock block) { |
| 612 assert(isClosed()); | 641 assert(isClosed()); |
| 613 assert(id !== null && block.id !== null); | 642 assert(id !== null && block.id !== null); |
| 614 assert(dominatedBlocks.indexOf(block) < 0); | 643 assert(dominatedBlocks.indexOf(block) < 0); |
| 615 // Keep the list of dominated blocks sorted such that if there are two | 644 // Keep the list of dominated blocks sorted such that if there are two |
| 616 // succeeding blocks in the list, the predecessor is before the successor. | 645 // succeeding blocks in the list, the predecessor is before the successor. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 } | 1026 } |
| 998 | 1027 |
| 999 /** | 1028 /** |
| 1000 * The code for computing a bailout environment, and the code | 1029 * The code for computing a bailout environment, and the code |
| 1001 * generation must agree on what does not need to be captured, | 1030 * generation must agree on what does not need to be captured, |
| 1002 * so should always be generated at use site. | 1031 * so should always be generated at use site. |
| 1003 */ | 1032 */ |
| 1004 bool isCodeMotionInvariant() => false; | 1033 bool isCodeMotionInvariant() => false; |
| 1005 | 1034 |
| 1006 bool isStatement(HTypeMap types) => false; | 1035 bool isStatement(HTypeMap types) => false; |
| 1036 | |
| 1037 bool dominates(HInstruction other) { | |
| 1038 if (block != other.block) return block.dominates(other.block); | |
| 1039 | |
| 1040 HInstruction current = this; | |
| 1041 while (current != null) { | |
|
kasperl
2012/08/21 10:37:41
!==
ngeoffray
2012/08/21 10:43:54
Done.
| |
| 1042 if (current == other) return true; | |
|
kasperl
2012/08/21 10:37:41
===
ngeoffray
2012/08/21 10:43:54
Done.
| |
| 1043 current = current.next; | |
| 1044 } | |
| 1045 return false; | |
| 1046 } | |
| 1007 } | 1047 } |
| 1008 | 1048 |
| 1009 class HBoolify extends HInstruction { | 1049 class HBoolify extends HInstruction { |
| 1010 HBoolify(HInstruction value) : super(<HInstruction>[value]); | 1050 HBoolify(HInstruction value) : super(<HInstruction>[value]); |
| 1011 void prepareGvn(HTypeMap types) { | 1051 void prepareGvn(HTypeMap types) { |
| 1012 assert(!hasSideEffects(types)); | 1052 assert(!hasSideEffects(types)); |
| 1013 setUseGvn(); | 1053 setUseGvn(); |
| 1014 } | 1054 } |
| 1015 | 1055 |
| 1016 HType get guaranteedType() => HType.BOOLEAN; | 1056 HType get guaranteedType() => HType.BOOLEAN; |
| (...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2751 HBasicBlock get start() => expression.start; | 2791 HBasicBlock get start() => expression.start; |
| 2752 HBasicBlock get end() { | 2792 HBasicBlock get end() { |
| 2753 // We don't create a switch block if there are no cases. | 2793 // We don't create a switch block if there are no cases. |
| 2754 assert(!statements.isEmpty()); | 2794 assert(!statements.isEmpty()); |
| 2755 return statements.last().end; | 2795 return statements.last().end; |
| 2756 } | 2796 } |
| 2757 | 2797 |
| 2758 bool accept(HStatementInformationVisitor visitor) => | 2798 bool accept(HStatementInformationVisitor visitor) => |
| 2759 visitor.visitSwitchInfo(this); | 2799 visitor.visitSwitchInfo(this); |
| 2760 } | 2800 } |
| OLD | NEW |