Skip to content

Commit

Permalink
[OpenMP] Fix incorrect interop type for number of dependencies
Browse files Browse the repository at this point in the history
The interop types use the number of dependencies in the function
interface. Every other function uses an `i32` to count the number of
dependencies except for the initialization function. This leads to
codegen issues when the rest of the compiler passes in an `i32` that
then creates an invalid call. Fix this to be consistent with the other
uses.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D150156
  • Loading branch information
jhuber6 committed May 9, 2023
1 parent 6fcb91b commit e494ebf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
52 changes: 20 additions & 32 deletions clang/test/OpenMP/interop_irbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ void test1() {
int D0, D1;
omp_interop_t interop;

#pragma omp interop init(target \
: interop)
#pragma omp interop init(target : interop)

#pragma omp interop init(targetsync \
: interop)
#pragma omp interop init(targetsync : interop)

#pragma omp interop init(target \
: interop) device(device_id)
#pragma omp interop init(target : interop) device(device_id)

#pragma omp interop init(targetsync \
: interop) device(device_id)
#pragma omp interop init(targetsync : interop) device(device_id)

#pragma omp interop use(interop) depend(in \
: D0, D1) nowait
#pragma omp interop use(interop) depend(in : D0, D1) nowait

#pragma omp interop destroy(interop) depend(in \
: D0, D1)
#pragma omp interop destroy(interop) depend(in : D0, D1)
}

struct S {
Expand All @@ -39,23 +33,17 @@ void S::member_test() {
int device_id = 4;
int D0, D1;

#pragma omp interop init(target \
: interop)
#pragma omp interop init(target : interop)

#pragma omp interop init(targetsync \
: interop)
#pragma omp interop init(targetsync : interop)

#pragma omp interop init(target \
: interop) device(device_id)
#pragma omp interop init(target : interop) device(device_id)

#pragma omp interop init(targetsync \
: interop) device(device_id)
#pragma omp interop init(targetsync : interop) device(device_id)

#pragma omp interop use(interop) depend(in \
: D0, D1) nowait
#pragma omp interop use(interop) depend(in : D0, D1) nowait

#pragma omp interop destroy(interop) depend(in \
: D0, D1)
#pragma omp interop destroy(interop) depend(in : D0, D1)
}
// CHECK-LABEL: @_Z5test1v(
// CHECK-NEXT: entry:
Expand All @@ -69,15 +57,15 @@ void S::member_test() {
// CHECK-NEXT: [[DEP_COUNTER_ADDR6:%.*]] = alloca i64, align 8
// CHECK-NEXT: store i32 4, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], ptr [[INTEROP]], i32 1, i32 -1, i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], ptr [[INTEROP]], i32 1, i32 -1, i32 0, ptr null, i32 0)
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM1:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM1]], ptr [[INTEROP]], i32 2, i32 -1, i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM1]], ptr [[INTEROP]], i32 2, i32 -1, i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM2:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM2]], ptr [[INTEROP]], i32 1, i32 [[TMP0]], i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM2]], ptr [[INTEROP]], i32 1, i32 [[TMP0]], i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM3:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM3]], ptr [[INTEROP]], i32 2, i32 [[TMP1]], i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM3]], ptr [[INTEROP]], i32 2, i32 [[TMP1]], i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [2 x %struct.kmp_depend_info], ptr [[DOTDEP_ARR_ADDR]], i64 0, i64 0
// CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[D0]] to i64
// CHECK-NEXT: [[TMP4:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO:%.*]], ptr [[TMP2]], i64 0
Expand Down Expand Up @@ -136,18 +124,18 @@ void S::member_test() {
// CHECK-NEXT: store i32 4, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[INTEROP:%.*]] = getelementptr inbounds [[STRUCT_S:%.*]], ptr [[THIS1]], i32 0, i32 0
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], ptr [[INTEROP]], i32 1, i32 -1, i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], ptr [[INTEROP]], i32 1, i32 -1, i32 0, ptr null, i32 0)
// CHECK-NEXT: [[INTEROP2:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[THIS1]], i32 0, i32 0
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM3:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM3]], ptr [[INTEROP2]], i32 2, i32 -1, i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM3]], ptr [[INTEROP2]], i32 2, i32 -1, i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[INTEROP4:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[THIS1]], i32 0, i32 0
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM5:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM5]], ptr [[INTEROP4]], i32 1, i32 [[TMP0]], i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM5]], ptr [[INTEROP4]], i32 1, i32 [[TMP0]], i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[DEVICE_ID]], align 4
// CHECK-NEXT: [[INTEROP6:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[THIS1]], i32 0, i32 0
// CHECK-NEXT: [[OMP_GLOBAL_THREAD_NUM7:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM7]], ptr [[INTEROP6]], i32 2, i32 [[TMP1]], i64 0, ptr null, i32 0)
// CHECK-NEXT: call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM7]], ptr [[INTEROP6]], i32 2, i32 [[TMP1]], i32 0, ptr null, i32 0)
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [2 x %struct.kmp_depend_info], ptr [[DOTDEP_ARR_ADDR]], i64 0, i64 0
// CHECK-NEXT: [[TMP3:%.*]] = ptrtoint ptr [[D0]] to i64
// CHECK-NEXT: [[TMP4:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO:%.*]], ptr [[TMP2]], i64 0
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ __OMP_RTL(__kmpc_aligned_alloc, false, VoidPtr, /* Int */ Int32, SizeTy, SizeTy,
__OMP_RTL(__kmpc_free, false, Void, /* Int */ Int32, VoidPtr, VoidPtr)

__OMP_RTL(__tgt_interop_init, false, Void, IdentPtr, Int32, VoidPtrPtr, Int32,
Int32, Int64, VoidPtr, Int32)
Int32, Int32, VoidPtr, Int32)
__OMP_RTL(__tgt_interop_destroy, false, Void, IdentPtr, Int32, VoidPtrPtr,
Int32, Int32, VoidPtr, Int32)
__OMP_RTL(__tgt_interop_use, false, Void, IdentPtr, Int32, VoidPtrPtr, Int32,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,7 @@ CallInst *OpenMPIRBuilder::createOMPInteropInit(
Device = ConstantInt::get(Int32, -1);
Constant *InteropTypeVal = ConstantInt::get(Int32, (int)InteropType);
if (NumDependences == nullptr) {
NumDependences = ConstantInt::get(Int64, 0);
NumDependences = ConstantInt::get(Int32, 0);
PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Transforms/OpenMP/add_attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ declare i32 @__kmpc_target_init(ptr, i8, i1);

declare void @__tgt_interop_destroy(ptr, i32, ptr, i32, i32, ptr, i32);

declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i64, ptr, i32);
declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i32, ptr, i32);

declare void @__tgt_interop_use(ptr, i32, ptr, i32, i32, ptr, i32);

Expand Down Expand Up @@ -1398,7 +1398,7 @@ declare i32 @__tgt_target_kernel_nowait(ptr, i64, i32, i32, ptr, ptr, i32, ptr,
; CHECK: declare void @__tgt_interop_destroy(ptr, i32, ptr, i32, i32, ptr, i32)

; CHECK-NOT: Function Attrs
; CHECK: declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i64, ptr, i32)
; CHECK: declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i32, ptr, i32)

