Skip to content

Commit 24ed33b

Browse files
authored
Merge pull request #77040 from atrick/predmem_markdep
PredictableMemOpts: handle mark_dependence
2 parents 493d37e + af86ad1 commit 24ed33b

File tree

7 files changed

+903
-30
lines changed

7 files changed

+903
-30
lines changed

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,14 @@ bool ElementUseCollector::collectContainerUses(SILValue boxValue) {
223223
return false;
224224
continue;
225225
}
226-
226+
if (auto *md = dyn_cast<MarkDependenceInst>(user)) {
227+
// Another value depends on the current in-memory value. Consider that a
228+
// load.
229+
if (md->getBase() == ui->get()) {
230+
Uses.emplace_back(user, PMOUseKind::DependenceBase);
231+
continue;
232+
}
233+
}
227234
// Other uses of the container are considered escapes of the underlying
228235
// value.
229236
//
@@ -457,6 +464,23 @@ bool ElementUseCollector::collectUses(SILValue Pointer) {
457464
if (User->isDebugInstruction())
458465
continue;
459466

467+
if (auto *md = dyn_cast<MarkDependenceInst>(User)) {
468+
if (md->getBase() == UI->get()) {
469+
Uses.emplace_back(User, PMOUseKind::DependenceBase);
470+
continue;
471+
}
472+
SILValue value = md->getValue();
473+
assert(value == UI->get() && "missing mark_dependence use");
474+
// A mark_dependence creates a new dependent value in the same memory
475+
// location. Analogous to a load + init.
476+
Uses.emplace_back(User, PMOUseKind::Load);
477+
Uses.emplace_back(User, PMOUseKind::Initialization);
478+
if (!collectUses(md))
479+
return false;
480+
481+
continue;
482+
}
483+
460484
// Otherwise, the use is something complicated, it escapes.
461485
Uses.emplace_back(User, PMOUseKind::Escape);
462486
}

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ enum PMOUseKind {
122122
/// An indirect 'in' parameter of an Apply instruction.
123123
IndirectIn,
124124

125+
/// The base of a dependence.
126+
DependenceBase,
127+
125128
/// This instruction is a general escape of the value, e.g. a call to a
126129
/// closure that captures it.
127130
Escape,

0 commit comments

Comments
 (0)