[llvm] ebdb6f4 - [MLInliner] Keep track of deleted functions (#97348)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 2 10:41:30 PDT 2024


Author: Arthur Eubanks
Date: 2024-07-02T10:41:26-07:00
New Revision: ebdb6f4ef4ba79eb73589fc96a64ce2c6994935d

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

LOG: [MLInliner] Keep track of deleted functions (#97348)

As opposed to using Node::isDead(), which is no longer accurate after
#94815.

This is only used in diagnostics.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/MLInlineAdvisor.h
    llvm/lib/Analysis/MLInlineAdvisor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/MLInlineAdvisor.h b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
index 2aa077fe0e035..0333f457c1a2d 100644
--- a/llvm/include/llvm/Analysis/MLInlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/MLInlineAdvisor.h
@@ -89,6 +89,7 @@ class MLInlineAdvisor : public InlineAdvisor {
   int32_t CurrentIRSize = 0;
   llvm::SmallPtrSet<const LazyCallGraph::Node *, 1> NodesInLastSCC;
   DenseSet<const LazyCallGraph::Node *> AllNodes;
+  DenseSet<Function *> DeadFunctions;
   bool ForceStop = false;
   ProfileSummaryInfo &PSI;
 };

diff  --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index 652f0d994b29c..8131acb3f0df3 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -311,11 +311,13 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice,
   int64_t NewCallerAndCalleeEdges =
       getCachedFPI(*Caller).DirectCallsToDefinedFunctions;
 
-  if (CalleeWasDeleted)
+  if (CalleeWasDeleted) {
     --NodeCount;
-  else
+    DeadFunctions.insert(Callee);
+  } else {
     NewCallerAndCalleeEdges +=
         getCachedFPI(*Callee).DirectCallsToDefinedFunctions;
+  }
   EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges);
   assert(CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0);
 }
@@ -493,7 +495,9 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
   OS << "\n";
   OS << "[MLInlineAdvisor] FuncLevels:\n";
   for (auto I : FunctionLevels)
-    OS << (I.first->isDead() ? "<deleted>" : I.first->getFunction().getName())
+    OS << (DeadFunctions.contains(&I.first->getFunction())
+               ? "<deleted>"
+               : I.first->getFunction().getName())
        << " : " << I.second << "\n";
 
   OS << "\n";


        


More information about the llvm-commits mailing list