[llvm] [OpenMPOpt] Null generic-mode wrappers for SPMDized kernels (PR #207611)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 07:39:56 PDT 2026
================
@@ -2250,6 +2268,47 @@ bool OpenMPOpt::rewriteDeviceCodeStateMachine() {
return Changed;
}
+bool OpenMPOpt::removeSPMDParallelWrappers() {
+ // Nothing to clean up unless we SPMD-ized at least one kernel.
+ if (OMPInfoCache.SPMDizedKernels.empty())
+ return false;
+
+ OMPInformationCache::RuntimeFunctionInfo &KernelParallelRFI =
+ OMPInfoCache.RFIs[OMPRTL___kmpc_parallel_60];
+ if (!KernelParallelRFI || !KernelParallelRFI.Declaration)
+ return false;
+
+ const unsigned WrapperFunctionArgNo = 6;
+ bool Changed = false;
+ for (User *U : KernelParallelRFI.Declaration->users()) {
+ auto *CI = dyn_cast<CallInst>(U);
+ if (!CI || CI->getCalledOperand() != KernelParallelRFI.Declaration ||
+ CI->arg_size() <= WrapperFunctionArgNo)
+ continue;
+
+ Value *Wrapper = CI->getArgOperand(WrapperFunctionArgNo);
+ if (isa<ConstantPointerNull>(Wrapper))
+ continue;
+
+ // Only drop the wrapper for a parallel region reached from a single kernel
+ // that we transformed to SPMD mode. A region also reachable from a
+ // generic-mode kernel still needs its wrapper for that kernel's state
+ // machine, and getUniqueKernelFor conservatively bails on such shared
+ // regions. (Mirrors the unique-kernel requirement in
+ // rewriteDeviceCodeStateMachine.)
+ Kernel K = getUniqueKernelFor(*CI->getFunction());
+ if (!K || !OMPInfoCache.SPMDizedKernels.contains(K))
+ continue;
+
+ CI->setArgOperand(
+ WrapperFunctionArgNo,
+ ConstantPointerNull::get(cast<PointerType>(Wrapper->getType())));
----------------
shiltian wrote:
Does it make more sense to do this when a kernel is SPMDized instead of a late update?
https://github.com/llvm/llvm-project/pull/207611
More information about the llvm-commits
mailing list