Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ void foo(void) {
// OMP-NEXT: entry:
// OMP-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: [[OMP_OUTLINED_ARG_AGG_:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
// OMP-NEXT: store i32 0, i32* [[RETVAL]], align 4
// OMP-NEXT: store i32 0, i32* [[I]], align 4
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon*)* @.omp_outlined. to void (i32*, i32*, ...)*), %struct.anon* [[OMP_OUTLINED_ARG_AGG_]])
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined. to void (i32*, i32*, ...)*))
// OMP-NEXT: call void @foo()
// OMP-NEXT: ret i32 0
//
Expand All @@ -46,7 +45,6 @@ void foo(void) {
// OMP-NEXT: entry:
// OMP-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
// OMP-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
// OMP-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon*, align 8
// OMP-NEXT: [[DOTOMP_IV:%.*]] = alloca i32, align 4
// OMP-NEXT: [[TMP:%.*]] = alloca i32, align 4
// OMP-NEXT: [[DOTOMP_LB:%.*]] = alloca i32, align 4
Expand All @@ -56,72 +54,68 @@ void foo(void) {
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: store i32* [[DOTGLOBAL_TID_:%.*]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: store i32* [[DOTBOUND_TID_:%.*]], i32** [[DOTBOUND_TID__ADDR]], align 8
// OMP-NEXT: store %struct.anon* [[__CONTEXT:%.*]], %struct.anon** [[__CONTEXT_ADDR]], align 8
// OMP-NEXT: [[TMP0:%.*]] = load %struct.anon*, %struct.anon** [[__CONTEXT_ADDR]], align 8
// OMP-NEXT: store i32 0, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 33554431, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: store i32 1, i32* [[DOTOMP_STRIDE]], align 4
// OMP-NEXT: store i32 0, i32* [[DOTOMP_IS_LAST]], align 4
// OMP-NEXT: [[TMP1:%.*]] = load i32*, i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4
// OMP-NEXT: call void @__kmpc_for_static_init_4(%struct.ident_t* @[[GLOB1:[0-9]+]], i32 [[TMP2]], i32 34, i32* [[DOTOMP_IS_LAST]], i32* [[DOTOMP_LB]], i32* [[DOTOMP_UB]], i32* [[DOTOMP_STRIDE]], i32 1, i32 1)
// OMP-NEXT: [[TMP3:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP3]], 33554431
// OMP-NEXT: [[TMP0:%.*]] = load i32*, i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
// OMP-NEXT: call void @__kmpc_for_static_init_4(%struct.ident_t* @[[GLOB1:[0-9]+]], i32 [[TMP1]], i32 34, i32* [[DOTOMP_IS_LAST]], i32* [[DOTOMP_LB]], i32* [[DOTOMP_UB]], i32* [[DOTOMP_STRIDE]], i32 1, i32 1)
// OMP-NEXT: [[TMP2:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 33554431
// OMP-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
// OMP: cond.true:
// OMP-NEXT: br label [[COND_END:%.*]]
// OMP: cond.false:
// OMP-NEXT: [[TMP4:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[TMP3:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: br label [[COND_END]]
// OMP: cond.end:
// OMP-NEXT: [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP4]], [[COND_FALSE]] ]
// OMP-NEXT: [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
// OMP-NEXT: store i32 [[COND]], i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[TMP5:%.*]] = load i32, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 [[TMP5]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP4:%.*]] = load i32, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 [[TMP4]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: br label [[OMP_INNER_FOR_COND:%.*]]
// OMP: omp.inner.for.cond:
// OMP-NEXT: [[TMP6:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP7:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP6]], [[TMP7]]
// OMP-NEXT: [[TMP5:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP6:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
// OMP-NEXT: br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
// OMP: omp.inner.for.body:
// OMP-NEXT: [[TMP8:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP8]], 1
// OMP-NEXT: [[TMP7:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
// OMP-NEXT: [[ADD:%.*]] = add nsw i32 0, [[MUL]]
// OMP-NEXT: store i32 [[ADD]], i32* [[I]], align 4
// OMP-NEXT: [[TMP9:%.*]] = load i32, i32* [[I]], align 4
// OMP-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP9]] to i64
// OMP-NEXT: [[TMP8:%.*]] = load i32, i32* [[I]], align 4
// OMP-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP8]] to i64
// OMP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], [33554432 x double]* @A, i64 0, i64 [[IDXPROM]]
// OMP-NEXT: store double 0.000000e+00, double* [[ARRAYIDX]], align 8
// OMP-NEXT: br label [[OMP_BODY_CONTINUE:%.*]]
// OMP: omp.body.continue:
// OMP-NEXT: br label [[OMP_INNER_FOR_INC:%.*]]
// OMP: omp.inner.for.inc:
// OMP-NEXT: [[TMP10:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP10]], 1
// OMP-NEXT: [[TMP9:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP9]], 1
// OMP-NEXT: store i32 [[ADD2]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: br label [[OMP_INNER_FOR_COND]]
// OMP: omp.inner.for.end:
// OMP-NEXT: br label [[OMP_LOOP_EXIT:%.*]]
// OMP: omp.loop.exit:
// OMP-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[TMP2]])
// OMP-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]])
// OMP-NEXT: ret void
//
//
// OMP-LABEL: @foo(
// OMP-NEXT: entry:
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: [[OMP_OUTLINED_ARG_AGG_:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 1
// OMP-NEXT: store i32 0, i32* [[I]], align 4
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon.0*)* @.omp_outlined..1 to void (i32*, i32*, ...)*), %struct.anon.0* [[OMP_OUTLINED_ARG_AGG_]])
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
// OMP-NEXT: ret void
//
//
// OMP-LABEL: @.omp_outlined..1(
// OMP-NEXT: entry:
// OMP-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
// OMP-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
// OMP-NEXT: [[__CONTEXT_ADDR:%.*]] = alloca %struct.anon.0*, align 8
// OMP-NEXT: [[DOTOMP_IV:%.*]] = alloca i32, align 4
// OMP-NEXT: [[TMP:%.*]] = alloca i32, align 4
// OMP-NEXT: [[DOTOMP_LB:%.*]] = alloca i32, align 4
Expand All @@ -131,55 +125,53 @@ void foo(void) {
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: store i32* [[DOTGLOBAL_TID_:%.*]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: store i32* [[DOTBOUND_TID_:%.*]], i32** [[DOTBOUND_TID__ADDR]], align 8
// OMP-NEXT: store %struct.anon.0* [[__CONTEXT:%.*]], %struct.anon.0** [[__CONTEXT_ADDR]], align 8
// OMP-NEXT: [[TMP0:%.*]] = load %struct.anon.0*, %struct.anon.0** [[__CONTEXT_ADDR]], align 8
// OMP-NEXT: store i32 0, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 33554431, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: store i32 1, i32* [[DOTOMP_STRIDE]], align 4
// OMP-NEXT: store i32 0, i32* [[DOTOMP_IS_LAST]], align 4
// OMP-NEXT: [[TMP1:%.*]] = load i32*, i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: [[TMP2:%.*]] = load i32, i32* [[TMP1]], align 4
// OMP-NEXT: call void @__kmpc_for_static_init_4(%struct.ident_t* @[[GLOB1]], i32 [[TMP2]], i32 34, i32* [[DOTOMP_IS_LAST]], i32* [[DOTOMP_LB]], i32* [[DOTOMP_UB]], i32* [[DOTOMP_STRIDE]], i32 1, i32 1)
// OMP-NEXT: [[TMP3:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP3]], 33554431
// OMP-NEXT: [[TMP0:%.*]] = load i32*, i32** [[DOTGLOBAL_TID__ADDR]], align 8
// OMP-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
// OMP-NEXT: call void @__kmpc_for_static_init_4(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]], i32 34, i32* [[DOTOMP_IS_LAST]], i32* [[DOTOMP_LB]], i32* [[DOTOMP_UB]], i32* [[DOTOMP_STRIDE]], i32 1, i32 1)
// OMP-NEXT: [[TMP2:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 33554431
// OMP-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
// OMP: cond.true:
// OMP-NEXT: br label [[COND_END:%.*]]
// OMP: cond.false:
// OMP-NEXT: [[TMP4:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[TMP3:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: br label [[COND_END]]
// OMP: cond.end:
// OMP-NEXT: [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP4]], [[COND_FALSE]] ]
// OMP-NEXT: [[COND:%.*]] = phi i32 [ 33554431, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
// OMP-NEXT: store i32 [[COND]], i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[TMP5:%.*]] = load i32, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 [[TMP5]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP4:%.*]] = load i32, i32* [[DOTOMP_LB]], align 4
// OMP-NEXT: store i32 [[TMP4]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: br label [[OMP_INNER_FOR_COND:%.*]]
// OMP: omp.inner.for.cond:
// OMP-NEXT: [[TMP6:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP7:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP6]], [[TMP7]]
// OMP-NEXT: [[TMP5:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[TMP6:%.*]] = load i32, i32* [[DOTOMP_UB]], align 4
// OMP-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
// OMP-NEXT: br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
// OMP: omp.inner.for.body:
// OMP-NEXT: [[TMP8:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP8]], 1
// OMP-NEXT: [[TMP7:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
// OMP-NEXT: [[ADD:%.*]] = add nsw i32 0, [[MUL]]
// OMP-NEXT: store i32 [[ADD]], i32* [[I]], align 4
// OMP-NEXT: [[TMP9:%.*]] = load i32, i32* [[I]], align 4
// OMP-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP9]] to i64
// OMP-NEXT: [[TMP8:%.*]] = load i32, i32* [[I]], align 4
// OMP-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP8]] to i64
// OMP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [33554432 x double], [33554432 x double]* @A, i64 0, i64 [[IDXPROM]]
// OMP-NEXT: store double 1.000000e+00, double* [[ARRAYIDX]], align 8
// OMP-NEXT: br label [[OMP_BODY_CONTINUE:%.*]]
// OMP: omp.body.continue:
// OMP-NEXT: br label [[OMP_INNER_FOR_INC:%.*]]
// OMP: omp.inner.for.inc:
// OMP-NEXT: [[TMP10:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP10]], 1
// OMP-NEXT: [[TMP9:%.*]] = load i32, i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP9]], 1
// OMP-NEXT: store i32 [[ADD2]], i32* [[DOTOMP_IV]], align 4
// OMP-NEXT: br label [[OMP_INNER_FOR_COND]]
// OMP: omp.inner.for.end:
// OMP-NEXT: br label [[OMP_LOOP_EXIT:%.*]]
// OMP: omp.loop.exit:
// OMP-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[TMP2]])
// OMP-NEXT: call void @__kmpc_for_static_fini(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]])
// OMP-NEXT: ret void
//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ void foo(void);
// OMP-NEXT: entry:
// OMP-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: [[OMP_OUTLINED_ARG_AGG_:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
// OMP-NEXT: store i32 0, i32* [[RETVAL]], align 4
// OMP-NEXT: store i32 0, i32* [[I]], align 4
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon*)* @.omp_outlined. to void (i32*, i32*, ...)*), %struct.anon* [[OMP_OUTLINED_ARG_AGG_]])
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2:[0-9]+]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined. to void (i32*, i32*, ...)*))
// OMP-NEXT: call void @foo()
// OMP-NEXT: ret i32 0
//
Expand Down Expand Up @@ -63,9 +62,8 @@ int main() {
// OMP-LABEL: @foo(
// OMP-NEXT: entry:
// OMP-NEXT: [[I:%.*]] = alloca i32, align 4
// OMP-NEXT: [[OMP_OUTLINED_ARG_AGG_:%.*]] = alloca [[STRUCT_ANON_0:%.*]], align 1
// OMP-NEXT: store i32 0, i32* [[I]], align 4
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon.0*)* @.omp_outlined..1 to void (i32*, i32*, ...)*), %struct.anon.0* [[OMP_OUTLINED_ARG_AGG_]])
// OMP-NEXT: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @[[GLOB2]], i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* @.omp_outlined..1 to void (i32*, i32*, ...)*))
// OMP-NEXT: ret void
//
// NOOMP-LABEL: @foo(
Expand Down
405 changes: 405 additions & 0 deletions openmp/libomptarget/deviceRTLs/common/generated_microtask_cases.gen

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions openmp/libomptarget/deviceRTLs/common/src/support.cu
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,9 @@ char *GetTeamsReductionScratchpad() {
void __kmp_invoke_microtask(kmp_int32 global_tid, kmp_int32 bound_tid, void *fn,
void **args, size_t nargs) {
switch (nargs) {
case 1:
((void (*)(kmp_int32 *, kmp_int32 *, void *))fn)(&global_tid, &bound_tid,
args[0]);
break;
case 3:
((void (*)(kmp_int32 *, kmp_int32 *, void *, void *, void *))fn)(
&global_tid, &bound_tid, args[0], args[1], args[2]);
break;
#include "common/generated_microtask_cases.gen"
default:
printf("Invalid number of arguments in kmp_invoke_microtask, expects 1 or "
"3 (for combined constructs), aborting execution.\n");
printf("Too many arguments in kmp_invoke_microtask, aborting execution.\n");
__builtin_trap();
}
}
Expand Down
31 changes: 31 additions & 0 deletions openmp/libomptarget/utils/generate_microtask_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

import argparse

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--max_args', type=int, help='Max number of arguments to generate case statements for', required=True)
parser.add_argument('--output', help='Output header file to include', required=True)
args = parser.parse_args()

output=''
for i in range(args.max_args+1):
output += 'case %d:\n'%(i)
output += '((void (*)(kmp_int32 *, kmp_int32 *\n'
for j in range(i):
output += ', void *'
if (j+1)%4 == 0:
output += '\n'
output += '))fn)(&global_tid, &bound_tid\n'
for j in range(i):
output += ', args[%d]'%(j)
if (j+1)%4 == 0:
output += '\n'
output += ');\n'
output += 'break;\n'

with open(args.output, 'w') as f:
print(output, file=f)

if __name__ == "__main__":
main()