llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-flang-openmp Author: Sergio Afonso (skatrak) <details> <summary>Changes</summary> This patch adds codegen for `kmpc_dist_for_static_init` runtime calls, used to support worksharing a single loop across teams and threads. This can be used to implement `distribute parallel for/do` support. --- Full diff: https://github.com/llvm/llvm-project/pull/127818.diff 1 Files Affected: - (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+30-4) ``````````diff diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index 9e380bf2d3dbe..7788897fc0795 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -4130,6 +4130,23 @@ Expected<CanonicalLoopInfo *> OpenMPIRBuilder::createCanonicalLoop( return createCanonicalLoop(LoopLoc, BodyGen, TripCount, Name); } +// Returns an LLVM function to call for initializing loop bounds using OpenMP +// static scheduling for composite `distribute parallel for` depending on +// `type`. Only i32 and i64 are supported by the runtime. Always interpret +// integers as unsigned similarly to CanonicalLoopInfo. +static FunctionCallee +getKmpcDistForStaticInitForType(Type *Ty, Module &M, + OpenMPIRBuilder &OMPBuilder) { + unsigned Bitwidth = Ty->getIntegerBitWidth(); + if (Bitwidth == 32) + return OMPBuilder.getOrCreateRuntimeFunction( + M, omp::RuntimeFunction::OMPRTL___kmpc_dist_for_static_init_4u); + if (Bitwidth == 64) + return OMPBuilder.getOrCreateRuntimeFunction( + M, omp::RuntimeFunction::OMPRTL___kmpc_dist_for_static_init_8u); + llvm_unreachable("unknown OpenMP loop iterator bitwidth"); +} + // Returns an LLVM function to call for initializing loop bounds using OpenMP // static scheduling depending on `type`. Only i32 and i64 are supported by the // runtime. Always interpret integers as unsigned similarly to @@ -4164,7 +4181,10 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop( // Declare useful OpenMP runtime functions. Value *IV = CLI->getIndVar(); Type *IVTy = IV->getType(); - FunctionCallee StaticInit = getKmpcForStaticInitForType(IVTy, M, *this); + FunctionCallee StaticInit = + LoopType == WorksharingLoopType::DistributeForStaticLoop + ? getKmpcDistForStaticInitForType(IVTy, M, *this) + : getKmpcForStaticInitForType(IVTy, M, *this); FunctionCallee StaticFini = getOrCreateRuntimeFunction(M, omp::OMPRTL___kmpc_for_static_fini); @@ -4200,9 +4220,15 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::applyStaticWorkshareLoop( // Call the "init" function and update the trip count of the loop with the // value it produced. - Builder.CreateCall(StaticInit, - {SrcLoc, ThreadNum, SchedulingType, PLastIter, PLowerBound, - PUpperBound, PStride, One, Zero}); + SmallVector<Value *, 10> Args( + {SrcLoc, ThreadNum, SchedulingType, PLastIter, PLowerBound, PUpperBound}); + if (LoopType == WorksharingLoopType::DistributeForStaticLoop) { + Value *PDistUpperBound = + Builder.CreateAlloca(IVTy, nullptr, "p.distupperbound"); + Args.push_back(PDistUpperBound); + } + Args.append({PStride, One, Zero}); + Builder.CreateCall(StaticInit, Args); Value *LowerBound = Builder.CreateLoad(IVTy, PLowerBound); Value *InclusiveUpperBound = Builder.CreateLoad(IVTy, PUpperBound); Value *TripCountMinusOne = Builder.CreateSub(InclusiveUpperBound, LowerBound); `````````` </details> https://github.com/llvm/llvm-project/pull/127818 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits