@@ -41,10 +41,17 @@ struct OwnershipModelEliminatorVisitor
41
41
SILBuilder &B;
42
42
43
43
OwnershipModelEliminatorVisitor (SILBuilder &B) : B(B) {}
44
+ void beforeVisit (ValueBase *V) {
45
+ auto *I = cast<SILInstruction>(V);
46
+ B.setInsertionPoint (I);
47
+ B.setCurrentDebugScope (I->getDebugScope ());
48
+ }
44
49
45
50
bool visitValueBase (ValueBase *V) { return false ; }
46
51
bool visitLoadInst (LoadInst *LI);
47
52
bool visitStoreInst (StoreInst *SI);
53
+ bool visitCopyValueInst (CopyValueInst *CVI);
54
+ bool visitDestroyValueInst (DestroyValueInst *DVI);
48
55
bool visitLoadBorrowInst (LoadBorrowInst *LBI);
49
56
bool visitEndBorrowInst (EndBorrowInst *EBI) {
50
57
EBI->eraseFromParent ();
@@ -64,8 +71,6 @@ bool OwnershipModelEliminatorVisitor::visitLoadInst(LoadInst *LI) {
64
71
65
72
// Otherwise, we need to break down the load inst into its unqualified
66
73
// components.
67
- B.setInsertionPoint (LI);
68
- B.setCurrentDebugScope (LI->getDebugScope ());
69
74
auto *UnqualifiedLoad = B.createLoad (LI->getLoc (), LI->getOperand ());
70
75
71
76
// If we have a copy, insert a retain_value. All other copies do not require
@@ -91,9 +96,6 @@ bool OwnershipModelEliminatorVisitor::visitStoreInst(StoreInst *SI) {
91
96
return false ;
92
97
93
98
// Otherwise, we need to break down the store.
94
- B.setInsertionPoint (SI);
95
- B.setCurrentDebugScope (SI->getDebugScope ());
96
-
97
99
if (Qualifier != StoreOwnershipQualifier::Assign) {
98
100
// If the ownership qualifier is not an assign, we can just emit an
99
101
// unqualified store.
@@ -118,8 +120,6 @@ bool OwnershipModelEliminatorVisitor::visitStoreInst(StoreInst *SI) {
118
120
bool
119
121
OwnershipModelEliminatorVisitor::visitLoadBorrowInst (LoadBorrowInst *LBI) {
120
122
// Break down the load borrow into an unqualified load.
121
- B.setInsertionPoint (LBI);
122
- B.setCurrentDebugScope (LBI->getDebugScope ());
123
123
auto *UnqualifiedLoad = B.createLoad (LBI->getLoc (), LBI->getOperand ());
124
124
125
125
// Then remove the qualified load and use the unqualified load as the def of
@@ -129,6 +129,19 @@ OwnershipModelEliminatorVisitor::visitLoadBorrowInst(LoadBorrowInst *LBI) {
129
129
return true ;
130
130
}
131
131
132
+ bool OwnershipModelEliminatorVisitor::visitCopyValueInst (CopyValueInst *CVI) {
133
+ B.createRetainValue (CVI->getLoc (), CVI->getOperand (), Atomicity::Atomic);
134
+ CVI->replaceAllUsesWith (CVI->getOperand ());
135
+ CVI->eraseFromParent ();
136
+ return true ;
137
+ }
138
+
139
+ bool OwnershipModelEliminatorVisitor::visitDestroyValueInst (DestroyValueInst *DVI) {
140
+ B.createReleaseValue (DVI->getLoc (), DVI->getOperand (), Atomicity::Atomic);
141
+ DVI->eraseFromParent ();
142
+ return true ;
143
+ }
144
+
132
145
// ===----------------------------------------------------------------------===//
133
146
// Top Level Entry Point
134
147
// ===----------------------------------------------------------------------===//
0 commit comments