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

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

Issue 221873002: Compute frontend/backend specific constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes Created 6 years, 8 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 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 implement [TypedElement.type] because our 9 * methods. We need to implement [TypedElement.type] because our
10 * optimizers may look at its declared type. 10 * optimizers may look at its declared type.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } else { 56 } else {
57 compiler.internalError(element, 'Unexpected element kind $kind.'); 57 compiler.internalError(element, 'Unexpected element kind $kind.');
58 } 58 }
59 assert(graph.isValid()); 59 assert(graph.isValid());
60 if (!identical(kind, ElementKind.FIELD)) { 60 if (!identical(kind, ElementKind.FIELD)) {
61 FunctionElement function = element; 61 FunctionElement function = element;
62 FunctionSignature signature = function.functionSignature; 62 FunctionSignature signature = function.functionSignature;
63 signature.forEachOptionalParameter((Element parameter) { 63 signature.forEachOptionalParameter((Element parameter) {
64 // This ensures the default value will be computed. 64 // This ensures the default value will be computed.
65 Constant constant = 65 Constant constant =
66 compiler.constantHandler.getConstantForVariable(parameter); 66 backend.constants.getConstantForVariable(parameter);
67 backend.registerCompileTimeConstant(constant, work.resolutionTree); 67 backend.registerCompileTimeConstant(constant, work.resolutionTree);
68 compiler.constantHandler.addCompileTimeConstantForEmission( 68 backend.constants.addCompileTimeConstantForEmission(constant);
69 constant);
70 }); 69 });
71 } 70 }
72 if (compiler.tracer.enabled) { 71 if (compiler.tracer.enabled) {
73 String name; 72 String name;
74 if (element.isMember()) { 73 if (element.isMember()) {
75 String className = element.getEnclosingClass().name; 74 String className = element.getEnclosingClass().name;
76 String memberName = element.name; 75 String memberName = element.name;
77 name = "$className.$memberName"; 76 name = "$className.$memberName";
78 if (element.isGenerativeConstructorBody()) { 77 if (element.isGenerativeConstructorBody()) {
79 name = "$name (body)"; 78 name = "$name (body)";
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 // The [sourceElementStack] contains declaration elements. 1302 // The [sourceElementStack] contains declaration elements.
1304 sourceElementStack.add(element.declaration); 1303 sourceElementStack.add(element.declaration);
1305 var result = f(); 1304 var result = f();
1306 sourceElementStack.removeLast(); 1305 sourceElementStack.removeLast();
1307 return result; 1306 return result;
1308 }); 1307 });
1309 } 1308 }
1310 1309
1311 HInstruction handleConstantForOptionalParameter(Element parameter) { 1310 HInstruction handleConstantForOptionalParameter(Element parameter) {
1312 Constant constant = 1311 Constant constant =
1313 compiler.constantHandler.getConstantForVariable(parameter); 1312 backend.constants.getConstantForVariable(parameter);
1314 assert(invariant(parameter, constant != null, 1313 assert(invariant(parameter, constant != null,
1315 message: 'No constant computed for $parameter')); 1314 message: 'No constant computed for $parameter'));
1316 return graph.addConstant(constant, compiler); 1315 return graph.addConstant(constant, compiler);
1317 } 1316 }
1318 1317
1319 Element get currentNonClosureClass { 1318 Element get currentNonClosureClass {
1320 ClassElement cls = sourceElement.getEnclosingClass(); 1319 ClassElement cls = sourceElement.getEnclosingClass();
1321 if (cls != null && cls.isClosure()) { 1320 if (cls != null && cls.isClosure()) {
1322 var closureClass = cls; 1321 var closureClass = cls;
1323 return closureClass.methodElement.getEnclosingClass(); 1322 return closureClass.methodElement.getEnclosingClass();
(...skipping 18 matching lines...) Expand all
1342 final List<DartType> currentInlinedInstantiations = <DartType>[]; 1341 final List<DartType> currentInlinedInstantiations = <DartType>[];
1343 1342
1344 final List<AstInliningState> inliningStack = <AstInliningState>[]; 1343 final List<AstInliningState> inliningStack = <AstInliningState>[];
1345 1344
1346 Element returnElement; 1345 Element returnElement;
1347 DartType returnType; 1346 DartType returnType;
1348 1347
1349 bool inTryStatement = false; 1348 bool inTryStatement = false;
1350 1349
1351 Constant getConstantForNode(ast.Node node) { 1350 Constant getConstantForNode(ast.Node node) {
1352 Constant constant = elements.getConstant(node); 1351 Constant constant =
1352 backend.constants.getConstantForNode(node, elements);
1353 assert(invariant(node, constant != null, 1353 assert(invariant(node, constant != null,
1354 message: 'No constant computed for $node')); 1354 message: 'No constant computed for $node'));
1355 return constant; 1355 return constant;
1356 } 1356 }
1357 1357
1358 HInstruction addConstant(ast.Node node) { 1358 HInstruction addConstant(ast.Node node) {
1359 return graph.addConstant(getConstantForNode(node), compiler); 1359 return graph.addConstant(getConstantForNode(node), compiler);
1360 } 1360 }
1361 1361
1362 bool isLazilyInitialized(VariableElement element) { 1362 bool isLazilyInitialized(VariableElement element) {
1363 Constant initialValue = 1363 Constant initialValue =
1364 compiler.constantHandler.getConstantForVariable(element); 1364 backend.constants.getConstantForVariable(element);
1365 return initialValue == null; 1365 return initialValue == null;
1366 } 1366 }
1367 1367
1368 TypeMask cachedTypeOfThis; 1368 TypeMask cachedTypeOfThis;
1369 1369
1370 TypeMask getTypeOfThis() { 1370 TypeMask getTypeOfThis() {
1371 TypeMask result = cachedTypeOfThis; 1371 TypeMask result = cachedTypeOfThis;
1372 if (result == null) { 1372 if (result == null) {
1373 Element element = localsHandler.closureData.thisElement; 1373 Element element = localsHandler.closureData.thisElement;
1374 ClassElement cls = element.enclosingElement.getEnclosingClass(); 1374 ClassElement cls = element.enclosingElement.getEnclosingClass();
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 } 2930 }
2931 2931
2932 void generateGetter(ast.Send send, Element element) { 2932 void generateGetter(ast.Send send, Element element) {
2933 if (element != null && element.isForeign(compiler)) { 2933 if (element != null && element.isForeign(compiler)) {
2934 visitForeignGetter(send); 2934 visitForeignGetter(send);
2935 } else if (Elements.isStaticOrTopLevelField(element)) { 2935 } else if (Elements.isStaticOrTopLevelField(element)) {
2936 Constant value; 2936 Constant value;
2937 if (element.isField() && !element.isAssignable()) { 2937 if (element.isField() && !element.isAssignable()) {
2938 // A static final or const. Get its constant value and inline it if 2938 // A static final or const. Get its constant value and inline it if
2939 // the value can be compiled eagerly. 2939 // the value can be compiled eagerly.
2940 value = compiler.constantHandler.getConstantForVariable(element); 2940 value = backend.constants.getConstantForVariable(element);
2941 } 2941 }
2942 if (value != null) { 2942 if (value != null) {
2943 HConstant instruction = graph.addConstant(value, compiler); 2943 HConstant instruction = graph.addConstant(value, compiler);
2944 stack.add(instruction); 2944 stack.add(instruction);
2945 // The inferrer may have found a better type than the constant 2945 // The inferrer may have found a better type than the constant
2946 // handler in the case of lists, because the constant handler 2946 // handler in the case of lists, because the constant handler
2947 // does not look at elements in the list. 2947 // does not look at elements in the list.
2948 TypeMask type = 2948 TypeMask type =
2949 TypeMaskFactory.inferredTypeForElement(element, compiler); 2949 TypeMaskFactory.inferredTypeForElement(element, compiler);
2950 if (!type.containsAll(compiler) && !instruction.isConstantNull()) { 2950 if (!type.containsAll(compiler) && !instruction.isConstantNull()) {
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
4334 generateThrowNoSuchMethod(node.send, 4334 generateThrowNoSuchMethod(node.send,
4335 getTargetName(error, 'constructor'), 4335 getTargetName(error, 'constructor'),
4336 argumentNodes: node.send.arguments); 4336 argumentNodes: node.send.arguments);
4337 } else { 4337 } else {
4338 Message message = error.messageKind.message(error.messageArguments); 4338 Message message = error.messageKind.message(error.messageArguments);
4339 generateRuntimeError(node.send, message.toString()); 4339 generateRuntimeError(node.send, message.toString());
4340 } 4340 }
4341 } else if (node.isConst()) { 4341 } else if (node.isConst()) {
4342 stack.add(addConstant(node)); 4342 stack.add(addConstant(node));
4343 if (isSymbolConstructor) { 4343 if (isSymbolConstructor) {
4344 ConstructedConstant symbol = elements.getConstant(node); 4344 ConstructedConstant symbol = getConstantForNode(node);
4345 StringConstant stringConstant = symbol.fields.single; 4345 StringConstant stringConstant = symbol.fields.single;
4346 String nameString = stringConstant.toDartString().slowToString(); 4346 String nameString = stringConstant.toDartString().slowToString();
4347 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements); 4347 compiler.enqueuer.codegen.registerConstSymbol(nameString, elements);
4348 } 4348 }
4349 } else { 4349 } else {
4350 handleNewSend(node); 4350 handleNewSend(node);
4351 } 4351 }
4352 } 4352 }
4353 4353
4354 void pushInvokeDynamic(ast.Node node, 4354 void pushInvokeDynamic(ast.Node node,
(...skipping 1861 matching lines...) Expand 10 before | Expand all | Expand 10 after
6216 DartType unaliased = type.unalias(builder.compiler); 6216 DartType unaliased = type.unalias(builder.compiler);
6217 if (unaliased is TypedefType) throw 'unable to unalias $type'; 6217 if (unaliased is TypedefType) throw 'unable to unalias $type';
6218 unaliased.accept(this, builder); 6218 unaliased.accept(this, builder);
6219 } 6219 }
6220 6220
6221 void visitDynamicType(DynamicType type, SsaBuilder builder) { 6221 void visitDynamicType(DynamicType type, SsaBuilder builder) {
6222 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType'); 6222 ClassElement cls = builder.compiler.findHelper('DynamicRuntimeType');
6223 builder.push(new HDynamicType(type, new TypeMask.exact(cls))); 6223 builder.push(new HDynamicType(type, new TypeMask.exact(cls)));
6224 } 6224 }
6225 } 6225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698