24
24
namespace swift {
25
25
26
26
class RegionAnalysisFunctionInfo ;
27
+ class RegionAnalysisValueMap ;
27
28
28
29
namespace regionanalysisimpl {
29
30
@@ -121,9 +122,11 @@ using TrackedValueFlagSet = OptionSet<TrackableValueFlag>;
121
122
} // namespace regionanalysisimpl
122
123
123
124
class regionanalysisimpl ::TrackableValueState {
125
+ friend RegionAnalysisValueMap;
126
+
124
127
unsigned id;
125
128
TrackedValueFlagSet flagSet = {TrackableValueFlag::isMayAlias};
126
- SILIsolationInfo regionInfo = SILIsolationInfo::getDisconnected() ;
129
+ std::optional< SILIsolationInfo> regionInfo = {} ;
127
130
128
131
public:
129
132
TrackableValueState (unsigned newID) : id(newID) {}
@@ -140,20 +143,28 @@ class regionanalysisimpl::TrackableValueState {
140
143
141
144
bool isNonSendable () const { return !isSendable (); }
142
145
146
+ SILIsolationInfo getIsolationRegionInfo () const {
147
+ if (!regionInfo) {
148
+ return SILIsolationInfo::getDisconnected (false );
149
+ }
150
+
151
+ return *regionInfo;
152
+ }
153
+
143
154
SILIsolationInfo::Kind getIsolationRegionInfoKind () const {
144
- return regionInfo .getKind ();
155
+ return getIsolationRegionInfo () .getKind ();
145
156
}
146
157
147
158
ActorIsolation getActorIsolation () const {
148
- return regionInfo .getActorIsolation ();
159
+ return getIsolationRegionInfo () .getActorIsolation ();
149
160
}
150
161
151
- void mergeIsolationRegionInfo (SILIsolationInfo newRegionInfo) {
152
- regionInfo = regionInfo.merge (newRegionInfo);
162
+ void setDisconnectedNonisolatedUnsafe () {
163
+ auto oldRegionInfo = getIsolationRegionInfo ();
164
+ assert (oldRegionInfo.isDisconnected ());
165
+ regionInfo = oldRegionInfo.withUnsafeNonIsolated ();
153
166
}
154
167
155
- SILIsolationInfo getIsolationRegionInfo () const { return regionInfo; }
156
-
157
168
Element getID () const { return Element (id); }
158
169
159
170
void addFlag (TrackableValueFlag flag) { flagSet |= flag; }
@@ -165,11 +176,22 @@ class regionanalysisimpl::TrackableValueState {
165
176
<< " ][is_no_alias: " << (isNoAlias () ? " yes" : " no" )
166
177
<< " ][is_sendable: " << (isSendable () ? " yes" : " no" )
167
178
<< " ][region_value_kind: " ;
168
- getIsolationRegionInfo ().printForDiagnostics (os);
179
+ getIsolationRegionInfo ().printForOneLineLogging (os);
169
180
os << " ]." ;
170
181
}
171
182
172
183
SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
184
+
185
+ private:
186
+ bool hasIsolationRegionInfo () const { return bool (regionInfo); }
187
+
188
+ // / Set the isolation region info for this TrackableValueState. Private so it
189
+ // / can only be used by RegionAnalysisValueMap::getTrackableValue.
190
+ void setIsolationRegionInfo (SILIsolationInfo newRegionInfo) {
191
+ assert (!regionInfo.has_value () &&
192
+ " Can only call setIsolationRegionInfo once!\n " );
193
+ regionInfo = newRegionInfo;
194
+ }
173
195
};
174
196
175
197
// / The representative value of the equivalence class that makes up a tracked
@@ -358,9 +380,17 @@ class RegionAnalysisValueMap {
358
380
TrackableValue
359
381
getActorIntroducingRepresentative (SILInstruction *introducingInst,
360
382
SILIsolationInfo isolation) const ;
361
- bool mergeIsolationRegionInfo (SILValue value, SILIsolationInfo isolation);
362
383
bool valueHasID (SILValue value, bool dumpIfHasNoID = false );
363
384
Element lookupValueID (SILValue value);
385
+
386
+ // / Initialize a TrackableValue with a SILIsolationInfo that we already know
387
+ // / instead of inferring.
388
+ // /
389
+ // / If we successfully initialize \p value with \p info, returns
390
+ // / {TrackableValue(), true}. If we already had a TrackableValue, we return
391
+ // / {TrackableValue(), false}.
392
+ std::pair<TrackableValue, bool >
393
+ initializeTrackableValue (SILValue value, SILIsolationInfo info) const ;
364
394
};
365
395
366
396
class RegionAnalysisFunctionInfo {
0 commit comments