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

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

Issue 2246623002: Delete CPS IR (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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
(Empty)
1 // Copyright (c) 2016, 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 library dart2js.cps_ir.effects;
5
6 import 'dart:typed_data';
7
8 import '../universe/side_effects.dart' show SideEffects;
9
10 /// Bitmasks for tracking non-local side effects and dependencies.
11 ///
12 /// All effects must be attributed to an effect area. The `other` area is a
13 /// catch-all for any effect that does not belong to any of the specific areas;
14 /// this includes external effects such as printing to the console.
15 class Effects {
16 // Effect areas.
17 // These are bit positions, not bit masks. They are private because it is
18 // otherwise easy to mistake them for bitmasks.
19 static const int _staticField = 0;
20 static const int _instanceField = 1;
21 static const int _indexableContent = 2;
22 static const int _indexableLength = 3;
23 static const int _other = 4;
24 static const int numberOfEffectAreas = 5;
25
26 // Bitmasks for computation that modifies state in a given area.
27 static const int _changes = 1;
28 static const int changesStaticField = _changes << _staticField;
29 static const int changesInstanceField = _changes << _instanceField;
30 static const int changesIndexableContent = _changes << _indexableContent;
31 static const int changesIndexableLength = _changes << _indexableLength;
32 static const int changesOther = _changes << _other;
33
34 static const int changesAll = changesStaticField |
35 changesInstanceField |
36 changesIndexableContent |
37 changesIndexableLength |
38 changesOther;
39
40 // Bitmasks for computation that depends on state in a given area.
41 static const int _depends = 1 << numberOfEffectAreas;
42 static const int dependsOnStaticField = _depends << _staticField;
43 static const int dependsOnInstanceField = _depends << _instanceField;
44 static const int dependsOnIndexableContent = _depends << _indexableContent;
45 static const int dependsOnIndexableLength = _depends << _indexableLength;
46 static const int dependsOnOther = _depends << _other;
47
48 static const int dependsOnAll = dependsOnStaticField |
49 dependsOnInstanceField |
50 dependsOnIndexableContent |
51 dependsOnIndexableLength |
52 dependsOnOther;
53
54 static const int all = changesAll | dependsOnAll;
55 static const int none = 0;
56
57 static int _changesArea(int effectArea) => _changes << effectArea;
58
59 static int _dependsOnArea(int effectArea) => _depends << effectArea;
60
61 static int changesToDepends(int changesFlags) {
62 return (changesFlags & changesAll) << numberOfEffectAreas;
63 }
64
65 static int dependsToChanges(int dependsFlags) {
66 return (dependsFlags & dependsOnAll) >> numberOfEffectAreas;
67 }
68
69 /// Converts [SideEffects] from a JS annotation or type inference to the
70 /// more fine-grained flag set.
71 //
72 // TODO(asgerf): Once we finalize the set of flags to use, unify the two
73 // systems.
74 static int from(SideEffects fx) {
75 int result = 0;
76 if (fx.changesInstanceProperty()) {
77 result |= changesInstanceField;
78 }
79 if (fx.changesStaticProperty()) {
80 result |= changesStaticField;
81 }
82 if (fx.changesIndex()) {
83 result |= changesIndexableContent | changesIndexableLength;
84 }
85 if (fx.hasSideEffects()) {
86 result |= changesOther;
87 }
88 if (fx.dependsOnInstancePropertyStore()) {
89 result |= dependsOnInstanceField;
90 }
91 if (fx.dependsOnStaticPropertyStore()) {
92 result |= dependsOnStaticField;
93 }
94 if (fx.dependsOnIndexStore()) {
95 result |= dependsOnIndexableContent | dependsOnIndexableLength;
96 }
97 if (fx.dependsOnSomething()) {
98 result |= dependsOnOther;
99 }
100 return result;
101 }
102 }
103
104 /// Creates fresh IDs to ensure effect numbers do not clash with each other.
105 class EffectNumberer {
106 int _id = 0;
107 int next() => ++_id;
108
109 /// Special effect number that can be used in place for an effect area that
110 /// is irrelevant for a computation.
111 ///
112 /// This value is never returned by [next].
113 static const int none = 0;
114 }
115
116 /// A mutable vector of effect numbers, one for each effect area.
117 ///
118 /// Effect numbers are used to identify regions of code wherein the given
119 /// effect area is unmodified.
120 class EffectNumbers {
121 final Int32List _effectNumbers = new Int32List(Effects.numberOfEffectAreas);
122
123 EffectNumbers._zero();
124
125 EffectNumbers.fresh(EffectNumberer numberer) {
126 reset(numberer);
127 }
128
129 EffectNumbers copy() {
130 return new EffectNumbers._zero().._effectNumbers.setAll(0, _effectNumbers);
131 }
132
133 int operator [](int i) => _effectNumbers[i];
134
135 void operator []=(int i, int value) {
136 _effectNumbers[i] = value;
137 }
138
139 int get staticField => _effectNumbers[Effects._staticField];
140 int get instanceField => _effectNumbers[Effects._instanceField];
141 int get indexableContent => _effectNumbers[Effects._indexableContent];
142 int get indexableLength => _effectNumbers[Effects._indexableLength];
143 int get other => _effectNumbers[Effects._other];
144
145 void set staticField(int n) {
146 _effectNumbers[Effects._staticField] = n;
147 }
148
149 void set instanceField(int n) {
150 _effectNumbers[Effects._instanceField] = n;
151 }
152
153 void set indexableContent(int n) {
154 _effectNumbers[Effects._indexableContent] = n;
155 }
156
157 void set indexableLength(int n) {
158 _effectNumbers[Effects._indexableLength] = n;
159 }
160
161 void set other(int n) {
162 _effectNumbers[Effects._other] = n;
163 }
164
165 void reset(EffectNumberer numberer) {
166 for (int i = 0; i < Effects.numberOfEffectAreas; ++i) {
167 _effectNumbers[i] = numberer.next();
168 }
169 }
170
171 void join(EffectNumberer numberer, EffectNumbers other) {
172 for (int i = 0; i < Effects.numberOfEffectAreas; ++i) {
173 if (_effectNumbers[i] != other._effectNumbers[i]) {
174 _effectNumbers[i] = numberer.next();
175 }
176 }
177 }
178
179 void change(EffectNumberer numberer, int changeFlags) {
180 for (int i = 0; i < Effects.numberOfEffectAreas; ++i) {
181 if (changeFlags & Effects._changesArea(i) != 0) {
182 _effectNumbers[i] = numberer.next();
183 }
184 }
185 }
186
187 /// Builds a vector where all entries that are not depended on are replaced
188 /// by [EffectNumberer.none].
189 //
190 // TODO(asgerf): Use this in GVN to simplify the dispatching code.
191 List<int> getDependencies(int dependsFlags) {
192 Int32List copy = new Int32List.fromList(_effectNumbers);
193 for (int i = 0; i < Effects.numberOfEffectAreas; ++i) {
194 if (dependsFlags & Effects._dependsOnArea(i) == 0) {
195 copy[i] = EffectNumberer.none;
196 }
197 }
198 return copy;
199 }
200 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/eagerly_load_statics.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