Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6363,13 +6363,23 @@ void CGOpenMPRuntime::emitTaskwaitCall(CodeGenFunction &CGF, SourceLocation Loc) { - if (!CGF.HaveInsertPoint()) - return; - // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 - // global_tid); - llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; - // Ignore return result until untied tasks are supported. - CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskwait), Args); + llvm::OpenMPIRBuilder *OMPBuilder = CGF.CGM.getOpenMPIRBuilder(); + + if (OMPBuilder) { + auto IP = OMPBuilder->CreateTaskwait(CGF.Builder); + if (!IP.getBlock()) + return; + CGF.Builder.restoreIP(IP); + } else { + if (!CGF.HaveInsertPoint()) + return; + // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 + // global_tid); + llvm::Value *Args[] = {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc)}; + // Ignore return result until untied tasks are supported. + CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskwait), Args); + } + if (auto *Region = dyn_cast_or_null(CGF.CapturedStmtInfo)) Region->emitUntiedSwitch(CGF); } Index: llvm/include/llvm/Frontend/OpenMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMPIRBuilder.h @@ -73,6 +73,13 @@ bool ForceSimpleCall = false, bool CheckCancelFlag = true); + /// Generator for '#omp taskwait' + /// + /// \param Loc The location where the taskwait directive was encountered. + /// + /// \returns The insertion point after the barrier. + InsertPointTy CreateTaskwait(const LocationDescription& Loc); + ///} private: @@ -112,6 +119,13 @@ omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag); + /// Generate a taskwait runtime call. + /// + /// \param Loc The location at which the request originated and is fulfilled. + /// + /// \returns The insertion point after the barrier. + InsertPointTy emitTaskwaitImpl(const LocationDescription &Loc); + /// Return the current thread ID. /// /// \param Ident The ident (ident_t*) describing the query origin. Index: llvm/include/llvm/Frontend/OpenMPKinds.def =================================================================== --- llvm/include/llvm/Frontend/OpenMPKinds.def +++ llvm/include/llvm/Frontend/OpenMPKinds.def @@ -167,6 +167,7 @@ __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr) __OMP_RTL(__kmpc_fork_call, true, Void, IdentPtr, Int32, ParallelTaskPtr) __OMP_RTL(omp_get_thread_num, false, Int32, ) +__OMP_RTL(__kmpc_omp_taskwait, false, Int32, IdentPtr, Int32) #undef __OMP_RTL #undef OMP_RTL Index: llvm/lib/Frontend/OpenMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMPIRBuilder.cpp @@ -254,3 +254,25 @@ return Builder.saveIP(); } + +OpenMPIRBuilder::InsertPointTy +OpenMPIRBuilder::emitTaskwaitImpl(const LocationDescription &Loc) { + // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 + // global_tid); + Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); + Value *Ident = getOrCreateIdent(SrcLocStr); + Value *Args[] = {Ident, getOrCreateThreadID(Ident)}; + + // Ignore return result until untied tasks are supported. + Builder.CreateCall(getOrCreateRuntimeFunction(OMPRTL___kmpc_omp_taskwait), + Args); + + return Builder.saveIP(); +} + +OpenMPIRBuilder::InsertPointTy +OpenMPIRBuilder::CreateTaskwait(const LocationDescription &Loc) { + if (!updateToLocation(Loc)) + return Loc.IP; + return emitTaskwaitImpl(Loc); +}