Skip to content

Commit c8c9651

Browse files
committed
[EscapeAnalysis] handle value delete notifications.
Needed for malloc/free instruction allocation method.
1 parent 6b244c7 commit c8c9651

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/swift/SILAnalysis/EscapeAnalysis.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ class EscapeAnalysis : public BottomUpIPAnalysis {
499499
/// Propagates the escape states through the graph.
500500
void propagateEscapeStates();
501501

502+
/// Removes a value from the graph.
503+
/// It does not delete its node but makes sure that the value cannot be
504+
/// lookup-up with getNode() anymore.
505+
void removeFromGraph(ValueBase *V) { Values2Nodes.erase(V); }
506+
502507
public:
503508

504509
/// Gets or creates a node for a value \p V.
@@ -719,6 +724,10 @@ class EscapeAnalysis : public BottomUpIPAnalysis {
719724

720725
virtual void invalidate(SILFunction *F, InvalidationKind K);
721726

727+
virtual void handleDeleteNotification(ValueBase *I) override;
728+
729+
virtual bool needsNotifications() override { return true; }
730+
722731
virtual void verify() const {
723732
#ifndef NDEBUG
724733
for (auto Iter : Function2Info) {

lib/SILAnalysis/EscapeAnalysis.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,18 @@ void EscapeAnalysis::invalidate(SILFunction *F, InvalidationKind K) {
15231523
}
15241524
}
15251525

1526+
void EscapeAnalysis::handleDeleteNotification(ValueBase *I) {
1527+
if (SILBasicBlock *Parent = I->getParentBB()) {
1528+
SILFunction *F = Parent->getParent();
1529+
if (FunctionInfo *FInfo = Function2Info.lookup(F)) {
1530+
if (FInfo->isValid()) {
1531+
FInfo->Graph.removeFromGraph(I);
1532+
FInfo->SummaryGraph.removeFromGraph(I);
1533+
}
1534+
}
1535+
}
1536+
}
1537+
15261538
SILAnalysis *swift::createEscapeAnalysis(SILModule *M) {
15271539
return new EscapeAnalysis(M);
15281540
}

0 commit comments

Comments
 (0)