@@ -2995,6 +2995,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
2995
2995
bool &) -> std::optional<Value *> { return nullptr ; };
2996
2996
for (User *U : RFI.Declaration ->users ())
2997
2997
if (CallBase *CB = dyn_cast<CallBase>(U)) {
2998
+ if (CB->getCaller () != getAnchorScope ())
2999
+ continue ;
2998
3000
MallocCalls.insert (CB);
2999
3001
A.registerSimplificationCallback (IRPosition::callsite_returned (*CB),
3000
3002
SCB);
@@ -3091,6 +3093,8 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
3091
3093
}
3092
3094
3093
3095
ChangeStatus updateImpl (Attributor &A) override {
3096
+ if (MallocCalls.empty ())
3097
+ return indicatePessimisticFixpoint ();
3094
3098
auto &OMPInfoCache = static_cast <OMPInformationCache &>(A.getInfoCache ());
3095
3099
auto &RFI = OMPInfoCache.RFIs [OMPRTL___kmpc_alloc_shared];
3096
3100
if (!RFI.Declaration )
@@ -3102,12 +3106,18 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
3102
3106
3103
3107
// Only consider malloc calls executed by a single thread with a constant.
3104
3108
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))
3110
3119
MallocCalls.remove (CB);
3120
+ }
3111
3121
}
3112
3122
3113
3123
findPotentialRemovedFreeCalls (A);
@@ -4829,13 +4839,6 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
4829
4839
GetterRFI.foreachUse (SCC, CreateAA);
4830
4840
}
4831
4841
}
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);
4839
4842
4840
4843
// Create an ExecutionDomain AA for every function and a HeapToStack AA for
4841
4844
// every function if there is a device kernel.
@@ -4846,6 +4849,8 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
4846
4849
if (F->isDeclaration ())
4847
4850
continue ;
4848
4851
4852
+ if (!DisableOpenMPOptDeglobalization)
4853
+ A.getOrCreateAAFor <AAHeapToShared>(IRPosition::function (F));
4849
4854
A.getOrCreateAAFor <AAExecutionDomain>(IRPosition::function (*F));
4850
4855
if (!DisableOpenMPOptDeglobalization)
4851
4856
A.getOrCreateAAFor <AAHeapToStack>(IRPosition::function (*F));
0 commit comments