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

Side by Side Diff: pkg/compiler/lib/src/ssa/builder.dart

Issue 2938853004: Rename ClosureClassMaps to ClosureDataLookup (Closed)
Patch Set: . Created 3 years, 6 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
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 import 'dart:collection'; 5 import 'dart:collection';
6 6
7 import 'package:js_runtime/shared/embedded_names.dart'; 7 import 'package:js_runtime/shared/embedded_names.dart';
8 8
9 import '../closure.dart'; 9 import '../closure.dart';
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 * stores it in the [returnLocal] field. 861 * stores it in the [returnLocal] field.
862 */ 862 */
863 void setupStateForInlining( 863 void setupStateForInlining(
864 MethodElement function, List<HInstruction> compiledArguments, 864 MethodElement function, List<HInstruction> compiledArguments,
865 {ResolutionInterfaceType instanceType}) { 865 {ResolutionInterfaceType instanceType}) {
866 ResolvedAst resolvedAst = function.resolvedAst; 866 ResolvedAst resolvedAst = function.resolvedAst;
867 assert(resolvedAst != null); 867 assert(resolvedAst != null);
868 localsHandler = new LocalsHandler(this, function, function.memberContext, 868 localsHandler = new LocalsHandler(this, function, function.memberContext,
869 function.contextClass, instanceType, nativeData, interceptorData); 869 function.contextClass, instanceType, nativeData, interceptorData);
870 localsHandler.closureData = 870 localsHandler.closureData =
871 closureToClassMapper.getClosureRepresentationInfo(function); 871 closureDataLookup.getClosureRepresentationInfo(function);
872 returnLocal = 872 returnLocal =
873 new SyntheticLocal("result", function, function.memberContext); 873 new SyntheticLocal("result", function, function.memberContext);
874 localsHandler.updateLocal(returnLocal, graph.addConstantNull(closedWorld)); 874 localsHandler.updateLocal(returnLocal, graph.addConstantNull(closedWorld));
875 875
876 inTryStatement = false; // TODO(lry): why? Document. 876 inTryStatement = false; // TODO(lry): why? Document.
877 877
878 int argumentIndex = 0; 878 int argumentIndex = 0;
879 if (function.isInstanceMember) { 879 if (function.isInstanceMember) {
880 localsHandler.updateLocal(localsHandler.closureData.thisLocal, 880 localsHandler.updateLocal(localsHandler.closureData.thisLocal,
881 compiledArguments[argumentIndex++]); 881 compiledArguments[argumentIndex++]);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 } 1029 }
1030 }); 1030 });
1031 1031
1032 // Build the initializers in the context of the new constructor. 1032 // Build the initializers in the context of the new constructor.
1033 ResolvedAst oldResolvedAst = resolvedAst; 1033 ResolvedAst oldResolvedAst = resolvedAst;
1034 resolvedAst = callee.resolvedAst; 1034 resolvedAst = callee.resolvedAst;
1035 final oldElementInferenceResults = elementInferenceResults; 1035 final oldElementInferenceResults = elementInferenceResults;
1036 elementInferenceResults = globalInferenceResults.resultOfMember(callee); 1036 elementInferenceResults = globalInferenceResults.resultOfMember(callee);
1037 ClosureRepresentationInfo oldClosureData = localsHandler.closureData; 1037 ClosureRepresentationInfo oldClosureData = localsHandler.closureData;
1038 ClosureRepresentationInfo newClosureData = 1038 ClosureRepresentationInfo newClosureData =
1039 closureToClassMapper.getClosureRepresentationInfo(callee); 1039 closureDataLookup.getClosureRepresentationInfo(callee);
1040 localsHandler.closureData = newClosureData; 1040 localsHandler.closureData = newClosureData;
1041 if (resolvedAst.kind == ResolvedAstKind.PARSED) { 1041 if (resolvedAst.kind == ResolvedAstKind.PARSED) {
1042 localsHandler.enterScope( 1042 localsHandler.enterScope(
1043 closureToClassMapper.getClosureAnalysisInfo(resolvedAst.node), 1043 closureDataLookup.getClosureAnalysisInfo(resolvedAst.node),
1044 forGenerativeConstructorBody: callee.isGenerativeConstructorBody); 1044 forGenerativeConstructorBody: callee.isGenerativeConstructorBody);
1045 } 1045 }
1046 buildInitializers(callee, constructorResolvedAsts, fieldValues); 1046 buildInitializers(callee, constructorResolvedAsts, fieldValues);
1047 localsHandler.closureData = oldClosureData; 1047 localsHandler.closureData = oldClosureData;
1048 resolvedAst = oldResolvedAst; 1048 resolvedAst = oldResolvedAst;
1049 elementInferenceResults = oldElementInferenceResults; 1049 elementInferenceResults = oldElementInferenceResults;
1050 }); 1050 });
1051 } 1051 }
1052 1052
1053 void buildInitializers( 1053 void buildInitializers(
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 // last parameter. So no need to directly pass it. 1388 // last parameter. So no need to directly pass it.
1389 if (!localsHandler.isBoxed(parameter)) { 1389 if (!localsHandler.isBoxed(parameter)) {
1390 bodyCallInputs.add(localsHandler.readLocal(parameter)); 1390 bodyCallInputs.add(localsHandler.readLocal(parameter));
1391 } 1391 }
1392 }); 1392 });
1393 1393
1394 // If there are locals that escape (ie mutated in closures), we 1394 // If there are locals that escape (ie mutated in closures), we
1395 // pass the box to the constructor. 1395 // pass the box to the constructor.
1396 // The box must be passed before any type variable. 1396 // The box must be passed before any type variable.
1397 ClosureAnalysisInfo scopeData = 1397 ClosureAnalysisInfo scopeData =
1398 closureToClassMapper.getClosureAnalysisInfo(node); 1398 closureDataLookup.getClosureAnalysisInfo(node);
1399 if (scopeData.requiresContextBox()) { 1399 if (scopeData.requiresContextBox()) {
1400 bodyCallInputs.add(localsHandler.readLocal(scopeData.context)); 1400 bodyCallInputs.add(localsHandler.readLocal(scopeData.context));
1401 } 1401 }
1402 1402
1403 // Type variables arguments must come after the box (if there is one). 1403 // Type variables arguments must come after the box (if there is one).
1404 ClassElement currentClass = constructor.enclosingClass; 1404 ClassElement currentClass = constructor.enclosingClass;
1405 if (rtiNeed.classNeedsRti(currentClass)) { 1405 if (rtiNeed.classNeedsRti(currentClass)) {
1406 // If [currentClass] needs RTI, we add the type variables as 1406 // If [currentClass] needs RTI, we add the type variables as
1407 // parameters of the generative constructor body. 1407 // parameters of the generative constructor body.
1408 currentClass.typeVariables 1408 currentClass.typeVariables
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 Map<Local, TypeMask> parameters = <Local, TypeMask>{}; 1447 Map<Local, TypeMask> parameters = <Local, TypeMask>{};
1448 if (element is MethodElement) { 1448 if (element is MethodElement) {
1449 element.functionSignature 1449 element.functionSignature
1450 .orderedForEachParameter((ParameterElement parameter) { 1450 .orderedForEachParameter((ParameterElement parameter) {
1451 parameters[parameter] = TypeMaskFactory.inferredTypeForParameter( 1451 parameters[parameter] = TypeMaskFactory.inferredTypeForParameter(
1452 parameter, globalInferenceResults); 1452 parameter, globalInferenceResults);
1453 }); 1453 });
1454 } 1454 }
1455 1455
1456 ClosureRepresentationInfo closureData = 1456 ClosureRepresentationInfo closureData =
1457 closureToClassMapper.getClosureRepresentationInfo(element); 1457 closureDataLookup.getClosureRepresentationInfo(element);
1458 localsHandler.startFunction(element, closureData, 1458 localsHandler.startFunction(element, closureData,
1459 closureToClassMapper.getClosureAnalysisInfo(node), parameters, 1459 closureDataLookup.getClosureAnalysisInfo(node), parameters,
1460 isGenerativeConstructorBody: element.isGenerativeConstructorBody); 1460 isGenerativeConstructorBody: element.isGenerativeConstructorBody);
1461 close(new HGoto()).addSuccessor(block); 1461 close(new HGoto()).addSuccessor(block);
1462 1462
1463 open(block); 1463 open(block);
1464 1464
1465 // Add the type parameters of the class as parameters of this method. This 1465 // Add the type parameters of the class as parameters of this method. This
1466 // must be done before adding the normal parameters, because their types 1466 // must be done before adding the normal parameters, because their types
1467 // may contain references to type variables. 1467 // may contain references to type variables.
1468 ClassElement cls = element.enclosingClass; 1468 ClassElement cls = element.enclosingClass;
1469 if ((element.isConstructor || element.isGenerativeConstructorBody) && 1469 if ((element.isConstructor || element.isGenerativeConstructorBody) &&
1470 rtiNeed.classNeedsRti(cls)) { 1470 rtiNeed.classNeedsRti(cls)) {
1471 cls.typeVariables.forEach((ResolutionTypeVariableType typeVariable) { 1471 cls.typeVariables.forEach((ResolutionTypeVariableType typeVariable) {
1472 HParameterValue param = 1472 HParameterValue param =
1473 addParameter(typeVariable.element, commonMasks.nonNullType); 1473 addParameter(typeVariable.element, commonMasks.nonNullType);
1474 localsHandler.directLocals[ 1474 localsHandler.directLocals[
1475 localsHandler.getTypeVariableAsLocal(typeVariable)] = param; 1475 localsHandler.getTypeVariableAsLocal(typeVariable)] = param;
1476 }); 1476 });
1477 } 1477 }
1478 1478
1479 if (element is MethodElement) { 1479 if (element is MethodElement) {
1480 MethodElement functionElement = element; 1480 MethodElement functionElement = element;
1481 FunctionSignature signature = functionElement.functionSignature; 1481 FunctionSignature signature = functionElement.functionSignature;
1482 1482
1483 // Put the type checks in the first successor of the entry, 1483 // Put the type checks in the first successor of the entry,
1484 // because that is where the type guards will also be inserted. 1484 // because that is where the type guards will also be inserted.
1485 // This way we ensure that a type guard will dominate the type 1485 // This way we ensure that a type guard will dominate the type
1486 // check. 1486 // check.
1487 signature.orderedForEachParameter((ParameterElement parameterElement) { 1487 signature.orderedForEachParameter((ParameterElement parameterElement) {
1488 if (element.isGenerativeConstructorBody) { 1488 if (element.isGenerativeConstructorBody) {
1489 if (closureToClassMapper 1489 if (closureDataLookup
1490 .getClosureAnalysisInfo(node) 1490 .getClosureAnalysisInfo(node)
1491 .isCaptured(parameterElement)) { 1491 .isCaptured(parameterElement)) {
1492 // The parameter will be a field in the box passed as the 1492 // The parameter will be a field in the box passed as the
1493 // last parameter. So no need to have it. 1493 // last parameter. So no need to have it.
1494 return; 1494 return;
1495 } 1495 }
1496 } 1496 }
1497 HInstruction newParameter = 1497 HInstruction newParameter =
1498 localsHandler.directLocals[parameterElement]; 1498 localsHandler.directLocals[parameterElement];
1499 if (!element.isConstructor || 1499 if (!element.isConstructor ||
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 pop(); 1724 pop();
1725 } 1725 }
1726 } 1726 }
1727 1727
1728 void buildBody() { 1728 void buildBody() {
1729 visit(node.body); 1729 visit(node.body);
1730 } 1730 }
1731 1731
1732 loopHandler.handleLoop( 1732 loopHandler.handleLoop(
1733 node, 1733 node,
1734 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 1734 closureDataLookup.getClosureRepresentationInfoForLoop(node),
1735 buildInitializer, 1735 buildInitializer,
1736 buildCondition, 1736 buildCondition,
1737 buildUpdate, 1737 buildUpdate,
1738 buildBody); 1738 buildBody);
1739 } 1739 }
1740 1740
1741 visitWhile(ast.While node) { 1741 visitWhile(ast.While node) {
1742 assert(isReachable); 1742 assert(isReachable);
1743 HInstruction buildCondition() { 1743 HInstruction buildCondition() {
1744 visit(node.condition); 1744 visit(node.condition);
1745 return popBoolified(); 1745 return popBoolified();
1746 } 1746 }
1747 1747
1748 loopHandler.handleLoop( 1748 loopHandler.handleLoop(
1749 node, 1749 node,
1750 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 1750 closureDataLookup.getClosureRepresentationInfoForLoop(node),
1751 () {}, 1751 () {},
1752 buildCondition, 1752 buildCondition,
1753 () {}, () { 1753 () {}, () {
1754 visit(node.body); 1754 visit(node.body);
1755 }); 1755 });
1756 } 1756 }
1757 1757
1758 visitDoWhile(ast.DoWhile node) { 1758 visitDoWhile(ast.DoWhile node) {
1759 assert(isReachable); 1759 assert(isReachable);
1760 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 1760 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
1761 var loopClosureInfo = 1761 var loopClosureInfo =
1762 closureToClassMapper.getClosureRepresentationInfoForLoop(node); 1762 closureDataLookup.getClosureRepresentationInfoForLoop(node);
1763 localsHandler.startLoop(loopClosureInfo); 1763 localsHandler.startLoop(loopClosureInfo);
1764 loopDepth++; 1764 loopDepth++;
1765 JumpHandler jumpHandler = loopHandler.beginLoopHeader(node); 1765 JumpHandler jumpHandler = loopHandler.beginLoopHeader(node);
1766 HLoopInformation loopInfo = current.loopInformation; 1766 HLoopInformation loopInfo = current.loopInformation;
1767 HBasicBlock loopEntryBlock = current; 1767 HBasicBlock loopEntryBlock = current;
1768 HBasicBlock bodyEntryBlock = current; 1768 HBasicBlock bodyEntryBlock = current;
1769 JumpTarget target = elements.getTargetDefinition(node); 1769 JumpTarget target = elements.getTargetDefinition(node);
1770 bool hasContinues = target != null && target.isContinueTarget; 1770 bool hasContinues = target != null && target.isContinueTarget;
1771 if (hasContinues) { 1771 if (hasContinues) {
1772 // Add extra block to hang labels on. 1772 // Add extra block to hang labels on.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 }); 1891 });
1892 } 1892 }
1893 } 1893 }
1894 jumpHandler.close(); 1894 jumpHandler.close();
1895 loopDepth--; 1895 loopDepth--;
1896 } 1896 }
1897 1897
1898 visitFunctionExpression(ast.FunctionExpression node) { 1898 visitFunctionExpression(ast.FunctionExpression node) {
1899 LocalFunctionElement methodElement = elements[node]; 1899 LocalFunctionElement methodElement = elements[node];
1900 ClosureRepresentationInfo closureInfo = 1900 ClosureRepresentationInfo closureInfo =
1901 closureToClassMapper.getClosureRepresentationInfo(methodElement); 1901 closureDataLookup.getClosureRepresentationInfo(methodElement);
1902 ClassEntity closureClassEntity = closureInfo.closureClassEntity; 1902 ClassEntity closureClassEntity = closureInfo.closureClassEntity;
1903 1903
1904 List<HInstruction> capturedVariables = <HInstruction>[]; 1904 List<HInstruction> capturedVariables = <HInstruction>[];
1905 closureInfo.createdFieldEntities.forEach((Local field) { 1905 closureInfo.createdFieldEntities.forEach((Local field) {
1906 assert(field != null); 1906 assert(field != null);
1907 capturedVariables.add(localsHandler.readLocal(field)); 1907 capturedVariables.add(localsHandler.readLocal(field));
1908 }); 1908 });
1909 1909
1910 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld); 1910 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld);
1911 push(new HCreate(closureClassEntity, capturedVariables, type, 1911 push(new HCreate(closureClassEntity, capturedVariables, type,
(...skipping 3543 matching lines...) Expand 10 before | Expand all | Expand 10 after
5455 pop(); // Pop the value pushed by the setter call. 5455 pop(); // Pop the value pushed by the setter call.
5456 5456
5457 visit(node.body); 5457 visit(node.body);
5458 } 5458 }
5459 5459
5460 void buildUpdate() {} 5460 void buildUpdate() {}
5461 5461
5462 buildProtectedByFinally(() { 5462 buildProtectedByFinally(() {
5463 loopHandler.handleLoop( 5463 loopHandler.handleLoop(
5464 node, 5464 node,
5465 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 5465 closureDataLookup.getClosureRepresentationInfoForLoop(node),
5466 buildInitializer, 5466 buildInitializer,
5467 buildCondition, 5467 buildCondition,
5468 buildUpdate, 5468 buildUpdate,
5469 buildBody); 5469 buildBody);
5470 }, () { 5470 }, () {
5471 pushInvokeDynamic(node, Selectors.cancel, null, [streamIterator]); 5471 pushInvokeDynamic(node, Selectors.cancel, null, [streamIterator]);
5472 push(new HAwait(pop(), 5472 push(new HAwait(pop(),
5473 new TypeMask.subclass(commonElements.objectClass, closedWorld))); 5473 new TypeMask.subclass(commonElements.objectClass, closedWorld)));
5474 pop(); 5474 pop();
5475 }); 5475 });
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
5527 void buildBody() { 5527 void buildBody() {
5528 Selector call = Selectors.current; 5528 Selector call = Selectors.current;
5529 TypeMask mask = elementInferenceResults.typeOfIteratorCurrent(node); 5529 TypeMask mask = elementInferenceResults.typeOfIteratorCurrent(node);
5530 pushInvokeDynamic(node, call, mask, [iterator]); 5530 pushInvokeDynamic(node, call, mask, [iterator]);
5531 buildAssignLoopVariable(node, pop()); 5531 buildAssignLoopVariable(node, pop());
5532 visit(node.body); 5532 visit(node.body);
5533 } 5533 }
5534 5534
5535 loopHandler.handleLoop( 5535 loopHandler.handleLoop(
5536 node, 5536 node,
5537 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 5537 closureDataLookup.getClosureRepresentationInfoForLoop(node),
5538 buildInitializer, 5538 buildInitializer,
5539 buildCondition, 5539 buildCondition,
5540 () {}, 5540 () {},
5541 buildBody); 5541 buildBody);
5542 } 5542 }
5543 5543
5544 buildAssignLoopVariable(ast.ForIn node, HInstruction value) { 5544 buildAssignLoopVariable(ast.ForIn node, HInstruction value) {
5545 ast.Node identifier = node.declaredIdentifier; 5545 ast.Node identifier = node.declaredIdentifier;
5546 Element variable = elements.getForInVariable(node); 5546 Element variable = elements.getForInVariable(node);
5547 Selector selector = elements.getSelector(identifier); 5547 Selector selector = elements.getSelector(identifier);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5651 HInstruction index = localsHandler.readLocal(indexVariable); 5651 HInstruction index = localsHandler.readLocal(indexVariable);
5652 HInstruction one = graph.addConstantInt(1, closedWorld); 5652 HInstruction one = graph.addConstantInt(1, closedWorld);
5653 HInstruction addInstruction = 5653 HInstruction addInstruction =
5654 new HAdd(index, one, null, commonMasks.positiveIntType); 5654 new HAdd(index, one, null, commonMasks.positiveIntType);
5655 add(addInstruction); 5655 add(addInstruction);
5656 localsHandler.updateLocal(indexVariable, addInstruction); 5656 localsHandler.updateLocal(indexVariable, addInstruction);
5657 } 5657 }
5658 5658
5659 loopHandler.handleLoop( 5659 loopHandler.handleLoop(
5660 node, 5660 node,
5661 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 5661 closureDataLookup.getClosureRepresentationInfoForLoop(node),
5662 buildInitializer, 5662 buildInitializer,
5663 buildCondition, 5663 buildCondition,
5664 buildUpdate, 5664 buildUpdate,
5665 buildBody); 5665 buildBody);
5666 } 5666 }
5667 5667
5668 visitLabel(ast.Label node) { 5668 visitLabel(ast.Label node) {
5669 reporter.internalError(node, 'SsaFromAstMixin.visitLabel.'); 5669 reporter.internalError(node, 'SsaFromAstMixin.visitLabel.');
5670 } 5670 }
5671 5671
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
6004 buildExpression, 6004 buildExpression,
6005 node.cases, 6005 node.cases,
6006 getConstants, 6006 getConstants,
6007 (_) => false, // No case is default. 6007 (_) => false, // No case is default.
6008 buildSwitchCase); 6008 buildSwitchCase);
6009 } 6009 }
6010 6010
6011 void buildLoop() { 6011 void buildLoop() {
6012 loopHandler.handleLoop( 6012 loopHandler.handleLoop(
6013 node, 6013 node,
6014 closureToClassMapper.getClosureRepresentationInfoForLoop(node), 6014 closureDataLookup.getClosureRepresentationInfoForLoop(node),
6015 () {}, 6015 () {},
6016 buildCondition, 6016 buildCondition,
6017 () {}, 6017 () {},
6018 buildSwitch); 6018 buildSwitch);
6019 } 6019 }
6020 6020
6021 if (hasDefault) { 6021 if (hasDefault) {
6022 buildLoop(); 6022 buildLoop();
6023 } else { 6023 } else {
6024 // If the switch statement has no default case, surround the loop with 6024 // If the switch statement has no default case, surround the loop with
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
6867 this.oldReturnLocal, 6867 this.oldReturnLocal,
6868 this.oldReturnType, 6868 this.oldReturnType,
6869 this.oldResolvedAst, 6869 this.oldResolvedAst,
6870 this.oldStack, 6870 this.oldStack,
6871 this.oldLocalsHandler, 6871 this.oldLocalsHandler,
6872 this.inTryStatement, 6872 this.inTryStatement,
6873 this.allFunctionsCalledOnce, 6873 this.allFunctionsCalledOnce,
6874 this.oldElementInferenceResults) 6874 this.oldElementInferenceResults)
6875 : super(function); 6875 : super(function);
6876 } 6876 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart ('k') | pkg/compiler/lib/src/ssa/builder_kernel.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698