Skip to content

Commit d3d998f

Browse files
authored
Merge pull request #37484 from rjmccall/di-box-scaling-5.4
[5.4] In DI, cache whether a memory object is a box.
2 parents 7b3dbf2 + c82eea2 commit d3d998f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
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 & 4 deletions
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,10 +101,11 @@ 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 *mui = dyn_cast<MarkUninitializedInst>(MemoryInst)) {
102-
if (auto *pbi = mui->getSingleUserOfType<ProjectBoxInst>()) {
103-
return pbi;
104-
}
104+
if (IsBox) {
105+
// TODO: consider just storing the ProjectBoxInst in this case.
106+
auto *pbi = MemoryInst->getSingleUserOfType<ProjectBoxInst>();
107+
assert(pbi);
108+
return pbi;
105109
}
106110
return MemoryInst;
107111
}

0 commit comments

Comments
 (0)