; CHECK-NOT: Function Attrs
; CHECK: declare void @__tgt_interop_use(ptr, i32, ptr, i32, i32, ptr, i32)
Expand Down Expand Up @@ -2046,7 +2046,7 @@ declare i32 @__tgt_target_kernel_nowait(ptr, i64, i32, i32, ptr, ptr, i32, ptr,
; OPTIMISTIC: declare void @__tgt_interop_destroy(ptr, i32, ptr, i32, i32, ptr, i32)

; OPTIMISTIC-NOT: Function Attrs
; OPTIMISTIC: declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i64, ptr, i32)
; OPTIMISTIC: declare void @__tgt_interop_init(ptr, i32, ptr, i32, i32, i32, ptr, i32)

; OPTIMISTIC-NOT: Function Attrs
; OPTIMISTIC: declare void @__tgt_interop_use(ptr, i32, ptr, i32, i32, ptr, i32)
Expand Down Expand Up @@ -2707,7 +2707,7 @@ declare i32 @__tgt_target_kernel_nowait(ptr, i64, i32, i32, ptr, ptr, i32, ptr,
; EXT: declare void @__tgt_interop_destroy(ptr, i32 signext, ptr, i32 signext, i32 signext, ptr, i32 signext)

; EXT-NOT: Function Attrs
; EXT: declare void @__tgt_interop_init(ptr, i32 signext, ptr, i32 signext, i32 signext, i64, ptr, i32 signext)
; EXT: declare void @__tgt_interop_init(ptr, i32 signext, ptr, i32 signext, i32 signext, i32, ptr, i32 signext)

; EXT-NOT: Function Attrs
; EXT: declare void @__tgt_interop_use(ptr, i32 signext, ptr, i32 signext, i32 signext, ptr, i32 signext)
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/src/interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extern "C" {
void __tgt_interop_init(ident_t *LocRef, kmp_int32 Gtid,
omp_interop_val_t *&InteropPtr,
kmp_interop_type_t InteropType, kmp_int32 DeviceId,
kmp_int64 Ndeps, kmp_depend_info_t *DepList,
kmp_int32 Ndeps, kmp_depend_info_t *DepList,
kmp_int32 HaveNowait) {
kmp_int32 NdepsNoalias = 0;
kmp_depend_info_t *NoaliasDepList = NULL;
Expand Down

0 comments on commit e494ebf

Please sign in to comment.