Skip to content

Commit 9233217

Browse files
committed
[ValueHandle] Allow invalidation of BB arguments.
This commit changes the invalidation handler from SILInstruction to ValueBase, and also invalidates SILArguments.
1 parent 881b2b4 commit 9233217

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

include/swift/SIL/Notifications.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace swift {
1717

1818
class ValueBase;
1919

20-
/// A protocol (or inferface) for handling instruction deletion notifications.
20+
/// A protocol (or inferface) for handling value deletion notifications.
2121
///
2222
/// This class is used as a base class for any class that need to accept
2323
/// instruction deletion notification messages. This is used by passes and

include/swift/SILAnalysis/AliasAnalysis.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class AliasAnalysis : public SILAnalysis {
8383
bool typesMayAlias(SILType T1, SILType T2);
8484

8585

86-
virtual void handleDeleteNotification(ValueBase *I) override {
87-
}
86+
virtual void handleDeleteNotification(ValueBase *I) override { }
8887

8988
public:
9089
AliasAnalysis(SILModule *M) :

lib/SIL/SILBasicBlock.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ SILBasicBlock::~SILBasicBlock() {
4343
getModule().notifyDeleteHandlers(&*I);
4444
}
4545

46+
// Invalidate all of the basic block arguments.
47+
for (auto *Arg : BBArgList) {
48+
getModule().notifyDeleteHandlers(Arg);
49+
}
50+
4651
// iplist's destructor is going to destroy the InstList.
4752
}
4853

@@ -100,10 +105,18 @@ void SILBasicBlock::removeFromParent() {
100105
SILArgument *SILBasicBlock::replaceBBArg(unsigned i, SILType Ty,
101106
const ValueDecl *D) {
102107
SILModule &M = getParent()->getModule();
108+
109+
103110
assert(BBArgList[i]->use_empty() && "Expected no uses of the old BB arg!");
104111

112+
// Notify the delete handlers that this argument is being deleted.
113+
M.notifyDeleteHandlers(BBArgList[i]);
114+
105115
auto *NewArg = new (M) SILArgument(Ty, D);
106116
NewArg->setParent(this);
117+
118+
// TODO: When we switch to malloc/free allocation we'll be leaking memory
119+
// here.
107120
BBArgList[i] = NewArg;
108121

109122
return NewArg;

lib/SIL/SILModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ removeDeleteNotificationHandler(DeleteNotificationHandler* Handler) {
676676
NotificationHandlers.remove(Handler);
677677
}
678678

679-
void SILModule::notifyDeleteHandlers(ValueBase *Item) {
679+
void SILModule::notifyDeleteHandlers(ValueBase *V) {
680680
for (auto *Handler : NotificationHandlers) {
681-
Handler->handleDeleteNotification(Item);
681+
Handler->handleDeleteNotification(V);
682682
}
683683
}

lib/SILPasses/SILCombiner/SILCombine.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ class SILCombine : public SILFunctionTransform {
355355
}
356356
}
357357

358-
virtual void handleDeleteNotification(ValueBase *I) override {
359-
}
358+
virtual void handleDeleteNotification(ValueBase *I) override { }
360359

361360
StringRef getName() override { return "SIL Combine"; }
362361
};

0 commit comments

Comments
 (0)