[llvm] 1bac510 - [Reduce] Function reduction: replace all users of function with undef

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 27 05:40:00 PDT 2020


Author: Roman Lebedev
Date: 2020-07-27T15:39:02+03:00
New Revision: 1bac5101cdaabfbc755a6d28936962d11240f932

URL: https://github.com/llvm/llvm-project/commit/1bac5101cdaabfbc755a6d28936962d11240f932
DIFF: https://github.com/llvm/llvm-project/commit/1bac5101cdaabfbc755a6d28936962d11240f932.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
index b29df88261d9..4dd7b98fca3b 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
@@ -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();


        


More information about the llvm-commits mailing list