[PATCH] D111586: [Inline] Make sure the InlineAdvisor is correctly cleared.

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 11 21:26:39 PDT 2021


mtrofin updated this revision to Diff 378869.
mtrofin marked 2 inline comments as done.
mtrofin edited the summary of this revision.
mtrofin added a comment.

feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111586/new/

https://reviews.llvm.org/D111586

Files:
  llvm/include/llvm/Analysis/InlineAdvisor.h
  llvm/lib/Transforms/IPO/Inliner.cpp
  llvm/test/Transforms/Inline/pr52118.ll


Index: llvm/test/Transforms/Inline/pr52118.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/pr52118.ll
@@ -0,0 +1,9 @@
+; Test that the InlineAdvisor, upon being cleared, is re-created correctly.
+; RUN: opt -S -passes="default<O1>,cgscc(inline)" < %s | FileCheck %s
+
+define double @foo() local_unnamed_addr {
+entry:
+  ret double undef
+}
+
+; CHECK: @foo
Index: llvm/lib/Transforms/IPO/Inliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -1048,10 +1048,11 @@
         createDevirtSCCRepeatedPass(std::move(PM), MaxDevirtIterations)));
   MPM.run(M, MAM);
 
-  IAA.clear();
-
-  // The ModulePassManager has already taken care of invalidating analyses.
-  return PreservedAnalyses::all();
+  // Discard the InlineAdvisor, a subsequent inlining session should construct
+  // its own.
+  auto PA = PreservedAnalyses::all();
+  PA.abandon<InlineAdvisorAnalysis>();
+  return PA;
 }
 
 void InlinerPass::printPipeline(
Index: llvm/include/llvm/Analysis/InlineAdvisor.h
===================================================================
--- llvm/include/llvm/Analysis/InlineAdvisor.h
+++ llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -219,15 +219,16 @@
   InlineAdvisorAnalysis() = default;
   struct Result {
     Result(Module &M, ModuleAnalysisManager &MAM) : M(M), MAM(MAM) {}
-    bool invalidate(Module &, const PreservedAnalyses &,
+    bool invalidate(Module &, const PreservedAnalyses &PA,
                     ModuleAnalysisManager::Invalidator &) {
-      // InlineAdvisor must be preserved across analysis invalidations.
-      return false;
+      // Check whether the analysis has been explicitly invalidated. Otherwise,
+      // it's stateless and remains preserved.
+      auto PAC = PA.getChecker<InlineAdvisorAnalysis>();
+      return !PAC.preservedWhenStateless();
     }
     bool tryCreate(InlineParams Params, InliningAdvisorMode Mode,
                    StringRef ReplayFile);
     InlineAdvisor *getAdvisor() const { return Advisor.get(); }
-    void clear() { Advisor.reset(); }
 
   private:
     Module &M;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111586.378869.patch
Type: text/x-patch
Size: 2217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211012/120c248b/attachment.bin>


More information about the llvm-commits mailing list