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);
}
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)
// 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);
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.
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));