[llvm] Invalidate analyses after running Attributor in OpenMPOpt (PR #74908)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 17:32:18 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Ivan R. Ivanov (ivanradanov)

<details>
<summary>Changes</summary>

Using the LoopInfo from OMPInfoCache after the Attributor ran resulted in a crash due to it being in an invalid state.

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


2 Files Affected:

- (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+8) 
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+3) 


``````````diff
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 97b18e51beeeeb..d46b331f873adb 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1157,6 +1157,10 @@ struct AnalysisGetter {
     return nullptr;
   }
 
+  void invalidate() {
+    FAM->clear();
+  }
+
   AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
       : FAM(&FAM), CachedOnly(CachedOnly) {}
   AnalysisGetter(Pass *P, bool CachedOnly = false)
@@ -1286,6 +1290,10 @@ struct InformationCache {
     return AssumeOnlyValues.contains(&I);
   }
 
+  void invalidate() {
+    AG.invalidate();
+  }
+
   /// Return the analysis result from a pass \p AP for function \p F.
   template <typename AP>
   typename AP::Result *getAnalysisResultForFunction(const Function &F,
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index b2665161c090df..63092f51c13fad 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -2053,6 +2053,9 @@ struct OpenMPOpt {
     LLVM_DEBUG(dbgs() << "[Attributor] Done with " << SCC.size()
                       << " functions, result: " << Changed << ".\n");
 
+    if (Changed == ChangeStatus::CHANGED)
+      OMPInfoCache.invalidate();
+
     return Changed == ChangeStatus::CHANGED;
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list