Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_offload_mandatory_codegen.cpp
blob5803a81c4b1a5bb756a203d510a13c46d96e491d
1 // 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]+"
2 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -fopenmp-offload-mandatory -emit-llvm %s -o - | FileCheck %s --check-prefix=MANDATORY
3 // expected-no-diagnostics
5 void foo() {}
6 #pragma omp declare target(foo)
8 void bar() {}
9 #pragma omp declare target device_type(nohost) to(bar)
11 void host() {
12 #pragma omp target
13 { bar(); }
16 void host_if(bool cond) {
17 #pragma omp target if(cond)
18 { bar(); }
21 void host_dev(int device) {
22 #pragma omp target device(device)
23 { bar(); }
25 // MANDATORY-LABEL: define {{[^@]+}}@_Z3foov
26 // MANDATORY-SAME: () #[[ATTR0:[0-9]+]] {
27 // MANDATORY-NEXT: entry:
28 // MANDATORY-NEXT: ret void
31 // MANDATORY-LABEL: define {{[^@]+}}@_Z4hostv
32 // MANDATORY-SAME: () #[[ATTR0]] {
33 // MANDATORY-NEXT: entry:
34 // MANDATORY-NEXT: [[KERNEL_ARGS:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
35 // MANDATORY-NEXT: [[TMP0:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
36 // MANDATORY-NEXT: store i32 2, ptr [[TMP0]], align 4
37 // MANDATORY-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
38 // MANDATORY-NEXT: store i32 0, ptr [[TMP1]], align 4
39 // MANDATORY-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 2
40 // MANDATORY-NEXT: store ptr null, ptr [[TMP2]], align 8
41 // MANDATORY-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 3
42 // MANDATORY-NEXT: store ptr null, ptr [[TMP3]], align 8
43 // MANDATORY-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 4
44 // MANDATORY-NEXT: store ptr null, ptr [[TMP4]], align 8
45 // MANDATORY-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 5
46 // MANDATORY-NEXT: store ptr null, ptr [[TMP5]], align 8
47 // MANDATORY-NEXT: [[TMP6:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 6
48 // MANDATORY-NEXT: store ptr null, ptr [[TMP6]], align 8
49 // MANDATORY-NEXT: [[TMP7:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 7
50 // MANDATORY-NEXT: store ptr null, ptr [[TMP7]], align 8
51 // MANDATORY-NEXT: [[TMP8:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 8
52 // MANDATORY-NEXT: store i64 0, ptr [[TMP8]], align 8
53 // MANDATORY-NEXT: [[TMP9:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 9
54 // MANDATORY-NEXT: store i64 0, ptr [[TMP9]], align 8
55 // MANDATORY-NEXT: [[TMP10:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 10
56 // MANDATORY-NEXT: store [3 x i32] [i32 -1, i32 0, i32 0], ptr [[TMP10]], align 4
57 // MANDATORY-NEXT: [[TMP11:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 11
58 // MANDATORY-NEXT: store [3 x i32] zeroinitializer, ptr [[TMP11]], align 4
59 // MANDATORY-NEXT: [[TMP12:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 12
60 // MANDATORY-NEXT: store i32 0, ptr [[TMP12]], align 4
61 // MANDATORY-NEXT: [[TMP13:%.*]] = call i32 @__tgt_target_kernel(ptr @[[GLOB1:[0-9]+]], i64 -1, i32 -1, i32 0, ptr @.{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4hostv_l12.region_id, ptr [[KERNEL_ARGS]])
62 // MANDATORY-NEXT: [[TMP14:%.*]] = icmp ne i32 [[TMP13]], 0
63 // MANDATORY-NEXT: br i1 [[TMP14]], label [[OMP_OFFLOAD_FAILED:%.*]], label [[OMP_OFFLOAD_CONT:%.*]]
64 // MANDATORY: omp_offload.failed:
65 // MANDATORY-NEXT: unreachable
66 // MANDATORY: omp_offload.cont:
67 // MANDATORY-NEXT: ret void
70 // MANDATORY-LABEL: define {{[^@]+}}@_Z7host_ifb
71 // MANDATORY-SAME: (i1 noundef zeroext [[COND:%.*]]) #[[ATTR0]] {
72 // MANDATORY-NEXT: entry:
73 // MANDATORY-NEXT: [[COND_ADDR:%.*]] = alloca i8, align 1
74 // MANDATORY-NEXT: [[KERNEL_ARGS:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
75 // MANDATORY-NEXT: [[FROMBOOL:%.*]] = zext i1 [[COND]] to i8
76 // MANDATORY-NEXT: store i8 [[FROMBOOL]], ptr [[COND_ADDR]], align 1
77 // MANDATORY-NEXT: [[TMP0:%.*]] = load i8, ptr [[COND_ADDR]], align 1
78 // MANDATORY-NEXT: [[TOBOOL:%.*]] = trunc i8 [[TMP0]] to i1
79 // MANDATORY-NEXT: br i1 [[TOBOOL]], label [[OMP_IF_THEN:%.*]], label [[OMP_IF_ELSE:%.*]]
80 // MANDATORY: omp_if.then:
81 // MANDATORY-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
82 // MANDATORY-NEXT: store i32 2, ptr [[TMP1]], align 4
83 // MANDATORY-NEXT: [[TMP2:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
84 // MANDATORY-NEXT: store i32 0, ptr [[TMP2]], align 4
85 // MANDATORY-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 2
86 // MANDATORY-NEXT: store ptr null, ptr [[TMP3]], align 8
87 // MANDATORY-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 3
88 // MANDATORY-NEXT: store ptr null, ptr [[TMP4]], align 8
89 // MANDATORY-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 4
90 // MANDATORY-NEXT: store ptr null, ptr [[TMP5]], align 8
91 // MANDATORY-NEXT: [[TMP6:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 5
92 // MANDATORY-NEXT: store ptr null, ptr [[TMP6]], align 8
93 // MANDATORY-NEXT: [[TMP7:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 6
94 // MANDATORY-NEXT: store ptr null, ptr [[TMP7]], align 8
95 // MANDATORY-NEXT: [[TMP8:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 7
96 // MANDATORY-NEXT: store ptr null, ptr [[TMP8]], align 8
97 // MANDATORY-NEXT: [[TMP9:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 8
98 // MANDATORY-NEXT: store i64 0, ptr [[TMP9]], align 8
99 // MANDATORY-NEXT: [[TMP10:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 9
100 // MANDATORY-NEXT: store i64 0, ptr [[TMP10]], align 8
101 // MANDATORY-NEXT: [[TMP11:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 10
102 // MANDATORY-NEXT: store [3 x i32] [i32 -1, i32 0, i32 0], ptr [[TMP11]], align 4
103 // MANDATORY-NEXT: [[TMP12:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 11
104 // MANDATORY-NEXT: store [3 x i32] zeroinitializer, ptr [[TMP12]], align 4
105 // MANDATORY-NEXT: [[TMP13:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 12
106 // MANDATORY-NEXT: store i32 0, ptr [[TMP13]], align 4
107 // MANDATORY-NEXT: [[TMP14:%.*]] = call i32 @__tgt_target_kernel(ptr @[[GLOB1]], i64 -1, i32 -1, i32 0, ptr @.{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z7host_ifb_l17.region_id, ptr [[KERNEL_ARGS]])
108 // MANDATORY-NEXT: [[TMP15:%.*]] = icmp ne i32 [[TMP14]], 0
109 // MANDATORY-NEXT: br i1 [[TMP15]], label [[OMP_OFFLOAD_FAILED:%.*]], label [[OMP_OFFLOAD_CONT:%.*]]
110 // MANDATORY: omp_offload.failed:
111 // MANDATORY-NEXT: unreachable
112 // MANDATORY: omp_offload.cont:
113 // MANDATORY-NEXT: br label [[OMP_IF_END:%.*]]
114 // MANDATORY: omp_if.else:
115 // MANDATORY-NEXT: unreachable
116 // MANDATORY: omp_if.end:
117 // MANDATORY-NEXT: ret void
120 // MANDATORY-LABEL: define {{[^@]+}}@_Z8host_devi
121 // MANDATORY-SAME: (i32 noundef signext [[DEVICE:%.*]]) #[[ATTR0]] {
122 // MANDATORY-NEXT: entry:
123 // MANDATORY-NEXT: [[DEVICE_ADDR:%.*]] = alloca i32, align 4
124 // MANDATORY-NEXT: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32, align 4
125 // MANDATORY-NEXT: [[KERNEL_ARGS:%.*]] = alloca [[STRUCT___TGT_KERNEL_ARGUMENTS:%.*]], align 8
126 // MANDATORY-NEXT: store i32 [[DEVICE]], ptr [[DEVICE_ADDR]], align 4
127 // MANDATORY-NEXT: [[TMP0:%.*]] = load i32, ptr [[DEVICE_ADDR]], align 4
128 // MANDATORY-NEXT: store i32 [[TMP0]], ptr [[DOTCAPTURE_EXPR_]], align 4
129 // MANDATORY-NEXT: [[TMP1:%.*]] = load i32, ptr [[DOTCAPTURE_EXPR_]], align 4
130 // MANDATORY-NEXT: [[TMP2:%.*]] = sext i32 [[TMP1]] to i64
131 // MANDATORY-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 0
132 // MANDATORY-NEXT: store i32 2, ptr [[TMP3]], align 4
133 // MANDATORY-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 1
134 // MANDATORY-NEXT: store i32 0, ptr [[TMP4]], align 4
135 // MANDATORY-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 2
136 // MANDATORY-NEXT: store ptr null, ptr [[TMP5]], align 8
137 // MANDATORY-NEXT: [[TMP6:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 3
138 // MANDATORY-NEXT: store ptr null, ptr [[TMP6]], align 8
139 // MANDATORY-NEXT: [[TMP7:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 4
140 // MANDATORY-NEXT: store ptr null, ptr [[TMP7]], align 8
141 // MANDATORY-NEXT: [[TMP8:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 5
142 // MANDATORY-NEXT: store ptr null, ptr [[TMP8]], align 8
143 // MANDATORY-NEXT: [[TMP9:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 6
144 // MANDATORY-NEXT: store ptr null, ptr [[TMP9]], align 8
145 // MANDATORY-NEXT: [[TMP10:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 7
146 // MANDATORY-NEXT: store ptr null, ptr [[TMP10]], align 8
147 // MANDATORY-NEXT: [[TMP11:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 8
148 // MANDATORY-NEXT: store i64 0, ptr [[TMP11]], align 8
149 // MANDATORY-NEXT: [[TMP12:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 9
150 // MANDATORY-NEXT: store i64 0, ptr [[TMP12]], align 8
151 // MANDATORY-NEXT: [[TMP13:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 10
152 // MANDATORY-NEXT: store [3 x i32] [i32 -1, i32 0, i32 0], ptr [[TMP13]], align 4
153 // MANDATORY-NEXT: [[TMP14:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 11
154 // MANDATORY-NEXT: store [3 x i32] zeroinitializer, ptr [[TMP14]], align 4
155 // MANDATORY-NEXT: [[TMP15:%.*]] = getelementptr inbounds [[STRUCT___TGT_KERNEL_ARGUMENTS]], ptr [[KERNEL_ARGS]], i32 0, i32 12
156 // MANDATORY-NEXT: store i32 0, ptr [[TMP15]], align 4
157 // MANDATORY-NEXT: [[TMP16:%.*]] = call i32 @__tgt_target_kernel(ptr @[[GLOB1]], i64 [[TMP2]], i32 -1, i32 0, ptr @.{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z8host_devi_l22.region_id, ptr [[KERNEL_ARGS]])
158 // MANDATORY-NEXT: [[TMP17:%.*]] = icmp ne i32 [[TMP16]], 0
159 // MANDATORY-NEXT: br i1 [[TMP17]], label [[OMP_OFFLOAD_FAILED:%.*]], label [[OMP_OFFLOAD_CONT:%.*]]
160 // MANDATORY: omp_offload.failed:
161 // MANDATORY-NEXT: unreachable
162 // MANDATORY: omp_offload.cont:
163 // MANDATORY-NEXT: ret void
166 // MANDATORY-LABEL: define {{[^@]+}}@.omp_offloading.requires_reg
167 // MANDATORY-SAME: () #[[ATTR3:[0-9]+]] {
168 // MANDATORY-NEXT: entry:
169 // MANDATORY-NEXT: call void @__tgt_register_requires(i64 1)
170 // MANDATORY-NEXT: ret void