Skip to content

[5.4] In DI, cache whether a memory object is a box. #37484

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

Merged
merged 1 commit into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,8 @@ static unsigned getElementCountRec(TypeExpansionContext context,
}

static std::pair<SILType, bool>
computeMemorySILType(MarkUninitializedInst *MemoryInst) {
computeMemorySILType(MarkUninitializedInst *MUI, SILValue Address) {
// Compute the type of the memory object.
auto *MUI = MemoryInst;
SILValue Address = MUI;
if (auto *PBI = Address->getSingleUserOfType<ProjectBoxInst>()) {
Address = PBI;
}
SILType MemorySILType = Address->getType().getObjectType();

// If this is a let variable we're initializing, remember this so we don't
Expand All @@ -118,7 +113,13 @@ DIMemoryObjectInfo::DIMemoryObjectInfo(MarkUninitializedInst *MI)
: MemoryInst(MI) {
auto &Module = MI->getModule();

std::tie(MemorySILType, IsLet) = computeMemorySILType(MemoryInst);
SILValue Address = MemoryInst;
if (auto PBI = MemoryInst->getSingleUserOfType<ProjectBoxInst>()) {
IsBox = true;
Address = PBI;
}

std::tie(MemorySILType, IsLet) = computeMemorySILType(MI, Address);

// Compute the number of elements to track in this memory object.
// If this is a 'self' in a delegating initializer, we only track one bit:
Expand Down
12 changes: 8 additions & 4 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class DIMemoryObjectInfo {
/// non-empty.
bool HasDummyElement = false;

/// True if this object has a single user of type ProjectBoxInst.
bool IsBox = false;

public:
DIMemoryObjectInfo(MarkUninitializedInst *MemoryInst);

Expand All @@ -98,10 +101,11 @@ class DIMemoryObjectInfo {
/// instruction. For alloc_box though it returns the project_box associated
/// with the memory info.
SingleValueInstruction *getUninitializedValue() const {
if (auto *mui = dyn_cast<MarkUninitializedInst>(MemoryInst)) {
if (auto *pbi = mui->getSingleUserOfType<ProjectBoxInst>()) {
return pbi;
}
if (IsBox) {
// TODO: consider just storing the ProjectBoxInst in this case.
auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>();
assert(pbi);
return pbi;
}
return MemoryInst;
}
Expand Down