-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[opt] Update alloc_refs on the stack to have stack memory kind. #31423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,6 @@ AccessedStorage::AccessedStorage(SILValue base, Kind kind) { | |
value = base; | ||
break; | ||
case Stack: | ||
assert(isa<AllocStackInst>(base)); | ||
value = base; | ||
break; | ||
case Nested: | ||
|
@@ -772,3 +771,22 @@ void swift::visitAccessedAddress(SILInstruction *I, | |
return; | ||
} | ||
} | ||
|
||
template <typename Impl, typename Result> | ||
Result swift::AccessUseDefChainVisitor<Impl, Result>::visitClassAccess( | ||
RefElementAddrInst *field) { | ||
auto operand = field->getOperand(); | ||
while (isa<StructElementAddrInst>(operand) || | ||
isa<RefElementAddrInst>(operand) || | ||
isa<TupleElementAddrInst>(operand) || isa<LoadInst>(operand)) | ||
operand = operand.getDefiningInstruction()->getOperand(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what's happening here with peeking through operands. The UseDefChainVisitor needs to visit each instruction on the "access path" between the address of the memory access and the address of the access to formal storage. |
||
|
||
if (isa<AllocStackInst>(operand)) | ||
return asImpl().visitBase(field, AccessedStorage::Stack); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If an access is to a class property, it doesn't matter where the reference to the class is stored. Once you reach the base of the formal access, you've found the AccessStorage. This corresponds to language-level constructs: global variable, class property, local variable. |
||
if (auto allocRef = dyn_cast<AllocRefInst>(operand)) { | ||
if (allocRef->isAllocatingStack()) | ||
return asImpl().visitBase(field, AccessedStorage::Stack); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class properties have specific semantics at the language level and specific structural properties in SIL. Whether the object is allocated on the heap or stack is irrelevant to any of this. If we have an optimization that can somehow benefit from knowing that an object is stack-allocated, then we can teach that optimization about stack-allocated objects. But we can never pretend that a class property is a local variable. |
||
} | ||
|
||
return asImpl().visitBase(field, AccessedStorage::Class); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the assertion here but, it would require duplicating the code in
visitClassAccess
and I don't think it's worth it just for the assertion. WDYT?