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 visitBasicBlock(HBasicBlock node); | 7 R visitBasicBlock(HBasicBlock node); |
| 8 R visitDivide(HDivide node); | 8 R visitDivide(HDivide node); |
| 9 R visitExit(HExit node); | 9 R visitExit(HExit node); |
| 10 R visitGoto(HGoto node); | 10 R visitGoto(HGoto node); |
| 11 R visitIf(HIf node); | 11 R visitIf(HIf node); |
| 12 R visitInvoke(HInvoke node); | 12 R visitInvoke(HInvoke node); |
| 13 R visitInvokeForeign(HInvokeForeign node); | 13 R visitInvokeForeign(HInvokeForeign node); |
| 14 R visitLiteral(HLiteral node); | 14 R visitLiteral(HLiteral node); |
| 15 R visitParameter(HParameter node); | 15 R visitParameter(HParameter node); |
| 16 R visitPhi(HPhi node); | 16 R visitPhi(HPhi node); |
| 17 R visitSubtract(HSubtract node); | 17 R visitSubtract(HSubtract node); |
| 18 R visitMultiply(HMultiply node); | 18 R visitMultiply(HMultiply node); |
| 19 R visitReturn(HReturn node); | 19 R visitReturn(HReturn node); |
| 20 R visitThrow(HThrow node); | |
| 20 R visitTruncatingDivide(HTruncatingDivide node); | 21 R visitTruncatingDivide(HTruncatingDivide node); |
| 21 } | 22 } |
| 22 | 23 |
| 23 class HGraphVisitor { | 24 class HGraphVisitor { |
| 24 visitDominatorTree(HGraph graph) { | 25 visitDominatorTree(HGraph graph) { |
| 25 void visitBasicBlockAndSuccessors(HBasicBlock block) { | 26 void visitBasicBlockAndSuccessors(HBasicBlock block) { |
| 26 visitBasicBlock(block); | 27 visitBasicBlock(block); |
| 27 List dominated = block.dominatedBlocks; | 28 List dominated = block.dominatedBlocks; |
| 28 for (int i = 0; i < dominated.length; i++) { | 29 for (int i = 0; i < dominated.length; i++) { |
| 29 visitBasicBlockAndSuccessors(dominated[i]); | 30 visitBasicBlockAndSuccessors(dominated[i]); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 HInstruction instruction = node.first; | 149 HInstruction instruction = node.first; |
| 149 while (instruction !== null) { | 150 while (instruction !== null) { |
| 150 instruction.accept(this); | 151 instruction.accept(this); |
| 151 instruction = instruction.next; | 152 instruction = instruction.next; |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 visitInstruction(HInstruction) {} | 156 visitInstruction(HInstruction) {} |
| 156 | 157 |
| 157 visitArithmetic(HArithmetic node) => visitInvoke(node); | 158 visitArithmetic(HArithmetic node) => visitInvoke(node); |
| 159 visitControlFlow(HControlFlow node) => visitInstruction(node); | |
| 158 | 160 |
| 159 visitAdd(HAdd node) => visitArithmetic(node); | 161 visitAdd(HAdd node) => visitArithmetic(node); |
| 160 visitDivide(HDivide node) => visitArithmetic(node); | 162 visitDivide(HDivide node) => visitArithmetic(node); |
| 161 visitExit(HExit node) => visitInstruction(node); | 163 visitExit(HExit node) => visitControlFlow(node); |
| 162 visitGoto(HGoto node) => visitInstruction(node); | 164 visitGoto(HGoto node) => visitControlFlow(node); |
| 163 visitIf(HIf node) => visitInstruction(node); | 165 visitIf(HIf node) => visitControlFlow(node); |
| 164 visitInvoke(HInvoke node) => visitInstruction(node); | 166 visitInvoke(HInvoke node) => visitInstruction(node); |
| 165 visitInvokeForeign(HInvokeForeign node) => visitInvoke(node); | 167 visitInvokeForeign(HInvokeForeign node) => visitInvoke(node); |
| 166 visitLiteral(HLiteral node) => visitInstruction(node); | 168 visitLiteral(HLiteral node) => visitInstruction(node); |
| 167 visitPhi(HPhi node) => visitInstruction(node); | 169 visitPhi(HPhi node) => visitInstruction(node); |
| 168 visitMultiply(HMultiply node) => visitArithmetic(node); | 170 visitMultiply(HMultiply node) => visitArithmetic(node); |
| 169 visitParameter(HParameter node) => visitInstruction(node); | 171 visitParameter(HParameter node) => visitInstruction(node); |
| 170 visitReturn(HReturn node) => visitInstruction(node); | 172 visitReturn(HReturn node) => visitControlFlow(node); |
| 171 visitSubtract(HSubtract node) => visitArithmetic(node); | 173 visitSubtract(HSubtract node) => visitArithmetic(node); |
| 174 visitThrow(HThrow node) => visitControlFlow(node); | |
| 172 visitTruncatingDivide(HTruncatingDivide node) => visitArithmetic(node); | 175 visitTruncatingDivide(HTruncatingDivide node) => visitArithmetic(node); |
| 173 } | 176 } |
| 174 | 177 |
| 175 class HBasicBlock { | 178 class HBasicBlock { |
| 176 // [id] must be such that any successor's id is greater than this [id]. The | 179 // [id] must be such that any successor's id is greater than this [id]. The |
| 177 // exception are back-edges. | 180 // exception are back-edges. |
| 178 int id; | 181 int id; |
| 179 HInstruction first = null; | 182 HInstruction first = null; |
| 180 HInstruction last = null; | 183 HInstruction last = null; |
| 181 final List<HBasicBlock> predecessors; | 184 final List<HBasicBlock> predecessors; |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 bool isLiteralNumber() => false; | 470 bool isLiteralNumber() => false; |
| 468 bool isLiteralString() => false; | 471 bool isLiteralString() => false; |
| 469 | 472 |
| 470 bool isValid() { | 473 bool isValid() { |
| 471 HValidator validator = new HValidator(); | 474 HValidator validator = new HValidator(); |
| 472 validator.visitInstruction(this); | 475 validator.visitInstruction(this); |
| 473 return validator.isValid; | 476 return validator.isValid; |
| 474 } | 477 } |
| 475 } | 478 } |
| 476 | 479 |
| 480 class HControlFlow extends HInstruction { | |
| 481 HControlFlow(inputs) : super(inputs); | |
| 482 abstract toString(); | |
| 483 } | |
| 484 | |
| 477 class HInvoke extends HInstruction { | 485 class HInvoke extends HInstruction { |
| 478 final SourceString selector; | 486 final SourceString selector; |
| 479 HInvoke(this.selector, inputs) : super(inputs); | 487 HInvoke(this.selector, inputs) : super(inputs); |
| 480 toString() => 'invoke: $selector'; | 488 toString() => 'invoke: $selector'; |
| 481 accept(HVisitor visitor) => visitor.visitInvoke(this); | 489 accept(HVisitor visitor) => visitor.visitInvoke(this); |
| 482 } | 490 } |
| 483 | 491 |
| 484 class HInvokeForeign extends HInvoke { | 492 class HInvokeForeign extends HInvoke { |
| 485 HInvokeForeign(code, inputs) : super(code, inputs); | 493 HInvokeForeign(code, inputs) : super(code, inputs); |
| 486 accept(HVisitor visitor) => visitor.visitInvokeForeign(this); | 494 accept(HVisitor visitor) => visitor.visitInvokeForeign(this); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 } | 547 } |
| 540 | 548 |
| 541 class HTruncatingDivide extends HArithmetic { | 549 class HTruncatingDivide extends HArithmetic { |
| 542 HTruncatingDivide(inputs) : super(const SourceString('~/'), inputs); | 550 HTruncatingDivide(inputs) : super(const SourceString('~/'), inputs); |
| 543 accept(HVisitor visitor) => visitor.visitTruncatingDivide(this); | 551 accept(HVisitor visitor) => visitor.visitTruncatingDivide(this); |
| 544 num evaluate(num a, num b) => a ~/ b; | 552 num evaluate(num a, num b) => a ~/ b; |
| 545 bool typeEquals(other) => other is HTruncatingDivide; | 553 bool typeEquals(other) => other is HTruncatingDivide; |
| 546 bool dataEquals(HInstruction other) => true; | 554 bool dataEquals(HInstruction other) => true; |
| 547 } | 555 } |
| 548 | 556 |
| 549 class HExit extends HInstruction { | 557 class HExit extends HControlFlow { |
| 550 HExit() : super(const <HInstruction>[]); | 558 HExit() : super(const <HInstruction>[]); |
| 551 toString() => 'exit'; | 559 toString() => 'exit'; |
| 552 accept(HVisitor visitor) => visitor.visitExit(this); | 560 accept(HVisitor visitor) => visitor.visitExit(this); |
| 553 } | 561 } |
| 554 | 562 |
| 555 class HGoto extends HInstruction { | 563 class HGoto extends HControlFlow { |
| 556 HGoto() : super(const <HInstruction>[]); | 564 HGoto() : super(const <HInstruction>[]); |
| 557 toString() => 'goto'; | 565 toString() => 'goto'; |
| 558 accept(HVisitor visitor) => visitor.visitGoto(this); | 566 accept(HVisitor visitor) => visitor.visitGoto(this); |
| 559 } | 567 } |
| 560 | 568 |
| 561 class HIf extends HInstruction { | 569 class HIf extends HControlFlow { |
| 562 bool hasElse; | 570 bool hasElse; |
| 563 HIf(HInstruction condition, this.hasElse) : super(<HInstruction>[condition]); | 571 HIf(HInstruction condition, this.hasElse) : super(<HInstruction>[condition]); |
| 564 toString() => 'if'; | 572 toString() => 'if'; |
| 565 accept(HVisitor visitor) => visitor.visitIf(this); | 573 accept(HVisitor visitor) => visitor.visitIf(this); |
| 566 } | 574 } |
| 567 | 575 |
| 568 class HLiteral extends HInstruction { | 576 class HLiteral extends HInstruction { |
| 569 final value; | 577 final value; |
| 570 HLiteral(this.value) : super([]); | 578 HLiteral(this.value) : super([]); |
| 571 void prepareGvn() { | 579 void prepareGvn() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 590 accept(HVisitor visitor) => visitor.visitParameter(this); | 598 accept(HVisitor visitor) => visitor.visitParameter(this); |
| 591 } | 599 } |
| 592 | 600 |
| 593 class HPhi extends HInstruction { | 601 class HPhi extends HInstruction { |
| 594 HPhi(HInstruction input1, HInstruction input2) | 602 HPhi(HInstruction input1, HInstruction input2) |
| 595 : super(<HInstruction>[input1, input2]); | 603 : super(<HInstruction>[input1, input2]); |
| 596 toString() => 'phi'; | 604 toString() => 'phi'; |
| 597 accept(HVisitor visitor) => visitor.visitPhi(this); | 605 accept(HVisitor visitor) => visitor.visitPhi(this); |
| 598 } | 606 } |
| 599 | 607 |
| 600 class HReturn extends HInstruction { | 608 class HReturn extends HControlFlow { |
| 601 HReturn(value) : super([value]); | 609 HReturn(value) : super([value]); |
| 602 toString() => 'return'; | 610 toString() => 'return'; |
| 603 accept(HVisitor visitor) => visitor.visitReturn(this); | 611 accept(HVisitor visitor) => visitor.visitReturn(this); |
| 604 } | 612 } |
| 613 | |
| 614 class HThrow extends HControlFlow { | |
| 615 HThrow(value) : super([value]); | |
|
ngeoffray
2011/11/10 13:22:37
does it still hold if value is null?
| |
| 616 toString() => 'throw'; | |
| 617 accept(HVisitor visitor) => visitor.visitThrow(this); | |
| 618 } | |
| OLD | NEW |