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

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

Issue 1251083002: dart2js cps: Avoid deep recursion using trampolines and basic blocks. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Rebase Created 5 years, 5 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
OLDNEW
1 library dart2js.unsugar_cps; 1 library dart2js.unsugar_cps;
2 2
3 import '../../cps_ir/cps_ir_nodes.dart'; 3 import '../../cps_ir/cps_ir_nodes.dart';
4 4
5 import '../../cps_ir/optimizers.dart' show ParentVisitor; 5 import '../../cps_ir/optimizers.dart' show ParentVisitor;
6 import '../../constants/values.dart'; 6 import '../../constants/values.dart';
7 import '../../elements/elements.dart'; 7 import '../../elements/elements.dart';
8 import '../../io/source_information.dart'; 8 import '../../io/source_information.dart';
9 import '../../js_backend/codegen/glue.dart'; 9 import '../../js_backend/codegen/glue.dart';
10 import '../../dart2jslib.dart' show Selector, World; 10 import '../../dart2jslib.dart' show Selector, World;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Set all parent pointers. 75 // Set all parent pointers.
76 _parentVisitor.visit(function); 76 _parentVisitor.visit(function);
77 77
78 if (inInterceptedMethod) { 78 if (inInterceptedMethod) {
79 explicitReceiverParameter.substituteFor(thisParameter); 79 explicitReceiverParameter.substituteFor(thisParameter);
80 } 80 }
81 81
82 visit(function); 82 visit(function);
83 } 83 }
84 84
85 @override
86 visit(Node node) {
87 Node result = node.accept(this);
88 return result != null ? result : node;
89 }
90
91 Constant get trueConstant { 85 Constant get trueConstant {
92 return new Constant(new TrueConstantValue()); 86 return new Constant(new TrueConstantValue());
93 } 87 }
94 88
95 Constant get falseConstant { 89 Constant get falseConstant {
96 return new Constant(new FalseConstantValue()); 90 return new Constant(new FalseConstantValue());
97 } 91 }
98 92
99 Constant get nullConstant { 93 Constant get nullConstant {
100 return new Constant(new NullConstantValue()); 94 return new Constant(new NullConstantValue());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 function, selector, arguments, continuation, null); 164 function, selector, arguments, continuation, null);
171 _parentVisitor.processInvokeStatic(invoke); 165 _parentVisitor.processInvokeStatic(invoke);
172 166
173 LetCont letCont = new LetCont(continuation, invoke); 167 LetCont letCont = new LetCont(continuation, invoke);
174 _parentVisitor.processLetCont(letCont); 168 _parentVisitor.processLetCont(letCont);
175 169
176 parent.body = letCont; 170 parent.body = letCont;
177 letCont.parent = parent; 171 letCont.parent = parent;
178 } 172 }
179 173
180 processLetHandler(LetHandler node) { 174 @override
175 Expression traverseLetHandler(LetHandler node) {
176 assert(node.handler.parameters.length == 2);
177 Parameter previousExceptionParameter = _exceptionParameter;
178
181 // BEFORE: Handlers have two parameters, exception and stack trace. 179 // BEFORE: Handlers have two parameters, exception and stack trace.
182 // AFTER: Handlers have a single parameter, which is unwrapped to get 180 // AFTER: Handlers have a single parameter, which is unwrapped to get
183 // the exception and stack trace. 181 // the exception and stack trace.
184 _exceptionParameter = node.handler.parameters.first; 182 _exceptionParameter = node.handler.parameters.first;
185 Parameter stackTraceParameter = node.handler.parameters.last; 183 Parameter stackTraceParameter = node.handler.parameters.last;
186 Expression body = node.handler.body; 184 Expression body = node.handler.body;
187 if (_exceptionParameter.hasAtLeastOneUse || 185 if (_exceptionParameter.hasAtLeastOneUse ||
188 stackTraceParameter.hasAtLeastOneUse) { 186 stackTraceParameter.hasAtLeastOneUse) {
189 Parameter exceptionValue = new Parameter(null); 187 Parameter exceptionValue = new Parameter(null);
190 exceptionValue.substituteFor(_exceptionParameter); 188 exceptionValue.substituteFor(_exceptionParameter);
191 insertStaticCall(_glue.getExceptionUnwrapper(), [_exceptionParameter], 189 insertStaticCall(_glue.getExceptionUnwrapper(), [_exceptionParameter],
192 exceptionValue, body); 190 exceptionValue, body);
193 191
194 if (stackTraceParameter.hasAtLeastOneUse) { 192 if (stackTraceParameter.hasAtLeastOneUse) {
195 Parameter stackTraceValue = new Parameter(null); 193 Parameter stackTraceValue = new Parameter(null);
196 stackTraceValue.substituteFor(stackTraceParameter); 194 stackTraceValue.substituteFor(stackTraceParameter);
197 insertStaticCall(_glue.getTraceFromException(), [_exceptionParameter], 195 insertStaticCall(_glue.getTraceFromException(), [_exceptionParameter],
198 stackTraceValue, body); 196 stackTraceValue, body);
199 } 197 }
200 } 198 }
201 199
202 assert(stackTraceParameter.hasNoUses); 200 assert(stackTraceParameter.hasNoUses);
203 node.handler.parameters.removeLast(); 201 node.handler.parameters.removeLast();
204 }
205 202
206 @override
207 visitLetHandler(LetHandler node) {
208 assert(node.handler.parameters.length == 2);
209 Parameter previousExceptionParameter = _exceptionParameter;
210 _exceptionParameter = node.handler.parameters.first;
211 processLetHandler(node);
212 visit(node.handler); 203 visit(node.handler);
213 _exceptionParameter = previousExceptionParameter; 204 _exceptionParameter = previousExceptionParameter;
214 205
215 visit(node.body); 206 return node.body;
216 } 207 }
217 208
218 processThrow(Throw node) { 209 processThrow(Throw node) {
219 // The subexpression of throw is wrapped in the JavaScript output. 210 // The subexpression of throw is wrapped in the JavaScript output.
220 Parameter value = new Parameter(null); 211 Parameter value = new Parameter(null);
221 insertStaticCall(_glue.getWrapExceptionHelper(), [node.value.definition], 212 insertStaticCall(_glue.getWrapExceptionHelper(), [node.value.definition],
222 value, node); 213 value, node);
223 node.value.unlink(); 214 node.value.unlink();
224 node.value = new Reference<Primitive>(value); 215 node.value = new Reference<Primitive>(value);
225 } 216 }
(...skipping 13 matching lines...) Expand all
239 /// [selector]. 230 /// [selector].
240 /// 231 ///
241 /// A single getInterceptor call will be created per primitive, bound 232 /// A single getInterceptor call will be created per primitive, bound
242 /// immediately after the primitive is bound. 233 /// immediately after the primitive is bound.
243 /// 234 ///
244 /// The type propagation pass will later narrow the set of interceptors 235 /// The type propagation pass will later narrow the set of interceptors
245 /// based on the input type, and the let sinking pass will propagate the 236 /// based on the input type, and the let sinking pass will propagate the
246 /// getInterceptor call closer to its use when this is profitable. 237 /// getInterceptor call closer to its use when this is profitable.
247 Interceptor getInterceptorFor(Primitive prim, Selector selector, 238 Interceptor getInterceptorFor(Primitive prim, Selector selector,
248 SourceInformation sourceInformation) { 239 SourceInformation sourceInformation) {
240 assert(prim is! Interceptor);
249 Interceptor interceptor = interceptors[prim]; 241 Interceptor interceptor = interceptors[prim];
250 if (interceptor == null) { 242 if (interceptor == null) {
251 interceptor = new Interceptor(prim, sourceInformation); 243 interceptor = new Interceptor(prim, sourceInformation);
252 interceptors[prim] = interceptor; 244 interceptors[prim] = interceptor;
253 InteriorNode parent = prim.parent; 245 InteriorNode parent = prim.parent;
254 insertLetPrim(interceptor, parent.body); 246 insertLetPrim(interceptor, parent.body);
255 if (prim.hint != null) { 247 if (prim.hint != null) {
256 interceptor.hint = new InterceptorEntity(prim.hint); 248 interceptor.hint = new InterceptorEntity(prim.hint);
257 } 249 }
258 } 250 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 condition.value.unlink(); 306 condition.value.unlink();
315 node.trueContinuation.unlink(); 307 node.trueContinuation.unlink();
316 node.falseContinuation.unlink(); 308 node.falseContinuation.unlink();
317 parent.body = newNode; 309 parent.body = newNode;
318 } 310 }
319 311
320 processInterceptor(Interceptor node) { 312 processInterceptor(Interceptor node) {
321 _glue.registerSpecializedGetInterceptor(node.interceptedClasses); 313 _glue.registerSpecializedGetInterceptor(node.interceptedClasses);
322 } 314 }
323 } 315 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698