OLD | NEW |
---|---|
(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] is known to have no effects. | |
sra1
2015/12/11 17:13:09
"is known to have" -> "has"
asgerf
2015/12/14 17:05:39
Done.
| |
16 class EagerlyLoadStatics extends TrampolineRecursiveVisitor implements Pass { | |
17 String get passName => 'Eagerly load statics'; | |
18 | |
19 Set<FieldElement> loadedStatics = new Set<FieldElement>(); | |
20 final Map<Continuation, Set<FieldElement>> loadedStaticsAt = {}; | |
sra1
2015/12/11 17:13:08
Put types on the map literal - that is what is che
asgerf
2015/12/14 17:05:39
The pass has changed quite a bit now, but there ar
| |
21 | |
22 void rewrite(FunctionDefinition node) { | |
23 visit(node); | |
24 } | |
25 | |
26 void visitBranch(Branch node) { | |
27 Continuation trueCont = node.trueContinuation.definition; | |
28 Continuation falseCont = node.falseContinuation.definition; | |
29 loadedStaticsAt[trueCont] = loadedStatics; | |
30 loadedStaticsAt[falseCont] = new Set<FieldElement>.from(loadedStatics); | |
31 } | |
32 | |
33 Expression traverseContinuation(Continuation cont) { | |
34 loadedStatics = loadedStaticsAt[cont] ?? new Set<FieldElement>(); | |
sra1
2015/12/11 17:13:08
Why is it null?
I would add two helpers - newSet
asgerf
2015/12/14 17:05:39
Null was for the case of unreachable continuations
| |
35 return cont.body; | |
36 } | |
37 | |
38 Expression traverseLetHandler(LetHandler node) { | |
39 loadedStaticsAt[node.handler] = new Set<FieldElement>.from(loadedStatics); | |
40 push(node.handler); | |
41 return node.body; | |
42 } | |
43 | |
44 void visitInvokeContinuation(InvokeContinuation node) { | |
45 if (node.isRecursive) return; | |
46 Continuation cont = node.continuation.definition; | |
47 if (cont.isReturnContinuation) return; | |
48 Set<FieldElement> targetSet = loadedStaticsAt[cont]; | |
49 if (targetSet == null) { | |
50 loadedStaticsAt[cont] = loadedStatics; | |
51 } else { | |
52 targetSet.retainAll(loadedStatics); | |
53 } | |
54 } | |
55 | |
56 void visitGetLazyStatic(GetLazyStatic node) { | |
57 // Mark the field as loaded, and replace it with a GetStatic if it was | |
58 // already loaded. | |
59 if (!loadedStatics.add(node.element)) { | |
60 node.replaceWith(new GetStatic(node.element, node.sourceInformation) | |
61 ..type = node.type); | |
62 } | |
63 } | |
64 | |
65 void visitSetStatic(SetStatic node) { | |
66 loadedStatics.add(node.element); | |
67 } | |
sra1
2015/12/11 17:13:08
Could there already be a GetStatic?
Is the pass id
asgerf
2015/12/14 17:05:39
There can't be any GetStatics unless the pass is r
| |
68 } | |
OLD | NEW |