Skip to content

[pmo] Change MemoryInst to be an AllocationInst since it will always … #21591

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
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
19 changes: 8 additions & 11 deletions lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,21 @@ static unsigned getElementCountRec(SILModule &Module, SILType T) {
return 1;
}

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

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

// Break down the initializer.
NumElements = getElementCountRec(Module, MemorySILType);
NumElements = getElementCountRec(module, MemorySILType);
}

SILInstruction *PMOMemoryObjectInfo::getFunctionEntryPoint() const {
Expand Down
8 changes: 4 additions & 4 deletions lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class SILBuilder;
/// not super.init() has been called or not.
class PMOMemoryObjectInfo {
public:
/// This is the instruction that represents the memory. It is either an
/// allocation (alloc_box, alloc_stack) or a mark_uninitialized.
SingleValueInstruction *MemoryInst;
/// This is the instruction that represents the memory. It is either an
/// alloc_box or alloc_stack.
AllocationInst *MemoryInst;

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

public:
PMOMemoryObjectInfo(SingleValueInstruction *MemoryInst);
PMOMemoryObjectInfo(AllocationInst *MemoryInst);

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