Skip to content

Commit 035fa37

Browse files
Merge pull request swiftlang#41438 from nate-chandler/lexical_lifetimes/lexical_destroy_addr_hoisting/handle-access-scopes
[SSADestroyHoisting] Handle access scopes.
2 parents e3af684 + be1ebe0 commit 035fa37

File tree

7 files changed

+564
-66
lines changed

7 files changed

+564
-66
lines changed

include/swift/SIL/MemAccessUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,6 @@ class AccessPath {
10981098
// ignores its subclass bits.
10991099
AccessPath(AccessStorage storage, PathNode pathNode, int offset)
11001100
: storage(storage), pathNode(pathNode), offset(offset) {
1101-
assert(storage.getKind() != AccessStorage::Nested);
11021101
assert(pathNode.isValid() || !storage && "Access path requires a pathNode");
11031102
}
11041103

@@ -1337,6 +1336,7 @@ namespace swift {
13371336
/// to the storage within this function is derived from these roots.
13381337
///
13391338
/// Gather the kinds of uses that are typically relevant to algorithms:
1339+
/// - accesses (specifically, begin_access insts)
13401340
/// - loads (including copies out of, not including inout args)
13411341
/// - stores (including copies into and inout args)
13421342
/// - destroys (of the entire aggregate)
@@ -1353,6 +1353,7 @@ struct UniqueStorageUseVisitor {
13531353

13541354
virtual ~UniqueStorageUseVisitor() = default;
13551355

1356+
virtual bool visitBeginAccess(Operand *use) = 0;
13561357
virtual bool visitLoad(Operand *use) = 0;
13571358
virtual bool visitStore(Operand *use) = 0;
13581359
virtual bool visitDestroy(Operand *use) = 0;

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,8 @@ struct GatherUniqueStorageUses : public AccessUseVisitor {
19411941
};
19421942

19431943
bool UniqueStorageUseVisitor::findUses(UniqueStorageUseVisitor &visitor) {
1944-
assert(visitor.storage.isUniquelyIdentified());
1944+
assert(visitor.storage.isUniquelyIdentified() ||
1945+
visitor.storage.getKind() == AccessStorage::Kind::Nested);
19451946

19461947
GatherUniqueStorageUses gather(visitor);
19471948
return visitAccessStorageUses(gather, visitor.storage, visitor.function);
@@ -1972,6 +1973,9 @@ bool GatherUniqueStorageUses::visitUse(Operand *use, AccessUseType useTy) {
19721973
}
19731974
}
19741975
switch (user->getKind()) {
1976+
case SILInstructionKind::BeginAccessInst:
1977+
return visitor.visitBeginAccess(use);
1978+
19751979
case SILInstructionKind::DestroyAddrInst:
19761980
case SILInstructionKind::DestroyValueInst:
19771981
if (useTy == AccessUseType::Exact) {
@@ -1982,6 +1986,9 @@ bool GatherUniqueStorageUses::visitUse(Operand *use, AccessUseType useTy) {
19821986
case SILInstructionKind::DebugValueInst:
19831987
return visitor.visitDebugUse(use);
19841988

1989+
case SILInstructionKind::EndAccessInst:
1990+
return true;
1991+
19851992
case SILInstructionKind::LoadInst:
19861993
case SILInstructionKind::LoadWeakInst:
19871994
case SILInstructionKind::LoadUnownedInst:

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ llvm::cl::opt<bool> SILDisableLateOMEByDefault(
6666
llvm::cl::desc(
6767
"Disable late OME for non-transparent functions by default"));
6868

69+
llvm::cl::opt<bool>
70+
EnableDestroyHoisting("enable-destroy-hoisting", llvm::cl::init(true),
71+
llvm::cl::desc("Enable the DestroyHoisting pass."));
72+
6973
//===----------------------------------------------------------------------===//
7074
// Diagnostic Pass Pipeline
7175
//===----------------------------------------------------------------------===//
@@ -145,7 +149,7 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
145149
P.addSILSkippingChecker();
146150
#endif
147151

148-
if (Options.shouldOptimize()) {
152+
if (Options.shouldOptimize() && EnableDestroyHoisting) {
149153
P.addDestroyHoisting();
150154
}
151155
P.addMandatoryInlining();

0 commit comments

Comments
 (0)