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

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

Issue 10991034: Order the parameters of a function at the definition site. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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) 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 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 HType type = HGraph.mapConstantTypeToSsaType(defaultValue); 205 HType type = HGraph.mapConstantTypeToSsaType(defaultValue);
206 defaultValueTypes.update(index, parameter.name, type); 206 defaultValueTypes.update(index, parameter.name, type);
207 index++; 207 index++;
208 }); 208 });
209 } 209 }
210 HTypeList parameterTypes = 210 HTypeList parameterTypes =
211 backend.optimisticParameterTypes(element.declaration, 211 backend.optimisticParameterTypes(element.declaration,
212 defaultValueTypes); 212 defaultValueTypes);
213 if (!parameterTypes.allUnknown) { 213 if (!parameterTypes.allUnknown) {
214 int i = 0; 214 int i = 0;
215 signature.forEachParameter((Element param) { 215 signature.orderedForEachParameter((Element param) {
216 builder.parameters[param].guaranteedType = parameterTypes[i++]; 216 builder.parameters[param].guaranteedType = parameterTypes[i++];
217 }); 217 });
218 } 218 }
219 backend.registerParameterTypesOptimization( 219 backend.registerParameterTypesOptimization(
220 element, parameterTypes, defaultValueTypes); 220 element, parameterTypes, defaultValueTypes);
221 } 221 }
222 222
223 if (compiler.tracer.enabled) { 223 if (compiler.tracer.enabled) {
224 String name; 224 String name;
225 if (element.isMember()) { 225 if (element.isMember()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 * 358 *
359 * Invariant: [function] must be an implementation element. 359 * Invariant: [function] must be an implementation element.
360 */ 360 */
361 void startFunction(FunctionElement function, 361 void startFunction(FunctionElement function,
362 FunctionExpression node) { 362 FunctionExpression node) {
363 assert(invariant(node, function.isImplementation)); 363 assert(invariant(node, function.isImplementation));
364 Compiler compiler = builder.compiler; 364 Compiler compiler = builder.compiler;
365 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( 365 closureData = compiler.closureToClassMapper.computeClosureToClassMapping(
366 node, builder.elements); 366 node, builder.elements);
367 FunctionSignature signature = function.computeSignature(compiler); 367 FunctionSignature signature = function.computeSignature(compiler);
368 signature.forEachParameter((Element element) { 368 signature.orderedForEachParameter((Element element) {
369 HInstruction parameter = new HParameterValue(element); 369 HInstruction parameter = new HParameterValue(element);
370 builder.add(parameter); 370 builder.add(parameter);
371 builder.parameters[element] = parameter; 371 builder.parameters[element] = parameter;
372 directLocals[element] = parameter; 372 directLocals[element] = parameter;
373 parameter.guaranteedType = 373 parameter.guaranteedType =
374 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element)); 374 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element));
375 }); 375 });
376 376
377 enterScope(node); 377 enterScope(node);
378 378
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 stack = <HInstruction>[]; 1007 stack = <HInstruction>[];
1008 returnElement = new Element(const SourceString("result"), 1008 returnElement = new Element(const SourceString("result"),
1009 ElementKind.VARIABLE, 1009 ElementKind.VARIABLE,
1010 function); 1010 function);
1011 localsHandler.updateLocal(returnElement, 1011 localsHandler.updateLocal(returnElement,
1012 graph.addConstantNull(constantSystem)); 1012 graph.addConstantNull(constantSystem));
1013 elements = compiler.enqueuer.resolution.getCachedElements(function); 1013 elements = compiler.enqueuer.resolution.getCachedElements(function);
1014 assert(elements !== null); 1014 assert(elements !== null);
1015 FunctionSignature signature = function.computeSignature(compiler); 1015 FunctionSignature signature = function.computeSignature(compiler);
1016 int index = 0; 1016 int index = 0;
1017 signature.forEachParameter((Element parameter) { 1017 signature.orderedForEachParameter((Element parameter) {
1018 HInstruction argument = compiledArguments[index++]; 1018 HInstruction argument = compiledArguments[index++];
1019 localsHandler.updateLocal(parameter, argument); 1019 localsHandler.updateLocal(parameter, argument);
1020 potentiallyCheckType(argument, parameter); 1020 potentiallyCheckType(argument, parameter);
1021 }); 1021 });
1022 return state; 1022 return state;
1023 } 1023 }
1024 1024
1025 void leaveInlinedMethod(InliningState state) { 1025 void leaveInlinedMethod(InliningState state) {
1026 InliningState poppedState = inliningStack.removeLast(); 1026 InliningState poppedState = inliningStack.removeLast();
1027 assert(state == poppedState); 1027 assert(state == poppedState);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 // checked by the resolver. 1110 // checked by the resolver.
1111 compiler.internalError( 1111 compiler.internalError(
1112 "Parameters and arguments didn't match for super/redirect call", 1112 "Parameters and arguments didn't match for super/redirect call",
1113 element: constructor); 1113 element: constructor);
1114 } 1114 }
1115 1115
1116 buildFieldInitializers(constructor.enclosingElement, fieldValues); 1116 buildFieldInitializers(constructor.enclosingElement, fieldValues);
1117 1117
1118 int index = 0; 1118 int index = 0;
1119 FunctionSignature params = constructor.computeSignature(compiler); 1119 FunctionSignature params = constructor.computeSignature(compiler);
1120 params.forEachParameter((Element parameter) { 1120 params.orderedForEachParameter((Element parameter) {
1121 HInstruction argument = compiledArguments[index++]; 1121 HInstruction argument = compiledArguments[index++];
1122 localsHandler.updateLocal(parameter, argument); 1122 localsHandler.updateLocal(parameter, argument);
1123 // Don't forget to update the field, if the parameter is of the 1123 // Don't forget to update the field, if the parameter is of the
1124 // form [:this.x:]. 1124 // form [:this.x:].
1125 if (parameter.kind == ElementKind.FIELD_PARAMETER) { 1125 if (parameter.kind == ElementKind.FIELD_PARAMETER) {
1126 FieldParameterElement fieldParameterElement = parameter; 1126 FieldParameterElement fieldParameterElement = parameter;
1127 fieldValues[fieldParameterElement.fieldElement] = argument; 1127 fieldValues[fieldParameterElement.fieldElement] = argument;
1128 } 1128 }
1129 }); 1129 });
1130 1130
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 openFunction(functionElement, function); 1262 openFunction(functionElement, function);
1263 1263
1264 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>(); 1264 Map<Element, HInstruction> fieldValues = new Map<Element, HInstruction>();
1265 1265
1266 // Compile the possible initialization code for local fields and 1266 // Compile the possible initialization code for local fields and
1267 // super fields. 1267 // super fields.
1268 buildFieldInitializers(classElement, fieldValues); 1268 buildFieldInitializers(classElement, fieldValues);
1269 1269
1270 // Compile field-parameters such as [:this.x:]. 1270 // Compile field-parameters such as [:this.x:].
1271 FunctionSignature params = functionElement.computeSignature(compiler); 1271 FunctionSignature params = functionElement.computeSignature(compiler);
1272 params.forEachParameter((Element element) { 1272 params.orderedForEachParameter((Element element) {
1273 if (element.kind == ElementKind.FIELD_PARAMETER) { 1273 if (element.kind == ElementKind.FIELD_PARAMETER) {
1274 // If the [element] is a field-parameter then 1274 // If the [element] is a field-parameter then
1275 // initialize the field element with its value. 1275 // initialize the field element with its value.
1276 FieldParameterElement fieldParameterElement = element; 1276 FieldParameterElement fieldParameterElement = element;
1277 HInstruction parameterValue = localsHandler.readLocal(element); 1277 HInstruction parameterValue = localsHandler.readLocal(element);
1278 fieldValues[fieldParameterElement.fieldElement] = parameterValue; 1278 fieldValues[fieldParameterElement.fieldElement] = parameterValue;
1279 } 1279 }
1280 }); 1280 });
1281 1281
1282 // Analyze the constructor and all referenced constructors and collect 1282 // Analyze the constructor and all referenced constructors and collect
(...skipping 27 matching lines...) Expand all
1310 // Generate calls to the constructor bodies. 1310 // Generate calls to the constructor bodies.
1311 for (int index = constructors.length - 1; index >= 0; index--) { 1311 for (int index = constructors.length - 1; index >= 0; index--) {
1312 FunctionElement constructor = constructors[index]; 1312 FunctionElement constructor = constructors[index];
1313 assert(invariant(functionElement, constructor.isImplementation)); 1313 assert(invariant(functionElement, constructor.isImplementation));
1314 ConstructorBodyElement body = getConstructorBody(constructor); 1314 ConstructorBodyElement body = getConstructorBody(constructor);
1315 if (body === null) continue; 1315 if (body === null) continue;
1316 List bodyCallInputs = <HInstruction>[]; 1316 List bodyCallInputs = <HInstruction>[];
1317 bodyCallInputs.add(newObject); 1317 bodyCallInputs.add(newObject);
1318 FunctionSignature functionSignature = body.computeSignature(compiler); 1318 FunctionSignature functionSignature = body.computeSignature(compiler);
1319 int arity = functionSignature.parameterCount; 1319 int arity = functionSignature.parameterCount;
1320 functionSignature.forEachParameter((parameter) { 1320 functionSignature.orderedForEachParameter((parameter) {
1321 bodyCallInputs.add(localsHandler.readLocal(parameter)); 1321 bodyCallInputs.add(localsHandler.readLocal(parameter));
1322 }); 1322 });
1323 // TODO(ahe): The constructor name is statically resolved. See 1323 // TODO(ahe): The constructor name is statically resolved. See
1324 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner 1324 // SsaCodeGenerator.visitInvokeDynamicMethod. Is there a cleaner
1325 // way to do this? 1325 // way to do this?
1326 SourceString name = 1326 SourceString name =
1327 new SourceString(backend.namer.getName(body.declaration)); 1327 new SourceString(backend.namer.getName(body.declaration));
1328 // TODO(kasperl): This seems fishy. We shouldn't be inventing all 1328 // TODO(kasperl): This seems fishy. We shouldn't be inventing all
1329 // these selectors. Maybe the resolver can do more of the work 1329 // these selectors. Maybe the resolver can do more of the work
1330 // for us here? 1330 // for us here?
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 assert(invariant(functionElement, functionElement.isImplementation)); 1392 assert(invariant(functionElement, functionElement.isImplementation));
1393 HBasicBlock block = graph.addNewBlock(); 1393 HBasicBlock block = graph.addNewBlock();
1394 open(graph.entry); 1394 open(graph.entry);
1395 1395
1396 localsHandler.startFunction(functionElement, node); 1396 localsHandler.startFunction(functionElement, node);
1397 close(new HGoto()).addSuccessor(block); 1397 close(new HGoto()).addSuccessor(block);
1398 1398
1399 open(block); 1399 open(block);
1400 1400
1401 FunctionSignature params = functionElement.computeSignature(compiler); 1401 FunctionSignature params = functionElement.computeSignature(compiler);
1402 params.forEachParameter((Element element) { 1402 params.orderedForEachParameter((Element element) {
1403 if (elements.isParameterChecked(element)) { 1403 if (elements.isParameterChecked(element)) {
1404 addParameterCheckInstruction(element); 1404 addParameterCheckInstruction(element);
1405 } 1405 }
1406 }); 1406 });
1407 1407
1408 // Put the type checks in the first successor of the entry, 1408 // Put the type checks in the first successor of the entry,
1409 // because that is where the type guards will also be inserted. 1409 // because that is where the type guards will also be inserted.
1410 // This way we ensure that a type guard will dominate the type 1410 // This way we ensure that a type guard will dominate the type
1411 // check. 1411 // check.
1412 params.forEachParameter((Element element) { 1412 params.orderedForEachParameter((Element element) {
1413 HInstruction newParameter = potentiallyCheckType( 1413 HInstruction newParameter = potentiallyCheckType(
1414 localsHandler.directLocals[element], element); 1414 localsHandler.directLocals[element], element);
1415 localsHandler.directLocals[element] = newParameter; 1415 localsHandler.directLocals[element] = newParameter;
1416 }); 1416 });
1417 1417
1418 // Add the type parameters of the class as parameters of this 1418 // Add the type parameters of the class as parameters of this
1419 // method. 1419 // method.
1420 var enclosing = functionElement.enclosingElement; 1420 var enclosing = functionElement.enclosingElement;
1421 if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) { 1421 if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) {
1422 enclosing.typeVariables.forEach((TypeVariableType typeVariable) { 1422 enclosing.typeVariables.forEach((TypeVariableType typeVariable) {
(...skipping 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after
4343 new HSubGraphBlockInformation(elseBranch.graph)); 4343 new HSubGraphBlockInformation(elseBranch.graph));
4344 4344
4345 HBasicBlock conditionStartBlock = conditionBranch.block; 4345 HBasicBlock conditionStartBlock = conditionBranch.block;
4346 conditionStartBlock.setBlockFlow(info, joinBlock); 4346 conditionStartBlock.setBlockFlow(info, joinBlock);
4347 SubGraph conditionGraph = conditionBranch.graph; 4347 SubGraph conditionGraph = conditionBranch.graph;
4348 HIf branch = conditionGraph.end.last; 4348 HIf branch = conditionGraph.end.last;
4349 assert(branch is HIf); 4349 assert(branch is HIf);
4350 branch.blockInformation = conditionStartBlock.blockFlow; 4350 branch.blockInformation = conditionStartBlock.blockFlow;
4351 } 4351 }
4352 } 4352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698