Skip to content

Commit d7a89a7

Browse files
authored
Merge pull request swiftlang#37328 from rjmccall/di-box-scaling
In DI, cache whether a memory object is a box
2 parents b24892b + 12a4d47 commit d7a89a7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,8 @@ static unsigned getElementCountRec(TypeExpansionContext context,
9393
}
9494

9595
static std::pair<SILType, bool>
96-
computeMemorySILType(MarkUninitializedInst *MemoryInst) {
96+
computeMemorySILType(MarkUninitializedInst *MUI, SILValue Address) {
9797
// Compute the type of the memory object.
98-
auto *MUI = MemoryInst;
99-
SILValue Address = MUI;
100-
if (auto *PBI = Address->getSingleUserOfType<ProjectBoxInst>()) {
101-
Address = PBI;
102-
}
10398
SILType MemorySILType = Address->getType().getObjectType();
10499

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

121-
std::tie(MemorySILType, IsLet) = computeMemorySILType(MemoryInst);
116+
SILValue Address = MemoryInst;
117+
if (auto PBI = MemoryInst->getSingleUserOfType<ProjectBoxInst>()) {
118+
IsBox = true;
119+
Address = PBI;
120+
}
121+
122+
std::tie(MemorySILType, IsLet) = computeMemorySILType(MI, Address);
122123

123124
// Compute the number of elements to track in this memory object.
124125
// If this is a 'self' in a delegating initializer, we only track one bit:

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class DIMemoryObjectInfo {
7272
/// non-empty.
7373
bool HasDummyElement = false;
7474

75+
/// True if this object has a single user of type ProjectBoxInst.
76+
bool IsBox = false;
77+
7578
public:
7679
DIMemoryObjectInfo(MarkUninitializedInst *MemoryInst);
7780

@@ -98,8 +101,12 @@ class DIMemoryObjectInfo {
98101
/// instruction. For alloc_box though it returns the project_box associated
99102
/// with the memory info.
100103
SingleValueInstruction *getUninitializedValue() const {
101-
if (auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>())
104+
if (IsBox) {
105+
// TODO: consider just storing the ProjectBoxInst in this case.
106+
auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>();
107+
assert(pbi);
102108
return pbi;
109+
}
103110
return MemoryInst;
104111
}
105112

0 commit comments

Comments
 (0)