@@ -87,6 +87,62 @@ bool swift::isOwnershipForwardingInst(SILInstruction *i) {
87
87
return isOwnershipForwardingValueKind (SILNodeKind (i->getKind ()));
88
88
}
89
89
90
+ // ===----------------------------------------------------------------------===//
91
+ // Borrow Scope Operand
92
+ // ===----------------------------------------------------------------------===//
93
+
94
+ void BorrowScopeOperandKind::print (llvm::raw_ostream &os) const {
95
+ switch (value) {
96
+ case Kind::BeginBorrow:
97
+ os << " BeginBorrow" ;
98
+ return ;
99
+ case Kind::BeginApply:
100
+ os << " BeginApply" ;
101
+ return ;
102
+ }
103
+ llvm_unreachable (" Covered switch isn't covered?!" );
104
+ }
105
+
106
+ llvm::raw_ostream &swift::operator <<(llvm::raw_ostream &os,
107
+ BorrowScopeOperandKind kind) {
108
+ kind.print (os);
109
+ return os;
110
+ }
111
+
112
+ void BorrowScopeOperand::print (llvm::raw_ostream &os) const {
113
+ os << " BorrowScopeOperand:\n "
114
+ " Kind: " << kind << " \n "
115
+ " Value: " << op->get ()
116
+ << " User: " << op->getUser ();
117
+ }
118
+
119
+ llvm::raw_ostream &swift::operator <<(llvm::raw_ostream &os,
120
+ const BorrowScopeOperand &operand) {
121
+ operand.print (os);
122
+ return os;
123
+ }
124
+
125
+ void BorrowScopeOperand::visitEndScopeInstructions (
126
+ function_ref<void (Operand *)> func) const {
127
+ switch (kind) {
128
+ case BorrowScopeOperandKind::BeginBorrow:
129
+ for (auto *use : cast<BeginBorrowInst>(op->getUser ())->getUses ()) {
130
+ if (isa<EndBorrowInst>(use->getUser ())) {
131
+ func (use);
132
+ }
133
+ }
134
+ return ;
135
+ case BorrowScopeOperandKind::BeginApply: {
136
+ auto *user = cast<BeginApplyInst>(op->getUser ());
137
+ for (auto *use : user->getTokenResult ()->getUses ()) {
138
+ func (use);
139
+ }
140
+ return ;
141
+ }
142
+ }
143
+ llvm_unreachable (" Covered switch isn't covered" );
144
+ }
145
+
90
146
// ===----------------------------------------------------------------------===//
91
147
// Borrow Introducers
92
148
// ===----------------------------------------------------------------------===//
@@ -106,10 +162,10 @@ void BorrowScopeIntroducingValueKind::print(llvm::raw_ostream &os) const {
106
162
llvm_unreachable (" Covered switch isn't covered?!" );
107
163
}
108
164
109
- void BorrowScopeIntroducingValueKind::dump ( ) const {
110
- # ifndef NDEBUG
111
- print ( llvm::dbgs ());
112
- # endif
165
+ void BorrowScopeIntroducingValue::print (llvm::raw_ostream &os ) const {
166
+ os << " BorrowScopeIntroducingValue: \n "
167
+ " Kind: " << kind << " \n "
168
+ " Value: " << value;
113
169
}
114
170
115
171
void BorrowScopeIntroducingValue::getLocalScopeEndingInstructions (
@@ -120,12 +176,12 @@ void BorrowScopeIntroducingValue::getLocalScopeEndingInstructions(
120
176
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
121
177
llvm_unreachable (" Should only call this with a local scope" );
122
178
case BorrowScopeIntroducingValueKind::BeginBorrow:
123
- llvm::copy (cast<BeginBorrowInst>(value)->getEndBorrows (),
124
- std::back_inserter (scopeEndingInsts));
125
- return ;
126
179
case BorrowScopeIntroducingValueKind::LoadBorrow:
127
- llvm::copy (cast<LoadBorrowInst>(value)->getEndBorrows (),
128
- std::back_inserter (scopeEndingInsts));
180
+ for (auto *use : value->getUses ()) {
181
+ if (use->isConsumingUse ()) {
182
+ scopeEndingInsts.push_back (use->getUser ());
183
+ }
184
+ }
129
185
return ;
130
186
}
131
187
llvm_unreachable (" Covered switch isn't covered?!" );
@@ -137,16 +193,10 @@ void BorrowScopeIntroducingValue::visitLocalScopeEndingUses(
137
193
switch (kind) {
138
194
case BorrowScopeIntroducingValueKind::SILFunctionArgument:
139
195
llvm_unreachable (" Should only call this with a local scope" );
140
- case BorrowScopeIntroducingValueKind::BeginBorrow:
141
- for (auto *use : value->getUses ()) {
142
- if (isa<EndBorrowInst>(use->getUser ())) {
143
- visitor (use);
144
- }
145
- }
146
- return ;
147
196
case BorrowScopeIntroducingValueKind::LoadBorrow:
197
+ case BorrowScopeIntroducingValueKind::BeginBorrow:
148
198
for (auto *use : value->getUses ()) {
149
- if (isa<EndBorrowInst>( use->getUser () )) {
199
+ if (use->isConsumingUse ( )) {
150
200
visitor (use);
151
201
}
152
202
}
@@ -212,6 +262,12 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
212
262
return os;
213
263
}
214
264
265
+ llvm::raw_ostream &swift::operator <<(llvm::raw_ostream &os,
266
+ const BorrowScopeIntroducingValue &value) {
267
+ value.print (os);
268
+ return os;
269
+ }
270
+
215
271
bool BorrowScopeIntroducingValue::areInstructionsWithinScope (
216
272
ArrayRef<SILInstruction *> instructions,
217
273
SmallVectorImpl<SILInstruction *> &scratchSpace,
0 commit comments