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

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: Remove obsolete comment 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 = <FieldElement, Primitive>{};
20
21 final Map<Continuation, Map<FieldElement, Primitive>> initializersAt =
22 <Continuation, Map<FieldElement, Primitive>>{};
23
24 static Map<FieldElement, Primitive> cloneFieldMap(
25 Map<FieldElement, Primitive> map) {
26 return new Map<FieldElement, Primitive>.from(map);
27 }
28
29 void rewrite(FunctionDefinition node) {
30 visit(node.body);
31 }
32
33 Expression traverseLetCont(LetCont node) {
34 for (Continuation cont in node.continuations) {
35 initializersAt[cont] = cloneFieldMap(initializerFor);
36 push(cont);
37 }
38 return node.body;
39 }
40
41 Expression traverseLetHandler(LetHandler node) {
42 initializersAt[node.handler] = cloneFieldMap(initializerFor);
43 push(node.handler);
44 return node.body;
45 }
46
47 Expression traverseContinuation(Continuation cont) {
48 initializerFor = initializersAt[cont];
49 return cont.body;
50 }
51
52 void visitGetLazyStatic(GetLazyStatic node) {
53 Primitive initializer = initializerFor[node.element];
54 if (initializer != null) {
55 GetStatic newNode = new GetStatic.witnessed(node.element, initializer,
56 node.sourceInformation);
57 newNode.type = node.type;
58 node.replaceWith(newNode);
59 } else {
60 initializerFor[node.element] = node;
61 }
62 }
63
64 void visitSetStatic(SetStatic node) {
65 initializerFor.putIfAbsent(node.element, () => node);
66 }
67 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/cps_ir/finalize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698