Skip to content

Commit b5126a9

Browse files
committed
[SILOptimizer] DI: Add a way to check whether TheMemory is _storage local var
1 parent 1ee14f5 commit b5126a9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,30 @@ ConstructorDecl *DIMemoryObjectInfo::getActorInitSelf() const {
538538
return nullptr;
539539
}
540540

541+
VarDecl *DIMemoryObjectInfo::getAsTypeWrapperLocalStorageVar() const {
542+
if (!MemoryInst->isVar())
543+
return nullptr;
544+
545+
if (!isa<TupleType>(getASTType()))
546+
return nullptr;
547+
548+
auto *DC = MemoryInst->getFunction()->getDeclContext();
549+
if (!DC)
550+
return nullptr;
551+
552+
auto *ctor = dyn_cast_or_null<ConstructorDecl>(DC->getAsDecl());
553+
if (!ctor || ctor->isImplicit())
554+
return nullptr;
555+
556+
if (auto *var = getLoc().getAsASTNode<VarDecl>()) {
557+
auto &ctx = var->getASTContext();
558+
if (var->isImplicit() && var->getName() == ctx.Id_localStorageVar)
559+
return var;
560+
}
561+
562+
return nullptr;
563+
}
564+
541565
//===----------------------------------------------------------------------===//
542566
// DIMemoryUse Implementation
543567
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class DIMemoryObjectInfo {
164164
/// actor's initializer. Otherwise, returns nullptr.
165165
ConstructorDecl *getActorInitSelf() const;
166166

167+
/// If \c TheMemory is a temporary variable that is responsible for
168+
/// member-by-member initialization of `$Storage` in a user-defined
169+
/// initializer of a type wrapped type, return its declaration.
170+
VarDecl *getAsTypeWrapperLocalStorageVar() const;
171+
167172
/// True if this memory object is the 'self' of a derived class initializer.
168173
bool isDerivedClassSelf() const { return MemoryInst->isDerivedClassSelf(); }
169174

0 commit comments

Comments
 (0)