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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 221873002: Compute frontend/backend specific constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Classes renamed and comments added. 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 js_backend; 5 part of js_backend;
6 6
7 const VERBOSE_OPTIMIZER_HINTS = false; 7 const VERBOSE_OPTIMIZER_HINTS = false;
8 8
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { 9 class JavaScriptItemCompilationContext extends ItemCompilationContext {
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // If we can't inline a function inside a loop, then we should not inline 45 // If we can't inline a function inside a loop, then we should not inline
46 // it outside a loop either. 46 // it outside a loop either.
47 canBeInlined[element] = false; 47 canBeInlined[element] = false;
48 canBeInlinedInsideLoop[element] = false; 48 canBeInlinedInsideLoop[element] = false;
49 } else { 49 } else {
50 canBeInlined[element] = false; 50 canBeInlined[element] = false;
51 } 51 }
52 } 52 }
53 } 53 }
54 54
55
56 class JavaScriptBackend extends Backend { 55 class JavaScriptBackend extends Backend {
57 SsaBuilderTask builder; 56 SsaBuilderTask builder;
58 SsaOptimizerTask optimizer; 57 SsaOptimizerTask optimizer;
59 SsaCodeGeneratorTask generator; 58 SsaCodeGeneratorTask generator;
60 CodeEmitterTask emitter; 59 CodeEmitterTask emitter;
61 60
62 /** 61 /**
63 * The generated code as a js AST for compiled methods. 62 * The generated code as a js AST for compiled methods.
64 */ 63 */
65 Map<Element, jsAst.Expression> get generatedCode { 64 Map<Element, jsAst.Expression> get generatedCode {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 280
282 TypeVariableHandler typeVariableHandler; 281 TypeVariableHandler typeVariableHandler;
283 282
284 /// Number of methods compiled before considering reflection. 283 /// Number of methods compiled before considering reflection.
285 int preMirrorsMethodCount = 0; 284 int preMirrorsMethodCount = 0;
286 285
287 /// Resolution and codegen support for generating table of interceptors and 286 /// Resolution and codegen support for generating table of interceptors and
288 /// constructors for custom elements. 287 /// constructors for custom elements.
289 CustomElementsAnalysis customElementsAnalysis; 288 CustomElementsAnalysis customElementsAnalysis;
290 289
290 JavaScriptConstantTask constantCompilerTask;
291
291 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 292 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
292 : namer = determineNamer(compiler), 293 : namer = determineNamer(compiler),
293 oneShotInterceptors = new Map<String, Selector>(), 294 oneShotInterceptors = new Map<String, Selector>(),
294 interceptedElements = new Map<String, Set<Element>>(), 295 interceptedElements = new Map<String, Set<Element>>(),
295 rti = new RuntimeTypes(compiler), 296 rti = new RuntimeTypes(compiler),
296 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 297 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
297 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { 298 super(compiler) {
298 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); 299 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap);
299 builder = new SsaBuilderTask(this); 300 builder = new SsaBuilderTask(this);
300 optimizer = new SsaOptimizerTask(this); 301 optimizer = new SsaOptimizerTask(this);
301 generator = new SsaCodeGeneratorTask(this); 302 generator = new SsaCodeGeneratorTask(this);
302 typeVariableHandler = new TypeVariableHandler(this); 303 typeVariableHandler = new TypeVariableHandler(this);
303 customElementsAnalysis = new CustomElementsAnalysis(this); 304 customElementsAnalysis = new CustomElementsAnalysis(this);
305 constantCompilerTask = new JavaScriptConstantTask(compiler);
306 }
307
308 ConstantSystem get constantSystem => constants.constantSystem;
309
310 JavaScriptConstantCompiler get constants {
floitsch 2014/04/07 12:21:42 Add comment that these are now the JS constants.
Johnni Winther 2014/04/08 07:09:56 Done.
311 return constantCompilerTask.jsConstantCompiler;
304 } 312 }
305 313
306 static Namer determineNamer(Compiler compiler) { 314 static Namer determineNamer(Compiler compiler) {
307 return compiler.enableMinification ? 315 return compiler.enableMinification ?
308 new MinifyNamer(compiler) : 316 new MinifyNamer(compiler) :
309 new Namer(compiler); 317 new Namer(compiler);
310 } 318 }
311 319
312 bool usedByBackend(Element element) { 320 bool usedByBackend(Element element) {
313 if (element.isParameter() 321 if (element.isParameter()
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 1143
1136 void codegen(CodegenWorkItem work) { 1144 void codegen(CodegenWorkItem work) {
1137 Element element = work.element; 1145 Element element = work.element;
1138 var kind = element.kind; 1146 var kind = element.kind;
1139 if (kind == ElementKind.TYPEDEF) return; 1147 if (kind == ElementKind.TYPEDEF) return;
1140 if (element.isConstructor() && element.getEnclosingClass() == jsNullClass) { 1148 if (element.isConstructor() && element.getEnclosingClass() == jsNullClass) {
1141 // Work around a problem compiling JSNull's constructor. 1149 // Work around a problem compiling JSNull's constructor.
1142 return; 1150 return;
1143 } 1151 }
1144 if (kind.category == ElementCategory.VARIABLE) { 1152 if (kind.category == ElementCategory.VARIABLE) {
1145 Constant initialValue = 1153 Constant initialValue = constants.getConstantForVariable(element);
1146 compiler.constantHandler.getConstantForVariable(element);
1147 if (initialValue != null) { 1154 if (initialValue != null) {
1148 registerCompileTimeConstant(initialValue, work.resolutionTree); 1155 registerCompileTimeConstant(initialValue, work.resolutionTree);
1149 compiler.constantHandler.addCompileTimeConstantForEmission( 1156 constants.addCompileTimeConstantForEmission(initialValue);
1150 initialValue);
1151 // We don't need to generate code for static or top-level 1157 // We don't need to generate code for static or top-level
1152 // variables. For instance variables, we may need to generate 1158 // variables. For instance variables, we may need to generate
1153 // the checked setter. 1159 // the checked setter.
1154 if (Elements.isStaticOrTopLevel(element)) return; 1160 if (Elements.isStaticOrTopLevel(element)) return;
1155 } else { 1161 } else {
1156 // If the constant-handler was not able to produce a result we have to 1162 // If the constant-handler was not able to produce a result we have to
1157 // go through the builder (below) to generate the lazy initializer for 1163 // go through the builder (below) to generate the lazy initializer for
1158 // the static variable. 1164 // the static variable.
1159 // We also need to register the use of the cyclic-error helper. 1165 // We also need to register the use of the cyclic-error helper.
1160 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper()); 1166 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper());
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 return symbolsUsed.contains(name); 1606 return symbolsUsed.contains(name);
1601 } 1607 }
1602 1608
1603 bool get rememberLazies => isTreeShakingDisabled; 1609 bool get rememberLazies => isTreeShakingDisabled;
1604 1610
1605 bool retainMetadataOf(Element element) { 1611 bool retainMetadataOf(Element element) {
1606 if (mustRetainMetadata) hasRetainedMetadata = true; 1612 if (mustRetainMetadata) hasRetainedMetadata = true;
1607 if (mustRetainMetadata && isNeededForReflection(element)) { 1613 if (mustRetainMetadata && isNeededForReflection(element)) {
1608 for (MetadataAnnotation metadata in element.metadata) { 1614 for (MetadataAnnotation metadata in element.metadata) {
1609 metadata.ensureResolved(compiler); 1615 metadata.ensureResolved(compiler);
1610 compiler.constantHandler.addCompileTimeConstantForEmission( 1616 Constant constant = constants.getConstantForMetadata(metadata);
1611 metadata.value); 1617 constants.addCompileTimeConstantForEmission(constant);
1612 } 1618 }
1613 return true; 1619 return true;
1614 } 1620 }
1615 return false; 1621 return false;
1616 } 1622 }
1617 1623
1618 Future onLibraryLoaded(LibraryElement library, Uri uri) { 1624 Future onLibraryLoaded(LibraryElement library, Uri uri) {
1619 if (uri == Uri.parse('dart:_js_mirrors')) { 1625 if (uri == Uri.parse('dart:_js_mirrors')) {
1620 disableTreeShakingMarker = 1626 disableTreeShakingMarker =
1621 library.find('disableTreeShaking'); 1627 library.find('disableTreeShaking');
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 } 1885 }
1880 } 1886 }
1881 1887
1882 /// Records that [constant] is used by [user.element]. 1888 /// Records that [constant] is used by [user.element].
1883 class Dependency { 1889 class Dependency {
1884 final Constant constant; 1890 final Constant constant;
1885 final TreeElements user; 1891 final TreeElements user;
1886 1892
1887 const Dependency(this.constant, this.user); 1893 const Dependency(this.constant, this.user);
1888 } 1894 }
1889
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698