Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3871,11 +3871,16 @@ void CGOpenMPRuntime::emitFlush(CodeGenFunction &CGF, ArrayRef, 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->CreateFlush(CGF.Builder); + } else { + if (!CGF.HaveInsertPoint()) + return; + // Build call void __kmpc_flush(ident_t *loc) + CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_flush), + emitUpdateLocation(CGF, Loc)); + } } namespace { Index: clang/test/OpenMP/flush_codegen.cpp =================================================================== --- clang/test/OpenMP/flush_codegen.cpp +++ clang/test/OpenMP/flush_codegen.cpp @@ -1,6 +1,9 @@ // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s 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 @@ ///} + /// Generator for '#omp flush' + /// + /// \param Loc The location where the flush directive was encountered + void CreateFlush(const LocationDescription &Loc); + + private: /// Update the internal location to \p Loc. bool updateToLocation(const LocationDescription &Loc) { @@ -112,6 +118,11 @@ omp::Directive DK, bool ForceSimpleCall, bool CheckCancelFlag); + /// Generate a flush runtime call. + /// + /// \param Loc The location at which the request originated and is fulfilled. + void emitFlush(const LocationDescription &Loc); + /// Return the current thread ID. /// /// \param Ident The ident (ident_t*) describing the query origin. Index: llvm/lib/Frontend/OpenMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMPIRBuilder.cpp @@ -243,3 +243,19 @@ return Builder.saveIP(); } + +void OpenMPIRBuilder::emitFlush(const LocationDescription &Loc) +{ + // Build call void __kmpc_flush(ident_t *loc) + Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); + Value *Args[] = {getOrCreateIdent(SrcLocStr)}; + + Builder.CreateCall(getOrCreateRuntimeFunction(OMPRTL___kmpc_flush), Args); +} + +void OpenMPIRBuilder::CreateFlush(const LocationDescription &Loc) +{ + if (!updateToLocation(Loc)) + return; + emitFlush(Loc); +}