Skip to content

Commit 6f0e9c4

Browse files
authored
[OpenMP][Clang] Migrate OpenMP UserDefinedMapper from Clang to OMPIRBuilder (#110001)
This patch migrates the OpenMP UserDefinedMapper codegen from Clang to the OpenMPIRBuilder. I will be adding further patches in the near future so that OpenMP dialect in MLIR can make use of these.
1 parent 0e8d022 commit 6f0e9c4

File tree

8 files changed

+461
-466
lines changed

8 files changed

+461
-466
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 49 additions & 317 deletions
Large diffs are not rendered by default.

clang/lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,6 @@ class CGOpenMPRuntime {
559559
llvm::Value *Ctor, llvm::Value *CopyCtor,
560560
llvm::Value *Dtor, SourceLocation Loc);
561561

562-
/// Emit the array initialization or deletion portion for user-defined mapper
563-
/// code generation.
564-
void emitUDMapperArrayInitOrDel(CodeGenFunction &MapperCGF,
565-
llvm::Value *Handle, llvm::Value *BasePtr,
566-
llvm::Value *Ptr, llvm::Value *Size,
567-
llvm::Value *MapType, llvm::Value *MapName,
568-
CharUnits ElementSize,
569-
llvm::BasicBlock *ExitBB, bool IsInit);
570-
571562
struct TaskResultTy {
572563
llvm::Value *NewTask = nullptr;
573564
llvm::Function *TaskEntry = nullptr;

clang/test/OpenMP/declare_mapper_codegen.cpp

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,9 @@ class C {
8686

8787
#pragma omp declare mapper(id: C s) map(s.a, s.b[0:2])
8888

89-
// CK0: define {{.*}}void [[MPRFUNC:@[.]omp_mapper[.].*C[.]id]](ptr{{.*}}, ptr{{.*}}, ptr{{.*}}, i64{{.*}}, i64{{.*}}, ptr{{.*}})
90-
// CK0: store ptr %{{[^,]+}}, ptr [[HANDLEADDR:%[^,]+]]
91-
// CK0: store ptr %{{[^,]+}}, ptr [[BPTRADDR:%[^,]+]]
92-
// CK0: store ptr %{{[^,]+}}, ptr [[VPTRADDR:%[^,]+]]
93-
// CK0: store i64 %{{[^,]+}}, ptr [[SIZEADDR:%[^,]+]]
94-
// CK0: store i64 %{{[^,]+}}, ptr [[TYPEADDR:%[^,]+]]
95-
// CK0-DAG: [[BYTESIZE:%.+]] = load i64, ptr [[SIZEADDR]]
89+
// CK0: define {{.*}}void [[MPRFUNC:@[.]omp_mapper[.].*C[.]id]](ptr noundef [[HANDLE:%.+]], ptr noundef [[BPTR:%.+]], ptr noundef [[BEGIN:%.+]], i64 noundef [[BYTESIZE:%.+]], i64 noundef [[TYPE:%.+]], ptr{{.*}})
9690
// CK0-64-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 16
9791
// CK0-32-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 8
98-
// CK0-DAG: [[TYPE:%.+]] = load i64, ptr [[TYPEADDR]]
99-
// CK0-DAG: [[HANDLE:%.+]] = load ptr, ptr [[HANDLEADDR]]
100-
// CK0-DAG: [[BPTR:%.+]] = load ptr, ptr [[BPTRADDR]]
101-
// CK0-DAG: [[BEGIN:%.+]] = load ptr, ptr [[VPTRADDR]]
10292
// CK0-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
10393
// CK0-DAG: [[PTREND:%.+]] = getelementptr %class.C, ptr [[BEGIN]], i64 [[SIZE]]
10494
// CK0-DAG: [[PTRSNE:%.+]] = icmp ne ptr [[BPTR]], [[BEGIN]]
@@ -597,18 +587,8 @@ class C {
597587

598588
#pragma omp declare mapper(id: C<int> s) map(s.a)
599589

600-
// CK1-LABEL: define {{.*}}void @.omp_mapper.{{.*}}C{{.*}}.id{{.*}}(ptr{{.*}}, ptr{{.*}}, ptr{{.*}}, i64{{.*}}, i64{{.*}}, ptr{{.*}})
601-
// CK1: store ptr %{{[^,]+}}, ptr [[HANDLEADDR:%[^,]+]]
602-
// CK1: store ptr %{{[^,]+}}, ptr [[BPTRADDR:%[^,]+]]
603-
// CK1: store ptr %{{[^,]+}}, ptr [[VPTRADDR:%[^,]+]]
604-
// CK1: store i64 %{{[^,]+}}, ptr [[SIZEADDR:%[^,]+]]
605-
// CK1: store i64 %{{[^,]+}}, ptr [[TYPEADDR:%[^,]+]]
606-
// CK1-DAG: [[BYTESIZE:%.+]] = load i64, ptr [[SIZEADDR]]
590+
// CK1: define {{.*}}void @.omp_mapper.{{.*}}C{{.*}}.id{{.*}}(ptr noundef [[HANDLE:%.+]], ptr noundef [[BPTR:%.+]], ptr noundef [[BEGIN:%.+]], i64 noundef [[BYTESIZE:%.+]], i64 noundef [[TYPE:%.+]], ptr{{.*}})
607591
// CK1-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 4
608-
// CK1-DAG: [[TYPE:%.+]] = load i64, ptr [[TYPEADDR]]
609-
// CK1-DAG: [[HANDLE:%.+]] = load ptr, ptr [[HANDLEADDR]]
610-
// CK1-DAG: [[BPTR:%.+]] = load ptr, ptr [[BPTRADDR]]
611-
// CK1-DAG: [[BEGIN:%.+]] = load ptr, ptr [[VPTRADDR]]
612592
// CK1-DAG: [[PTREND:%.+]] = getelementptr %class.C, ptr [[BEGIN]], i64 [[SIZE]]
613593
// CK1-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
614594
// CK1-DAG: [[PTRSNE:%.+]] = icmp ne ptr [[BPTR]], [[BEGIN]]
@@ -717,18 +697,8 @@ class C {
717697

718698
// CK2: define {{.*}}void [[BMPRFUNC:@[.]omp_mapper[.].*B[.]default]](ptr{{.*}}, ptr{{.*}}, ptr{{.*}}, i64{{.*}}, i64{{.*}}, ptr{{.*}})
719699

720-
// CK2-LABEL: define {{.*}}void @.omp_mapper.{{.*}}C{{.*}}.id(ptr{{.*}}, ptr{{.*}}, ptr{{.*}}, i64{{.*}}, i64{{.*}}, ptr{{.*}})
721-
// CK2: store ptr %{{[^,]+}}, ptr [[HANDLEADDR:%[^,]+]]
722-
// CK2: store ptr %{{[^,]+}}, ptr [[BPTRADDR:%[^,]+]]
723-
// CK2: store ptr %{{[^,]+}}, ptr [[VPTRADDR:%[^,]+]]
724-
// CK2: store i64 %{{[^,]+}}, ptr [[SIZEADDR:%[^,]+]]
725-
// CK2: store i64 %{{[^,]+}}, ptr [[TYPEADDR:%[^,]+]]
726-
// CK2-DAG: [[BYTESIZE:%.+]] = load i64, ptr [[SIZEADDR]]
700+
// CK2: define {{.*}}void @.omp_mapper.{{.*}}C{{.*}}.id(ptr noundef [[HANDLE:%.+]], ptr noundef [[BPTR:%.+]], ptr noundef [[BEGIN:%.+]], i64 noundef [[BYTESIZE:%.+]], i64 noundef [[TYPE:%.+]], ptr{{.*}})
727701
// CK2-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 16
728-
// CK2-DAG: [[TYPE:%.+]] = load i64, ptr [[TYPEADDR]]
729-
// CK2-DAG: [[HANDLE:%.+]] = load ptr, ptr [[HANDLEADDR]]
730-
// CK2-DAG: [[BPTR:%.+]] = load ptr, ptr [[BPTRADDR]]
731-
// CK2-DAG: [[BEGIN:%.+]] = load ptr, ptr [[VPTRADDR]]
732702
// CK2-DAG: [[PTREND:%.+]] = getelementptr %class.C, ptr [[BEGIN]], i64 [[SIZE]]
733703
// CK2-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
734704
// CK2-DAG: [[PTRSNE:%.+]] = icmp ne ptr [[BPTR]], [[BEGIN]]
@@ -921,19 +891,9 @@ class C {
921891

922892
#pragma omp declare mapper(id: C s) map(s.a, s.b[0:2])
923893

924-
// CK4: define {{.*}}void [[MPRFUNC:@[.]omp_mapper[.].*C[.]id]](ptr{{.*}}, ptr{{.*}}, ptr{{.*}}, i64{{.*}}, i64{{.*}}, ptr{{.*}})
925-
// CK4: store ptr %{{[^,]+}}, ptr [[HANDLEADDR:%[^,]+]]
926-
// CK4: store ptr %{{[^,]+}}, ptr [[BPTRADDR:%[^,]+]]
927-
// CK4: store ptr %{{[^,]+}}, ptr [[VPTRADDR:%[^,]+]]
928-
// CK4: store i64 %{{[^,]+}}, ptr [[SIZEADDR:%[^,]+]]
929-
// CK4: store i64 %{{[^,]+}}, ptr [[TYPEADDR:%[^,]+]]
930-
// CK4-DAG: [[BYTESIZE:%.+]] = load i64, ptr [[SIZEADDR]]
894+
// CK4: define {{.*}}void [[MPRFUNC:@[.]omp_mapper[.].*C[.]id]](ptr noundef [[HANDLE:%.+]], ptr noundef [[BPTR:%.+]], ptr noundef [[BEGIN:%.+]], i64 noundef [[BYTESIZE:%.+]], i64 noundef [[TYPE:%.+]], ptr{{.*}})
931895
// CK4-64-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 16
932896
// CK4-32-DAG: [[SIZE:%.+]] = udiv exact i64 [[BYTESIZE]], 8
933-
// CK4-DAG: [[TYPE:%.+]] = load i64, ptr [[TYPEADDR]]
934-
// CK4-DAG: [[HANDLE:%.+]] = load ptr, ptr [[HANDLEADDR]]
935-
// CK4-DAG: [[BPTR:%.+]] = load ptr, ptr [[BPTRADDR]]
936-
// CK4-DAG: [[BEGIN:%.+]] = load ptr, ptr [[VPTRADDR]]
937897
// CK4-DAG: [[PTREND:%.+]] = getelementptr %class.C, ptr [[BEGIN]], i64 [[SIZE]]
938898
// CK4-DAG: [[ISARRAY:%.+]] = icmp sgt i64 [[SIZE]], 1
939899
// CK4-DAG: [[PTRSNE:%.+]] = icmp ne ptr [[BPTR]], [[BEGIN]]

clang/test/OpenMP/target_map_names.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ void secondMapNameInClause() {
201201
// DEBUG: store ptr @[[NAME:.offload_mapnames.[0-9]+]], ptr %[[ARG:.+]]
202202
// CHECK-NOT: store ptr @[[NAME:.offload_mapnames.[0-9]+]], ptr %[[ARG:.+]]
203203

204-
// DEBUG: void @.omp_mapper._ZTS2S3.id(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, i64 {{.*}}, i64 {{.*}}, ptr noundef [[NAME_ARG:%.+]])
205-
// DEBUG: store ptr [[NAME_ARG]], ptr [[NAME_STACK:%.+]]
206-
// DEBUG: [[MAPPER_NAME:%.+]] = load ptr, ptr [[NAME_STACK]]
204+
// DEBUG: void @.omp_mapper._ZTS2S3.id(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, i64 {{.*}}, i64 {{.*}}, ptr noundef [[MAPPER_NAME:%.+]])
207205
// DEBUG: call void @__tgt_push_mapper_component(ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, ptr [[MAPPER_NAME]])
208206

209207
#endif

clang/test/OpenMP/target_map_names_attr.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ void secondMapNameInClause() {
186186
// DEBUG: store ptr @[[NAME:.offload_mapnames.[0-9]+]], ptr %[[ARG:.+]]
187187
// CHECK-NOT: store ptr @[[NAME:.offload_mapnames.[0-9]+]], ptr %[[ARG:.+]]
188188

189-
// DEBUG: void @.omp_mapper._ZTS2S3.id(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, i64 {{.*}}, i64 {{.*}}, ptr noundef [[NAME_ARG:%.+]])
190-
// DEBUG: store ptr [[NAME_ARG]], ptr [[NAME_STACK:%.+]]
191-
// DEBUG: [[MAPPER_NAME:%.+]] = load ptr, ptr [[NAME_STACK]]
189+
// DEBUG: void @.omp_mapper._ZTS2S3.id(ptr {{.*}}, ptr {{.*}}, ptr {{.*}}, i64 {{.*}}, i64 {{.*}}, ptr noundef [[MAPPER_NAME:%.+]])
192190
// DEBUG: call void @__tgt_push_mapper_component(ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, ptr [[MAPPER_NAME]])
193191

194192
#endif

0 commit comments

Comments
 (0)