Skip to content

Commit ff5b9ad

Browse files
authored
Merge pull request swiftlang#22210 from gottesmm/pr-c053be8563b434e2b87534db96989cba4884fe3c
2 parents d072ceb + 41aedaa commit ff5b9ad

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,19 +1317,22 @@ void LoadableStorageAllocation::allocateLoadableStorage() {
13171317
SILArgument *LoadableStorageAllocation::replaceArgType(SILBuilder &argBuilder,
13181318
SILArgument *arg,
13191319
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+
}
13231325

1324-
arg->replaceAllUsesWith(copyArg);
1326+
// Make sure that this is an argument we want to replace.
13251327
assert(std::find(pass.largeLoadableArgs.begin(), pass.largeLoadableArgs.end(),
13261328
arg) == pass.largeLoadableArgs.end());
13271329

13281330
arg = arg->getParent()->replaceFunctionArgument(
13291331
arg->getIndex(), newSILType, ValueOwnershipKind::Any, arg->getDecl());
13301332

1331-
copyArg->replaceAllUsesWith(arg);
1332-
copyArg->eraseFromParent();
1333+
for (auto *use : useList) {
1334+
use->set(arg);
1335+
}
13331336

13341337
return arg;
13351338
}
@@ -1384,16 +1387,17 @@ void LoadableStorageAllocation::convertIndirectFunctionArgs() {
13841387

13851388
static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
13861389
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+
}
13901395

1391-
arg->replaceAllUsesWith(copyArg);
13921396
arg = arg->getParent()->replacePhiArgument(arg->getIndex(), newSILType,
13931397
arg->getOwnershipKind());
1394-
1395-
copyArg->replaceAllUsesWith(arg);
1396-
copyArg->eraseFromParent();
1398+
for (auto *use : useList) {
1399+
use->set(arg);
1400+
}
13971401
}
13981402

13991403
void LoadableStorageAllocation::convertApplyResults() {

0 commit comments

Comments
 (0)