blob: 228736987b62130000e5c1e8e4bf102e3d9ec7b7 [file] [log] [blame]
Alexey Bataevf41c88f2018-01-16 15:05:16 +00001// Test host codegen.
2// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
3// RUN: %clang_cc1 -fopenmp -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 -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 --check-prefix CHECK --check-prefix CHECK-64
5// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
6// RUN: %clang_cc1 -fopenmp -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 -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 --check-prefix CHECK --check-prefix CHECK-32
8
9// RUN: %clang_cc1 -verify -fopenmp-simd -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 -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 -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 -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 -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 -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 codegen - host bc file has to be created first.
18// RUN: %clang_cc1 -verify -fopenmp -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 -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 --check-prefix TCHECK-64
20// RUN: %clang_cc1 -fopenmp -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 -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 --check-prefix TCHECK-64
22// RUN: %clang_cc1 -verify -fopenmp -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 -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 --check-prefix TCHECK-32
24// RUN: %clang_cc1 -fopenmp -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 -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 --check-prefix TCHECK-32
26
27// RUN: %clang_cc1 -verify -fopenmp-simd -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 -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 -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 -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 -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 -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 -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 -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// expected-no-diagnostics
38#ifndef HEADER
39#define HEADER
40
41// CHECK-DAG: [[TT:%.+]] = type { i64, i8 }
42// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
43// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
44// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
45
46// TCHECK: [[ENTTY:%.+]] = type { i8*, i8*, i{{32|64}}, i32, i32 }
47
48// CHECK-DAG: $[[REGFN:\.omp_offloading\..+]] = comdat
49
Alexey Bataeva90fc662019-06-25 16:00:43 +000050// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 4]
Alexey Bataevb3638132018-07-19 16:34:13 +000051// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]
Alexey Bataev9a700172018-05-08 14:16:57 +000052// CHECK-DAG: @{{.*}} = weak constant i8 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +000053
Alexey Bataev03f270c2018-03-30 18:31:07 +000054// TCHECK: @{{.+}} = weak constant [[ENTTY]]
Alexey Bataevf41c88f2018-01-16 15:05:16 +000055// TCHECK: @{{.+}} = {{.*}}constant [[ENTTY]]
Alexey Bataev03f270c2018-03-30 18:31:07 +000056// TCHECK-NOT: @{{.+}} = weak constant [[ENTTY]]
Alexey Bataevf41c88f2018-01-16 15:05:16 +000057
58// Check if offloading descriptor is created.
59// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
60// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
Alexey Bataev62a4cb02018-07-31 18:27:42 +000061// CHECK: [[DEVBEGIN:@.+]] = extern_weak constant i8
62// CHECK: [[DEVEND:@.+]] = extern_weak constant i8
Alexey Bataevf41c88f2018-01-16 15:05:16 +000063// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [1 x [[DEVTY]]] [{{.+}} { i8* [[DEVBEGIN]], i8* [[DEVEND]], [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]])
64// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 1, [[DEVTY]]* getelementptr inbounds ([1 x [[DEVTY]]], [1 x [[DEVTY]]]* [[IMAGES]], i32 0, i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
65
66// Check target registration is registered as a Ctor.
Gheorghe-Teodor Bercea66cdbb472019-05-21 19:42:01 +000067// CHECK: appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @.omp_offloading.requires_reg, i8* null }, { i32, void ()*, i8* } { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
Alexey Bataevf41c88f2018-01-16 15:05:16 +000068
69
70template<typename tx, typename ty>
71struct TT{
72 tx X;
73 ty Y;
74};
75
76int global;
77extern int global;
78
79// CHECK: define {{.*}}[[FOO:@.+]](
80int foo(int n) {
81 int a = 0;
82 short aa = 0;
83 float b[10];
84 float bn[n];
85 double c[5][10];
86 double cn[5][n];
87 TT<long long, char> d;
88 static long *plocal;
89
90 // CHECK: [[ADD:%.+]] = add nsw i32
91 // CHECK: store i32 [[ADD]], i32* [[DEVICE_CAP:%.+]],
92 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
93 // CHECK: [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
94 // CHECK: store i32 [[DEV]], i32* [[GEP]],
Alexey Bataeva4fa0b82018-04-16 17:59:34 +000095 // CHECK: [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @0, i32 [[GTID:%.+]], i32 1, i[[SZ]] {{20|40}}, i[[SZ]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY0:@.+]] to i32 (i32, i8*)*))
Alexey Bataevf41c88f2018-01-16 15:05:16 +000096 // CHECK: [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY0:%.+]]*
97 // CHECK: getelementptr inbounds [4 x %struct.kmp_depend_info], [4 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
98 // CHECK: getelementptr inbounds [4 x %struct.kmp_depend_info], [4 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
99 // CHECK: getelementptr inbounds [4 x %struct.kmp_depend_info], [4 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 2
100 // CHECK: getelementptr inbounds [4 x %struct.kmp_depend_info], [4 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 3
James Y Knightf5f1b0e2019-02-08 15:34:12 +0000101 // CHECK: [[DEP_START:%.+]] = getelementptr inbounds [4 x %struct.kmp_depend_info], [4 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000102 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[DEP_START]] to i8*
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000103 // CHECK: call void @__kmpc_omp_wait_deps(%struct.ident_t* @0, i32 [[GTID]], i32 4, i8* [[DEP]], i32 0, i8* null)
104 // CHECK: call void @__kmpc_omp_task_begin_if0(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000105 // CHECK: call i32 [[TASK_ENTRY0]](i32 [[GTID]], [[TASK_TY0]]* [[BC_TASK]])
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000106 // CHECK: call void @__kmpc_omp_task_complete_if0(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000107 #pragma omp target simd device(global + a) depend(in: global) depend(out: a, b, cn[4])
108 for (int i = 0; i < 10; ++i) {
109 }
110
111 // CHECK: [[ADD:%.+]] = add nsw i32
112 // CHECK: store i32 [[ADD]], i32* [[DEVICE_CAP:%.+]],
113
114 // CHECK: [[BOOL:%.+]] = icmp ne i32 %{{.+}}, 0
115 // CHECK: br i1 [[BOOL]], label %[[THEN:.+]], label %[[ELSE:.+]]
116 // CHECK: [[THEN]]:
117 // CHECK-DAG: [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP:%.+]], i32 0, i32 0
118 // CHECK-DAG: [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P:%.+]], i32 0, i32 0
119 // CHECK-DAG: [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]**
120 // CHECK-DAG: [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]**
121 // CHECK-DAG: store i[[SZ]]* [[BP0:%[^,]+]], i[[SZ]]** [[CBPADDR0]]
122 // CHECK-DAG: store i[[SZ]]* [[BP0]], i[[SZ]]** [[CPADDR0]]
123
124 // CHECK-DAG: [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1
125 // CHECK-DAG: [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1
126 // CHECK-DAG: [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
127 // CHECK-DAG: [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
128 // CHECK-DAG: store i[[SZ]] [[BP1:%[^,]+]], i[[SZ]]* [[CBPADDR1]]
129 // CHECK-DAG: store i[[SZ]] [[BP1]], i[[SZ]]* [[CPADDR1]]
130 // CHECK-DAG: getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0
131 // CHECK-DAG: getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0
132 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
133 // CHECK: [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
134 // CHECK: store i32 [[DEV]], i32* [[GEP]],
Gheorghe-Teodor Berceac74707c2019-06-19 14:26:43 +0000135 // CHECK: [[DEV1:%.+]] = load i32, i32* [[DEVICE_CAP]],
136 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000137
Alexey Bataeva90fc662019-06-25 16:00:43 +0000138 // CHECK: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* @0, i32 [[GTID]], i32 1, i[[SZ]] {{104|60}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1_:@.+]] to i32 (i32, i8*)*), i64 [[DEV2]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000139 // CHECK: [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1_:%.+]]*
140 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
141 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
142 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 2
James Y Knightf5f1b0e2019-02-08 15:34:12 +0000143 // CHECK: [[DEP_START:%.+]] = getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000144 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[DEP_START]] to i8*
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000145 // CHECK: call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]], i32 3, i8* [[DEP]], i32 0, i8* null)
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000146 // CHECK: br label %[[EXIT:.+]]
147
148 // CHECK: [[ELSE]]:
149 // CHECK-NOT: getelementptr inbounds [2 x i8*], [2 x i8*]*
150 // CHECK: [[GEP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
151 // CHECK: [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
152 // CHECK: store i32 [[DEV]], i32* [[GEP]],
Gheorghe-Teodor Berceac74707c2019-06-19 14:26:43 +0000153 // CHECK: [[DEV1:%.+]] = load i32, i32* [[DEVICE_CAP]],
154 // CHECK: [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000155
Gheorghe-Teodor Berceac74707c2019-06-19 14:26:43 +0000156 // CHECK: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* @0, i32 [[GTID]], i32 1, i[[SZ]] {{56|28}}, i[[SZ]] {{16|12}}, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY1__:@.+]] to i32 (i32, i8*)*), i64 [[DEV2]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000157 // CHECK: [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY1__:%.+]]*
158 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
159 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 1
160 // CHECK: getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 2
James Y Knightf5f1b0e2019-02-08 15:34:12 +0000161 // CHECK: [[DEP_START:%.+]] = getelementptr inbounds [3 x %struct.kmp_depend_info], [3 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000162 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[DEP_START]] to i8*
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000163 // CHECK: call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]], i32 3, i8* [[DEP]], i32 0, i8* null)
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000164 // CHECK: br label %[[EXIT:.+]]
165 // CHECK: [[EXIT]]:
166
167 #pragma omp target simd device(global + a) nowait depend(inout: global, a, bn) if(a)
168 for (int i = 0; i < *plocal; ++i) {
169 static int local1;
170 *plocal = global;
171 local1 = global;
172 }
173
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000174 // CHECK: [[TASK:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @0, i32 [[GTID]], i32 1, i[[SZ]] {{48|24}}, i[[SZ]] 4, i32 (i32, i8*)* bitcast (i32 (i32, %{{.+}}*)* [[TASK_ENTRY2:@.+]] to i32 (i32, i8*)*))
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000175 // CHECK: [[BC_TASK:%.+]] = bitcast i8* [[TASK]] to [[TASK_TY2:%.+]]*
176 // CHECK: getelementptr inbounds [1 x %struct.kmp_depend_info], [1 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
James Y Knightf5f1b0e2019-02-08 15:34:12 +0000177 // CHECK: [[DEP_START:%.+]] = getelementptr inbounds [1 x %struct.kmp_depend_info], [1 x %struct.kmp_depend_info]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000178 // CHECK: [[DEP:%.+]] = bitcast %struct.kmp_depend_info* [[DEP_START]] to i8*
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000179 // CHECK: call void @__kmpc_omp_wait_deps(%struct.ident_t* @0, i32 [[GTID]], i32 1, i8* [[DEP]], i32 0, i8* null)
180 // CHECK: call void @__kmpc_omp_task_begin_if0(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000181 // CHECK: call i32 [[TASK_ENTRY2]](i32 [[GTID]], [[TASK_TY2]]* [[BC_TASK]])
Alexey Bataeva4fa0b82018-04-16 17:59:34 +0000182 // CHECK: call void @__kmpc_omp_task_complete_if0(%struct.ident_t* @0, i32 [[GTID]], i8* [[TASK]])
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000183 #pragma omp target simd if(0) firstprivate(global) depend(out:global)
184 for (int i = 0; i < global; ++i) {
185 global += 1;
186 }
187
188 return a;
189}
190
191// Check that the offloading functions are emitted and that the arguments are
192// correct and loaded correctly for the target regions in foo().
193
194// CHECK: define internal void [[HVT0:@.+]]()
195
196// CHECK: define internal{{.*}} i32 [[TASK_ENTRY0]](i32{{.*}}, [[TASK_TY0]]* noalias)
197// CHECK: store void (i8*, ...)* null, void (i8*, ...)** %
198// CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 0
199// CHECK: [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
200// CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
Alexey Bataeva90fc662019-06-25 16:00:43 +0000201// CHECK: [[RET:%.+]] = call i32 @__tgt_target_teams(i64 [[DEVICE]], i8* @{{[^,]+}}, i32 0, i8** null, i8** null, i64* null, i64* null, i32 1, i32 1)
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000202// CHECK-NEXT: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
203// CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
204// CHECK: [[FAIL]]
205// CHECK: call void [[HVT0]]()
206// CHECK-NEXT: br label %[[END]]
207// CHECK: [[END]]
208// CHECK: ret i32 0
209
210// CHECK: define internal void [[HVT1:@.+]](i[[SZ]]* %{{.+}}, i[[SZ]] %{{.+}})
211
212// CHECK: define internal{{.*}} i32 [[TASK_ENTRY1_]](i32{{.*}}, [[TASK_TY1_]]* noalias)
213// CHECK: call void (i8*, ...) %
Alexey Bataeva90fc662019-06-25 16:00:43 +0000214// CHECK: [[SZT:%.+]] = getelementptr inbounds [2 x i64], [2 x i64]* %{{.+}}, i[[SZ]] 0, i[[SZ]] 0
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000215// CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
216// CHECK: [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
217// CHECK: [[DEVICE:%.+]] = sext i32 [[DEV]] to i64
Alexey Bataeva90fc662019-06-25 16:00:43 +0000218// CHECK: [[RET:%.+]] = call i32 @__tgt_target_teams_nowait(i64 [[DEVICE]], i8* @{{[^,]+}}, i32 2, i8** [[BPR:%[^,]+]], i8** [[PR:%[^,]+]], i64* [[SZT]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[MAPT]], i32 0, i32 0), i32 1, i32 1)
Alexey Bataevf41c88f2018-01-16 15:05:16 +0000219
220// CHECK: [[ERROR:%.+]] = icmp ne i32 [[RET]], 0
221// CHECK-NEXT: br i1 [[ERROR]], label %[[FAIL:[^,]+]], label %[[END:[^,]+]]
222// CHECK: [[FAIL]]
223// CHECK: [[BP0:%.+]] = load i[[SZ]]*, i[[SZ]]** %
224// CHECK: [[BP1_I32:%.+]] = load i32, i32* %
225// CHECK-64: [[BP1_CAST:%.+]] = bitcast i[[SZ]]* [[BP1_PTR:%.+]] to i32*
226// CHECK-64: store i32 [[BP1_I32]], i32* [[BP1_CAST]],
227// CHECK-32: store i32 [[BP1_I32]], i32* [[BP1_PTR:%.+]],
228// CHECK: [[BP1:%.+]] = load i[[SZ]], i[[SZ]]* [[BP1_PTR]],
229// CHECK: call void [[HVT1]](i[[SZ]]* [[BP0]], i[[SZ]] [[BP1]])
230// CHECK-NEXT: br label %[[END]]
231// CHECK: [[END]]
232// CHECK: ret i32 0
233
234// CHECK: define internal{{.*}} i32 [[TASK_ENTRY1__]](i32{{.*}}, [[TASK_TY1__]]* noalias)
235// CHECK: call void (i8*, ...) %
236// CHECK: [[DEVICE_CAP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
237// CHECK: [[BP0:%.+]] = load i[[SZ]]*, i[[SZ]]** %
238// CHECK: [[BP1_I32:%.+]] = load i32, i32* %
239// CHECK-64: [[BP1_CAST:%.+]] = bitcast i[[SZ]]* [[BP1_PTR:%.+]] to i32*
240// CHECK-64: store i32 [[BP1_I32]], i32* [[BP1_CAST]],
241// CHECK-32: store i32 [[BP1_I32]], i32* [[BP1_PTR:%.+]],
242// CHECK: [[BP1:%.+]] = load i[[SZ]], i[[SZ]]* [[BP1_PTR]],
243// CHECK: call void [[HVT1]](i[[SZ]]* [[BP0]], i[[SZ]] [[BP1]])
244// CHECK: ret i32 0
245
246// CHECK: define internal void [[HVT2:@.+]](i[[SZ]] %{{.+}})
247// Create stack storage and store argument in there.
248// CHECK: [[AA_ADDR:%.+]] = alloca i[[SZ]], align
249// CHECK: store i[[SZ]] %{{.+}}, i[[SZ]]* [[AA_ADDR]], align
250// CHECK-64: [[AA_CADDR:%.+]] = bitcast i[[SZ]]* [[AA_ADDR]] to i32*
251// CHECK-64: load i32, i32* [[AA_CADDR]], align
252// CHECK-32: load i32, i32* [[AA_ADDR]], align
253
254// CHECK: define internal{{.*}} i32 [[TASK_ENTRY2]](i32{{.*}}, [[TASK_TY2]]* noalias)
255// CHECK: call void (i8*, ...) %
256// CHECK: [[BP1_I32:%.+]] = load i32, i32* %
257// CHECK-64: [[BP1_CAST:%.+]] = bitcast i[[SZ]]* [[BP1_PTR:%.+]] to i32*
258// CHECK-64: store i32 [[BP1_I32]], i32* [[BP1_CAST]],
259// CHECK-32: store i32 [[BP1_I32]], i32* [[BP1_PTR:%.+]],
260// CHECK: [[BP1:%.+]] = load i[[SZ]], i[[SZ]]* [[BP1_PTR]],
261// CHECK: call void [[HVT2]](i[[SZ]] [[BP1]])
262// CHECK: ret i32 0
263
264
265#endif