@@ -1317,19 +1317,22 @@ void LoadableStorageAllocation::allocateLoadableStorage() {
1317
1317
SILArgument *LoadableStorageAllocation::replaceArgType (SILBuilder &argBuilder,
1318
1318
SILArgument *arg,
1319
1319
SILType newSILType) {
1320
- CopyValueInst *copyArg = argBuilder.createCopyValue (
1321
- RegularLocation (const_cast <ValueDecl *>(arg->getDecl ())),
1322
- SILUndef::get (newSILType, pass.F ->getModule ()));
1320
+ SILValue undef = SILUndef::get (newSILType, pass.F ->getModule ());
1321
+ SmallVector<Operand *, 8 > useList (arg->use_begin (), arg->use_end ());
1322
+ for (auto *use : useList) {
1323
+ use->set (undef);
1324
+ }
1323
1325
1324
- arg-> replaceAllUsesWith (copyArg);
1326
+ // Make sure that this is an argument we want to replace.
1325
1327
assert (std::find (pass.largeLoadableArgs .begin (), pass.largeLoadableArgs .end (),
1326
1328
arg) == pass.largeLoadableArgs .end ());
1327
1329
1328
1330
arg = arg->getParent ()->replaceFunctionArgument (
1329
1331
arg->getIndex (), newSILType, ValueOwnershipKind::Any, arg->getDecl ());
1330
1332
1331
- copyArg->replaceAllUsesWith (arg);
1332
- copyArg->eraseFromParent ();
1333
+ for (auto *use : useList) {
1334
+ use->set (arg);
1335
+ }
1333
1336
1334
1337
return arg;
1335
1338
}
@@ -1384,16 +1387,17 @@ void LoadableStorageAllocation::convertIndirectFunctionArgs() {
1384
1387
1385
1388
static void convertBBArgType (SILBuilder &argBuilder, SILType newSILType,
1386
1389
SILArgument *arg) {
1387
- CopyValueInst *copyArg = argBuilder.createCopyValue (
1388
- RegularLocation (const_cast <ValueDecl *>(arg->getDecl ())),
1389
- SILUndef::get (newSILType, arg->getFunction ()->getModule ()));
1390
+ SILValue undef = SILUndef::get (newSILType, argBuilder.getModule ());
1391
+ SmallVector<Operand *, 8 > useList (arg->use_begin (), arg->use_end ());
1392
+ for (auto *use : useList) {
1393
+ use->set (undef);
1394
+ }
1390
1395
1391
- arg->replaceAllUsesWith (copyArg);
1392
1396
arg = arg->getParent ()->replacePhiArgument (arg->getIndex (), newSILType,
1393
1397
arg->getOwnershipKind ());
1394
-
1395
- copyArg-> replaceAllUsesWith (arg);
1396
- copyArg-> eraseFromParent ();
1398
+ for ( auto *use : useList) {
1399
+ use-> set (arg);
1400
+ }
1397
1401
}
1398
1402
1399
1403
void LoadableStorageAllocation::convertApplyResults () {
0 commit comments