[llvm] cb0ecc5 - [CallGraphUpdater] Remove dead constants before replacing a function
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 21:03:48 PDT 2020
Author: Johannes Doerfert
Date: 2020-04-08T22:52:46-05:00
New Revision: cb0ecc5c33bd56a3eed0fa30ac787accec45d637
URL: https://github.com/llvm/llvm-project/commit/cb0ecc5c33bd56a3eed0fa30ac787accec45d637
DIFF: https://github.com/llvm/llvm-project/commit/cb0ecc5c33bd56a3eed0fa30ac787accec45d637.diff
LOG: [CallGraphUpdater] Remove dead constants before replacing a function
Dead constants might be left when a function is replaced, we can
gracefully handle this case and avoid complexity for the users who would
see an assertion otherwise.
Added:
Modified:
llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
index a7a214d5b519..4de7124a0dff 100644
--- a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
@@ -106,6 +106,7 @@ void CallGraphUpdater::removeFunction(Function &DeadFn) {
}
void CallGraphUpdater::replaceFunctionWith(Function &OldFn, Function &NewFn) {
+ OldFn.removeDeadConstantUsers();
ReplacedFunctions.insert(&OldFn);
if (CG) {
// Update the call graph for the newly promoted function.
diff --git a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
index 0ed3ca353507..1930b7a882c3 100644
--- a/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
+++ b/llvm/unittests/Analysis/CGSCCPassManagerTest.cpp
@@ -1608,6 +1608,10 @@ TEST_F(CGSCCPassManagerTest, TestUpdateCGAndAnalysisManagerForPasses8) {
FnF->getEntryBlock().front().moveBefore(RI);
ASSERT_NE(FnF, nullptr);
+ // Create an unsused constant that is referencing the old (=replaced)
+ // function.
+ ConstantExpr::getBitCast(FnF, Type::getInt8PtrTy(FnF->getContext()));
+
// Use the CallGraphUpdater to update the call graph.
CallGraphUpdater CGU;
CGU.initialize(CG, C, AM, UR);
More information about the llvm-commits
mailing list