| 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class HVisitor<R> { | 7 abstract class HVisitor<R> { |
| 8 R visitAdd(HAdd node); | 8 R visitAdd(HAdd node); |
| 9 R visitBailoutTarget(HBailoutTarget node); | 9 R visitBailoutTarget(HBailoutTarget node); |
| 10 R visitBitAnd(HBitAnd node); | 10 R visitBitAnd(HBitAnd node); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 } | 730 } |
| 731 } | 731 } |
| 732 | 732 |
| 733 bool isValid() { | 733 bool isValid() { |
| 734 assert(isClosed()); | 734 assert(isClosed()); |
| 735 HValidator validator = new HValidator(); | 735 HValidator validator = new HValidator(); |
| 736 validator.visitBasicBlock(this); | 736 validator.visitBasicBlock(this); |
| 737 return validator.isValid; | 737 return validator.isValid; |
| 738 } | 738 } |
| 739 | 739 |
| 740 // TODO(ngeoffray): Cache the information if this method ends up | 740 Map<HBasicBlock, bool> dominatesCache; |
| 741 // being hot. | 741 |
| 742 bool dominates(HBasicBlock other) { | 742 bool dominates(HBasicBlock other) { |
| 743 if (dominatesCache == null) { |
| 744 dominatesCache = new Map<HBasicBlock, bool>(); |
| 745 } else { |
| 746 bool res = dominatesCache[other]; |
| 747 if (res != null) return res; |
| 748 } |
| 743 do { | 749 do { |
| 744 if (identical(this, other)) return true; | 750 if (identical(this, other)) return dominatesCache[other] = true; |
| 745 other = other.dominator; | 751 other = other.dominator; |
| 746 } while (other != null && other.id >= id); | 752 } while (other != null && other.id >= id); |
| 747 return false; | 753 return dominatesCache[other] = false; |
| 748 } | 754 } |
| 749 } | 755 } |
| 750 | 756 |
| 751 | 757 |
| 752 abstract class HInstruction implements Spannable { | 758 abstract class HInstruction implements Spannable { |
| 753 Element sourceElement; | 759 Element sourceElement; |
| 754 SourceFileLocation sourcePosition; | 760 SourceFileLocation sourcePosition; |
| 755 | 761 |
| 756 final int id; | 762 final int id; |
| 757 static int idCounter; | 763 static int idCounter; |
| (...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2409 | 2415 |
| 2410 /** Corresponding block information for the loop. */ | 2416 /** Corresponding block information for the loop. */ |
| 2411 HLoopBlockInformation loopBlockInformation; | 2417 HLoopBlockInformation loopBlockInformation; |
| 2412 | 2418 |
| 2413 HLoopInformation(this.header, this.target, this.labels) | 2419 HLoopInformation(this.header, this.target, this.labels) |
| 2414 : blocks = new List<HBasicBlock>(), | 2420 : blocks = new List<HBasicBlock>(), |
| 2415 backEdges = new List<HBasicBlock>(); | 2421 backEdges = new List<HBasicBlock>(); |
| 2416 | 2422 |
| 2417 void addBackEdge(HBasicBlock predecessor) { | 2423 void addBackEdge(HBasicBlock predecessor) { |
| 2418 backEdges.add(predecessor); | 2424 backEdges.add(predecessor); |
| 2419 addBlock(predecessor); | 2425 List<HBasicBlock> workQueue = <HBasicBlock>[predecessor]; |
| 2426 do { |
| 2427 HBasicBlock current = workQueue.removeLast(); |
| 2428 addBlock(current, workQueue); |
| 2429 } while (!workQueue.isEmpty); |
| 2420 } | 2430 } |
| 2421 | 2431 |
| 2422 // Adds a block and transitively all its predecessors in the loop as | 2432 // Adds a block and transitively all its predecessors in the loop as |
| 2423 // loop blocks. | 2433 // loop blocks. |
| 2424 void addBlock(HBasicBlock block) { | 2434 void addBlock(HBasicBlock block, List<HBasicBlock> workQueue) { |
| 2425 if (identical(block, header)) return; | 2435 if (identical(block, header)) return; |
| 2426 HBasicBlock parentHeader = block.parentLoopHeader; | 2436 HBasicBlock parentHeader = block.parentLoopHeader; |
| 2427 if (identical(parentHeader, header)) { | 2437 if (identical(parentHeader, header)) { |
| 2428 // Nothing to do in this case. | 2438 // Nothing to do in this case. |
| 2429 } else if (parentHeader != null) { | 2439 } else if (parentHeader != null) { |
| 2430 addBlock(parentHeader); | 2440 workQueue.add(parentHeader); |
| 2431 } else { | 2441 } else { |
| 2432 block.parentLoopHeader = header; | 2442 block.parentLoopHeader = header; |
| 2433 blocks.add(block); | 2443 blocks.add(block); |
| 2434 for (int i = 0, length = block.predecessors.length; i < length; i++) { | 2444 workQueue.addAll(block.predecessors); |
| 2435 addBlock(block.predecessors[i]); | |
| 2436 } | |
| 2437 } | 2445 } |
| 2438 } | 2446 } |
| 2439 | 2447 |
| 2440 HBasicBlock getLastBackEdge() { | 2448 HBasicBlock getLastBackEdge() { |
| 2441 int maxId = -1; | 2449 int maxId = -1; |
| 2442 HBasicBlock result = null; | 2450 HBasicBlock result = null; |
| 2443 for (int i = 0, length = backEdges.length; i < length; i++) { | 2451 for (int i = 0, length = backEdges.length; i < length; i++) { |
| 2444 HBasicBlock current = backEdges[i]; | 2452 HBasicBlock current = backEdges[i]; |
| 2445 if (current.id > maxId) { | 2453 if (current.id > maxId) { |
| 2446 maxId = current.id; | 2454 maxId = current.id; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2728 HBasicBlock get start => expression.start; | 2736 HBasicBlock get start => expression.start; |
| 2729 HBasicBlock get end { | 2737 HBasicBlock get end { |
| 2730 // We don't create a switch block if there are no cases. | 2738 // We don't create a switch block if there are no cases. |
| 2731 assert(!statements.isEmpty); | 2739 assert(!statements.isEmpty); |
| 2732 return statements.last.end; | 2740 return statements.last.end; |
| 2733 } | 2741 } |
| 2734 | 2742 |
| 2735 bool accept(HStatementInformationVisitor visitor) => | 2743 bool accept(HStatementInformationVisitor visitor) => |
| 2736 visitor.visitSwitchInfo(this); | 2744 visitor.visitSwitchInfo(this); |
| 2737 } | 2745 } |
| OLD | NEW |