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

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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5172 matching lines...) Expand 10 before | Expand all | Expand 10 after
5183 HBasicBlock expressionStart = openNewBlock(); 5183 HBasicBlock expressionStart = openNewBlock();
5184 HInstruction expression = buildExpression(); 5184 HInstruction expression = buildExpression();
5185 if (switchCases.isEmpty) { 5185 if (switchCases.isEmpty) {
5186 return; 5186 return;
5187 } 5187 }
5188 5188
5189 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]); 5189 HSwitch switchInstruction = new HSwitch(<HInstruction>[expression]);
5190 HBasicBlock expressionEnd = close(switchInstruction); 5190 HBasicBlock expressionEnd = close(switchInstruction);
5191 LocalsHandler savedLocals = localsHandler; 5191 LocalsHandler savedLocals = localsHandler;
5192 5192
5193 List<List<Constant>> matchExpressions = <List<Constant>>[];
5194 List<HStatementInformation> statements = <HStatementInformation>[]; 5193 List<HStatementInformation> statements = <HStatementInformation>[];
5195 bool hasDefault = false; 5194 bool hasDefault = false;
5196 Element getFallThroughErrorElement = backend.getFallThroughError(); 5195 Element getFallThroughErrorElement = backend.getFallThroughError();
5197 HasNextIterator<Node> caseIterator = 5196 HasNextIterator<Node> caseIterator =
5198 new HasNextIterator<Node>(switchCases.iterator); 5197 new HasNextIterator<Node>(switchCases.iterator);
5199 while (caseIterator.hasNext) { 5198 while (caseIterator.hasNext) {
5200 SwitchCase switchCase = caseIterator.next(); 5199 SwitchCase switchCase = caseIterator.next();
5201 List<Constant> caseConstants = <Constant>[];
5202 HBasicBlock block = graph.addNewBlock(); 5200 HBasicBlock block = graph.addNewBlock();
5203 for (Constant constant in getConstants(switchCase)) { 5201 for (Constant constant in getConstants(switchCase)) {
5204 caseConstants.add(constant);
5205 HConstant hConstant = graph.addConstant(constant, compiler); 5202 HConstant hConstant = graph.addConstant(constant, compiler);
5206 switchInstruction.inputs.add(hConstant); 5203 switchInstruction.inputs.add(hConstant);
5207 hConstant.usedBy.add(switchInstruction); 5204 hConstant.usedBy.add(switchInstruction);
5208 expressionEnd.addSuccessor(block); 5205 expressionEnd.addSuccessor(block);
5209 } 5206 }
5210 matchExpressions.add(caseConstants);
5211 5207
5212 if (isDefaultCase(switchCase)) { 5208 if (isDefaultCase(switchCase)) {
5213 // An HSwitch has n inputs and n+1 successors, the last being the 5209 // An HSwitch has n inputs and n+1 successors, the last being the
5214 // default case. 5210 // default case.
5215 expressionEnd.addSuccessor(block); 5211 expressionEnd.addSuccessor(block);
5216 hasDefault = true; 5212 hasDefault = true;
5217 } 5213 }
5218 open(block); 5214 open(block);
5219 localsHandler = new LocalsHandler.from(savedLocals); 5215 localsHandler = new LocalsHandler.from(savedLocals);
5220 buildSwitchCase(switchCase); 5216 buildSwitchCase(switchCase);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
5258 } 5254 }
5259 if (!hasDefault) { 5255 if (!hasDefault) {
5260 // Always create a default case, to avoid a critical edge in the 5256 // Always create a default case, to avoid a critical edge in the
5261 // graph. 5257 // graph.
5262 HBasicBlock defaultCase = addNewBlock(); 5258 HBasicBlock defaultCase = addNewBlock();
5263 expressionEnd.addSuccessor(defaultCase); 5259 expressionEnd.addSuccessor(defaultCase);
5264 open(defaultCase); 5260 open(defaultCase);
5265 close(new HGoto()); 5261 close(new HGoto());
5266 defaultCase.addSuccessor(joinBlock); 5262 defaultCase.addSuccessor(joinBlock);
5267 caseHandlers.add(savedLocals); 5263 caseHandlers.add(savedLocals);
5268 matchExpressions.add(<Constant>[]);
5269 statements.add(new HSubGraphBlockInformation(new SubGraph( 5264 statements.add(new HSubGraphBlockInformation(new SubGraph(
5270 defaultCase, defaultCase))); 5265 defaultCase, defaultCase)));
5271 } 5266 }
5272 assert(caseHandlers.length == joinBlock.predecessors.length); 5267 assert(caseHandlers.length == joinBlock.predecessors.length);
5273 if (caseHandlers.length != 0) { 5268 if (caseHandlers.length != 0) {
5274 graph.addBlock(joinBlock); 5269 graph.addBlock(joinBlock);
5275 open(joinBlock); 5270 open(joinBlock);
5276 if (caseHandlers.length == 1) { 5271 if (caseHandlers.length == 1) {
5277 localsHandler = caseHandlers[0]; 5272 localsHandler = caseHandlers[0];
5278 } else { 5273 } else {
5279 localsHandler = savedLocals.mergeMultiple(caseHandlers, joinBlock); 5274 localsHandler = savedLocals.mergeMultiple(caseHandlers, joinBlock);
5280 } 5275 }
5281 } else { 5276 } else {
5282 // The joinblock is not used. 5277 // The joinblock is not used.
5283 joinBlock = null; 5278 joinBlock = null;
5284 } 5279 }
5285 5280
5286 HSubExpressionBlockInformation expressionInfo = 5281 HSubExpressionBlockInformation expressionInfo =
5287 new HSubExpressionBlockInformation(new SubExpression(expressionStart, 5282 new HSubExpressionBlockInformation(new SubExpression(expressionStart,
5288 expressionEnd)); 5283 expressionEnd));
5289 expressionStart.setBlockFlow( 5284 expressionStart.setBlockFlow(
5290 new HSwitchBlockInformation(expressionInfo, 5285 new HSwitchBlockInformation(expressionInfo,
5291 matchExpressions,
5292 statements, 5286 statements,
5293 jumpHandler.target, 5287 jumpHandler.target,
5294 jumpHandler.labels()), 5288 jumpHandler.labels()),
5295 joinBlock); 5289 joinBlock);
5296 5290
5297 jumpHandler.close(); 5291 jumpHandler.close();
5298 } 5292 }
5299 5293
5300 Element lookupOperator(ClassElement classElement, String operatorName) { 5294 Element lookupOperator(ClassElement classElement, String operatorName) {
5301 String dartMethodName = 5295 String dartMethodName =
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
5938 new HSubGraphBlockInformation(elseBranch.graph)); 5932 new HSubGraphBlockInformation(elseBranch.graph));
5939 5933
5940 HBasicBlock conditionStartBlock = conditionBranch.block; 5934 HBasicBlock conditionStartBlock = conditionBranch.block;
5941 conditionStartBlock.setBlockFlow(info, joinBlock); 5935 conditionStartBlock.setBlockFlow(info, joinBlock);
5942 SubGraph conditionGraph = conditionBranch.graph; 5936 SubGraph conditionGraph = conditionBranch.graph;
5943 HIf branch = conditionGraph.end.last; 5937 HIf branch = conditionGraph.end.last;
5944 assert(branch is HIf); 5938 assert(branch is HIf);
5945 branch.blockInformation = conditionStartBlock.blockFlow; 5939 branch.blockInformation = conditionStartBlock.blockFlow;
5946 } 5940 }
5947 } 5941 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698