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

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

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

Powered by Google App Engine
This is Rietveld 408576698