Skip to content

Commit 1bac510

Browse files
committed
[Reduce] Function reduction: replace all users of function with undef
There may be other users of a function other than CallInsts, but what's more important, we can't actually replace function pointer with undef, because for constants, that would not preserve the type and RAUW would assert. In particular, that affects blockaddress, however it proves to be prohibitively complex to come up with a good test involving blockaddress: we'd need to both ensure that the function body survives until this pass, and is not interesting in this pass.
1 parent d127112 commit 1bac510

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
3232
if (O.shouldKeep())
3333
FuncsToKeep.insert(&F);
3434

35-
// Delete out-of-chunk functions, and replace their calls with undef
35+
// Delete out-of-chunk functions, and replace their users with undef
3636
std::vector<Function *> FuncsToRemove;
37-
SetVector<CallInst *> CallsToRemove;
37+
SetVector<Instruction *> InstrsToRemove;
3838
for (auto &F : *Program)
3939
if (!FuncsToKeep.count(&F)) {
40-
for (auto U : F.users())
41-
if (auto *Call = dyn_cast<CallInst>(U)) {
42-
Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
43-
CallsToRemove.insert(Call);
44-
}
45-
F.replaceAllUsesWith(UndefValue::get(F.getType()));
40+
for (auto U : F.users()) {
41+
U->replaceAllUsesWith(UndefValue::get(U->getType()));
42+
if (auto *I = dyn_cast<Instruction>(U))
43+
InstrsToRemove.insert(I);
44+
}
4645
FuncsToRemove.push_back(&F);
4746
}
4847

49-
for (auto *C : CallsToRemove)
50-
C->eraseFromParent();
48+
for (auto *I : InstrsToRemove)
49+
I->eraseFromParent();
5150

5251
for (auto *F : FuncsToRemove)
5352
F->eraseFromParent();

0 commit comments

Comments
 (0)