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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/builder.dart

Issue 85593002: Make sure the SSA codegen visit constants used in a switch through the 'visitConstant' method, to e… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of ssa; 5 part of ssa;
6 6
7 /** 7 /**
8 * A special element for the extra parameter taken by intercepted 8 * A special element for the extra parameter taken by intercepted
9 * methods. We need to override [Element.computeType] because our 9 * methods. We need to override [Element.computeType] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 5138 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 HBasicBlock expressionStart = openNewBlock(); 5149 HBasicBlock expressionStart = openNewBlock();
5150 HInstruction expression = buildExpression(); 5150 HInstruction expression = buildExpression();
5151 if (switchCases.isEmpty) { 5151 if (switchCases.isEmpty) {
5152 return; 5152 return;
5153 } 5153 }
5154 5154
5155 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]); 5155 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]);
5156 HBasicBlock expressionEnd = close(switchInstruction); 5156 HBasicBlock expressionEnd = close(switchInstruction);
5157 LocalsHandler savedLocals = localsHandler; 5157 LocalsHandler savedLocals = localsHandler;
5158 5158
5159 List<List<Constant>> matchExpressions = <List<Constant>>[];
5160 List<HStatementInformation> statements = <HStatementInformation>[]; 5159 List<HStatementInformation> statements = <HStatementInformation>[];
5161 bool hasDefault = false; 5160 bool hasDefault = false;
5162 Element getFallThroughErrorElement = backend.getFallThroughError(); 5161 Element getFallThroughErrorElement = backend.getFallThroughError();
5163 HasNextIterator<Node> caseIterator = 5162 HasNextIterator<Node> caseIterator =
5164 new HasNextIterator<Node>(switchCases.iterator); 5163 new HasNextIterator<Node>(switchCases.iterator);
5165 while (caseIterator.hasNext) { 5164 while (caseIterator.hasNext) {
5166 SwitchCase switchCase = caseIterator.next(); 5165 SwitchCase switchCase = caseIterator.next();
5167 List<Constant> caseConstants = <Constant>[];
5168 HBasicBlock block = graph.addNewBlock(); 5166 HBasicBlock block = graph.addNewBlock();
5169 for (Constant constant in getConstants(switchCase)) { 5167 for (Constant constant in getConstants(switchCase)) {
5170 caseConstants.add(constant);
5171 HConstant hConstant = graph.addConstant(constant, compiler); 5168 HConstant hConstant = graph.addConstant(constant, compiler);
5172 switchInstruction.inputs.add(hConstant); 5169 switchInstruction.inputs.add(hConstant);
5173 hConstant.usedBy.add(switchInstruction); 5170 hConstant.usedBy.add(switchInstruction);
5174 expressionEnd.addSuccessor(block); 5171 expressionEnd.addSuccessor(block);
5175 } 5172 }
5176 matchExpressions.add(caseConstants);
5177 5173
5178 if (isDefaultCase(switchCase)) { 5174 if (isDefaultCase(switchCase)) {
5179 // An HSwitch has n inputs and n+1 successors, the last being the 5175 // An HSwitch has n inputs and n+1 successors, the last being the
5180 // default case. 5176 // default case.
5181 expressionEnd.addSuccessor(block); 5177 expressionEnd.addSuccessor(block);
5182 hasDefault = true; 5178 hasDefault = true;
5183 } 5179 }
5184 open(block); 5180 open(block);
5185 localsHandler = new LocalsHandler.from(savedLocals); 5181 localsHandler = new LocalsHandler.from(savedLocals);
5186 buildSwitchCase(switchCase); 5182 buildSwitchCase(switchCase);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5224 } 5220 }
5225 if (!hasDefault) { 5221 if (!hasDefault) {
5226 // Always create a default case, to avoid a critical edge in the 5222 // Always create a default case, to avoid a critical edge in the
5227 // graph. 5223 // graph.
5228 HBasicBlock defaultCase = addNewBlock(); 5224 HBasicBlock defaultCase = addNewBlock();
5229 expressionEnd.addSuccessor(defaultCase); 5225 expressionEnd.addSuccessor(defaultCase);
5230 open(defaultCase); 5226 open(defaultCase);
5231 close(new HGoto()); 5227 close(new HGoto());
5232 defaultCase.addSuccessor(joinBlock); 5228 defaultCase.addSuccessor(joinBlock);
5233 caseHandlers.add(savedLocals); 5229 caseHandlers.add(savedLocals);
5234 matchExpressions.add(<Constant>[]);
5235 statements.add(new HSubGraphBlockInformation(new SubGraph( 5230 statements.add(new HSubGraphBlockInformation(new SubGraph(
5236 defaultCase, defaultCase))); 5231 defaultCase, defaultCase)));
5237 } 5232 }
5238 assert(caseHandlers.length == joinBlock.predecessors.length); 5233 assert(caseHandlers.length == joinBlock.predecessors.length);
5239 if (caseHandlers.length != 0) { 5234 if (caseHandlers.length != 0) {
5240 graph.addBlock(joinBlock); 5235 graph.addBlock(joinBlock);
5241 open(joinBlock); 5236 open(joinBlock);
5242 if (caseHandlers.length == 1) { 5237 if (caseHandlers.length == 1) {
5243 localsHandler = caseHandlers[0]; 5238 localsHandler = caseHandlers[0];
5244 } else { 5239 } else {
5245 localsHandler = savedLocals.mergeMultiple(caseHandlers, joinBlock); 5240 localsHandler = savedLocals.mergeMultiple(caseHandlers, joinBlock);
5246 } 5241 }
5247 } else { 5242 } else {
5248 // The joinblock is not used. 5243 // The joinblock is not used.
5249 joinBlock = null; 5244 joinBlock = null;
5250 } 5245 }
5251 5246
5252 HSubExpressionBlockInformation expressionInfo = 5247 HSubExpressionBlockInformation expressionInfo =
5253 new HSubExpressionBlockInformation(new SubExpression(expressionStart, 5248 new HSubExpressionBlockInformation(new SubExpression(expressionStart,
5254 expressionEnd)); 5249 expressionEnd));
5255 expressionStart.setBlockFlow( 5250 expressionStart.setBlockFlow(
5256 new HSwitchBlockInformation(expressionInfo, 5251 new HSwitchBlockInformation(expressionInfo,
5257 matchExpressions,
5258 statements, 5252 statements,
5259 jumpHandler.target, 5253 jumpHandler.target,
5260 jumpHandler.labels()), 5254 jumpHandler.labels()),
5261 joinBlock); 5255 joinBlock);
5262 5256
5263 jumpHandler.close(); 5257 jumpHandler.close();
5264 } 5258 }
5265 5259
5266 Element lookupOperator(ClassElement classElement, String operatorName) { 5260 Element lookupOperator(ClassElement classElement, String operatorName) {
5267 String dartMethodName = 5261 String dartMethodName =
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
5904 new HSubGraphBlockInformation(elseBranch.graph)); 5898 new HSubGraphBlockInformation(elseBranch.graph));
5905 5899
5906 HBasicBlock conditionStartBlock = conditionBranch.block; 5900 HBasicBlock conditionStartBlock = conditionBranch.block;
5907 conditionStartBlock.setBlockFlow(info, joinBlock); 5901 conditionStartBlock.setBlockFlow(info, joinBlock);
5908 SubGraph conditionGraph = conditionBranch.graph; 5902 SubGraph conditionGraph = conditionBranch.graph;
5909 HIf branch = conditionGraph.end.last; 5903 HIf branch = conditionGraph.end.last;
5910 assert(branch is HIf); 5904 assert(branch is HIf);
5911 branch.blockInformation = conditionStartBlock.blockFlow; 5905 branch.blockInformation = conditionStartBlock.blockFlow;
5912 } 5906 }
5913 } 5907 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698