Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(773)

Side by Side Diff: frog/leg/ssa/nodes.dart

Issue 9632018: Switch-implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Finished implementation Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 blocks.add(block); 135 blocks.add(block);
136 assert(blocks[id] === block); 136 assert(blocks[id] === block);
137 } 137 }
138 138
139 HBasicBlock addNewBlock() { 139 HBasicBlock addNewBlock() {
140 HBasicBlock result = new HBasicBlock(); 140 HBasicBlock result = new HBasicBlock();
141 addBlock(result); 141 addBlock(result);
142 return result; 142 return result;
143 } 143 }
144 144
145 HBasicBlock addNewLoopHeaderBlock(List<SourceString> labels) { 145 HBasicBlock addNewLoopHeaderBlock(List<LabelElement> labels) {
146 HBasicBlock result = addNewBlock(); 146 HBasicBlock result = addNewBlock();
147 result.loopInformation = new HLoopInformation(result, labels); 147 result.loopInformation = new HLoopInformation(result, labels);
148 return result; 148 return result;
149 } 149 }
150 150
151 static HType mapConstantTypeToSsaType(Constant constant) { 151 static HType mapConstantTypeToSsaType(Constant constant) {
152 if (constant.isNull()) return HType.UNKNOWN; 152 if (constant.isNull()) return HType.UNKNOWN;
153 if (constant.isBool()) return HType.BOOLEAN; 153 if (constant.isBool()) return HType.BOOLEAN;
154 if (constant.isInt()) return HType.INTEGER; 154 if (constant.isInt()) return HType.INTEGER;
155 if (constant.isDouble()) return HType.DOUBLE; 155 if (constant.isDouble()) return HType.DOUBLE;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 314 }
315 315
316 class SubGraph { 316 class SubGraph {
317 // The first and last block of the sub-graph. 317 // The first and last block of the sub-graph.
318 final HBasicBlock start; 318 final HBasicBlock start;
319 final HBasicBlock end; 319 final HBasicBlock end;
320 320
321 const SubGraph(this.start, this.end); 321 const SubGraph(this.start, this.end);
322 322
323 bool contains(HBasicBlock block) { 323 bool contains(HBasicBlock block) {
324 assert(start !== null);
325 assert(end !== null);
326 assert(block !== null);
324 return start.id <= block.id && block.id <= end.id; 327 return start.id <= block.id && block.id <= end.id;
325 } 328 }
326 } 329 }
327 330
328 class HInstructionList { 331 class HInstructionList {
329 HInstruction first = null; 332 HInstruction first = null;
330 HInstruction last = null; 333 HInstruction last = null;
331 334
332 bool isEmpty() { 335 bool isEmpty() {
333 return first === null; 336 return first === null;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 HLabeledBlockInformation labeledBlockInformation = null; 417 HLabeledBlockInformation labeledBlockInformation = null;
415 HBasicBlock parentLoopHeader = null; 418 HBasicBlock parentLoopHeader = null;
416 List<HBailoutTarget> bailouts; 419 List<HBailoutTarget> bailouts;
417 420
418 final List<HBasicBlock> predecessors; 421 final List<HBasicBlock> predecessors;
419 List<HBasicBlock> successors; 422 List<HBasicBlock> successors;
420 423
421 HBasicBlock dominator = null; 424 HBasicBlock dominator = null;
422 final List<HBasicBlock> dominatedBlocks; 425 final List<HBasicBlock> dominatedBlocks;
423 426
424 // For recognizing labeled statements.
425 List<SourceString> labels;
426
427 HBasicBlock() : this.withId(null); 427 HBasicBlock() : this.withId(null);
428 HBasicBlock.withId(this.id) 428 HBasicBlock.withId(this.id)
429 : phis = new HInstructionList(), 429 : phis = new HInstructionList(),
430 predecessors = <HBasicBlock>[], 430 predecessors = <HBasicBlock>[],
431 successors = const <HBasicBlock>[], 431 successors = const <HBasicBlock>[],
432 dominatedBlocks = <HBasicBlock>[], 432 dominatedBlocks = <HBasicBlock>[],
433 bailouts = <HBailoutTarget>[]; 433 bailouts = <HBailoutTarget>[];
434 434
435 bool isNew() => status == STATUS_NEW; 435 bool isNew() => status == STATUS_NEW;
436 bool isOpen() => status == STATUS_OPEN; 436 bool isOpen() => status == STATUS_OPEN;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 } 650 }
651 } 651 }
652 652
653 class HBlockInformation { 653 class HBlockInformation {
654 // Just a marker class. 654 // Just a marker class.
655 } 655 }
656 656
657 class HLabeledBlockInformation extends HBlockInformation { 657 class HLabeledBlockInformation extends HBlockInformation {
658 final SubGraph body; 658 final SubGraph body;
659 final HBasicBlock joinBlock; 659 final HBasicBlock joinBlock;
660 final List<SourceString> labels; 660 final List<LabelElement> labels;
661 HLabeledBlockInformation(this.body, this.joinBlock, this.labels); 661 final StatementElement target;
662
663 HLabeledBlockInformation(this.body, this.joinBlock,
664 List<LabelElement> labels) :
665 this.labels = labels, this.target = labels[0].target;
666
667 // For creating block information when there are no explicit labels.
668 HLabeledBlockInformation.implicit(this.body, this.joinBlock, this.target) :
669 this.labels = const<LabelElement>[];
670
671 bool get isSwitch() => target is SwitchStatementElement;
662 } 672 }
663 673
664 class HLoopInformation extends HBlockInformation { 674 class HLoopInformation extends HBlockInformation {
665 final HBasicBlock header; 675 final HBasicBlock header;
666 final List<HBasicBlock> blocks; 676 final List<HBasicBlock> blocks;
667 final List<HBasicBlock> backEdges; 677 final List<HBasicBlock> backEdges;
668 final List<SourceString> labels; 678 final List<LabelElement> labels;
669 679
670 HLoopInformation(this.header, this.labels) 680 HLoopInformation(this.header, this.labels)
671 : blocks = new List<HBasicBlock>(), 681 : blocks = new List<HBasicBlock>(),
672 backEdges = new List<HBasicBlock>(); 682 backEdges = new List<HBasicBlock>();
673 683
674 void addBackEdge(HBasicBlock predecessor) { 684 void addBackEdge(HBasicBlock predecessor) {
675 backEdges.add(predecessor); 685 backEdges.add(predecessor);
676 addBlock(predecessor); 686 addBlock(predecessor);
677 } 687 }
678 688
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 accept(HVisitor visitor) => visitor.visitExit(this); 1608 accept(HVisitor visitor) => visitor.visitExit(this);
1599 } 1609 }
1600 1610
1601 class HGoto extends HControlFlow { 1611 class HGoto extends HControlFlow {
1602 HGoto() : super(const <HInstruction>[]); 1612 HGoto() : super(const <HInstruction>[]);
1603 toString() => 'goto'; 1613 toString() => 'goto';
1604 accept(HVisitor visitor) => visitor.visitGoto(this); 1614 accept(HVisitor visitor) => visitor.visitGoto(this);
1605 } 1615 }
1606 1616
1607 class HBreak extends HGoto { 1617 class HBreak extends HGoto {
1608 final SourceString label; 1618 // Target is either a LabelElement or a StatementElement.
1609 HBreak([this.label]); 1619 final Element target;
1610 toString() => 'break'; 1620 HBreak(this.target);
1621 toString() => (target is LabelElement) ? 'break ${label.labelName}' : 'break';
1611 accept(HVisitor visitor) => visitor.visitBreak(this); 1622 accept(HVisitor visitor) => visitor.visitBreak(this);
1612 } 1623 }
1613 1624
1614 class HTry extends HControlFlow { 1625 class HTry extends HControlFlow {
1615 HParameterValue exception; 1626 HParameterValue exception;
1616 HBasicBlock finallyBlock; 1627 HBasicBlock finallyBlock;
1617 HTry() : super(const <HInstruction>[]); 1628 HTry() : super(const <HInstruction>[]);
1618 toString() => 'try'; 1629 toString() => 'try';
1619 accept(HVisitor visitor) => visitor.visitTry(this); 1630 accept(HVisitor visitor) => visitor.visitTry(this);
1620 HBasicBlock get joinBlock() => this.block.successors.last(); 1631 HBasicBlock get joinBlock() => this.block.successors.last();
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 class HIfBlockInformation { 2128 class HIfBlockInformation {
2118 final HIf branch; 2129 final HIf branch;
2119 final SubGraph thenGraph; 2130 final SubGraph thenGraph;
2120 final SubGraph elseGraph; 2131 final SubGraph elseGraph;
2121 final HBasicBlock joinBlock; 2132 final HBasicBlock joinBlock;
2122 HIfBlockInformation(this.branch, 2133 HIfBlockInformation(this.branch,
2123 this.thenGraph, 2134 this.thenGraph,
2124 this.elseGraph, 2135 this.elseGraph,
2125 this.joinBlock); 2136 this.joinBlock);
2126 } 2137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698