1 // Test host codegen.
2 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s
3 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
4 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
8 
9 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
14 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
15 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
16 
17 // Test target teams distribute codegen - host bc file has to be created first.
18 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
19 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s -check-prefix=TCHECK
20 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s
21 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=TCHECK
22 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc
23 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s -check-prefix=TCHECK
24 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s
25 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s -check-prefix=TCHECK
26 
27 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc
28 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s
29 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t %s
30 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
31 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm-bc %s -o %t-x86-host.bc
32 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck --check-prefix SIMD-ONLY1 %s
33 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o %t %s
34 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
35 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
36 
37 // Check that no target code is emitted if no omptests flag was provided.
38 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-NTARGET
39 
40 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY2 %s
41 // SIMD-ONLY2-NOT: {{__kmpc|__tgt}}
42 
43 // expected-no-diagnostics
44 #ifndef HEADER
45 #define HEADER
46 
47 // CHECK-DAG: [[SA:%.+]] = type { [4 x i32] }
48 // CHECK-DAG: [[SB:%.+]] = type { [8 x i32] }
49 // CHECK-DAG: [[SC:%.+]] = type { [16 x i32] }
50 // CHECK-DAG: [[SD:%.+]] = type { [32 x i32] }
51 // CHECK-DAG: [[SE:%.+]] = type { [64 x i32] }
52 // CHECK-DAG: [[ST1:%.+]] = type { [228 x i32] }
53 // CHECK-DAG: [[ST2:%.+]] = type { [1128 x i32] }
54 // CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
55 
56 // TCHECK:    [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
57 
58 // CHECK-DAG: [[A1:@.+]] = internal global [[SA]]
59 // CHECK-DAG: [[A2:@.+]] = global [[SA]]
60 // CHECK-DAG: [[B1:@.+]] = global [[SB]]
61 // CHECK-DAG: [[B2:@.+]] = global [[SB]]
62 // CHECK-DAG: [[C1:@.+]] = internal global [[SC]]
63 // CHECK-DAG: [[D1:@.+]] = global [[SD]]
64 // CHECK-DAG: [[E1:@.+]] = global [[SE]]
65 // CHECK-DAG: [[T1:@.+]] = global [[ST1]]
66 // CHECK-DAG: [[T2:@.+]] = global [[ST2]]
67 
68 // CHECK-NTARGET-DAG: [[SA:%.+]] = type { [4 x i32] }
69 // CHECK-NTARGET-DAG: [[SB:%.+]] = type { [8 x i32] }
70 // CHECK-NTARGET-DAG: [[SC:%.+]] = type { [16 x i32] }
71 // CHECK-NTARGET-DAG: [[SD:%.+]] = type { [32 x i32] }
72 // CHECK-NTARGET-DAG: [[SE:%.+]] = type { [64 x i32] }
73 // CHECK-NTARGET-DAG: [[ST1:%.+]] = type { [228 x i32] }
74 // CHECK-NTARGET-DAG: [[ST2:%.+]] = type { [1128 x i32] }
75 // CHECK-NTARGET-NOT: type { i8*, i8*, %
76 // CHECK-NTARGET-NOT: type { i32, %
77 
78 // We have 7 target regions
79 
80 // CHECK-DAG: {{@.+}} = weak constant i8 0
81 // TCHECK-NOT: {{@.+}} = weak constant i8 0
82 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
83 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
84 // CHECK-DAG: {{@.+}} = weak constant i8 0
85 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
86 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
87 // CHECK-DAG: {{@.+}} = weak constant i8 0
88 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
89 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
90 // CHECK-DAG: {{@.+}} = weak constant i8 0
91 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
92 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
93 // CHECK-DAG: {{@.+}} = weak constant i8 0
94 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
95 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
96 // CHECK-DAG: {{@.+}} = weak constant i8 0
97 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
98 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
99 // CHECK-DAG: {{@.+}} = weak constant i8 0
100 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
101 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
102 // CHECK-DAG: {{@.+}} = weak constant i8 0
103 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
104 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
105 // CHECK-DAG: {{@.+}} = weak constant i8 0
106 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
107 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
108 // CHECK-DAG: {{@.+}} = weak constant i8 0
109 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
110 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
111 // CHECK-DAG: {{@.+}} = weak constant i8 0
112 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
113 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
114 // CHECK-DAG: {{@.+}} = weak constant i8 0
115 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 4]
116 // CHECK-DAG: {{@.+}} = private unnamed_addr constant [1 x i64] [i64 800]
117 
118 // CHECK-NTARGET-NOT: weak constant i8 0
119 // CHECK-NTARGET-NOT: private unnamed_addr constant [1 x i
120 
121 // CHECK-DAG: [[NAMEPTR1:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME1:__omp_offloading_[0-9a-f]+_[0-9a-f]+__Z.+_l[0-9]+]]\00"
122 // CHECK-DAG: [[ENTRY1:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR1]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
123 // CHECK-DAG: [[NAMEPTR2:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME2:.+]]\00"
124 // CHECK-DAG: [[ENTRY2:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR2]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
125 // CHECK-DAG: [[NAMEPTR3:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME3:.+]]\00"
126 // CHECK-DAG: [[ENTRY3:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR3]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
127 // CHECK-DAG: [[NAMEPTR4:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME4:.+]]\00"
128 // CHECK-DAG: [[ENTRY4:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR4]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
129 // CHECK-DAG: [[NAMEPTR5:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME5:.+]]\00"
130 // CHECK-DAG: [[ENTRY5:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR5]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
131 // CHECK-DAG: [[NAMEPTR6:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME6:.+]]\00"
132 // CHECK-DAG: [[ENTRY6:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR6]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
133 // CHECK-DAG: [[NAMEPTR7:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME7:.+]]\00"
134 // CHECK-DAG: [[ENTRY7:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR7]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
135 // CHECK-DAG: [[NAMEPTR8:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME8:.+]]\00"
136 // CHECK-DAG: [[ENTRY8:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR8]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
137 // CHECK-DAG: [[NAMEPTR9:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME9:.+]]\00"
138 // CHECK-DAG: [[ENTRY9:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR9]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
139 // CHECK-DAG: [[NAMEPTR10:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME10:.+]]\00"
140 // CHECK-DAG: [[ENTRY10:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR10]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
141 // CHECK-DAG: [[NAMEPTR11:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME11:.+]]\00"
142 // CHECK-DAG: [[ENTRY11:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR11]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
143 // CHECK-DAG: [[NAMEPTR12:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME12:.+]]\00"
144 // CHECK-DAG: [[ENTRY12:@.+]] = weak constant [[ENTTY]] { i8* @{{.*}}, i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR12]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
145 
146 // TCHECK-DAG: [[NAMEPTR1:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME1:__omp_offloading_[0-9a-f]+_[0-9a-f]+__Z.+_l[0-9]+]]\00"
147 // TCHECK-DAG: [[ENTRY1:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR1]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
148 // TCHECK-DAG: [[NAMEPTR2:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME2:.+]]\00"
149 // TCHECK-DAG: [[ENTRY2:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR2]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
150 // TCHECK-DAG: [[NAMEPTR3:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME3:.+]]\00"
151 // TCHECK-DAG: [[ENTRY3:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR3]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
152 // TCHECK-DAG: [[NAMEPTR4:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME4:.+]]\00"
153 // TCHECK-DAG: [[ENTRY4:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR4]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
154 // TCHECK-DAG: [[NAMEPTR5:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME5:.+]]\00"
155 // TCHECK-DAG: [[ENTRY5:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR5]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
156 // TCHECK-DAG: [[NAMEPTR6:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME6:.+]]\00"
157 // TCHECK-DAG: [[ENTRY6:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR6]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
158 // TCHECK-DAG: [[NAMEPTR7:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME7:.+]]\00"
159 // TCHECK-DAG: [[ENTRY7:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR7]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
160 // TCHECK-DAG: [[NAMEPTR8:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME8:.+]]\00"
161 // TCHECK-DAG: [[ENTRY8:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR8]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
162 // TCHECK-DAG: [[NAMEPTR9:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME9:.+]]\00"
163 // TCHECK-DAG: [[ENTRY9:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR9]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
164 // TCHECK-DAG: [[NAMEPTR10:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME10:.+]]\00"
165 // TCHECK-DAG: [[ENTRY10:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR10]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
166 // TCHECK-DAG: [[NAMEPTR11:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME11:.+]]\00"
167 // TCHECK-DAG: [[ENTRY11:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR11]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
168 // TCHECK-DAG: [[NAMEPTR12:@.+]] = internal unnamed_addr constant [{{.*}} x i8] c"[[NAME12:.+]]\00"
169 // TCHECK-DAG: [[ENTRY12:@.+]] = weak constant [[ENTTY]] { i8* bitcast (void (i[[SZ]])* @{{.*}} to i8*), i8* getelementptr inbounds ([{{.*}} x i8], [{{.*}} x i8]* [[NAMEPTR12]], i32 0, i32 0), i[[SZ]] 0, i32 0, i32 0 }, section "omp_offloading_entries", align 1
170 
171 // We have 4 initializers, one for the 500 priority, another one for 501, or more for the default priority, and the last one for the offloading registration function.
172 // CHECK: @llvm.global_ctors = appending global [4 x { i32, void ()*, i8* }] [
173 // CHECK-SAME: { i32, void ()*, i8* } { i32 500, void ()* [[P500:@[^,]+]], i8* null },
174 // CHECK-SAME: { i32, void ()*, i8* } { i32 501, void ()* [[P501:@[^,]+]], i8* null },
175 // CHECK-SAME: { i32, void ()*, i8* } { i32 65535, void ()* [[PMAX:@[^,]+]], i8* null },
176 
177 // CHECK-NTARGET: @llvm.global_ctors = appending global [3   x { i32, void ()*, i8* }] [
178 
179 extern int *R;
180 
181 struct SA {
182   int arr[4];
fooSA183   void foo() {
184     int a = *R;
185     a += 1;
186     *R = a;
187   }
SASA188   SA() {
189     int a = *R;
190     a += 2;
191     *R = a;
192   }
~SASA193   ~SA() {
194     int a = *R;
195     a += 3;
196     *R = a;
197   }
198 };
199 
200 struct SB {
201   int arr[8];
fooSB202   void foo() {
203     int a = *R;
204     #pragma omp target teams distribute
205     for (int i = 0; i < 10; ++i)
206       a += 4;
207     *R = a;
208   }
SBSB209   SB() {
210     int a = *R;
211     a += 5;
212     *R = a;
213   }
~SBSB214   ~SB() {
215     int a = *R;
216     a += 6;
217     *R = a;
218   }
219 };
220 
221 struct SC {
222   int arr[16];
fooSC223   void foo() {
224     int a = *R;
225     a += 7;
226     *R = a;
227   }
SCSC228   SC() {
229     int a = *R;
230     #pragma omp target teams distribute
231     for (int i = 0; i < 10; ++i)
232       a += 8;
233     *R = a;
234   }
~SCSC235   ~SC() {
236     int a = *R;
237     a += 9;
238     *R = a;
239   }
240 };
241 
242 struct SD {
243   int arr[32];
fooSD244   void foo() {
245     int a = *R;
246     a += 10;
247     *R = a;
248   }
SDSD249   SD() {
250     int a = *R;
251     a += 11;
252     *R = a;
253   }
~SDSD254   ~SD() {
255     int a = *R;
256     #pragma omp target teams distribute
257     for (int i = 0; i < 10; ++i)
258       a += 12;
259     *R = a;
260   }
261 };
262 
263 struct SE {
264   int arr[64];
fooSE265   void foo() {
266     int a = *R;
267     #pragma omp target teams distribute if(target: 0)
268     for (int i = 0; i < 10; ++i)
269       a += 13;
270     *R = a;
271   }
SESE272   SE() {
273     int a = *R;
274     #pragma omp target teams distribute
275     for (int i = 0; i < 10; ++i)
276       a += 14;
277     *R = a;
278   }
~SESE279   ~SE() {
280     int a = *R;
281     #pragma omp target teams distribute
282     for (int i = 0; i < 10; ++i)
283       a += 15;
284     *R = a;
285   }
286 };
287 
288 template <int x>
289 struct ST {
290   int arr[128 + x];
fooST291   void foo() {
292     int a = *R;
293     #pragma omp target teams distribute
294     for (int i = 0; i < 10; ++i)
295       a += 16 + x;
296     *R = a;
297   }
STST298   ST() {
299     int a = *R;
300     #pragma omp target teams distribute
301     for (int i = 0; i < 10; ++i)
302       a += 17 + x;
303     *R = a;
304   }
~STST305   ~ST() {
306     int a = *R;
307     #pragma omp target teams distribute
308     for (int i = 0; i < 10; ++i)
309       a += 18 + x;
310     *R = a;
311   }
312 };
313 
314 // We have to make sure we us all the target regions:
315 //CHECK-DAG: define internal void @[[NAME1]](
316 //CHECK-DAG: call void @[[NAME1]](
317 //CHECK-DAG: define internal void @[[NAME2]](
318 //CHECK-DAG: call void @[[NAME2]](
319 //CHECK-DAG: define internal void @[[NAME3]](
320 //CHECK-DAG: call void @[[NAME3]](
321 //CHECK-DAG: define internal void @[[NAME4]](
322 //CHECK-DAG: call void @[[NAME4]](
323 //CHECK-DAG: define internal void @[[NAME5]](
324 //CHECK-DAG: call void @[[NAME5]](
325 //CHECK-DAG: define internal void @[[NAME6]](
326 //CHECK-DAG: call void @[[NAME6]](
327 //CHECK-DAG: define internal void @[[NAME7]](
328 //CHECK-DAG: call void @[[NAME7]](
329 //CHECK-DAG: define internal void @[[NAME8]](
330 //CHECK-DAG: call void @[[NAME8]](
331 //CHECK-DAG: define internal void @[[NAME9]](
332 //CHECK-DAG: call void @[[NAME9]](
333 //CHECK-DAG: define internal void @[[NAME10]](
334 //CHECK-DAG: call void @[[NAME10]](
335 //CHECK-DAG: define internal void @[[NAME11]](
336 //CHECK-DAG: call void @[[NAME11]](
337 //CHECK-DAG: define internal void @[[NAME12]](
338 //CHECK-DAG: call void @[[NAME12]](
339 
340 //TCHECK-DAG: define weak void @[[NAME1]](
341 //TCHECK-DAG: define weak void @[[NAME2]](
342 //TCHECK-DAG: define weak void @[[NAME3]](
343 //TCHECK-DAG: define weak void @[[NAME4]](
344 //TCHECK-DAG: define weak void @[[NAME5]](
345 //TCHECK-DAG: define weak void @[[NAME6]](
346 //TCHECK-DAG: define weak void @[[NAME7]](
347 //TCHECK-DAG: define weak void @[[NAME8]](
348 //TCHECK-DAG: define weak void @[[NAME9]](
349 //TCHECK-DAG: define weak void @[[NAME10]](
350 //TCHECK-DAG: define weak void @[[NAME11]](
351 //TCHECK-DAG: define weak void @[[NAME12]](
352 
353 // CHECK-NTARGET-NOT: __tgt_target
354 
355 // TCHECK-NOT: __tgt_target
356 
357 // We have 2 initializers with priority 500
358 //CHECK: define internal void [[P500]](
359 //CHECK:     call void @{{.+}}()
360 //CHECK:     call void @{{.+}}()
361 //CHECK-NOT: call void @{{.+}}()
362 //CHECK:     ret void
363 
364 // We have 1 initializers with priority 501
365 //CHECK: define internal void [[P501]](
366 //CHECK:     call void @{{.+}}()
367 //CHECK-NOT: call void @{{.+}}()
368 //CHECK:     ret void
369 
370 // We have 6 initializers with default priority
371 //CHECK: define internal void [[PMAX]](
372 //CHECK:     call void @{{.+}}()
373 //CHECK:     call void @{{.+}}()
374 //CHECK:     call void @{{.+}}()
375 //CHECK:     call void @{{.+}}()
376 //CHECK:     call void @{{.+}}()
377 //CHECK:     call void @{{.+}}()
378 //CHECK-NOT: call void @{{.+}}()
379 //CHECK:     ret void
380 
381 static __attribute__((init_priority(500))) SA a1;
382 SA a2;
383 SB __attribute__((init_priority(500))) b1;
384 SB __attribute__((init_priority(501))) b2;
385 static SC c1;
386 SD d1;
387 SE e1;
388 ST<100> t1;
389 ST<1000> t2;
390 
391 
bar(int a)392 int bar(int a){
393   int r = a;
394 
395   a1.foo();
396   a2.foo();
397   b1.foo();
398   b2.foo();
399   c1.foo();
400   d1.foo();
401   e1.foo();
402   t1.foo();
403   t2.foo();
404 
405   #pragma omp target teams distribute
406   for (int i = 0; i < 10; ++i)
407     ++r;
408 
409   return r + *R;
410 }
411 
412 // Check metadata is properly generated:
413 // CHECK:     !omp_offload.info = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
414 // CHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 204, i32 {{[0-9]+}}}
415 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 256, i32 {{[0-9]+}}}
416 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 274, i32 {{[0-9]+}}}
417 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 281, i32 {{[0-9]+}}}
418 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 293, i32 {{[0-9]+}}}
419 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 300, i32 {{[0-9]+}}}
420 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 405, i32 {{[0-9]+}}}
421 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 307, i32 {{[0-9]+}}}
422 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 300, i32 {{[0-9]+}}}
423 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 307, i32 {{[0-9]+}}}
424 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 293, i32 {{[0-9]+}}}
425 // CHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SCC1Ev", i32 230, i32 {{[0-9]+}}}
426 
427 // TCHECK:     !omp_offload.info = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
428 // TCHECK-DAG: = !{i32 0, i32 [[DEVID:-?[0-9]+]], i32 [[FILEID:-?[0-9]+]], !"_ZN2SB3fooEv", i32 204, i32 {{[0-9]+}}}
429 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SDD1Ev", i32 256, i32 {{[0-9]+}}}
430 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SEC1Ev", i32 274, i32 {{[0-9]+}}}
431 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SED1Ev", i32 281, i32 {{[0-9]+}}}
432 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EE3fooEv", i32 293, i32 {{[0-9]+}}}
433 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EEC1Ev", i32 300, i32 {{[0-9]+}}}
434 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_Z3bari", i32 405, i32 {{[0-9]+}}}
435 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EED1Ev", i32 307, i32 {{[0-9]+}}}
436 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EEC1Ev", i32 300, i32 {{[0-9]+}}}
437 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi1000EED1Ev", i32 307, i32 {{[0-9]+}}}
438 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2STILi100EE3fooEv", i32 293, i32 {{[0-9]+}}}
439 // TCHECK-DAG: = !{i32 0, i32 [[DEVID]], i32 [[FILEID]], !"_ZN2SCC1Ev", i32 230, i32 {{[0-9]+}}}
440 
441 #endif
442