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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/eagerly_load_statics.dart

Issue 1521553003: dart2js cps: Replace GetLazyStatic with GetStatic. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add witness to GetStatic and switch to scope-based analysis Created 5 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
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library dart2js.cps_ir.eagerly_load_statics;
6
7 import 'cps_ir_nodes.dart';
8 import 'optimizers.dart' show Pass;
9 import '../elements/elements.dart';
10
11 /// Replaces [GetLazyStatic] with [GetStatic] when the static field is known
12 /// to have been initialized.
13 ///
14 /// Apart from [GetStatic] generating better code, this improves the side-effect
15 /// analysis in the [GVN] pass, since [GetStatic] has no effects.
16 class EagerlyLoadStatics extends TrampolineRecursiveVisitor implements Pass {
17 String get passName => 'Eagerly load statics';
18
19 Map<FieldElement, Primitive> initializerFor = makeFieldMap();
20
21 final Map<Continuation, Map<FieldElement, Primitive>> initializersAt =
22 <Continuation, Map<FieldElement, Primitive>>{};
23
24 static Map<FieldElement, Primitive> makeFieldMap() {
25 return <FieldElement, Primitive>{};
26 }
27
28 static Map<FieldElement, Primitive> cloneFieldMap(
29 Map<FieldElement, Primitive> map) {
30 return new Map<FieldElement, Primitive>.from(map);
31 }
32
33 void rewrite(FunctionDefinition node) {
34 visit(node.body);
35 }
36
37 Expression traverseLetCont(LetCont node) {
38 for (Continuation cont in node.continuations) {
39 initializersAt[cont] = cloneFieldMap(initializerFor);
40 push(cont);
41 }
42 return node.body;
43 }
44
45 Expression traverseLetHandler(LetHandler node) {
46 initializersAt[node.handler] = cloneFieldMap(initializerFor);
47 push(node.handler);
48 return node.body;
49 }
50
51 Expression traverseContinuation(Continuation cont) {
52 initializerFor = initializersAt[cont];
53 return cont.body;
54 }
55
56 void visitGetLazyStatic(GetLazyStatic node) {
57 Primitive initializer = initializerFor[node.element];
58 if (initializer != null) {
59 GetStatic newNode = new GetStatic.witnessed(node.element, initializer,
60 node.sourceInformation);
61 newNode.type = node.type;
62 node.replaceWith(newNode);
63 } else {
64 initializerFor[node.element] = node;
65 }
66 }
67
68 void visitSetStatic(SetStatic node) {
69 initializerFor.putIfAbsent(node.element, () => node);
70 }
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698