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

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

Issue 2575083002: Pass ClosedWorld directly to codegen tasks (Closed)
Patch Set: Updated cf. comment. Created 4 years 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) 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 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import '../common.dart'; 6 import '../common.dart';
7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
8 import '../common/tasks.dart' show CompilerTask; 8 import '../common/tasks.dart' show CompilerTask;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constant_system.dart'; 10 import '../constants/constant_system.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 : (element.asyncMarker.isYielding 52 : (element.asyncMarker.isYielding
53 ? const js.AsyncModifier.syncStar() 53 ? const js.AsyncModifier.syncStar()
54 : const js.AsyncModifier.sync()); 54 : const js.AsyncModifier.sync());
55 55
56 return new js.Fun(parameters, body, asyncModifier: asyncModifier) 56 return new js.Fun(parameters, body, asyncModifier: asyncModifier)
57 .withSourceInformation(sourceInformationFactory 57 .withSourceInformation(sourceInformationFactory
58 .createBuilderForContext(resolvedAst) 58 .createBuilderForContext(resolvedAst)
59 .buildDeclaration(resolvedAst)); 59 .buildDeclaration(resolvedAst));
60 } 60 }
61 61
62 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { 62 js.Expression generateCode(
63 CodegenWorkItem work, HGraph graph, ClosedWorld closedWorld) {
63 if (work.element.isField) { 64 if (work.element.isField) {
64 return generateLazyInitializer(work, graph); 65 return generateLazyInitializer(work, graph, closedWorld);
65 } else { 66 } else {
66 return generateMethod(work, graph); 67 return generateMethod(work, graph, closedWorld);
67 } 68 }
68 } 69 }
69 70
70 js.Expression generateLazyInitializer(CodegenWorkItem work, HGraph graph) { 71 js.Expression generateLazyInitializer(
72 CodegenWorkItem work, HGraph graph, ClosedWorld closedWorld) {
71 return measure(() { 73 return measure(() {
72 compiler.tracer.traceGraph("codegen", graph); 74 backend.tracer.traceGraph("codegen", graph);
73 SourceInformation sourceInformation = sourceInformationFactory 75 SourceInformation sourceInformation = sourceInformationFactory
74 .createBuilderForContext(work.resolvedAst) 76 .createBuilderForContext(work.resolvedAst)
75 .buildDeclaration(work.resolvedAst); 77 .buildDeclaration(work.resolvedAst);
76 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); 78 SsaCodeGenerator codegen =
79 new SsaCodeGenerator(backend, closedWorld, work);
77 codegen.visitGraph(graph); 80 codegen.visitGraph(graph);
78 return new js.Fun(codegen.parameters, codegen.body) 81 return new js.Fun(codegen.parameters, codegen.body)
79 .withSourceInformation(sourceInformation); 82 .withSourceInformation(sourceInformation);
80 }); 83 });
81 } 84 }
82 85
83 js.Expression generateMethod(CodegenWorkItem work, HGraph graph) { 86 js.Expression generateMethod(
87 CodegenWorkItem work, HGraph graph, ClosedWorld closedWorld) {
84 return measure(() { 88 return measure(() {
85 FunctionElement element = work.element; 89 FunctionElement element = work.element;
86 if (element.asyncMarker != AsyncMarker.SYNC) { 90 if (element.asyncMarker != AsyncMarker.SYNC) {
87 work.registry.registerAsyncMarker(element); 91 work.registry.registerAsyncMarker(element);
88 } 92 }
89 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); 93 SsaCodeGenerator codegen =
94 new SsaCodeGenerator(backend, closedWorld, work);
90 codegen.visitGraph(graph); 95 codegen.visitGraph(graph);
91 compiler.tracer.traceGraph("codegen", graph); 96 backend.tracer.traceGraph("codegen", graph);
92 return buildJavaScriptFunction( 97 return buildJavaScriptFunction(
93 work.resolvedAst, codegen.parameters, codegen.body); 98 work.resolvedAst, codegen.parameters, codegen.body);
94 }); 99 });
95 } 100 }
96 } 101 }
97 102
98 typedef void EntityAction(Entity element); 103 typedef void EntityAction(Entity element);
99 104
100 class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { 105 class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
101 /** 106 /**
(...skipping 12 matching lines...) Expand all
114 static const int TYPE_EXPRESSION = 1; 119 static const int TYPE_EXPRESSION = 1;
115 static const int TYPE_DECLARATION = 2; 120 static const int TYPE_DECLARATION = 2;
116 121
117 /** 122 /**
118 * Whether we are currently generating expressions instead of statements. 123 * Whether we are currently generating expressions instead of statements.
119 * This includes declarations, which are generated as expressions. 124 * This includes declarations, which are generated as expressions.
120 */ 125 */
121 bool isGeneratingExpression = false; 126 bool isGeneratingExpression = false;
122 127
123 final JavaScriptBackend backend; 128 final JavaScriptBackend backend;
129 final ClosedWorld closedWorld;
124 final CodegenWorkItem work; 130 final CodegenWorkItem work;
125 131
126 final Set<HInstruction> generateAtUseSite; 132 final Set<HInstruction> generateAtUseSite;
127 final Set<HInstruction> controlFlowOperators; 133 final Set<HInstruction> controlFlowOperators;
128 final Map<Entity, EntityAction> breakAction; 134 final Map<Entity, EntityAction> breakAction;
129 final Map<Entity, EntityAction> continueAction; 135 final Map<Entity, EntityAction> continueAction;
130 final List<js.Parameter> parameters; 136 final List<js.Parameter> parameters;
131 137
132 js.Block currentContainer; 138 js.Block currentContainer;
133 js.Block get body => currentContainer; 139 js.Block get body => currentContainer;
(...skipping 22 matching lines...) Expand all
156 162
157 HGraph currentGraph; 163 HGraph currentGraph;
158 164
159 // Records a block-information that is being handled specially. 165 // Records a block-information that is being handled specially.
160 // Used to break bad recursion. 166 // Used to break bad recursion.
161 HBlockInformation currentBlockInformation; 167 HBlockInformation currentBlockInformation;
162 // The subgraph is used to delimit traversal for some constructions, e.g., 168 // The subgraph is used to delimit traversal for some constructions, e.g.,
163 // if branches. 169 // if branches.
164 SubGraph subGraph; 170 SubGraph subGraph;
165 171
166 SsaCodeGenerator(this.backend, CodegenWorkItem work, 172 SsaCodeGenerator(this.backend, this.closedWorld, CodegenWorkItem work,
167 {SourceInformation sourceInformation}) 173 {SourceInformation sourceInformation})
168 : this.work = work, 174 : this.work = work,
169 declaredLocals = new Set<String>(), 175 declaredLocals = new Set<String>(),
170 collectedVariableDeclarations = new Set<String>(), 176 collectedVariableDeclarations = new Set<String>(),
171 currentContainer = new js.Block.empty(), 177 currentContainer = new js.Block.empty(),
172 parameters = <js.Parameter>[], 178 parameters = <js.Parameter>[],
173 expressionStack = <js.Expression>[], 179 expressionStack = <js.Expression>[],
174 oldContainerStack = <js.Block>[], 180 oldContainerStack = <js.Block>[],
175 generateAtUseSite = new Set<HInstruction>(), 181 generateAtUseSite = new Set<HInstruction>(),
176 controlFlowOperators = new Set<HInstruction>(), 182 controlFlowOperators = new Set<HInstruction>(),
177 breakAction = new Map<Entity, EntityAction>(), 183 breakAction = new Map<Entity, EntityAction>(),
178 continueAction = new Map<Entity, EntityAction>(); 184 continueAction = new Map<Entity, EntityAction>();
179 185
180 Compiler get compiler => backend.compiler; 186 Compiler get compiler => backend.compiler;
181 187
182 ClosedWorld get closedWorld => compiler.closedWorld;
183
184 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; 188 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter;
185 189
186 CodegenRegistry get registry => work.registry; 190 CodegenRegistry get registry => work.registry;
187 191
188 BackendHelpers get helpers => backend.helpers; 192 BackendHelpers get helpers => backend.helpers;
189 193
190 native.NativeEnqueuer get nativeEnqueuer { 194 native.NativeEnqueuer get nativeEnqueuer {
191 return compiler.enqueuer.codegen.nativeEnqueuer; 195 return compiler.enqueuer.codegen.nativeEnqueuer;
192 } 196 }
193 197
(...skipping 2900 matching lines...) Expand 10 before | Expand all | Expand 10 after
3094 registry.registerStaticUse(new StaticUse.staticInvoke( 3098 registry.registerStaticUse(new StaticUse.staticInvoke(
3095 helper, new CallStructure.unnamed(argumentCount))); 3099 helper, new CallStructure.unnamed(argumentCount)));
3096 return backend.emitter.staticFunctionAccess(helper); 3100 return backend.emitter.staticFunctionAccess(helper);
3097 } 3101 }
3098 3102
3099 @override 3103 @override
3100 void visitRef(HRef node) { 3104 void visitRef(HRef node) {
3101 visit(node.value); 3105 visit(node.value);
3102 } 3106 }
3103 } 3107 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder_kernel.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698