1207b08a9SGiorgis Georgakoudis // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
2c99042baSAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
3207b08a9SGiorgis Georgakoudis // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -disable-llvm-optzns | FileCheck %s --check-prefix=CHECK1
4c99042baSAlexey Bataev // expected-no-diagnostics
5c99042baSAlexey Bataev 
6c99042baSAlexey Bataev int foo(int &a) { return a; }
7c99042baSAlexey Bataev 
8c99042baSAlexey Bataev int bar() {
9c99042baSAlexey Bataev   int a;
10c99042baSAlexey Bataev   return foo(a);
11c99042baSAlexey Bataev }
12c99042baSAlexey Bataev 
13c99042baSAlexey Bataev 
14c99042baSAlexey Bataev int maini1() {
15c99042baSAlexey Bataev   int a;
16c99042baSAlexey Bataev #pragma omp target parallel map(from:a)
17c99042baSAlexey Bataev   {
18c99042baSAlexey Bataev     int b;
19c99042baSAlexey Bataev     a = foo(b) + bar();
20c99042baSAlexey Bataev   }
21c99042baSAlexey Bataev   return a;
22c99042baSAlexey Bataev }
23c99042baSAlexey Bataev 
24c99042baSAlexey Bataev // parallel region
25c99042baSAlexey Bataev 
26c99042baSAlexey Bataev 
27207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z6maini1v_l16
28207b08a9SGiorgis Georgakoudis // CHECK1-SAME: (i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR0:[0-9]+]] {
29207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
30207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
31207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[CAPTURED_VARS_ADDRS:%.*]] = alloca [1 x i8*], align 8
32207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
33207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
34*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1:[0-9]+]], i1 true, i1 false, i1 true)
35*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
36*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
37*e2cfbfccSJohannes Doerfert // CHECK1:       user_code.entry:
38*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[TMP2:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB2:[0-9]+]])
39*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[CAPTURED_VARS_ADDRS]], i64 0, i64 0
40*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[TMP4:%.*]] = bitcast i32* [[TMP0]] to i8*
41*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    store i8* [[TMP4]], i8** [[TMP3]], align 8
42*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[TMP5:%.*]] = bitcast [1 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
43*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    call void @__kmpc_parallel_51(%struct.ident_t* @[[GLOB2]], i32 [[TMP2]], i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*, i32*)* @__omp_outlined__ to i8*), i8* null, i8** [[TMP5]], i64 1)
44*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i1 true, i1 true)
45*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    ret void
46*e2cfbfccSJohannes Doerfert // CHECK1:       worker.exit:
47207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret void
48207b08a9SGiorgis Georgakoudis //
49207b08a9SGiorgis Georgakoudis //
50207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@__omp_outlined__
51207b08a9SGiorgis Georgakoudis // CHECK1-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]], i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR0]] {
52207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
53207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
54207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
55207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
56207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[B:%.*]] = alloca i32, align 4
57207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
58207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8
59207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
60207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
61*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[CALL:%.*]] = call i32 @_Z3fooRi(i32* nonnull align 4 dereferenceable(4) [[B]]) #[[ATTR3:[0-9]+]]
62*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[CALL1:%.*]] = call i32 @_Z3barv() #[[ATTR3]]
63207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL]], [[CALL1]]
64207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32 [[ADD]], i32* [[TMP0]], align 4
65207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret void
66207b08a9SGiorgis Georgakoudis //
67207b08a9SGiorgis Georgakoudis //
68207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@_Z3fooRi
69*e2cfbfccSJohannes Doerfert // CHECK1-SAME: (i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR1:[0-9]+]] {
70207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
71207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
72207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
73207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
74207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
75207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret i32 [[TMP1]]
76207b08a9SGiorgis Georgakoudis //
77207b08a9SGiorgis Georgakoudis //
78207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@_Z3barv
79*e2cfbfccSJohannes Doerfert // CHECK1-SAME: () #[[ATTR1]] {
80207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
8168d133a3SJoseph Huber // CHECK1-NEXT:    [[A:%.*]] = call i8* @__kmpc_alloc_shared(i64 4)
8268d133a3SJoseph Huber // CHECK1-NEXT:    [[A_ON_STACK:%.*]] = bitcast i8* [[A]] to i32*
83*e2cfbfccSJohannes Doerfert // CHECK1-NEXT:    [[CALL:%.*]] = call i32 @_Z3fooRi(i32* nonnull align 4 dereferenceable(4) [[A_ON_STACK]]) #[[ATTR3]]
8468d133a3SJoseph Huber // CHECK1-NEXT:    call void @__kmpc_free_shared(i8* [[A]])
8568d133a3SJoseph Huber // CHECK1-NEXT:    ret i32 [[CALL]]
86207b08a9SGiorgis Georgakoudis //
87