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

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

Issue 2981423003: Move .getLocalFunction from KernelToElementMap to KernelToLocalsMap (Closed)
Patch Set: Updated cf. comments Created 3 years, 4 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 List<HInstruction> bodyCallInputs = <HInstruction>[]; 370 List<HInstruction> bodyCallInputs = <HInstruction>[];
371 bodyCallInputs.add(newObject); 371 bodyCallInputs.add(newObject);
372 372
373 // Pass uncaptured arguments first, captured arguments in a box, then type 373 // Pass uncaptured arguments first, captured arguments in a box, then type
374 // arguments. 374 // arguments.
375 375
376 ConstructorEntity constructorElement = _elementMap.getConstructor(body); 376 ConstructorEntity constructorElement = _elementMap.getConstructor(body);
377 377
378 void handleParameter(ir.VariableDeclaration node) { 378 void handleParameter(ir.VariableDeclaration node) {
379 Local parameter = localsMap.getLocal(node); 379 Local parameter = localsMap.getLocalVariable(node);
380 // If [parameter] is boxed, it will be a field in the box passed as the 380 // If [parameter] is boxed, it will be a field in the box passed as the
381 // last parameter. So no need to directly pass it. 381 // last parameter. So no need to directly pass it.
382 if (!localsHandler.isBoxed(parameter)) { 382 if (!localsHandler.isBoxed(parameter)) {
383 bodyCallInputs.add(localsHandler.readLocal(parameter)); 383 bodyCallInputs.add(localsHandler.readLocal(parameter));
384 } 384 }
385 } 385 }
386 386
387 // Provide the parameters to the generative constructor body. 387 // Provide the parameters to the generative constructor body.
388 body.function.positionalParameters.forEach(handleParameter); 388 body.function.positionalParameters.forEach(handleParameter);
389 body.function.namedParameters.toList() 389 body.function.namedParameters.toList()
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 629
630 void _inlineSuperOrRedirectCommon( 630 void _inlineSuperOrRedirectCommon(
631 ir.Initializer initializer, 631 ir.Initializer initializer,
632 ir.Constructor constructor, 632 ir.Constructor constructor,
633 List<HInstruction> arguments, 633 List<HInstruction> arguments,
634 List<ir.Constructor> constructorChain, 634 List<ir.Constructor> constructorChain,
635 Map<FieldEntity, HInstruction> fieldValues, 635 Map<FieldEntity, HInstruction> fieldValues,
636 ir.Constructor caller) { 636 ir.Constructor caller) {
637 var index = 0; 637 var index = 0;
638 void handleParameter(ir.VariableDeclaration node) { 638 void handleParameter(ir.VariableDeclaration node) {
639 Local parameter = localsMap.getLocal(node); 639 Local parameter = localsMap.getLocalVariable(node);
640 HInstruction argument = arguments[index++]; 640 HInstruction argument = arguments[index++];
641 // Because we are inlining the initializer, we must update 641 // Because we are inlining the initializer, we must update
642 // what was given as parameter. This will be used in case 642 // what was given as parameter. This will be used in case
643 // there is a parameter check expression in the initializer. 643 // there is a parameter check expression in the initializer.
644 parameters[parameter] = argument; 644 parameters[parameter] = argument;
645 localsHandler.updateLocal(parameter, argument); 645 localsHandler.updateLocal(parameter, argument);
646 } 646 }
647 647
648 constructor.function.positionalParameters.forEach(handleParameter); 648 constructor.function.positionalParameters.forEach(handleParameter);
649 constructor.function.namedParameters.toList() 649 constructor.function.namedParameters.toList()
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 void removeImplicitInstantiation(DartType type) { 719 void removeImplicitInstantiation(DartType type) {
720 if (type != null) { 720 if (type != null) {
721 currentImplicitInstantiations.removeLast(); 721 currentImplicitInstantiations.removeLast();
722 } 722 }
723 } 723 }
724 724
725 void openFunction([ir.FunctionNode function]) { 725 void openFunction([ir.FunctionNode function]) {
726 Map<Local, TypeMask> parameterMap = <Local, TypeMask>{}; 726 Map<Local, TypeMask> parameterMap = <Local, TypeMask>{};
727 if (function != null) { 727 if (function != null) {
728 void handleParameter(ir.VariableDeclaration node) { 728 void handleParameter(ir.VariableDeclaration node) {
729 Local local = localsMap.getLocal(node); 729 Local local = localsMap.getLocalVariable(node);
730 parameterMap[local] = 730 parameterMap[local] =
731 _typeInferenceMap.getInferredTypeOfParameter(local); 731 _typeInferenceMap.getInferredTypeOfParameter(local);
732 } 732 }
733 733
734 function.positionalParameters.forEach(handleParameter); 734 function.positionalParameters.forEach(handleParameter);
735 function.namedParameters.toList() 735 function.namedParameters.toList()
736 ..sort(namedOrdering) 736 ..sort(namedOrdering)
737 ..forEach(handleParameter); 737 ..forEach(handleParameter);
738 } 738 }
739 739
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 // Find a type for the element. Use the element type of the indexer of the 1034 // Find a type for the element. Use the element type of the indexer of the
1035 // array, as this is stronger than the iterator's `get current` type, for 1035 // array, as this is stronger than the iterator's `get current` type, for
1036 // example, `get current` includes null. 1036 // example, `get current` includes null.
1037 // TODO(sra): The element type of a container type mask might be better. 1037 // TODO(sra): The element type of a container type mask might be better.
1038 TypeMask type = _typeInferenceMap.inferredIndexType(forInStatement); 1038 TypeMask type = _typeInferenceMap.inferredIndexType(forInStatement);
1039 1039
1040 HInstruction index = localsHandler.readLocal(indexVariable); 1040 HInstruction index = localsHandler.readLocal(indexVariable);
1041 HInstruction value = new HIndex(array, index, null, type); 1041 HInstruction value = new HIndex(array, index, null, type);
1042 add(value); 1042 add(value);
1043 1043
1044 Local loopVariableLocal = localsMap.getLocal(forInStatement.variable); 1044 Local loopVariableLocal =
1045 localsMap.getLocalVariable(forInStatement.variable);
1045 localsHandler.updateLocal(loopVariableLocal, value); 1046 localsHandler.updateLocal(loopVariableLocal, value);
1046 // Hint to name loop value after name of loop variable. 1047 // Hint to name loop value after name of loop variable.
1047 if (loopVariableLocal is! SyntheticLocal) { 1048 if (loopVariableLocal is! SyntheticLocal) {
1048 value.sourceElement ??= loopVariableLocal; 1049 value.sourceElement ??= loopVariableLocal;
1049 } 1050 }
1050 1051
1051 forInStatement.body.accept(this); 1052 forInStatement.body.accept(this);
1052 } 1053 }
1053 1054
1054 void buildUpdate() { 1055 void buildUpdate() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 TypeMask mask = _typeInferenceMap.typeOfIteratorMoveNext(forInStatement); 1102 TypeMask mask = _typeInferenceMap.typeOfIteratorMoveNext(forInStatement);
1102 _pushDynamicInvocation(forInStatement, mask, <HInstruction>[iterator], 1103 _pushDynamicInvocation(forInStatement, mask, <HInstruction>[iterator],
1103 selector: Selectors.moveNext); 1104 selector: Selectors.moveNext);
1104 return popBoolified(); 1105 return popBoolified();
1105 } 1106 }
1106 1107
1107 void buildBody() { 1108 void buildBody() {
1108 TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement); 1109 TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement);
1109 _pushDynamicInvocation(forInStatement, mask, [iterator], 1110 _pushDynamicInvocation(forInStatement, mask, [iterator],
1110 selector: Selectors.current); 1111 selector: Selectors.current);
1111 Local loopVariableLocal = localsMap.getLocal(forInStatement.variable); 1112 Local loopVariableLocal =
1113 localsMap.getLocalVariable(forInStatement.variable);
1112 HInstruction value = pop(); 1114 HInstruction value = pop();
1113 localsHandler.updateLocal(loopVariableLocal, value); 1115 localsHandler.updateLocal(loopVariableLocal, value);
1114 // Hint to name loop value after name of loop variable. 1116 // Hint to name loop value after name of loop variable.
1115 if (loopVariableLocal is! SyntheticLocal) { 1117 if (loopVariableLocal is! SyntheticLocal) {
1116 value.sourceElement ??= loopVariableLocal; 1118 value.sourceElement ??= loopVariableLocal;
1117 } 1119 }
1118 forInStatement.body.accept(this); 1120 forInStatement.body.accept(this);
1119 } 1121 }
1120 1122
1121 loopHandler.handleLoop( 1123 loopHandler.handleLoop(
(...skipping 27 matching lines...) Expand all
1149 HInstruction future = pop(); 1151 HInstruction future = pop();
1150 push(new HAwait(future, closedWorld.commonMasks.dynamicType)); 1152 push(new HAwait(future, closedWorld.commonMasks.dynamicType));
1151 return popBoolified(); 1153 return popBoolified();
1152 } 1154 }
1153 1155
1154 void buildBody() { 1156 void buildBody() {
1155 TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement); 1157 TypeMask mask = _typeInferenceMap.typeOfIteratorCurrent(forInStatement);
1156 _pushDynamicInvocation(forInStatement, mask, [streamIterator], 1158 _pushDynamicInvocation(forInStatement, mask, [streamIterator],
1157 selector: Selectors.current); 1159 selector: Selectors.current);
1158 localsHandler.updateLocal( 1160 localsHandler.updateLocal(
1159 localsMap.getLocal(forInStatement.variable), pop()); 1161 localsMap.getLocalVariable(forInStatement.variable), pop());
1160 forInStatement.body.accept(this); 1162 forInStatement.body.accept(this);
1161 } 1163 }
1162 1164
1163 void buildUpdate() {} 1165 void buildUpdate() {}
1164 1166
1165 // Creates a synthetic try/finally block in case anything async goes amiss. 1167 // Creates a synthetic try/finally block in case anything async goes amiss.
1166 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this); 1168 TryCatchFinallyBuilder tryBuilder = new TryCatchFinallyBuilder(this);
1167 // Build fake try body: 1169 // Build fake try body:
1168 loopHandler.handleLoop( 1170 loopHandler.handleLoop(
1169 forInStatement, 1171 forInStatement,
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 2204
2203 @override 2205 @override
2204 void visitVariableGet(ir.VariableGet variableGet) { 2206 void visitVariableGet(ir.VariableGet variableGet) {
2205 ir.VariableDeclaration variable = variableGet.variable; 2207 ir.VariableDeclaration variable = variableGet.variable;
2206 HInstruction letBinding = letBindings[variable]; 2208 HInstruction letBinding = letBindings[variable];
2207 if (letBinding != null) { 2209 if (letBinding != null) {
2208 stack.add(letBinding); 2210 stack.add(letBinding);
2209 return; 2211 return;
2210 } 2212 }
2211 2213
2212 Local local = localsMap.getLocal(variableGet.variable); 2214 Local local = localsMap.getLocalVariable(variableGet.variable);
2213 stack.add(localsHandler.readLocal(local)); 2215 stack.add(localsHandler.readLocal(local));
2214 } 2216 }
2215 2217
2216 @override 2218 @override
2217 void visitPropertySet(ir.PropertySet propertySet) { 2219 void visitPropertySet(ir.PropertySet propertySet) {
2218 propertySet.receiver.accept(this); 2220 propertySet.receiver.accept(this);
2219 HInstruction receiver = pop(); 2221 HInstruction receiver = pop();
2220 propertySet.value.accept(this); 2222 propertySet.value.accept(this);
2221 HInstruction value = pop(); 2223 HInstruction value = pop();
2222 2224
(...skipping 27 matching lines...) Expand all
2250 2252
2251 @override 2253 @override
2252 void visitVariableSet(ir.VariableSet variableSet) { 2254 void visitVariableSet(ir.VariableSet variableSet) {
2253 variableSet.value.accept(this); 2255 variableSet.value.accept(this);
2254 HInstruction value = pop(); 2256 HInstruction value = pop();
2255 _visitLocalSetter(variableSet.variable, value); 2257 _visitLocalSetter(variableSet.variable, value);
2256 } 2258 }
2257 2259
2258 @override 2260 @override
2259 void visitVariableDeclaration(ir.VariableDeclaration declaration) { 2261 void visitVariableDeclaration(ir.VariableDeclaration declaration) {
2260 Local local = localsMap.getLocal(declaration); 2262 Local local = localsMap.getLocalVariable(declaration);
2261 if (declaration.initializer == null) { 2263 if (declaration.initializer == null) {
2262 HInstruction initialValue = graph.addConstantNull(closedWorld); 2264 HInstruction initialValue = graph.addConstantNull(closedWorld);
2263 localsHandler.updateLocal(local, initialValue); 2265 localsHandler.updateLocal(local, initialValue);
2264 } else { 2266 } else {
2265 declaration.initializer.accept(this); 2267 declaration.initializer.accept(this);
2266 HInstruction initialValue = pop(); 2268 HInstruction initialValue = pop();
2267 2269
2268 _visitLocalSetter(declaration, initialValue); 2270 _visitLocalSetter(declaration, initialValue);
2269 2271
2270 // Ignore value 2272 // Ignore value
2271 pop(); 2273 pop();
2272 } 2274 }
2273 } 2275 }
2274 2276
2275 void _visitLocalSetter(ir.VariableDeclaration variable, HInstruction value) { 2277 void _visitLocalSetter(ir.VariableDeclaration variable, HInstruction value) {
2276 Local local = localsMap.getLocal(variable); 2278 Local local = localsMap.getLocalVariable(variable);
2277 2279
2278 // Give the value a name if it doesn't have one already. 2280 // Give the value a name if it doesn't have one already.
2279 if (value.sourceElement == null) { 2281 if (value.sourceElement == null) {
2280 value.sourceElement = local; 2282 value.sourceElement = local;
2281 } 2283 }
2282 2284
2283 stack.add(value); 2285 stack.add(value);
2284 localsHandler.updateLocal( 2286 localsHandler.updateLocal(
2285 local, 2287 local,
2286 typeBuilder.potentiallyCheckOrTrustType( 2288 typeBuilder.potentiallyCheckOrTrustType(
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
2937 } else if (selector.isSetter) { 2939 } else if (selector.isSetter) {
2938 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); 2940 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type));
2939 } else { 2941 } else {
2940 push(new HInvokeDynamicMethod( 2942 push(new HInvokeDynamicMethod(
2941 selector, mask, inputs, type, isIntercepted)); 2943 selector, mask, inputs, type, isIntercepted));
2942 } 2944 }
2943 } 2945 }
2944 2946
2945 @override 2947 @override
2946 visitFunctionNode(ir.FunctionNode node) { 2948 visitFunctionNode(ir.FunctionNode node) {
2947 Local methodElement = _elementMap.getLocalFunction(node.parent); 2949 Local methodElement = localsMap.getLocalFunction(node.parent);
2948 ClosureRepresentationInfo closureInfo = 2950 ClosureRepresentationInfo closureInfo =
2949 closureDataLookup.getClosureRepresentationInfo(methodElement); 2951 closureDataLookup.getClosureRepresentationInfo(methodElement);
2950 ClassEntity closureClassEntity = closureInfo.closureClassEntity; 2952 ClassEntity closureClassEntity = closureInfo.closureClassEntity;
2951 2953
2952 List<HInstruction> capturedVariables = <HInstruction>[]; 2954 List<HInstruction> capturedVariables = <HInstruction>[];
2953 closureInfo.createdFieldEntities.forEach((Local capturedLocal) { 2955 closureInfo.createdFieldEntities.forEach((Local capturedLocal) {
2954 assert(capturedLocal != null); 2956 assert(capturedLocal != null);
2955 capturedVariables.add(localsHandler.readLocal(capturedLocal)); 2957 capturedVariables.add(localsHandler.readLocal(capturedLocal));
2956 }); 2958 });
2957 2959
2958 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld); 2960 TypeMask type = new TypeMask.nonNullExact(closureClassEntity, closedWorld);
2959 // TODO(efortuna): Add source information here. 2961 // TODO(efortuna): Add source information here.
2960 push(new HCreate(closureClassEntity, capturedVariables, type, 2962 push(new HCreate(closureClassEntity, capturedVariables, type,
2961 callMethod: closureInfo.callMethod, localFunction: methodElement)); 2963 callMethod: closureInfo.callMethod, localFunction: methodElement));
2962 } 2964 }
2963 2965
2964 @override 2966 @override
2965 visitFunctionDeclaration(ir.FunctionDeclaration declaration) { 2967 visitFunctionDeclaration(ir.FunctionDeclaration declaration) {
2966 assert(isReachable); 2968 assert(isReachable);
2967 declaration.function.accept(this); 2969 declaration.function.accept(this);
2968 Local localFunction = _elementMap.getLocalFunction(declaration); 2970 Local localFunction = localsMap.getLocalFunction(declaration);
2969 localsHandler.updateLocal(localFunction, pop()); 2971 localsHandler.updateLocal(localFunction, pop());
2970 } 2972 }
2971 2973
2972 @override 2974 @override
2973 void visitFunctionExpression(ir.FunctionExpression funcExpression) { 2975 void visitFunctionExpression(ir.FunctionExpression funcExpression) {
2974 funcExpression.function.accept(this); 2976 funcExpression.function.accept(this);
2975 } 2977 }
2976 2978
2977 // TODO(het): Decide when to inline 2979 // TODO(het): Decide when to inline
2978 @override 2980 @override
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 // `guard` is often `dynamic`, which generates `true`. 3493 // `guard` is often `dynamic`, which generates `true`.
3492 kernelBuilder.pushIsTest( 3494 kernelBuilder.pushIsTest(
3493 catchBlock.exception, catchBlock.guard, unwrappedException); 3495 catchBlock.exception, catchBlock.guard, unwrappedException);
3494 } 3496 }
3495 3497
3496 void visitThen() { 3498 void visitThen() {
3497 ir.Catch catchBlock = tryCatch.catches[catchesIndex]; 3499 ir.Catch catchBlock = tryCatch.catches[catchesIndex];
3498 catchesIndex++; 3500 catchesIndex++;
3499 if (catchBlock.exception != null) { 3501 if (catchBlock.exception != null) {
3500 Local exceptionVariable = 3502 Local exceptionVariable =
3501 kernelBuilder.localsMap.getLocal(catchBlock.exception); 3503 kernelBuilder.localsMap.getLocalVariable(catchBlock.exception);
3502 kernelBuilder.localsHandler 3504 kernelBuilder.localsHandler
3503 .updateLocal(exceptionVariable, unwrappedException); 3505 .updateLocal(exceptionVariable, unwrappedException);
3504 } 3506 }
3505 if (catchBlock.stackTrace != null) { 3507 if (catchBlock.stackTrace != null) {
3506 kernelBuilder._pushStaticInvocation( 3508 kernelBuilder._pushStaticInvocation(
3507 kernelBuilder._commonElements.traceFromException, 3509 kernelBuilder._commonElements.traceFromException,
3508 [exception], 3510 [exception],
3509 kernelBuilder._typeInferenceMap.getReturnTypeOf( 3511 kernelBuilder._typeInferenceMap.getReturnTypeOf(
3510 kernelBuilder._commonElements.traceFromException)); 3512 kernelBuilder._commonElements.traceFromException));
3511 HInstruction traceInstruction = kernelBuilder.pop(); 3513 HInstruction traceInstruction = kernelBuilder.pop();
3512 Local traceVariable = 3514 Local traceVariable =
3513 kernelBuilder.localsMap.getLocal(catchBlock.stackTrace); 3515 kernelBuilder.localsMap.getLocalVariable(catchBlock.stackTrace);
3514 kernelBuilder.localsHandler 3516 kernelBuilder.localsHandler
3515 .updateLocal(traceVariable, traceInstruction); 3517 .updateLocal(traceVariable, traceInstruction);
3516 } 3518 }
3517 catchBlock.body.accept(kernelBuilder); 3519 catchBlock.body.accept(kernelBuilder);
3518 } 3520 }
3519 3521
3520 void visitElse() { 3522 void visitElse() {
3521 if (catchesIndex >= tryCatch.catches.length) { 3523 if (catchesIndex >= tryCatch.catches.length) {
3522 kernelBuilder.closeAndGotoExit(new HThrow( 3524 kernelBuilder.closeAndGotoExit(new HThrow(
3523 exception, exception.sourceInformation, 3525 exception, exception.sourceInformation,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3563 enterBlock.setBlockFlow( 3565 enterBlock.setBlockFlow(
3564 new HTryBlockInformation( 3566 new HTryBlockInformation(
3565 kernelBuilder.wrapStatementGraph(bodyGraph), 3567 kernelBuilder.wrapStatementGraph(bodyGraph),
3566 exception, 3568 exception,
3567 kernelBuilder.wrapStatementGraph(catchGraph), 3569 kernelBuilder.wrapStatementGraph(catchGraph),
3568 kernelBuilder.wrapStatementGraph(finallyGraph)), 3570 kernelBuilder.wrapStatementGraph(finallyGraph)),
3569 exitBlock); 3571 exitBlock);
3570 kernelBuilder.inTryStatement = previouslyInTryStatement; 3572 kernelBuilder.inTryStatement = previouslyInTryStatement;
3571 } 3573 }
3572 } 3574 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map_impl.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698