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

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: Address review comments. 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 int hashCode() => id; 435 int hashCode() => id;
436 436
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 652 }
653 } 653 }
654 654
655 class HBlockInformation { 655 class HBlockInformation {
656 // Just a marker class. 656 // Just a marker class.
657 } 657 }
658 658
659 class HLabeledBlockInformation extends HBlockInformation { 659 class HLabeledBlockInformation extends HBlockInformation {
660 final SubGraph body; 660 final SubGraph body;
661 final HBasicBlock joinBlock; 661 final HBasicBlock joinBlock;
662 final List<SourceString> labels; 662 final List<LabelElement> labels;
663 HLabeledBlockInformation(this.body, this.joinBlock, this.labels); 663 final StatementElement target;
664
665 HLabeledBlockInformation(this.body, this.joinBlock,
666 List<LabelElement> labels) :
667 this.labels = labels, this.target = labels[0].target;
668
669 // For creating block information when there are no explicit labels.
670 HLabeledBlockInformation.implicit(this.body, this.joinBlock, this.target) :
671 this.labels = const<LabelElement>[];
672
673 bool get isSwitch() => target is SwitchStatementElement;
664 } 674 }
665 675
666 class HLoopInformation extends HBlockInformation { 676 class HLoopInformation extends HBlockInformation {
667 final HBasicBlock header; 677 final HBasicBlock header;
668 final List<HBasicBlock> blocks; 678 final List<HBasicBlock> blocks;
669 final List<HBasicBlock> backEdges; 679 final List<HBasicBlock> backEdges;
670 final List<SourceString> labels; 680 final List<LabelElement> labels;
671 681
672 HLoopInformation(this.header, this.labels) 682 HLoopInformation(this.header, this.labels)
673 : blocks = new List<HBasicBlock>(), 683 : blocks = new List<HBasicBlock>(),
674 backEdges = new List<HBasicBlock>(); 684 backEdges = new List<HBasicBlock>();
675 685
676 void addBackEdge(HBasicBlock predecessor) { 686 void addBackEdge(HBasicBlock predecessor) {
677 backEdges.add(predecessor); 687 backEdges.add(predecessor);
678 addBlock(predecessor); 688 addBlock(predecessor);
679 } 689 }
680 690
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 accept(HVisitor visitor) => visitor.visitExit(this); 1610 accept(HVisitor visitor) => visitor.visitExit(this);
1601 } 1611 }
1602 1612
1603 class HGoto extends HControlFlow { 1613 class HGoto extends HControlFlow {
1604 HGoto() : super(const <HInstruction>[]); 1614 HGoto() : super(const <HInstruction>[]);
1605 toString() => 'goto'; 1615 toString() => 'goto';
1606 accept(HVisitor visitor) => visitor.visitGoto(this); 1616 accept(HVisitor visitor) => visitor.visitGoto(this);
1607 } 1617 }
1608 1618
1609 class HBreak extends HGoto { 1619 class HBreak extends HGoto {
1610 final SourceString label; 1620 // Target is either a LabelElement or a StatementElement.
1611 HBreak([this.label]); 1621 final StatementElement target;
1612 toString() => 'break'; 1622 final LabelElement label;
1623 HBreak(this.target) : label = null;
1624 HBreak.toLabel(LabelElement label) : label = label, target = label.target;
1625 toString() => (target is LabelElement) ? 'break ${label.labelName}' : 'break';
1613 accept(HVisitor visitor) => visitor.visitBreak(this); 1626 accept(HVisitor visitor) => visitor.visitBreak(this);
1614 } 1627 }
1615 1628
1616 class HTry extends HControlFlow { 1629 class HTry extends HControlFlow {
1617 HParameterValue exception; 1630 HParameterValue exception;
1618 HBasicBlock finallyBlock; 1631 HBasicBlock finallyBlock;
1619 HTry() : super(const <HInstruction>[]); 1632 HTry() : super(const <HInstruction>[]);
1620 toString() => 'try'; 1633 toString() => 'try';
1621 accept(HVisitor visitor) => visitor.visitTry(this); 1634 accept(HVisitor visitor) => visitor.visitTry(this);
1622 HBasicBlock get joinBlock() => this.block.successors.last(); 1635 HBasicBlock get joinBlock() => this.block.successors.last();
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 class HIfBlockInformation { 2135 class HIfBlockInformation {
2123 final HIf branch; 2136 final HIf branch;
2124 final SubGraph thenGraph; 2137 final SubGraph thenGraph;
2125 final SubGraph elseGraph; 2138 final SubGraph elseGraph;
2126 final HBasicBlock joinBlock; 2139 final HBasicBlock joinBlock;
2127 HIfBlockInformation(this.branch, 2140 HIfBlockInformation(this.branch,
2128 this.thenGraph, 2141 this.thenGraph,
2129 this.elseGraph, 2142 this.elseGraph,
2130 this.joinBlock); 2143 this.joinBlock);
2131 } 2144 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/codegen.dart ('k') | frog/leg/ssa/tracer.dart » ('j') | tests/co19/co19-leg.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698