rogfer01 created this revision. rogfer01 added reviewers: jdoerfert, kiranchandramohan. Herald added subscribers: llvm-commits, cfe-commits, guansong, hiraditya. Herald added projects: clang, LLVM. rogfer01 added a parent revision: D69922: [OpenMP] Use the OpenMP-IR-Builder.
This is similar to D69828 <https://reviews.llvm.org/D69828>. Special codegen for enclosing untied tasks is still done in clang. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70799 Files: clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/test/OpenMP/taskyield_codegen.cpp llvm/include/llvm/Frontend/OpenMPIRBuilder.h llvm/include/llvm/Frontend/OpenMPKinds.def llvm/lib/Frontend/OpenMPIRBuilder.cpp
Index: llvm/lib/Frontend/OpenMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMPIRBuilder.cpp @@ -272,3 +272,20 @@ return; emitTaskwaitImpl(Loc); } + +void OpenMPIRBuilder::emitTaskyieldImpl(const LocationDescription &Loc) { + // Build call __kmpc_omp_taskyield(loc, thread_id, 0); + Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); + Value *Ident = getOrCreateIdent(SrcLocStr); + Constant *I32Null = ConstantInt::getNullValue(Int32); + Value *Args[] = {Ident, getOrCreateThreadID(Ident), I32Null}; + + Builder.CreateCall(getOrCreateRuntimeFunction(OMPRTL___kmpc_omp_taskyield), + Args); +} + +void OpenMPIRBuilder::CreateTaskyield(const LocationDescription &Loc) { + if (!updateToLocation(Loc)) + return; + emitTaskyieldImpl(Loc); +} Index: llvm/include/llvm/Frontend/OpenMPKinds.def =================================================================== --- llvm/include/llvm/Frontend/OpenMPKinds.def +++ llvm/include/llvm/Frontend/OpenMPKinds.def @@ -168,6 +168,7 @@ __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) +__OMP_RTL(__kmpc_omp_taskyield, false, Int32, IdentPtr, Int32, Int32) #undef __OMP_RTL #undef OMP_RTL Index: llvm/include/llvm/Frontend/OpenMPIRBuilder.h =================================================================== --- llvm/include/llvm/Frontend/OpenMPIRBuilder.h +++ llvm/include/llvm/Frontend/OpenMPIRBuilder.h @@ -78,6 +78,11 @@ /// \param Loc The location where the taskwait directive was encountered. void CreateTaskwait(const LocationDescription& Loc); + /// Generator for '#omp taskyield' + /// + /// \param Loc The location where the taskyield directive was encountered. + void CreateTaskyield(const LocationDescription& Loc); + ///} private: @@ -122,6 +127,11 @@ /// \param Loc The location at which the request originated and is fulfilled. void emitTaskwaitImpl(const LocationDescription &Loc); + /// Generate a taskyield runtime call. + /// + /// \param Loc The location at which the request originated and is fulfilled. + void emitTaskyieldImpl(const LocationDescription &Loc); + /// Return the current thread ID. /// /// \param Ident The ident (ident_t*) describing the query origin. Index: clang/test/OpenMP/taskyield_codegen.cpp =================================================================== --- clang/test/OpenMP/taskyield_codegen.cpp +++ clang/test/OpenMP/taskyield_codegen.cpp @@ -1,6 +1,10 @@ // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s +// +// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -3247,11 +3247,18 @@ SourceLocation Loc) { if (!CGF.HaveInsertPoint()) return; - // Build call __kmpc_omp_taskyield(loc, thread_id, 0); - llvm::Value *Args[] = { - emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc), - llvm::ConstantInt::get(CGM.IntTy, /*V=*/0, /*isSigned=*/true)}; - CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskyield), Args); + llvm::OpenMPIRBuilder *OMPBuilder = CGF.CGM.getOpenMPIRBuilder(); + if (OMPBuilder) { + OMPBuilder->CreateTaskyield(CGF.Builder); + } else { + // Build call __kmpc_omp_taskyield(loc, thread_id, 0); + llvm::Value *Args[] = { + emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc), + llvm::ConstantInt::get(CGM.IntTy, /*V=*/0, /*isSigned=*/true)}; + CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskyield), + Args); + } + if (auto *Region = dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo)) Region->emitUntiedSwitch(CGF); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits