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

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

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 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 part of ssa; 5 part of ssa;
6 6
7 /// A synthetic local variable only used with the SSA graph. 7 /// A synthetic local variable only used with the SSA graph.
8 /// 8 ///
9 /// For instance used for holding return value of function or the exception of a 9 /// For instance used for holding return value of function or the exception of a
10 /// try-catch statement. 10 /// try-catch statement.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } else { 52 } else {
53 compiler.internalError(element, 'Unexpected element kind $kind.'); 53 compiler.internalError(element, 'Unexpected element kind $kind.');
54 } 54 }
55 assert(graph.isValid()); 55 assert(graph.isValid());
56 if (!identical(kind, ElementKind.FIELD)) { 56 if (!identical(kind, ElementKind.FIELD)) {
57 FunctionElement function = element; 57 FunctionElement function = element;
58 FunctionSignature signature = function.functionSignature; 58 FunctionSignature signature = function.functionSignature;
59 signature.forEachOptionalParameter((ParameterElement parameter) { 59 signature.forEachOptionalParameter((ParameterElement parameter) {
60 // This ensures the default value will be computed. 60 // This ensures the default value will be computed.
61 Constant constant = 61 Constant constant =
62 backend.constants.getConstantForVariable(parameter); 62 backend.constants.getConstantForVariable(parameter).value;
63 CodegenRegistry registry = work.registry; 63 CodegenRegistry registry = work.registry;
64 registry.registerCompileTimeConstant(constant); 64 registry.registerCompileTimeConstant(constant);
65 }); 65 });
66 } 66 }
67 if (compiler.tracer.isEnabled) { 67 if (compiler.tracer.isEnabled) {
68 String name; 68 String name;
69 if (element.isClassMember) { 69 if (element.isClassMember) {
70 String className = element.enclosingClass.name; 70 String className = element.enclosingClass.name;
71 String memberName = element.name; 71 String memberName = element.name;
72 name = "$className.$memberName"; 72 name = "$className.$memberName";
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 return compiler.withCurrentElement(element, () { 1339 return compiler.withCurrentElement(element, () {
1340 // The [sourceElementStack] contains declaration elements. 1340 // The [sourceElementStack] contains declaration elements.
1341 sourceElementStack.add(element.declaration); 1341 sourceElementStack.add(element.declaration);
1342 var result = f(); 1342 var result = f();
1343 sourceElementStack.removeLast(); 1343 sourceElementStack.removeLast();
1344 return result; 1344 return result;
1345 }); 1345 });
1346 } 1346 }
1347 1347
1348 HInstruction handleConstantForOptionalParameter(Element parameter) { 1348 HInstruction handleConstantForOptionalParameter(Element parameter) {
1349 Constant constant = 1349 ConstExp constant =
1350 backend.constants.getConstantForVariable(parameter); 1350 backend.constants.getConstantForVariable(parameter);
1351 assert(invariant(parameter, constant != null, 1351 assert(invariant(parameter, constant != null,
1352 message: 'No constant computed for $parameter')); 1352 message: 'No constant computed for $parameter'));
1353 return graph.addConstant(constant, compiler); 1353 return graph.addConstant(constant.value, compiler);
1354 } 1354 }
1355 1355
1356 Element get currentNonClosureClass { 1356 Element get currentNonClosureClass {
1357 ClassElement cls = sourceElement.enclosingClass; 1357 ClassElement cls = sourceElement.enclosingClass;
1358 if (cls != null && cls.isClosure) { 1358 if (cls != null && cls.isClosure) {
1359 var closureClass = cls; 1359 var closureClass = cls;
1360 return closureClass.methodElement.enclosingClass; 1360 return closureClass.methodElement.enclosingClass;
1361 } else { 1361 } else {
1362 return cls; 1362 return cls;
1363 } 1363 }
(...skipping 15 matching lines...) Expand all
1379 final List<DartType> currentInlinedInstantiations = <DartType>[]; 1379 final List<DartType> currentInlinedInstantiations = <DartType>[];
1380 1380
1381 final List<AstInliningState> inliningStack = <AstInliningState>[]; 1381 final List<AstInliningState> inliningStack = <AstInliningState>[];
1382 1382
1383 Local returnLocal; 1383 Local returnLocal;
1384 DartType returnType; 1384 DartType returnType;
1385 1385
1386 bool inTryStatement = false; 1386 bool inTryStatement = false;
1387 1387
1388 Constant getConstantForNode(ast.Node node) { 1388 Constant getConstantForNode(ast.Node node) {
1389 Constant constant = 1389 ConstExp constant =
1390 backend.constants.getConstantForNode(node, elements); 1390 backend.constants.getConstantForNode(node, elements);
1391 assert(invariant(node, constant != null, 1391 assert(invariant(node, constant != null,
1392 message: 'No constant computed for $node')); 1392 message: 'No constant computed for $node'));
1393 return constant; 1393 return constant.value;
1394 } 1394 }
1395 1395
1396 HInstruction addConstant(ast.Node node) { 1396 HInstruction addConstant(ast.Node node) {
1397 return graph.addConstant(getConstantForNode(node), compiler); 1397 return graph.addConstant(getConstantForNode(node), compiler);
1398 } 1398 }
1399 1399
1400 bool isLazilyInitialized(VariableElement element) { 1400 bool isLazilyInitialized(VariableElement element) {
1401 Constant initialValue = 1401 ConstExp initialValue =
1402 backend.constants.getConstantForVariable(element); 1402 backend.constants.getConstantForVariable(element);
1403 return initialValue == null; 1403 return initialValue == null;
1404 } 1404 }
1405 1405
1406 TypeMask cachedTypeOfThis; 1406 TypeMask cachedTypeOfThis;
1407 1407
1408 TypeMask getTypeOfThis() { 1408 TypeMask getTypeOfThis() {
1409 TypeMask result = cachedTypeOfThis; 1409 TypeMask result = cachedTypeOfThis;
1410 if (result == null) { 1410 if (result == null) {
1411 ThisLocal local = localsHandler.closureData.thisLocal; 1411 ThisLocal local = localsHandler.closureData.thisLocal;
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 Element helper = backend.getCheckDeferredIsLoaded(); 3066 Element helper = backend.getCheckDeferredIsLoaded();
3067 pushInvokeStatic(node, helper, [loadIdConstant, uriConstant]); 3067 pushInvokeStatic(node, helper, [loadIdConstant, uriConstant]);
3068 pop(); 3068 pop();
3069 } 3069 }
3070 } 3070 }
3071 3071
3072 void generateGetter(ast.Send send, Element element) { 3072 void generateGetter(ast.Send send, Element element) {
3073 if (element != null && element.isForeign(backend)) { 3073 if (element != null && element.isForeign(backend)) {
3074 visitForeignGetter(send); 3074 visitForeignGetter(send);
3075 } else if (Elements.isStaticOrTopLevelField(element)) { 3075 } else if (Elements.isStaticOrTopLevelField(element)) {
3076 Constant value; 3076 ConstExp constant;
3077 if (element.isField && !element.isAssignable) { 3077 if (element.isField && !element.isAssignable) {
3078 // A static final or const. Get its constant value and inline it if 3078 // A static final or const. Get its constant value and inline it if
3079 // the value can be compiled eagerly. 3079 // the value can be compiled eagerly.
3080 value = backend.constants.getConstantForVariable(element); 3080 constant = backend.constants.getConstantForVariable(element);
3081 } 3081 }
3082 if (value != null) { 3082 if (constant != null) {
3083 Constant value = constant.value;
3083 HConstant instruction; 3084 HConstant instruction;
3084 // Constants that are referred via a deferred prefix should be referred 3085 // Constants that are referred via a deferred prefix should be referred
3085 // by reference. 3086 // by reference.
3086 PrefixElement prefix = compiler.deferredLoadTask 3087 PrefixElement prefix = compiler.deferredLoadTask
3087 .deferredPrefixElement(send, elements); 3088 .deferredPrefixElement(send, elements);
3088 if (prefix != null) { 3089 if (prefix != null) {
3089 instruction = graph.addDeferredConstant(value, prefix, compiler); 3090 instruction = graph.addDeferredConstant(value, prefix, compiler);
3090 } else { 3091 } else {
3091 instruction = graph.addConstant(value, compiler); 3092 instruction = graph.addConstant(value, compiler);
3092 } 3093 }
(...skipping 3440 matching lines...) Expand 10 before | Expand all | Expand 10 after
6533 if (unaliased is TypedefType) throw 'unable to unalias $type'; 6534 if (unaliased is TypedefType) throw 'unable to unalias $type';
6534 unaliased.accept(this, builder); 6535 unaliased.accept(this, builder);
6535 } 6536 }
6536 6537
6537 void visitDynamicType(DynamicType type, SsaBuilder builder) { 6538 void visitDynamicType(DynamicType type, SsaBuilder builder) {
6538 JavaScriptBackend backend = builder.compiler.backend; 6539 JavaScriptBackend backend = builder.compiler.backend;
6539 ClassElement cls = backend.findHelper('DynamicRuntimeType'); 6540 ClassElement cls = backend.findHelper('DynamicRuntimeType');
6540 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld))); 6541 builder.push(new HDynamicType(type, new TypeMask.exact(cls, classWorld)));
6541 } 6542 }
6542 } 6543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698