| OLD | NEW |
| 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 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); |
| 11 R visitBitXor(HBitXor node); | 11 R visitBitXor(HBitXor node); |
| 12 R visitBoolify(HBoolify node); | 12 R visitBoolify(HBoolify node); |
| 13 R visitBoundsCheck(HBoundsCheck node); | 13 R visitBoundsCheck(HBoundsCheck node); |
| 14 R visitBreak(HBreak node); |
| 14 R visitDivide(HDivide node); | 15 R visitDivide(HDivide node); |
| 15 R visitEquals(HEquals node); | 16 R visitEquals(HEquals node); |
| 16 R visitExit(HExit node); | 17 R visitExit(HExit node); |
| 17 R visitFieldGet(HFieldGet node); | 18 R visitFieldGet(HFieldGet node); |
| 18 R visitFieldSet(HFieldSet node); | 19 R visitFieldSet(HFieldSet node); |
| 19 R visitForeign(HForeign node); | 20 R visitForeign(HForeign node); |
| 20 R visitForeignNew(HForeignNew); | 21 R visitForeignNew(HForeignNew); |
| 21 R visitGoto(HGoto node); | 22 R visitGoto(HGoto node); |
| 22 R visitGreater(HGreater node); | 23 R visitGreater(HGreater node); |
| 23 R visitGreaterEqual(HGreaterEqual node); | 24 R visitGreaterEqual(HGreaterEqual node); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 blocks.add(block); | 140 blocks.add(block); |
| 140 assert(blocks[id] === block); | 141 assert(blocks[id] === block); |
| 141 } | 142 } |
| 142 | 143 |
| 143 HBasicBlock addNewBlock() { | 144 HBasicBlock addNewBlock() { |
| 144 HBasicBlock result = new HBasicBlock(); | 145 HBasicBlock result = new HBasicBlock(); |
| 145 addBlock(result); | 146 addBlock(result); |
| 146 return result; | 147 return result; |
| 147 } | 148 } |
| 148 | 149 |
| 149 HBasicBlock addNewLoopHeaderBlock() { | 150 HBasicBlock addNewLoopHeaderBlock(List<SourceString> labels) { |
| 150 HBasicBlock result = addNewBlock(); | 151 HBasicBlock result = addNewBlock(); |
| 151 result.loopInformation = new HLoopInformation(result); | 152 result.loopInformation = new HLoopInformation(result, labels); |
| 152 return result; | 153 return result; |
| 153 } | 154 } |
| 154 | 155 |
| 155 HLiteral addNewLiteralInt(int value) { | 156 HLiteral addNewLiteralInt(int value) { |
| 156 if (intLiterals === null) intLiterals = new Map<int, HLiteral>(); | 157 if (intLiterals === null) intLiterals = new Map<int, HLiteral>(); |
| 157 HLiteral result = intLiterals[value]; | 158 HLiteral result = intLiterals[value]; |
| 158 if (result === null) { | 159 if (result === null) { |
| 159 result = new HLiteral.internal(value, HType.INTEGER); | 160 result = new HLiteral.internal(value, HType.INTEGER); |
| 160 entry.addAtExit(result); | 161 entry.addAtExit(result); |
| 161 intLiterals[value] = result; | 162 intLiterals[value] = result; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 visitRelational(HRelational node) => visitInvokeBinary(node); | 302 visitRelational(HRelational node) => visitInvokeBinary(node); |
| 302 | 303 |
| 303 visitAdd(HAdd node) => visitBinaryArithmetic(node); | 304 visitAdd(HAdd node) => visitBinaryArithmetic(node); |
| 304 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); | 305 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); |
| 305 visitBitNot(HBitNot node) => visitInvokeUnary(node); | 306 visitBitNot(HBitNot node) => visitInvokeUnary(node); |
| 306 visitBitOr(HBitOr node) => visitBinaryBitOp(node); | 307 visitBitOr(HBitOr node) => visitBinaryBitOp(node); |
| 307 visitBitXor(HBitXor node) => visitBinaryBitOp(node); | 308 visitBitXor(HBitXor node) => visitBinaryBitOp(node); |
| 308 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node); | 309 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node); |
| 309 visitBoolify(HBoolify node) => visitInstruction(node); | 310 visitBoolify(HBoolify node) => visitInstruction(node); |
| 310 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); | 311 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); |
| 312 visitBreak(HBreak node) => visitGoto(node); |
| 311 visitCheck(HCheck node) => visitInstruction(node); | 313 visitCheck(HCheck node) => visitInstruction(node); |
| 312 visitDivide(HDivide node) => visitBinaryArithmetic(node); | 314 visitDivide(HDivide node) => visitBinaryArithmetic(node); |
| 313 visitEquals(HEquals node) => visitRelational(node); | 315 visitEquals(HEquals node) => visitRelational(node); |
| 314 visitExit(HExit node) => visitControlFlow(node); | 316 visitExit(HExit node) => visitControlFlow(node); |
| 315 visitFieldGet(HFieldGet node) => visitInstruction(node); | 317 visitFieldGet(HFieldGet node) => visitInstruction(node); |
| 316 visitFieldSet(HFieldSet node) => visitInstruction(node); | 318 visitFieldSet(HFieldSet node) => visitInstruction(node); |
| 317 visitForeign(HForeign node) => visitInstruction(node); | 319 visitForeign(HForeign node) => visitInstruction(node); |
| 318 visitForeignNew(HForeignNew node) => visitForeign(node); | 320 visitForeignNew(HForeignNew node) => visitForeign(node); |
| 319 visitGoto(HGoto node) => visitControlFlow(node); | 321 visitGoto(HGoto node) => visitControlFlow(node); |
| 320 visitGreater(HGreater node) => visitRelational(node); | 322 visitGreater(HGreater node) => visitRelational(node); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 int id; | 446 int id; |
| 445 | 447 |
| 446 static final int STATUS_NEW = 0; | 448 static final int STATUS_NEW = 0; |
| 447 static final int STATUS_OPEN = 1; | 449 static final int STATUS_OPEN = 1; |
| 448 static final int STATUS_CLOSED = 2; | 450 static final int STATUS_CLOSED = 2; |
| 449 int status = STATUS_NEW; | 451 int status = STATUS_NEW; |
| 450 | 452 |
| 451 HInstructionList phis; | 453 HInstructionList phis; |
| 452 | 454 |
| 453 HLoopInformation loopInformation = null; | 455 HLoopInformation loopInformation = null; |
| 456 HLabeledBlockInformation labeledBlockInformation = null; |
| 454 HBasicBlock parentLoopHeader = null; | 457 HBasicBlock parentLoopHeader = null; |
| 455 List<HBailoutTarget> bailouts; | 458 List<HBailoutTarget> bailouts; |
| 456 | 459 |
| 457 final List<HBasicBlock> predecessors; | 460 final List<HBasicBlock> predecessors; |
| 458 List<HBasicBlock> successors; | 461 List<HBasicBlock> successors; |
| 459 | 462 |
| 460 HBasicBlock dominator = null; | 463 HBasicBlock dominator = null; |
| 461 final List<HBasicBlock> dominatedBlocks; | 464 final List<HBasicBlock> dominatedBlocks; |
| 462 | 465 |
| 466 // For recognizing labeled statements. |
| 467 List<SourceString> labels; |
| 468 |
| 463 HBasicBlock() : this.withId(null); | 469 HBasicBlock() : this.withId(null); |
| 464 HBasicBlock.withId(this.id) | 470 HBasicBlock.withId(this.id) |
| 465 : phis = new HInstructionList(), | 471 : phis = new HInstructionList(), |
| 466 predecessors = <HBasicBlock>[], | 472 predecessors = <HBasicBlock>[], |
| 467 successors = const <HBasicBlock>[], | 473 successors = const <HBasicBlock>[], |
| 468 dominatedBlocks = <HBasicBlock>[], | 474 dominatedBlocks = <HBasicBlock>[], |
| 469 bailouts = <HBailoutTarget>[]; | 475 bailouts = <HBailoutTarget>[]; |
| 470 | 476 |
| 471 bool isNew() => status == STATUS_NEW; | 477 bool isNew() => status == STATUS_NEW; |
| 472 bool isOpen() => status == STATUS_OPEN; | 478 bool isOpen() => status == STATUS_OPEN; |
| 473 bool isClosed() => status == STATUS_CLOSED; | 479 bool isClosed() => status == STATUS_CLOSED; |
| 474 | 480 |
| 475 bool isLoopHeader() => loopInformation !== null; | 481 bool isLoopHeader() => loopInformation !== null; |
| 482 bool hasLabeledBlockInformation() => labeledBlockInformation !== null; |
| 483 |
| 476 bool hasBailouts() => !bailouts.isEmpty(); | 484 bool hasBailouts() => !bailouts.isEmpty(); |
| 477 | 485 |
| 478 void open() { | 486 void open() { |
| 479 assert(isNew()); | 487 assert(isNew()); |
| 480 status = STATUS_OPEN; | 488 status = STATUS_OPEN; |
| 481 } | 489 } |
| 482 | 490 |
| 483 void close(HControlFlow end) { | 491 void close(HControlFlow end) { |
| 484 assert(isOpen()); | 492 assert(isOpen()); |
| 485 addAfter(last, end); | 493 addAfter(last, end); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 685 } |
| 678 | 686 |
| 679 bool isValid() { | 687 bool isValid() { |
| 680 assert(isClosed()); | 688 assert(isClosed()); |
| 681 HValidator validator = new HValidator(); | 689 HValidator validator = new HValidator(); |
| 682 validator.visitBasicBlock(this); | 690 validator.visitBasicBlock(this); |
| 683 return validator.isValid; | 691 return validator.isValid; |
| 684 } | 692 } |
| 685 } | 693 } |
| 686 | 694 |
| 687 class HLoopInformation { | 695 class HBlockInformation { |
| 696 // Just a marker class. |
| 697 } |
| 698 |
| 699 class HLabeledBlockInformation extends HBlockInformation { |
| 700 final HBasicBlock start; |
| 701 final HBasicBlock end; |
| 702 final List<SourceString> labels; |
| 703 HLabeledBlockInformation(this.start, this.end, this.labels); |
| 704 } |
| 705 |
| 706 class HLoopInformation extends HBlockInformation { |
| 688 final HBasicBlock header; | 707 final HBasicBlock header; |
| 689 final List<HBasicBlock> blocks; | 708 final List<HBasicBlock> blocks; |
| 690 final List<HBasicBlock> backEdges; | 709 final List<HBasicBlock> backEdges; |
| 710 final List<SourceString> labels; |
| 691 | 711 |
| 692 HLoopInformation(this.header) | 712 HLoopInformation(this.header, this.labels) |
| 693 : blocks = new List<HBasicBlock>(), | 713 : blocks = new List<HBasicBlock>(), |
| 694 backEdges = new List<HBasicBlock>(); | 714 backEdges = new List<HBasicBlock>(); |
| 695 | 715 |
| 696 void addBackEdge(HBasicBlock predecessor) { | 716 void addBackEdge(HBasicBlock predecessor) { |
| 697 backEdges.add(predecessor); | 717 backEdges.add(predecessor); |
| 698 addBlock(predecessor); | 718 addBlock(predecessor); |
| 699 } | 719 } |
| 700 | 720 |
| 701 // Adds a block and transitively all its predecessors in the loop as | 721 // Adds a block and transitively all its predecessors in the loop as |
| 702 // loop blocks. | 722 // loop blocks. |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 toString() => 'exit'; | 1759 toString() => 'exit'; |
| 1740 accept(HVisitor visitor) => visitor.visitExit(this); | 1760 accept(HVisitor visitor) => visitor.visitExit(this); |
| 1741 } | 1761 } |
| 1742 | 1762 |
| 1743 class HGoto extends HControlFlow { | 1763 class HGoto extends HControlFlow { |
| 1744 HGoto() : super(const <HInstruction>[]); | 1764 HGoto() : super(const <HInstruction>[]); |
| 1745 toString() => 'goto'; | 1765 toString() => 'goto'; |
| 1746 accept(HVisitor visitor) => visitor.visitGoto(this); | 1766 accept(HVisitor visitor) => visitor.visitGoto(this); |
| 1747 } | 1767 } |
| 1748 | 1768 |
| 1769 class HBreak extends HGoto { |
| 1770 final SourceString label; |
| 1771 HBreak([this.label]); |
| 1772 toString() => 'break'; |
| 1773 accept(HVisitor visitor) => visitor.visitBreak(this); |
| 1774 } |
| 1775 |
| 1749 class HTry extends HControlFlow { | 1776 class HTry extends HControlFlow { |
| 1750 HParameterValue exception; | 1777 HParameterValue exception; |
| 1751 HBasicBlock finallyBlock; | 1778 HBasicBlock finallyBlock; |
| 1752 HTry() : super(const <HInstruction>[]); | 1779 HTry() : super(const <HInstruction>[]); |
| 1753 toString() => 'try'; | 1780 toString() => 'try'; |
| 1754 accept(HVisitor visitor) => visitor.visitTry(this); | 1781 accept(HVisitor visitor) => visitor.visitTry(this); |
| 1755 HBasicBlock get joinBlock() => this.block.successors.last(); | 1782 HBasicBlock get joinBlock() => this.block.successors.last(); |
| 1756 } | 1783 } |
| 1757 | 1784 |
| 1758 class HIf extends HConditionalBranch { | 1785 class HIf extends HConditionalBranch { |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 | 2268 |
| 2242 HInstruction get expression() => inputs[0]; | 2269 HInstruction get expression() => inputs[0]; |
| 2243 | 2270 |
| 2244 HType computeType() => HType.BOOLEAN; | 2271 HType computeType() => HType.BOOLEAN; |
| 2245 bool hasExpectedType() => true; | 2272 bool hasExpectedType() => true; |
| 2246 | 2273 |
| 2247 accept(HVisitor visitor) => visitor.visitIs(this); | 2274 accept(HVisitor visitor) => visitor.visitIs(this); |
| 2248 | 2275 |
| 2249 toString() => "$expression is $typeExpression"; | 2276 toString() => "$expression is $typeExpression"; |
| 2250 } | 2277 } |
| OLD | NEW |