Skip to content

Commit cbe583b

Browse files
[Flang] Add translation support for MutexInOutSet and InOutSet (#120715)
Implementatoin details: Both Mutexinoutset and Inoutset is recognized as flag=0x4 and 0x8 respectively, the flags is set to `kmp_depend_info` and passed as argument to `__kmpc_omp_task_with_deps` runtime call
1 parent 9f75b66 commit cbe583b

File tree

8 files changed

+73
-33
lines changed

8 files changed

+73
-33
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,13 @@ genDependKindAttr(lower::AbstractConverter &converter,
153153
pbKind = mlir::omp::ClauseTaskDepend::taskdependinout;
154154
break;
155155
case omp::clause::DependenceType::Mutexinoutset:
156+
pbKind = mlir::omp::ClauseTaskDepend::taskdependmutexinoutset;
157+
break;
156158
case omp::clause::DependenceType::Inoutset:
159+
pbKind = mlir::omp::ClauseTaskDepend::taskdependinoutset;
160+
break;
157161
case omp::clause::DependenceType::Depobj:
158-
TODO(currentLocation,
159-
"INOUTSET, MUTEXINOUTSET and DEPOBJ dependence-types");
162+
TODO(currentLocation, "DEPOBJ dependence-type");
160163
break;
161164
case omp::clause::DependenceType::Sink:
162165
case omp::clause::DependenceType::Source:

flang/test/Lower/OpenMP/Todo/depend-clause-depobj.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
22
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
33

4-
!CHECK: not yet implemented: INOUTSET, MUTEXINOUTSET and DEPOBJ dependence-types
4+
!CHECK: not yet implemented: DEPOBJ dependence-type
55

66
subroutine f00(x)
77
integer :: x

flang/test/Lower/OpenMP/Todo/depend-clause-inoutset.f90

Lines changed: 0 additions & 11 deletions
This file was deleted.

flang/test/Lower/OpenMP/Todo/depend-clause-mutexinoutset.f90

Lines changed: 0 additions & 11 deletions
This file was deleted.

flang/test/Lower/OpenMP/task.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ subroutine task_depend_multi_task()
144144
x = x + 12
145145
!CHECK: omp.terminator
146146
!$omp end task
147+
!CHECK: omp.task depend(taskdependmutexinoutset -> %{{.+}} : !fir.ref<i32>)
148+
!$omp task depend(mutexinoutset : x)
149+
!CHECK: arith.subi
150+
x = x - 12
151+
!CHECK: omp.terminator
152+
!$omp end task
153+
!CHECK: omp.task depend(taskdependinoutset -> %{{.+}} : !fir.ref<i32>)
154+
!$omp task depend(inoutset : x)
155+
!CHECK: arith.subi
156+
x = x - 12
157+
!CHECK: omp.terminator
158+
!$omp end task
147159
end subroutine task_depend_multi_task
148160

149161
!===============================================================================

mlir/include/mlir/Dialect/OpenMP/OpenMPEnums.td

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ def ClauseRequiresAttr : OpenMP_EnumAttr<ClauseRequires, "clause_requires">;
108108
def ClauseTaskDependIn : I32EnumAttrCase<"taskdependin", 0>;
109109
def ClauseTaskDependOut : I32EnumAttrCase<"taskdependout", 1>;
110110
def ClauseTaskDependInOut : I32EnumAttrCase<"taskdependinout", 2>;
111-
112-
def ClauseTaskDepend : OpenMP_I32EnumAttr<
113-
"ClauseTaskDepend",
114-
"depend clause in a target or task construct", [
115-
ClauseTaskDependIn,
116-
ClauseTaskDependOut,
117-
ClauseTaskDependInOut
118-
]>;
111+
def ClauseTaskDependMutexInOutSet
112+
: I32EnumAttrCase<"taskdependmutexinoutset", 3>;
113+
def ClauseTaskDependInOutSet : I32EnumAttrCase<"taskdependinoutset", 4>;
114+
115+
def ClauseTaskDepend
116+
: OpenMP_I32EnumAttr<
117+
"ClauseTaskDepend", "depend clause in a target or task construct",
118+
[ClauseTaskDependIn, ClauseTaskDependOut, ClauseTaskDependInOut,
119+
ClauseTaskDependMutexInOutSet, ClauseTaskDependInOutSet]>;
119120

120121
def ClauseTaskDependAttr : OpenMP_EnumAttr<ClauseTaskDepend,
121122
"clause_task_depend"> {

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,12 @@ buildDependData(std::optional<ArrayAttr> dependKinds, OperandRange dependVars,
17011701
case mlir::omp::ClauseTaskDepend::taskdependinout:
17021702
type = llvm::omp::RTLDependenceKindTy::DepInOut;
17031703
break;
1704+
case mlir::omp::ClauseTaskDepend::taskdependmutexinoutset:
1705+
type = llvm::omp::RTLDependenceKindTy::DepMutexInOutSet;
1706+
break;
1707+
case mlir::omp::ClauseTaskDepend::taskdependinoutset:
1708+
type = llvm::omp::RTLDependenceKindTy::DepInOutSet;
1709+
break;
17041710
};
17051711
llvm::Value *depVal = moduleTranslation.lookupValue(std::get<0>(dep));
17061712
llvm::OpenMPIRBuilder::DependData dd(type, depVal->getType(), depVal);

mlir/test/Target/LLVMIR/openmp-llvm.mlir

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,34 @@ llvm.func @omp_task_attrs() -> () attributes {
25902590
// CHECK: store i64 8, ptr %[[dep_arr_addr_0_size]], align 4
25912591
// CHECK: %[[dep_arr_addr_0_kind:.+]] = getelementptr inbounds nuw %struct.kmp_dep_info, ptr %[[dep_arr_addr_0]], i32 0, i32 2
25922592
// CHECK: store i8 1, ptr %[[dep_arr_addr_0_kind]], align 1
2593+
// -----
2594+
// dependence_type: Out
2595+
// CHECK: %[[DEP_ARR_ADDR1:.+]] = alloca [1 x %struct.kmp_dep_info], align 8
2596+
// CHECK: %[[DEP_ARR_ADDR_1:.+]] = getelementptr inbounds [1 x %struct.kmp_dep_info], ptr %[[DEP_ARR_ADDR1]], i64 0, i64 0
2597+
// [...]
2598+
// CHECK: %[[DEP_TYPE_1:.+]] = getelementptr inbounds nuw %struct.kmp_dep_info, ptr %[[DEP_ARR_ADDR_1]], i32 0, i32 2
2599+
// CHECK: store i8 3, ptr %[[DEP_TYPE_1]], align 1
2600+
// -----
2601+
// dependence_type: Inout
2602+
// CHECK: %[[DEP_ARR_ADDR2:.+]] = alloca [1 x %struct.kmp_dep_info], align 8
2603+
// CHECK: %[[DEP_ARR_ADDR_2:.+]] = getelementptr inbounds [1 x %struct.kmp_dep_info], ptr %[[DEP_ARR_ADDR2]], i64 0, i64 0
2604+
// [...]
2605+
// CHECK: %[[DEP_TYPE_2:.+]] = getelementptr inbounds nuw %struct.kmp_dep_info, ptr %[[DEP_ARR_ADDR_2]], i32 0, i32 2
2606+
// CHECK: store i8 3, ptr %[[DEP_TYPE_2]], align 1
2607+
// -----
2608+
// dependence_type: Mutexinoutset
2609+
// CHECK: %[[DEP_ARR_ADDR3:.+]] = alloca [1 x %struct.kmp_dep_info], align 8
2610+
// CHECK: %[[DEP_ARR_ADDR_3:.+]] = getelementptr inbounds [1 x %struct.kmp_dep_info], ptr %[[DEP_ARR_ADDR3]], i64 0, i64 0
2611+
// [...]
2612+
// CHECK: %[[DEP_TYPE_3:.+]] = getelementptr inbounds nuw %struct.kmp_dep_info, ptr %[[DEP_ARR_ADDR_3]], i32 0, i32 2
2613+
// CHECK: store i8 4, ptr %[[DEP_TYPE_3]], align 1
2614+
// -----
2615+
// dependence_type: Inoutset
2616+
// CHECK: %[[DEP_ARR_ADDR4:.+]] = alloca [1 x %struct.kmp_dep_info], align 8
2617+
// CHECK: %[[DEP_ARR_ADDR_4:.+]] = getelementptr inbounds [1 x %struct.kmp_dep_info], ptr %[[DEP_ARR_ADDR4]], i64 0, i64 0
2618+
// [...]
2619+
// CHECK: %[[DEP_TYPE_4:.+]] = getelementptr inbounds nuw %struct.kmp_dep_info, ptr %[[DEP_ARR_ADDR_4]], i32 0, i32 2
2620+
// CHECK: store i8 8, ptr %[[DEP_TYPE_4]], align 1
25932621
llvm.func @omp_task_with_deps(%zaddr: !llvm.ptr) {
25942622
// CHECK: %[[omp_global_thread_num:.+]] = call i32 @__kmpc_global_thread_num({{.+}})
25952623
// CHECK: %[[task_data:.+]] = call ptr @__kmpc_omp_task_alloc
@@ -2604,6 +2632,18 @@ llvm.func @omp_task_with_deps(%zaddr: !llvm.ptr) {
26042632
llvm.store %double, %valaddr : i32, !llvm.ptr
26052633
omp.terminator
26062634
}
2635+
omp.task depend(taskdependout -> %zaddr : !llvm.ptr) {
2636+
omp.terminator
2637+
}
2638+
omp.task depend(taskdependinout -> %zaddr : !llvm.ptr) {
2639+
omp.terminator
2640+
}
2641+
omp.task depend(taskdependmutexinoutset -> %zaddr : !llvm.ptr) {
2642+
omp.terminator
2643+
}
2644+
omp.task depend(taskdependinoutset -> %zaddr : !llvm.ptr) {
2645+
omp.terminator
2646+
}
26072647
llvm.return
26082648
}
26092649

0 commit comments

Comments
 (0)