[llvm] c3de9c1 - [OpenMP] Ensure AAHeapToShared is only looking at one function
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 10 15:04:40 PST 2023
Author: Johannes Doerfert
Date: 2023-01-10T15:03:51-08:00
New Revision: c3de9c1c7b93683ab9d390cb2d830204bfa657bc
URL: https://github.com/llvm/llvm-project/commit/c3de9c1c7b93683ab9d390cb2d830204bfa657bc
DIFF: https://github.com/llvm/llvm-project/commit/c3de9c1c7b93683ab9d390cb2d830204bfa657bc.diff
LOG: [OpenMP] Ensure AAHeapToShared is only looking at one function
When we collect and process allocations we did not verify the call
against the anchor scope / associated function. This should be done to
avoid processing calls multiple times and generally looking at calls not
in the AAs scope.
Added:
Modified:
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 1b226c763a9c..eebe8d347cb1 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -2995,6 +2995,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
bool &) -> std::optional<Value *> { return nullptr; };
for (User *U : RFI.Declaration->users())
if (CallBase *CB = dyn_cast<CallBase>(U)) {
+ if (CB->getCaller() != getAnchorScope())
+ continue;
MallocCalls.insert(CB);
A.registerSimplificationCallback(IRPosition::callsite_returned(*CB),
SCB);
@@ -3091,6 +3093,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
}
ChangeStatus updateImpl(Attributor &A) override {
+ if (MallocCalls.empty())
+ return indicatePessimisticFixpoint();
auto &OMPInfoCache = static_cast<OMPInformationCache &>(A.getInfoCache());
auto &RFI = OMPInfoCache.RFIs[OMPRTL___kmpc_alloc_shared];
if (!RFI.Declaration)
@@ -3102,12 +3106,18 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
// Only consider malloc calls executed by a single thread with a constant.
for (User *U : RFI.Declaration->users()) {
- const auto &ED = A.getAAFor<AAExecutionDomain>(
- *this, IRPosition::function(*F), DepClassTy::REQUIRED);
- if (CallBase *CB = dyn_cast<CallBase>(U))
- if (!isa<ConstantInt>(CB->getArgOperand(0)) ||
- !ED.isExecutedByInitialThreadOnly(*CB))
+ if (CallBase *CB = dyn_cast<CallBase>(U)) {
+ if (CB->getCaller() != F)
+ continue;
+ if (!isa<ConstantInt>(CB->getArgOperand(0))) {
+ MallocCalls.remove(CB);
+ continue;
+ }
+ const auto &ED = A.getAAFor<AAExecutionDomain>(
+ *this, IRPosition::function(*F), DepClassTy::REQUIRED);
+ if (!ED.isExecutedByInitialThreadOnly(*CB))
MallocCalls.remove(CB);
+ }
}
findPotentialRemovedFreeCalls(A);
@@ -4829,13 +4839,6 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
GetterRFI.foreachUse(SCC, CreateAA);
}
}
- auto &GlobalizationRFI = OMPInfoCache.RFIs[OMPRTL___kmpc_alloc_shared];
- auto CreateAA = [&](Use &U, Function &F) {
- A.getOrCreateAAFor<AAHeapToShared>(IRPosition::function(F));
- return false;
- };
- if (!DisableOpenMPOptDeglobalization)
- GlobalizationRFI.foreachUse(SCC, CreateAA);
// Create an ExecutionDomain AA for every function and a HeapToStack AA for
// every function if there is a device kernel.
@@ -4846,6 +4849,8 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
if (F->isDeclaration())
continue;
+ if (!DisableOpenMPOptDeglobalization)
+ A.getOrCreateAAFor<AAHeapToShared>(IRPosition::function(F));
A.getOrCreateAAFor<AAExecutionDomain>(IRPosition::function(*F));
if (!DisableOpenMPOptDeglobalization)
A.getOrCreateAAFor<AAHeapToStack>(IRPosition::function(*F));
More information about the llvm-commits
mailing list