xref: /minix3/external/bsd/llvm/dist/clang/test/OpenMP/parallel_codegen.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -g -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-DEBUG %s
4*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
5*0a6a1f1dSLionel Sambuc #ifndef HEADER
6*0a6a1f1dSLionel Sambuc #define HEADER
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc // CHECK-DAG: %ident_t = type { i32, i32, i32, i32, i8* }
9*0a6a1f1dSLionel Sambuc // CHECK-DAG: %struct.anon = type { i32* }
10*0a6a1f1dSLionel Sambuc // CHECK-DAG: %struct.anon.0 = type { i8*** }
11*0a6a1f1dSLionel Sambuc // CHECK-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
12*0a6a1f1dSLionel Sambuc // CHECK-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr constant %ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8]* [[STR]], i32 0, i32 0) }
13*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: %ident_t = type { i32, i32, i32, i32, i8* }
14*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: %struct.anon = type { i32* }
15*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: %struct.anon.0 = type { i8*** }
16*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
17*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr constant %ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8]* [[STR]], i32 0, i32 0) }
18*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+14]];9;;\00"
19*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: [[LOC2:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;tmain;[[@LINE+7]];9;;\00"
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc template <class T>
foo(T argc)22*0a6a1f1dSLionel Sambuc void foo(T argc) {}
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc template <typename T>
tmain(T argc)25*0a6a1f1dSLionel Sambuc int tmain(T argc) {
26*0a6a1f1dSLionel Sambuc #pragma omp parallel
27*0a6a1f1dSLionel Sambuc   foo(argc);
28*0a6a1f1dSLionel Sambuc   return 0;
29*0a6a1f1dSLionel Sambuc }
30*0a6a1f1dSLionel Sambuc 
main(int argc,char ** argv)31*0a6a1f1dSLionel Sambuc int main (int argc, char **argv) {
32*0a6a1f1dSLionel Sambuc #pragma omp parallel
33*0a6a1f1dSLionel Sambuc   foo(argc);
34*0a6a1f1dSLionel Sambuc   return tmain(argv);
35*0a6a1f1dSLionel Sambuc }
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{[a-z]*[ ]?i32}} @main({{i32[ ]?[a-z]*}} %argc, i8** %argv)
38*0a6a1f1dSLionel Sambuc // CHECK:       [[AGG_CAPTURED:%.+]] = alloca %struct.anon
39*0a6a1f1dSLionel Sambuc // CHECK:       [[ARGC_REF:%.+]] = getelementptr inbounds %struct.anon* [[AGG_CAPTURED]], i32 0, i32 0
40*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  store i32* {{%[a-z0-9.]+}}, i32** [[ARGC_REF]]
41*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[BITCAST:%.+]] = bitcast %struct.anon* [[AGG_CAPTURED]] to i8*
42*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...)* @__kmpc_fork_call(%ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon*)* @.omp_outlined. to void (i32*, i32*, ...)*), i8* [[BITCAST]])
43*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGV:%.+]] = load i8*** {{%[a-z0-9.]+}}
44*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[RET:%.+]] = call {{[a-z]*[ ]?i32}} [[TMAIN:@.+tmain.+]](i8** [[ARGV]])
45*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  ret i32 [[RET]]
46*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  }
47*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-LABEL: define i32 @main(i32 %argc, i8** %argv)
48*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG:   [[AGG_CAPTURED:%.+]] = alloca %struct.anon
49*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG:   [[LOC_2_ADDR:%.+]] = alloca %ident_t
50*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[KMPC_LOC_VOIDPTR:%.+]] = bitcast %ident_t* [[LOC_2_ADDR]] to i8*
51*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[KMPC_DEFAULT_LOC_VOIDPTR:%.+]] = bitcast %ident_t* [[DEF_LOC_2]] to i8*
52*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:   call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[KMPC_LOC_VOIDPTR]], i8* [[KMPC_DEFAULT_LOC_VOIDPTR]], i64 ptrtoint (%ident_t* getelementptr (%ident_t* null, i32 1) to i64), i32 8, i1 false)
53*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[ARGC_REF:%.+]] = getelementptr inbounds %struct.anon* [[AGG_CAPTURED]], i32 0, i32 0
54*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  store i32* {{%[a-z0-9.]+}}, i32** [[ARGC_REF]]
55*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[KMPC_LOC_PSOURCE_REF:%.+]] = getelementptr inbounds %ident_t* [[LOC_2_ADDR]], i32 0, i32 4
56*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  store i8* getelementptr inbounds ([{{.+}} x i8]* [[LOC1]], i32 0, i32 0), i8** [[KMPC_LOC_PSOURCE_REF]]
57*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[BITCAST:%.+]] = bitcast %struct.anon* [[AGG_CAPTURED]] to i8*
58*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...)* @__kmpc_fork_call(%ident_t* [[LOC_2_ADDR]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon*)* @.omp_outlined. to void (i32*, i32*, ...)*), i8* [[BITCAST]])
59*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGV:%.+]] = load i8*** {{%[a-z0-9.]+}}
60*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[RET:%.+]] = call i32 [[TMAIN:@.+tmain.+]](i8** [[ARGV]])
61*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  ret i32 [[RET]]
62*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  }
63*0a6a1f1dSLionel Sambuc 
64*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define internal void @.omp_outlined.(i32* %.global_tid., i32* %.bound_tid., %struct.anon* %__context)
65*0a6a1f1dSLionel Sambuc // CHECK:       [[CONTEXT_ADDR:%.+]] = alloca %struct.anon*
66*0a6a1f1dSLionel Sambuc // CHECK:       store %struct.anon* %__context, %struct.anon** [[CONTEXT_ADDR]]
67*0a6a1f1dSLionel Sambuc // CHECK:       [[CONTEXT_PTR:%.+]] = load %struct.anon** [[CONTEXT_ADDR]]
68*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC_PTR_REF:%.+]] = getelementptr inbounds %struct.anon* [[CONTEXT_PTR]], i32 0, i32 0
69*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC_REF:%.+]] = load i32** [[ARGC_PTR_REF]]
70*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC:%.+]] = load i32* [[ARGC_REF]]
71*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  invoke void [[FOO:@.+foo.+]](i32{{[ ]?[a-z]*}} [[ARGC]])
72*0a6a1f1dSLionel Sambuc // CHECK:       ret void
73*0a6a1f1dSLionel Sambuc // CHECK:       call void @{{.+terminate.*}}(
74*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  unreachable
75*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  }
76*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-LABEL: define internal void @.omp_outlined.(i32* %.global_tid., i32* %.bound_tid., %struct.anon* %__context)
77*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[CONTEXT_ADDR:%.+]] = alloca %struct.anon*
78*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       store %struct.anon* %__context, %struct.anon** [[CONTEXT_ADDR]]
79*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[CONTEXT_PTR:%.+]] = load %struct.anon** [[CONTEXT_ADDR]]
80*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC_PTR_REF:%.+]] = getelementptr inbounds %struct.anon* [[CONTEXT_PTR]], i32 0, i32 0
81*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC_REF:%.+]] = load i32** [[ARGC_PTR_REF]]
82*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC:%.+]] = load i32* [[ARGC_REF]]
83*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  invoke void [[FOO:@.+foo.+]](i32 [[ARGC]])
84*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       ret void
85*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       call void @{{.+terminate.*}}(
86*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  unreachable
87*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  }
88*0a6a1f1dSLionel Sambuc 
89*0a6a1f1dSLionel Sambuc // CHECK-DAG: define linkonce_odr void [[FOO]]({{i32[ ]?[a-z]*}} %argc)
90*0a6a1f1dSLionel Sambuc // CHECK-DAG: declare void @__kmpc_fork_call(%ident_t*, i32, void (i32*, i32*, ...)*, ...)
91*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: define linkonce_odr void [[FOO]](i32 %argc)
92*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG: declare void @__kmpc_fork_call(%ident_t*, i32, void (i32*, i32*, ...)*, ...)
93*0a6a1f1dSLionel Sambuc 
94*0a6a1f1dSLionel Sambuc // CHECK:       define linkonce_odr {{[a-z]*[ ]?i32}} [[TMAIN]](i8** %argc)
95*0a6a1f1dSLionel Sambuc // CHECK:       [[AGG_CAPTURED:%.+]] = alloca %struct.anon.0
96*0a6a1f1dSLionel Sambuc // CHECK:       [[ARGC_REF:%.+]] = getelementptr inbounds %struct.anon.0* [[AGG_CAPTURED]], i32 0, i32 0
97*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  store i8*** {{%[a-z0-9.]+}}, i8**** [[ARGC_REF]]
98*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[BITCAST:%.+]] = bitcast %struct.anon.0* [[AGG_CAPTURED]] to i8*
99*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...)* @__kmpc_fork_call(%ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon.0*)* @.omp_outlined.1 to void (i32*, i32*, ...)*), i8* [[BITCAST]])
100*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  ret i32 0
101*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  }
102*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       define linkonce_odr i32 [[TMAIN]](i8** %argc)
103*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG:   [[AGG_CAPTURED:%.+]] = alloca %struct.anon.0
104*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-DAG:   [[LOC_2_ADDR:%.+]] = alloca %ident_t
105*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[KMPC_LOC_VOIDPTR:%.+]] = bitcast %ident_t* [[LOC_2_ADDR]] to i8*
106*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[KMPC_DEFAULT_LOC_VOIDPTR:%.+]] = bitcast %ident_t* [[DEF_LOC_2]] to i8*
107*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:   call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[KMPC_LOC_VOIDPTR]], i8* [[KMPC_DEFAULT_LOC_VOIDPTR]], i64 ptrtoint (%ident_t* getelementptr (%ident_t* null, i32 1) to i64), i32 8, i1 false)
108*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[ARGC_REF:%.+]] = getelementptr inbounds %struct.anon.0* [[AGG_CAPTURED]], i32 0, i32 0
109*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  store i8*** {{%[a-z0-9.]+}}, i8**** [[ARGC_REF]]
110*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[KMPC_LOC_PSOURCE_REF:%.+]] = getelementptr inbounds %ident_t* [[LOC_2_ADDR]], i32 0, i32 4
111*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  store i8* getelementptr inbounds ([{{.+}} x i8]* [[LOC2]], i32 0, i32 0), i8** [[KMPC_LOC_PSOURCE_REF]]
112*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[BITCAST:%.+]] = bitcast %struct.anon.0* [[AGG_CAPTURED]] to i8*
113*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  call void (%ident_t*, i32, void (i32*, i32*, ...)*, ...)* @__kmpc_fork_call(%ident_t* [[LOC_2_ADDR]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, %struct.anon.0*)* @.omp_outlined.1 to void (i32*, i32*, ...)*), i8* [[BITCAST]])
114*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  ret i32 0
115*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  }
116*0a6a1f1dSLionel Sambuc 
117*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define internal void @.omp_outlined.1(i32* %.global_tid., i32* %.bound_tid., %struct.anon.0* %__context)
118*0a6a1f1dSLionel Sambuc // CHECK:       [[CONTEXT_ADDR:%.+]] = alloca %struct.anon.0*
119*0a6a1f1dSLionel Sambuc // CHECK:       store %struct.anon.0* %__context, %struct.anon.0** [[CONTEXT_ADDR]]
120*0a6a1f1dSLionel Sambuc // CHECK:       [[CONTEXT_PTR:%.+]] = load %struct.anon.0** [[CONTEXT_ADDR]]
121*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC_PTR_REF:%.+]] = getelementptr inbounds %struct.anon.0* [[CONTEXT_PTR]], i32 0, i32 0
122*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC_REF:%.+]] = load i8**** [[ARGC_PTR_REF]]
123*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  [[ARGC:%.+]] = load i8*** [[ARGC_REF]]
124*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  invoke void [[FOO1:@.+foo.+]](i8** [[ARGC]])
125*0a6a1f1dSLionel Sambuc // CHECK:       ret void
126*0a6a1f1dSLionel Sambuc // CHECK:       call void @{{.+terminate.*}}(
127*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  unreachable
128*0a6a1f1dSLionel Sambuc // CHECK-NEXT:  }
129*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-LABEL: define internal void @.omp_outlined.1(i32* %.global_tid., i32* %.bound_tid., %struct.anon.0* %__context)
130*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[CONTEXT_ADDR:%.+]] = alloca %struct.anon.0*
131*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       store %struct.anon.0* %__context, %struct.anon.0** [[CONTEXT_ADDR]]
132*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       [[CONTEXT_PTR:%.+]] = load %struct.anon.0** [[CONTEXT_ADDR]]
133*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC_PTR_REF:%.+]] = getelementptr inbounds %struct.anon.0* [[CONTEXT_PTR]], i32 0, i32 0
134*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC_REF:%.+]] = load i8**** [[ARGC_PTR_REF]]
135*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  [[ARGC:%.+]] = load i8*** [[ARGC_REF]]
136*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  invoke void [[FOO1:@.+foo.+]](i8** [[ARGC]])
137*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       ret void
138*0a6a1f1dSLionel Sambuc // CHECK-DEBUG:       call void @{{.+terminate.*}}(
139*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  unreachable
140*0a6a1f1dSLionel Sambuc // CHECK-DEBUG-NEXT:  }
141*0a6a1f1dSLionel Sambuc 
142*0a6a1f1dSLionel Sambuc // CHECK: define linkonce_odr void [[FOO1]](i8** %argc)
143*0a6a1f1dSLionel Sambuc // CHECK-DEBUG: define linkonce_odr void [[FOO1]](i8** %argc)
144*0a6a1f1dSLionel Sambuc 
145*0a6a1f1dSLionel Sambuc #endif
146