1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[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.
This commit is contained in:
Roman Lebedev 2020-07-27 13:30:39 +03:00
parent 0c0782b95f
commit 49caf4bfe4

View File

@ -32,22 +32,21 @@ static void extractFunctionsFromModule(const std::vector<Chunk> &ChunksToKeep,
if (O.shouldKeep())
FuncsToKeep.insert(&F);
// Delete out-of-chunk functions, and replace their calls with undef
// Delete out-of-chunk functions, and replace their users with undef
std::vector<Function *> FuncsToRemove;
SetVector<CallInst *> CallsToRemove;
SetVector<Instruction *> InstrsToRemove;
for (auto &F : *Program)
if (!FuncsToKeep.count(&F)) {
for (auto U : F.users())
if (auto *Call = dyn_cast<CallInst>(U)) {
Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
CallsToRemove.insert(Call);
}
F.replaceAllUsesWith(UndefValue::get(F.getType()));
for (auto U : F.users()) {
U->replaceAllUsesWith(UndefValue::get(U->getType()));
if (auto *I = dyn_cast<Instruction>(U))
InstrsToRemove.insert(I);
}
FuncsToRemove.push_back(&F);
}
for (auto *C : CallsToRemove)
C->eraseFromParent();
for (auto *I : InstrsToRemove)
I->eraseFromParent();
for (auto *F : FuncsToRemove)
F->eraseFromParent();