Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6349,11 +6349,9 @@ 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); + + CGF.CGM.getOpenMPIRBuilder().emitOMPTaskwait({CGF.Builder.saveIP()}); + if (auto *Region = dyn_cast_or_null(CGF.CapturedStmtInfo)) Region->emitUntiedSwitch(CGF); } Index: llvm/include/llvm/IR/OpenMPIRBuilder.h =================================================================== --- llvm/include/llvm/IR/OpenMPIRBuilder.h +++ llvm/include/llvm/IR/OpenMPIRBuilder.h @@ -70,6 +70,12 @@ void emitOMPBarrier(const LocationDescription &Loc, DirektiveKind DK, bool CheckCancelFlag = true); + /// Generator for '#omp taskwait' + /// + /// \param Loc The location where the taskwait directive was encountered. + /// + void emitOMPTaskwait(const LocationDescription& Loc); + ///} private: Index: llvm/include/llvm/IR/OpenMPKinds.def =================================================================== --- llvm/include/llvm/IR/OpenMPKinds.def +++ llvm/include/llvm/IR/OpenMPKinds.def @@ -152,6 +152,7 @@ __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32) __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32) __OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr) +__OMP_RTL(__kmpc_omp_taskwait, false, Int32, IdentPtr, Int32) #undef __OMP_RTL #undef OMP_RTL Index: llvm/lib/IR/OpenMPIRBuilder.cpp =================================================================== --- llvm/lib/IR/OpenMPIRBuilder.cpp +++ llvm/lib/IR/OpenMPIRBuilder.cpp @@ -215,3 +215,16 @@ (void)Cmp; } } + +void OpenMPIRBuilder::emitOMPTaskwait(const LocationDescription &Loc) { + assert(Loc.IP.getBlock() && "No insertion point provided!"); + Builder.restoreIP(Loc.IP); + + // Build call kmp_int32 __kmpc_omp_taskwait(ident_t *loc, kmp_int32 + // global_tid); + Constant *SrcLocStr = getSrcLocStr(Loc); + Value *Args[] = {getIdent(SrcLocStr), getThreadID(getIdent(SrcLocStr))}; + + // Ignore return result until untied tasks are supported. + Builder.CreateCall(getRuntimeFunction(OMPRTL___kmpc_omp_taskwait), Args); +}