Chromium Code Reviews| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 blocks.add(block); | 129 blocks.add(block); |
| 129 assert(blocks[id] === block); | 130 assert(blocks[id] === block); |
| 130 } | 131 } |
| 131 | 132 |
| 132 HBasicBlock addNewBlock() { | 133 HBasicBlock addNewBlock() { |
| 133 HBasicBlock result = new HBasicBlock(); | 134 HBasicBlock result = new HBasicBlock(); |
| 134 addBlock(result); | 135 addBlock(result); |
| 135 return result; | 136 return result; |
| 136 } | 137 } |
| 137 | 138 |
| 138 HBasicBlock addNewLoopHeaderBlock() { | 139 HBasicBlock addNewLoopHeaderBlock(List<SourceString> labels) { |
| 139 HBasicBlock result = addNewBlock(); | 140 HBasicBlock result = addNewBlock(); |
| 140 result.loopInformation = new HLoopInformation(result); | 141 result.loopInformation = new HLoopInformation(result, labels); |
| 141 return result; | 142 return result; |
| 142 } | 143 } |
| 143 | 144 |
| 144 void finalize() { | 145 void finalize() { |
| 145 addBlock(exit); | 146 addBlock(exit); |
| 146 exit.open(); | 147 exit.open(); |
| 147 exit.close(new HExit()); | 148 exit.close(new HExit()); |
| 148 assignDominators(); | 149 assignDominators(); |
| 149 } | 150 } |
| 150 | 151 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 visitRelational(HRelational node) => visitInvokeBinary(node); | 201 visitRelational(HRelational node) => visitInvokeBinary(node); |
| 201 | 202 |
| 202 visitAdd(HAdd node) => visitBinaryArithmetic(node); | 203 visitAdd(HAdd node) => visitBinaryArithmetic(node); |
| 203 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); | 204 visitBitAnd(HBitAnd node) => visitBinaryBitOp(node); |
| 204 visitBitNot(HBitNot node) => visitInvokeUnary(node); | 205 visitBitNot(HBitNot node) => visitInvokeUnary(node); |
| 205 visitBitOr(HBitOr node) => visitBinaryBitOp(node); | 206 visitBitOr(HBitOr node) => visitBinaryBitOp(node); |
| 206 visitBitXor(HBitXor node) => visitBinaryBitOp(node); | 207 visitBitXor(HBitXor node) => visitBinaryBitOp(node); |
| 207 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node); | 208 visitBailoutTarget(HBailoutTarget node) => visitInstruction(node); |
| 208 visitBoolify(HBoolify node) => visitInstruction(node); | 209 visitBoolify(HBoolify node) => visitInstruction(node); |
| 209 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); | 210 visitBoundsCheck(HBoundsCheck node) => visitCheck(node); |
| 211 visitBreak(HBreak node) => visitGoto(node); | |
| 210 visitCheck(HCheck node) => visitInstruction(node); | 212 visitCheck(HCheck node) => visitInstruction(node); |
| 211 visitDivide(HDivide node) => visitBinaryArithmetic(node); | 213 visitDivide(HDivide node) => visitBinaryArithmetic(node); |
| 212 visitEquals(HEquals node) => visitRelational(node); | 214 visitEquals(HEquals node) => visitRelational(node); |
| 213 visitExit(HExit node) => visitControlFlow(node); | 215 visitExit(HExit node) => visitControlFlow(node); |
| 214 visitFieldGet(HFieldGet node) => visitInstruction(node); | 216 visitFieldGet(HFieldGet node) => visitInstruction(node); |
| 215 visitFieldSet(HFieldSet node) => visitInstruction(node); | 217 visitFieldSet(HFieldSet node) => visitInstruction(node); |
| 216 visitForeign(HForeign node) => visitInstruction(node); | 218 visitForeign(HForeign node) => visitInstruction(node); |
| 217 visitForeignNew(HForeignNew node) => visitForeign(node); | 219 visitForeignNew(HForeignNew node) => visitForeign(node); |
| 218 visitGoto(HGoto node) => visitControlFlow(node); | 220 visitGoto(HGoto node) => visitControlFlow(node); |
| 219 visitGreater(HGreater node) => visitRelational(node); | 221 visitGreater(HGreater node) => visitRelational(node); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 // this [id]. The exception are back-edges. | 344 // this [id]. The exception are back-edges. |
| 343 int id; | 345 int id; |
| 344 | 346 |
| 345 static final int STATUS_NEW = 0; | 347 static final int STATUS_NEW = 0; |
| 346 static final int STATUS_OPEN = 1; | 348 static final int STATUS_OPEN = 1; |
| 347 static final int STATUS_CLOSED = 2; | 349 static final int STATUS_CLOSED = 2; |
| 348 int status = STATUS_NEW; | 350 int status = STATUS_NEW; |
| 349 | 351 |
| 350 HInstructionList phis; | 352 HInstructionList phis; |
| 351 | 353 |
| 352 HLoopInformation loopInformation = null; | 354 HBlockInformation blockInformation = null; |
|
Lasse Reichstein Nielsen
2012/02/20 13:56:16
I store both loop information and labeled block in
floitsch
2012/02/20 19:01:54
I would prefer two fields. This way we could get r
Lasse Reichstein Nielsen
2012/02/21 13:53:56
Done.
| |
| 353 HBasicBlock parentLoopHeader = null; | 355 HBasicBlock parentLoopHeader = null; |
| 354 List<HBailoutTarget> bailouts; | 356 List<HBailoutTarget> bailouts; |
| 355 | 357 |
| 356 final List<HBasicBlock> predecessors; | 358 final List<HBasicBlock> predecessors; |
| 357 List<HBasicBlock> successors; | 359 List<HBasicBlock> successors; |
| 358 | 360 |
| 359 HBasicBlock dominator = null; | 361 HBasicBlock dominator = null; |
| 360 final List<HBasicBlock> dominatedBlocks; | 362 final List<HBasicBlock> dominatedBlocks; |
| 361 | 363 |
| 364 // For recognizing labeled statements. | |
| 365 List<SourceString> labels; | |
| 366 | |
| 367 bool isBlockEnd; | |
| 368 | |
| 362 HBasicBlock() : this.withId(null); | 369 HBasicBlock() : this.withId(null); |
| 363 HBasicBlock.withId(this.id) | 370 HBasicBlock.withId(this.id) |
| 364 : phis = new HInstructionList(), | 371 : phis = new HInstructionList(), |
| 365 predecessors = <HBasicBlock>[], | 372 predecessors = <HBasicBlock>[], |
| 366 successors = const <HBasicBlock>[], | 373 successors = const <HBasicBlock>[], |
| 367 dominatedBlocks = <HBasicBlock>[], | 374 dominatedBlocks = <HBasicBlock>[], |
| 368 bailouts = <HBailoutTarget>[]; | 375 bailouts = <HBailoutTarget>[]; |
| 369 | 376 |
| 370 bool isNew() => status == STATUS_NEW; | 377 bool isNew() => status == STATUS_NEW; |
| 371 bool isOpen() => status == STATUS_OPEN; | 378 bool isOpen() => status == STATUS_OPEN; |
| 372 bool isClosed() => status == STATUS_CLOSED; | 379 bool isClosed() => status == STATUS_CLOSED; |
| 373 | 380 |
| 374 bool isLoopHeader() => loopInformation !== null; | 381 bool isLoopHeader() => blockInformation is HLoopInformation; |
| 382 bool hasLabeledBlockInformation() => | |
| 383 blockInformation is HLabeledBlockInformation; | |
| 375 bool hasBailouts() => !bailouts.isEmpty(); | 384 bool hasBailouts() => !bailouts.isEmpty(); |
| 376 | 385 |
| 386 void set loopInformation(HLoopInformation info) { | |
| 387 assert(this.blockInformation === null); | |
| 388 blockInformation = info; | |
| 389 } | |
| 390 | |
| 391 void set labeledBlockInformation(HLabeledBlockInformation info) { | |
| 392 assert(this.blockInformation === null); | |
| 393 blockInformation = info; | |
| 394 } | |
| 395 | |
| 396 HLoopInformation get loopInformation() { | |
| 397 if (blockInformation is HLoopInformation) { | |
| 398 return blockInformation; | |
| 399 } | |
| 400 return null; | |
| 401 } | |
| 402 | |
| 403 HLabeledBlockInformation get labeledBlockInformation() { | |
| 404 if (blockInformation is HLabeledBlockInformation) { | |
| 405 return blockInformation; | |
| 406 } | |
| 407 return null; | |
| 408 } | |
| 409 | |
| 377 void open() { | 410 void open() { |
| 378 assert(isNew()); | 411 assert(isNew()); |
| 379 status = STATUS_OPEN; | 412 status = STATUS_OPEN; |
| 380 } | 413 } |
| 381 | 414 |
| 382 void close(HControlFlow end) { | 415 void close(HControlFlow end) { |
| 383 assert(isOpen()); | 416 assert(isOpen()); |
| 384 addAfter(last, end); | 417 addAfter(last, end); |
| 385 status = STATUS_CLOSED; | 418 status = STATUS_CLOSED; |
| 386 } | 419 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 } | 609 } |
| 577 | 610 |
| 578 bool isValid() { | 611 bool isValid() { |
| 579 assert(isClosed()); | 612 assert(isClosed()); |
| 580 HValidator validator = new HValidator(); | 613 HValidator validator = new HValidator(); |
| 581 validator.visitBasicBlock(this); | 614 validator.visitBasicBlock(this); |
| 582 return validator.isValid; | 615 return validator.isValid; |
| 583 } | 616 } |
| 584 } | 617 } |
| 585 | 618 |
| 586 class HLoopInformation { | 619 class HBlockInformation { |
| 620 // Just a marker class. | |
| 621 } | |
| 622 | |
| 623 class HLabeledBlockInformation extends HBlockInformation { | |
| 624 final HBasicBlock start; | |
| 625 final HBasicBlock end; | |
| 626 final List<SourceString> labels; | |
| 627 HLabeledBlockInformation(this.start, this.end, this.labels); | |
| 628 } | |
| 629 | |
| 630 class HLoopInformation extends HBlockInformation { | |
| 587 final HBasicBlock header; | 631 final HBasicBlock header; |
| 588 final List<HBasicBlock> blocks; | 632 final List<HBasicBlock> blocks; |
| 589 final List<HBasicBlock> backEdges; | 633 final List<HBasicBlock> backEdges; |
| 634 final List<SourceString> labels; | |
| 590 | 635 |
| 591 HLoopInformation(this.header) | 636 HLoopInformation(this.header, this.labels) |
| 592 : blocks = new List<HBasicBlock>(), | 637 : blocks = new List<HBasicBlock>(), |
| 593 backEdges = new List<HBasicBlock>(); | 638 backEdges = new List<HBasicBlock>(); |
| 594 | 639 |
| 595 void addBackEdge(HBasicBlock predecessor) { | 640 void addBackEdge(HBasicBlock predecessor) { |
| 596 backEdges.add(predecessor); | 641 backEdges.add(predecessor); |
| 597 addBlock(predecessor); | 642 addBlock(predecessor); |
| 598 } | 643 } |
| 599 | 644 |
| 600 // Adds a block and transitively all its predecessors in the loop as | 645 // Adds a block and transitively all its predecessors in the loop as |
| 601 // loop blocks. | 646 // loop blocks. |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1627 toString() => 'exit'; | 1672 toString() => 'exit'; |
| 1628 accept(HVisitor visitor) => visitor.visitExit(this); | 1673 accept(HVisitor visitor) => visitor.visitExit(this); |
| 1629 } | 1674 } |
| 1630 | 1675 |
| 1631 class HGoto extends HControlFlow { | 1676 class HGoto extends HControlFlow { |
| 1632 HGoto() : super(const <HInstruction>[]); | 1677 HGoto() : super(const <HInstruction>[]); |
| 1633 toString() => 'goto'; | 1678 toString() => 'goto'; |
| 1634 accept(HVisitor visitor) => visitor.visitGoto(this); | 1679 accept(HVisitor visitor) => visitor.visitGoto(this); |
| 1635 } | 1680 } |
| 1636 | 1681 |
| 1682 class HBreak extends HGoto { | |
| 1683 final SourceString label; | |
| 1684 HBreak([this.label]); | |
| 1685 toString() => 'break'; | |
| 1686 accept(HVisitor visitor) => visitor.visitBreak(this); | |
| 1687 } | |
| 1688 | |
| 1637 class HTry extends HControlFlow { | 1689 class HTry extends HControlFlow { |
| 1638 HParameterValue exception; | 1690 HParameterValue exception; |
| 1639 HBasicBlock finallyBlock; | 1691 HBasicBlock finallyBlock; |
| 1640 HTry() : super(const <HInstruction>[]); | 1692 HTry() : super(const <HInstruction>[]); |
| 1641 toString() => 'try'; | 1693 toString() => 'try'; |
| 1642 accept(HVisitor visitor) => visitor.visitTry(this); | 1694 accept(HVisitor visitor) => visitor.visitTry(this); |
| 1643 } | 1695 } |
| 1644 | 1696 |
| 1645 class HIf extends HConditionalBranch { | 1697 class HIf extends HConditionalBranch { |
| 1646 bool hasElse; | 1698 bool hasElse; |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2131 | 2183 |
| 2132 HInstruction get expression() => inputs[0]; | 2184 HInstruction get expression() => inputs[0]; |
| 2133 | 2185 |
| 2134 HType computeType() => HType.BOOLEAN; | 2186 HType computeType() => HType.BOOLEAN; |
| 2135 bool hasExpectedType() => true; | 2187 bool hasExpectedType() => true; |
| 2136 | 2188 |
| 2137 accept(HVisitor visitor) => visitor.visitIs(this); | 2189 accept(HVisitor visitor) => visitor.visitIs(this); |
| 2138 | 2190 |
| 2139 toString() => "$expression is $typeExpression"; | 2191 toString() => "$expression is $typeExpression"; |
| 2140 } | 2192 } |
| OLD | NEW |