[llvm] Invalidate analyses after running Attributor in OpenMPOpt (PR #74908)
Ivan R. Ivanov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 11:31:54 PST 2023
https://github.com/ivanradanov updated https://github.com/llvm/llvm-project/pull/74908
>From 6fd90240e1e6d910da983d05a4b00207ad3a084a Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov2 at llnl.gov>
Date: Fri, 8 Dec 2023 17:17:49 -0800
Subject: [PATCH 1/4] Invalidate analyses after running Attributor in OpenMPOpt
Using the LoopInfo from OMPInfoCache after the Attributor ran resulted
in a crash due to it being in an invalid state.
---
llvm/include/llvm/Transforms/IPO/Attributor.h | 8 ++++++++
llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 3 +++
2 files changed, 11 insertions(+)
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;
}
>From a060ec210f1bc97cdcee538cab4f04bc2b3c6a65 Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov2 at llnl.gov>
Date: Fri, 8 Dec 2023 17:37:23 -0800
Subject: [PATCH 2/4] formatting
---
llvm/include/llvm/Transforms/IPO/Attributor.h | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index d46b331f873adb..6cc31ce8c6abb1 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1157,9 +1157,7 @@ struct AnalysisGetter {
return nullptr;
}
- void invalidate() {
- FAM->clear();
- }
+ void invalidate() { FAM->clear(); }
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
: FAM(&FAM), CachedOnly(CachedOnly) {}
@@ -1290,9 +1288,7 @@ struct InformationCache {
return AssumeOnlyValues.contains(&I);
}
- void invalidate() {
- AG.invalidate();
- }
+ void invalidate() { AG.invalidate(); }
/// Return the analysis result from a pass \p AP for function \p F.
template <typename AP>
>From 21049a1cc686382ecf0b688dea984d23437584ab Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov2 at llnl.gov>
Date: Fri, 8 Dec 2023 17:45:37 -0800
Subject: [PATCH 3/4] Change function names
---
llvm/include/llvm/Transforms/IPO/Attributor.h | 4 ++--
llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 6cc31ce8c6abb1..4874b84ca9b90b 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1157,7 +1157,7 @@ struct AnalysisGetter {
return nullptr;
}
- void invalidate() { FAM->clear(); }
+ void invalidateAnalyses() { FAM->clear(); }
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
: FAM(&FAM), CachedOnly(CachedOnly) {}
@@ -1288,7 +1288,7 @@ struct InformationCache {
return AssumeOnlyValues.contains(&I);
}
- void invalidate() { AG.invalidate(); }
+ void invalidateAnalyses() { AG.invalidateAnalyses(); }
/// Return the analysis result from a pass \p AP for function \p F.
template <typename AP>
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 63092f51c13fad..c66f03eefb3dfa 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -2054,7 +2054,7 @@ struct OpenMPOpt {
<< " functions, result: " << Changed << ".\n");
if (Changed == ChangeStatus::CHANGED)
- OMPInfoCache.invalidate();
+ OMPInfoCache.invalidateAnalyses();
return Changed == ChangeStatus::CHANGED;
}
>From fb273fa6d516739dbaade8c14105a8b15c28e9b2 Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov <ivanov2 at llnl.gov>
Date: Mon, 11 Dec 2023 11:31:29 -0800
Subject: [PATCH 4/4] Do not crash when used by legacy pass
---
llvm/include/llvm/Transforms/IPO/Attributor.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 4874b84ca9b90b..ba59852b888c63 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1157,7 +1157,11 @@ struct AnalysisGetter {
return nullptr;
}
- void invalidateAnalyses() { FAM->clear(); }
+ /// Invalidates the analyses. Valid only when using the new pass manager.
+ void invalidateAnalyses() {
+ if (FAM)
+ FAM->clear();
+ }
AnalysisGetter(FunctionAnalysisManager &FAM, bool CachedOnly = false)
: FAM(&FAM), CachedOnly(CachedOnly) {}
@@ -1288,6 +1292,7 @@ struct InformationCache {
return AssumeOnlyValues.contains(&I);
}
+ /// Invalidates the cached analyses.
void invalidateAnalyses() { AG.invalidateAnalyses(); }
/// Return the analysis result from a pass \p AP for function \p F.
More information about the llvm-commits
mailing list