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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 1 14:07:31 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-analysis

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

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

This is only used in diagnostics.

---
Full diff: https://github.com/llvm/llvm-project/pull/97348.diff


2 Files Affected:

- (modified) llvm/include/llvm/Analysis/MLInlineAdvisor.h (+1) 
- (modified) llvm/lib/Analysis/MLInlineAdvisor.cpp (+7-3) 


``````````diff
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";

``````````

</details>


https://github.com/llvm/llvm-project/pull/97348


More information about the llvm-commits mailing list