Skip to content

Commit 2bef1c0

Browse files
committed
[OpenMP] Lower taskyield using OpenMP IR Builder
This is similar to D69828. Special codegen for enclosing untied tasks is still done in clang. Differential Revision: https://reviews.llvm.org/D70799
1 parent 430fc53 commit 2bef1c0

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,11 +3295,18 @@ void CGOpenMPRuntime::emitTaskyieldCall(CodeGenFunction &CGF,
32953295
SourceLocation Loc) {
32963296
if (!CGF.HaveInsertPoint())
32973297
return;
3298-
// Build call __kmpc_omp_taskyield(loc, thread_id, 0);
3299-
llvm::Value *Args[] = {
3300-
emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
3301-
llvm::ConstantInt::get(CGM.IntTy, /*V=*/0, /*isSigned=*/true)};
3302-
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskyield), Args);
3298+
llvm::OpenMPIRBuilder *OMPBuilder = CGF.CGM.getOpenMPIRBuilder();
3299+
if (OMPBuilder) {
3300+
OMPBuilder->CreateTaskyield(CGF.Builder);
3301+
} else {
3302+
// Build call __kmpc_omp_taskyield(loc, thread_id, 0);
3303+
llvm::Value *Args[] = {
3304+
emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
3305+
llvm::ConstantInt::get(CGM.IntTy, /*V=*/0, /*isSigned=*/true)};
3306+
CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_omp_taskyield),
3307+
Args);
3308+
}
3309+
33033310
if (auto *Region = dyn_cast_or_null<CGOpenMPRegionInfo>(CGF.CapturedStmtInfo))
33043311
Region->emitUntiedSwitch(CGF);
33053312
}

clang/test/OpenMP/taskyield_codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
22
// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
33
// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4+
//
5+
// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
6+
// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s
7+
// 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
48

59
// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
610
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -emit-pch -o %t %s

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class OpenMPIRBuilder {
171171
Value *IfCondition, Value *NumThreads,
172172
omp::ProcBindKind ProcBind, bool IsCancellable);
173173

174+
174175
/// Generator for '#omp flush'
175176
///
176177
/// \param Loc The location where the flush directive was encountered
@@ -181,6 +182,11 @@ class OpenMPIRBuilder {
181182
/// \param Loc The location where the taskwait directive was encountered.
182183
void CreateTaskwait(const LocationDescription& Loc);
183184

185+
/// Generator for '#omp taskyield'
186+
///
187+
/// \param Loc The location where the taskyield directive was encountered.
188+
void CreateTaskyield(const LocationDescription& Loc);
189+
184190
///}
185191

186192

@@ -251,6 +257,11 @@ class OpenMPIRBuilder {
251257
/// \param Loc The location at which the request originated and is fulfilled.
252258
void emitTaskwaitImpl(const LocationDescription &Loc);
253259

260+
/// Generate a taskyield runtime call.
261+
///
262+
/// \param Loc The location at which the request originated and is fulfilled.
263+
void emitTaskyieldImpl(const LocationDescription &Loc);
264+
254265
/// Return the current thread ID.
255266
///
256267
/// \param Ident The ident (ident_t*) describing the query origin.

llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ __OMP_RTL(__kmpc_flush, false, Void, IdentPtr)
170170
__OMP_RTL(__kmpc_global_thread_num, false, Int32, IdentPtr)
171171
__OMP_RTL(__kmpc_fork_call, true, Void, IdentPtr, Int32, ParallelTaskPtr)
172172
__OMP_RTL(__kmpc_omp_taskwait, false, Int32, IdentPtr, Int32)
173+
__OMP_RTL(__kmpc_omp_taskyield, false, Int32, IdentPtr, Int32, Int32)
173174
__OMP_RTL(__kmpc_push_num_threads, false, Void, IdentPtr, Int32,
174175
/* Int */ Int32)
175176
__OMP_RTL(__kmpc_push_proc_bind, false, Void, IdentPtr, Int32, /* Int */ Int32)

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,20 @@ void OpenMPIRBuilder::CreateTaskwait(const LocationDescription &Loc) {
709709
return;
710710
emitTaskwaitImpl(Loc);
711711
}
712+
713+
void OpenMPIRBuilder::emitTaskyieldImpl(const LocationDescription &Loc) {
714+
// Build call __kmpc_omp_taskyield(loc, thread_id, 0);
715+
Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
716+
Value *Ident = getOrCreateIdent(SrcLocStr);
717+
Constant *I32Null = ConstantInt::getNullValue(Int32);
718+
Value *Args[] = {Ident, getOrCreateThreadID(Ident), I32Null};
719+
720+
Builder.CreateCall(getOrCreateRuntimeFunction(OMPRTL___kmpc_omp_taskyield),
721+
Args);
722+
}
723+
724+
void OpenMPIRBuilder::CreateTaskyield(const LocationDescription &Loc) {
725+
if (!updateToLocation(Loc))
726+
return;
727+
emitTaskyieldImpl(Loc);
728+
}

0 commit comments

Comments
 (0)