@@ -147,67 +147,8 @@ bool swift::canCloneTerminator(TermInst *termInst) {
147
147
return true ;
148
148
}
149
149
150
- // / Given a terminator result, either from the original or the cloned block,
151
- // / update OSSA for any phis created for the result during edge splitting.
152
- void BasicBlockCloner::updateOSSATerminatorResult (SILPhiArgument *termResult) {
153
- assert (termResult->isTerminatorResult () && " precondition" );
154
-
155
- // If the terminator result is used by a phi, then it is invalid OSSA
156
- // which was created by edge splitting.
157
- for (Operand *termUse : termResult->getUses ()) {
158
- if (auto phiOper = PhiOperand (termUse)) {
159
- createBorrowScopeForPhiOperands (phiOper.getValue ());
160
- }
161
- }
162
- }
163
-
164
- // Cloning does not invalidate ownership lifetime. When it clones values, it
165
- // also either clones the consumes, or creates the necessary phis that consume
166
- // the new values on all paths. However, cloning may create new phis of
167
- // inner guaranteed values. Since phis are reborrows, they are only allowed to
168
- // use BorrowedValues. Therefore, we must create nested borrow scopes for any
169
- // new phis whose arguments aren't BorrowedValues. Note that other newly created
170
- // phis are themselves BorrowedValues, so only one level of nested borrow is
171
- // needed per value, per new phi that the value reaches.
172
- void BasicBlockCloner::updateOSSAAfterCloning () {
150
+ void BasicBlockCloner::updateSSAAfterCloning () {
173
151
SmallVector<SILPhiArgument *, 4 > updateSSAPhis;
174
- if (!origBB->getParent ()->hasOwnership ()) {
175
- updateSSAAfterCloning (updateSSAPhis);
176
- return ;
177
- }
178
-
179
- // If the original basic block has terminator results, then all phis in the
180
- // exit blocks are new phis that used to be terminator results.
181
- //
182
- // Create nested borrow scopes for terminator results that were converted to
183
- // phis during edge splitting. This is simpler to check before SSA update.
184
- //
185
- // This assumes that the phis introduced by update-SSA below cannot be users
186
- // of the phis that were created in exitBBs during block cloning. Otherwise
187
- // borrowPhiArguments would handle them twice.
188
- auto *termInst = origBB->getTerminator ();
189
- // FIXME: cond_br args should not exist in OSSA
190
- if (!isa<BranchInst>(termInst) && !isa<CondBranchInst>(termInst)) {
191
- // Update all of the terminator results.
192
- for (auto *succBB : origBB->getSuccessorBlocks ()) {
193
- for (SILArgument *termResult : succBB->getArguments ()) {
194
- updateOSSATerminatorResult (cast<SILPhiArgument>(termResult));
195
- }
196
- }
197
- }
198
-
199
- // Update SSA form before calling OSSA update utilities to maintain a layering
200
- // of SIL invariants.
201
- updateSSAAfterCloning (updateSSAPhis);
202
-
203
- // Create nested borrow scopes for phis created during SSA update.
204
- for (auto *phi : updateSSAPhis) {
205
- createBorrowScopeForPhiOperands (phi);
206
- }
207
- }
208
-
209
- void BasicBlockCloner::updateSSAAfterCloning (
210
- SmallVectorImpl<SILPhiArgument *> &newPhis) {
211
152
// All instructions should have been checked by canCloneInstruction. But we
212
153
// still need to check the arguments.
213
154
for (auto arg : origBB->getArguments ()) {
@@ -218,7 +159,7 @@ void BasicBlockCloner::updateSSAAfterCloning(
218
159
if (!needsSSAUpdate)
219
160
return ;
220
161
221
- SILSSAUpdater ssaUpdater (&newPhis );
162
+ SILSSAUpdater ssaUpdater (&updateSSAPhis );
222
163
for (auto availValPair : availVals) {
223
164
auto inst = availValPair.first ;
224
165
if (inst->use_empty ())
0 commit comments