Skip to content

Commit 0d962b2

Browse files
committed
[pmo] Change MemoryInst to be an AllocationInst since it will always be so.
Just a part of a series of small cleanups I found over the break in PMO that I am landing in preparation for landing patches that fix PMO for ownership.
1 parent 45429ff commit 0d962b2

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,21 @@ static unsigned getElementCountRec(SILModule &Module, SILType T) {
3939
return 1;
4040
}
4141

42-
PMOMemoryObjectInfo::PMOMemoryObjectInfo(SingleValueInstruction *MI) {
43-
auto &Module = MI->getModule();
42+
PMOMemoryObjectInfo::PMOMemoryObjectInfo(AllocationInst *allocation)
43+
: MemoryInst(allocation) {
44+
auto &module = MemoryInst->getModule();
4445

45-
MemoryInst = MI;
4646
// Compute the type of the memory object.
47-
if (auto *ABI = dyn_cast<AllocBoxInst>(MemoryInst)) {
48-
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1 &&
47+
if (auto *abi = dyn_cast<AllocBoxInst>(MemoryInst)) {
48+
assert(abi->getBoxType()->getLayout()->getFields().size() == 1 &&
4949
"analyzing multi-field boxes not implemented");
50-
MemorySILType = ABI->getBoxType()->getFieldType(Module, 0);
51-
} else if (auto *ASI = dyn_cast<AllocStackInst>(MemoryInst)) {
52-
MemorySILType = ASI->getElementType();
50+
MemorySILType = abi->getBoxType()->getFieldType(module, 0);
5351
} else {
54-
llvm_unreachable(
55-
"Predictable Mem Opts should only be analyzing alloc_box/alloc_stack");
52+
MemorySILType = cast<AllocStackInst>(MemoryInst)->getElementType();
5653
}
5754

5855
// Break down the initializer.
59-
NumElements = getElementCountRec(Module, MemorySILType);
56+
NumElements = getElementCountRec(module, MemorySILType);
6057
}
6158

6259
SILInstruction *PMOMemoryObjectInfo::getFunctionEntryPoint() const {

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class SILBuilder;
7070
/// not super.init() has been called or not.
7171
class PMOMemoryObjectInfo {
7272
public:
73-
/// This is the instruction that represents the memory. It is either an
74-
/// allocation (alloc_box, alloc_stack) or a mark_uninitialized.
75-
SingleValueInstruction *MemoryInst;
73+
/// This is the instruction that represents the memory. It is either an
74+
/// alloc_box or alloc_stack.
75+
AllocationInst *MemoryInst;
7676

7777
/// This is the base type of the memory allocation.
7878
SILType MemorySILType;
@@ -87,7 +87,7 @@ class PMOMemoryObjectInfo {
8787
unsigned NumElements;
8888

8989
public:
90-
PMOMemoryObjectInfo(SingleValueInstruction *MemoryInst);
90+
PMOMemoryObjectInfo(AllocationInst *MemoryInst);
9191

9292
SILLocation getLoc() const { return MemoryInst->getLoc(); }
9393
SILFunction &getFunction() const { return *MemoryInst->getFunction(); }

0 commit comments

Comments
 (0)