Skip to content

Commit c3de9c1

Browse files
committed
[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.
1 parent d1033e3 commit c3de9c1

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
29952995
bool &) -> std::optional<Value *> { return nullptr; };
29962996
for (User *U : RFI.Declaration->users())
29972997
if (CallBase *CB = dyn_cast<CallBase>(U)) {
2998+
if (CB->getCaller() != getAnchorScope())
2999+
continue;
29983000
MallocCalls.insert(CB);
29993001
A.registerSimplificationCallback(IRPosition::callsite_returned(*CB),
30003002
SCB);
@@ -3091,6 +3093,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
30913093
}
30923094

30933095
ChangeStatus updateImpl(Attributor &A) override {
3096+
if (MallocCalls.empty())
3097+
return indicatePessimisticFixpoint();
30943098
auto &OMPInfoCache = static_cast<OMPInformationCache &>(A.getInfoCache());
30953099
auto &RFI = OMPInfoCache.RFIs[OMPRTL___kmpc_alloc_shared];
30963100
if (!RFI.Declaration)
@@ -3102,12 +3106,18 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
31023106

31033107
// Only consider malloc calls executed by a single thread with a constant.
31043108
for (User *U : RFI.Declaration->users()) {
3105-
const auto &ED = A.getAAFor<AAExecutionDomain>(
3106-
*this, IRPosition::function(*F), DepClassTy::REQUIRED);
3107-
if (CallBase *CB = dyn_cast<CallBase>(U))
3108-
if (!isa<ConstantInt>(CB->getArgOperand(0)) ||
3109-
!ED.isExecutedByInitialThreadOnly(*CB))
3109+
if (CallBase *CB = dyn_cast<CallBase>(U)) {
3110+
if (CB->getCaller() != F)
3111+
continue;
3112+
if (!isa<ConstantInt>(CB->getArgOperand(0))) {
3113+
MallocCalls.remove(CB);
3114+
continue;
3115+
}
3116+
const auto &ED = A.getAAFor<AAExecutionDomain>(
3117+
*this, IRPosition::function(*F), DepClassTy::REQUIRED);
3118+
if (!ED.isExecutedByInitialThreadOnly(*CB))
31103119
MallocCalls.remove(CB);
3120+
}
31113121
}
31123122

31133123
findPotentialRemovedFreeCalls(A);
@@ -4829,13 +4839,6 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
48294839
GetterRFI.foreachUse(SCC, CreateAA);
48304840
}
48314841
}
4832-
auto &GlobalizationRFI = OMPInfoCache.RFIs[OMPRTL___kmpc_alloc_shared];
4833-
auto CreateAA = [&](Use &U, Function &F) {
4834-
A.getOrCreateAAFor<AAHeapToShared>(IRPosition::function(F));
4835-
return false;
4836-
};
4837-
if (!DisableOpenMPOptDeglobalization)
4838-
GlobalizationRFI.foreachUse(SCC, CreateAA);
48394842

48404843
// Create an ExecutionDomain AA for every function and a HeapToStack AA for
48414844
// every function if there is a device kernel.
@@ -4846,6 +4849,8 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
48464849
if (F->isDeclaration())
48474850
continue;
48484851

4852+
if (!DisableOpenMPOptDeglobalization)
4853+
A.getOrCreateAAFor<AAHeapToShared>(IRPosition::function(F));
48494854
A.getOrCreateAAFor<AAExecutionDomain>(IRPosition::function(*F));
48504855
if (!DisableOpenMPOptDeglobalization)
48514856
A.getOrCreateAAFor<AAHeapToStack>(IRPosition::function(*F));

0 commit comments

Comments
 (0)