Skip to content

Commit 513ab78

Browse files
committed
[region-isolation] Move SILIsolationInfo determining code for ref_element_addr and global_addr onto SILIsolationInfo and call that instead.
1 parent 20c2429 commit 513ab78

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ class SILIsolationInfo {
209209
/// Attempt to infer the isolation region info for \p arg.
210210
static SILIsolationInfo get(SILFunctionArgument *arg);
211211

212+
static SILIsolationInfo get(SILValue value) {
213+
if (auto *fArg = dyn_cast<SILFunctionArgument>(value))
214+
return get(fArg);
215+
if (auto *inst = dyn_cast<SingleValueInstruction>(value))
216+
return get(inst);
217+
return {};
218+
}
219+
212220
bool hasSameIsolation(ActorIsolation actorIsolation) const;
213221

214222
/// Returns true if \p this and \p other have the same isolation. It allows

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,28 +3292,8 @@ TrackableValue RegionAnalysisValueMap::getTrackableValue(
32923292
iter.first->getSecond().removeFlag(TrackableValueFlag::isMayAlias);
32933293
}
32943294

3295-
// Then see if the memory base is a ref_element_addr from an address. If
3296-
// so, add the actor derived flag.
3297-
//
3298-
// This is important so we properly handle setters.
3299-
if (auto *rei = dyn_cast<RefElementAddrInst>(storage.base)) {
3300-
auto *nomDecl =
3301-
rei->getOperand()->getType().getNominalOrBoundGenericNominal();
3302-
iter.first->getSecond().mergeIsolationRegionInfo(
3303-
SILIsolationInfo::getActorIsolated(rei, nomDecl));
3304-
}
3305-
3306-
// See if the memory base is a global_addr from a global actor protected global.
3307-
if (auto *ga = dyn_cast<GlobalAddrInst>(storage.base)) {
3308-
if (auto *global = ga->getReferencedGlobal()) {
3309-
if (auto *globalDecl = global->getDecl()) {
3310-
auto isolation = getActorIsolation(globalDecl);
3311-
if (isolation.isGlobalActor()) {
3312-
iter.first->getSecond().mergeIsolationRegionInfo(
3313-
SILIsolationInfo::getActorIsolated(ga, isolation));
3314-
}
3315-
}
3316-
}
3295+
if (auto isolation = SILIsolationInfo::get(storage.base)) {
3296+
iter.first->getSecond().mergeIsolationRegionInfo(isolation);
33173297
}
33183298
}
33193299
}

lib/SILOptimizer/Utils/PartitionUtils.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "swift/SILOptimizer/Utils/PartitionUtils.h"
1414
#include "swift/AST/Expr.h"
1515
#include "swift/SIL/ApplySite.h"
16+
#include "swift/SIL/SILGlobalVariable.h"
1617
#include "llvm/Support/CommandLine.h"
1718

1819
using namespace swift;
@@ -81,12 +82,37 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
8182
}
8283
}
8384

84-
// We assume that any instruction that does not correspond to an ApplyExpr
85-
// cannot cross an isolation domain.
85+
// See if the memory base is a ref_element_addr from an address. If so, add
86+
// the actor derived flag.
87+
//
88+
// This is important so we properly handle setters.
89+
if (auto *rei = dyn_cast<RefElementAddrInst>(inst)) {
90+
auto *nomDecl =
91+
rei->getOperand()->getType().getNominalOrBoundGenericNominal();
92+
return SILIsolationInfo::getActorIsolated(rei, nomDecl);
93+
}
94+
95+
// Check if we have a global_addr inst.
96+
if (auto *ga = dyn_cast<GlobalAddrInst>(inst)) {
97+
if (auto *global = ga->getReferencedGlobal()) {
98+
if (auto *globalDecl = global->getDecl()) {
99+
auto isolation = swift::getActorIsolation(globalDecl);
100+
if (isolation.isGlobalActor()) {
101+
return SILIsolationInfo::getActorIsolated(ga, isolation);
102+
}
103+
}
104+
}
105+
}
106+
86107
return SILIsolationInfo();
87108
}
88109

89110
SILIsolationInfo SILIsolationInfo::get(SILFunctionArgument *arg) {
111+
// Transferring is always disconnected.
112+
if (!arg->isIndirectResult() && !arg->isIndirectErrorResult() &&
113+
arg->isTransferring())
114+
return SILIsolationInfo::getDisconnected();
115+
90116
// If we have self and our function is actor isolated, all of our arguments
91117
// should be marked as actor isolated.
92118
if (auto *self = arg->getFunction()->maybeGetSelfArgument()) {

0 commit comments

Comments
 (0)