Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3873,9 +3873,14 @@ SourceLocation Loc) { if (!CGF.HaveInsertPoint()) return; - // Build call void __kmpc_flush(ident_t *loc) - CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_flush), - emitUpdateLocation(CGF, Loc)); + llvm::OpenMPIRBuilder *OMPBuilder = CGF.CGM.getOpenMPIRBuilder(); + if (OMPBuilder) + OMPBuilder->emitFlush({CGF.Builder.saveIP()}); + else { + // Build call void __kmpc_flush(ident_t *loc) + CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_flush), + emitUpdateLocation(CGF, Loc)); + } } namespace { Index: llvm/include/llvm/Frontend/OpenMPKinds.def =================================================================== --- llvm/include/llvm/Frontend/OpenMPKinds.def +++ llvm/include/llvm/Frontend/OpenMPKinds.def @@ -164,6 +164,7 @@ __OMP_RTL(__kmpc_barrier, false, Void, IdentPtr, Int32) __OMP_RTL(__kmpc_cancel_barrier, false, Int32, IdentPtr, Int32) +__OMP_RTL(__kmpc_flush, false, Void, IdentPtr) __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, ) Index: llvm/include/llvm/Transforms/Utils/OpenMPIRBuilder.h =================================================================== --- llvm/include/llvm/Transforms/Utils/OpenMPIRBuilder.h +++ llvm/include/llvm/Transforms/Utils/OpenMPIRBuilder.h @@ -75,6 +75,12 @@ ///} + /// Generate a flush runtime call. + /// + /// \param Loc The location at which the request originated and is fulfilled. + void emitFlush(const LocationDescription &Loc); + + private: /// Update the internal location to \p Loc. bool updateToLocation(const LocationDescription &Loc) { Index: llvm/lib/Frontend/OpenMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMPIRBuilder.cpp @@ -243,3 +243,15 @@ return Builder.saveIP(); } + +void OpenMPIRBuilder::emitFlush(const LocationDescription &Loc) +{ + assert(Loc.IP.getBlock() && "No insertion point provided!"); + Builder.restoreIP(Loc.IP); + + // Build call void __kmpc_flush(ident_t *loc) + Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); + Value *Args[] = {getOrCreateIdent(SrcLocStr)}; + + Builder.CreateCall(getOrCreateRuntimeFunction(OMPRTL___kmpc_flush), Args); +}