1 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_ size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ --version 2
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-version=51 -emit-llvm %s -o - | FileCheck --check-prefix=OMP51 %s
3 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s
4 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix=OMP51
6 // expected-no-diagnostics
11 int thread_limit_target_parallel_loop() {
13 // Check that the offloading function is called after setting thread_limit in the task entry function
14 #pragma omp target parallel loop thread_limit(2)
15 for(int i
=0; i
<2; i
++) {}
21 // OMP51-LABEL: define dso_local noundef i32 @_Z33thread_limit_target_parallel_loopv
22 // OMP51-SAME: () #[[ATTR0:[0-9]+]] {
24 // OMP51-NEXT: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]], align 1
25 // OMP51-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB2:[0-9]+]])
26 // OMP51-NEXT: [[TMP1:%.*]] = call ptr @__kmpc_omp_task_alloc(ptr @[[GLOB2]], i32 [[TMP0]], i32 1, i64 40, i64 1, ptr @.omp_task_entry.)
27 // OMP51-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP1]], i32 0, i32 0
28 // OMP51-NEXT: call void @__kmpc_omp_task_begin_if0(ptr @[[GLOB2]], i32 [[TMP0]], ptr [[TMP1]])
29 // OMP51-NEXT: [[TMP3:%.*]] = call i32 @.omp_task_entry.(i32 [[TMP0]], ptr [[TMP1]]) #[[ATTR2:[0-9]+]]
30 // OMP51-NEXT: call void @__kmpc_omp_task_complete_if0(ptr @[[GLOB2]], i32 [[TMP0]], ptr [[TMP1]])
31 // OMP51-NEXT: ret i32 0
34 // OMP51-LABEL: define internal void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z33thread_limit_target_parallel_loopv_l14
35 // OMP51-SAME: () #[[ATTR1:[0-9]+]] {
37 // OMP51-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z33thread_limit_target_parallel_loopv_l14.omp_outlined)
38 // OMP51-NEXT: ret void
41 // OMP51-LABEL: define internal void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z33thread_limit_target_parallel_loopv_l14.omp_outlined
42 // OMP51-SAME: (ptr noalias noundef [[DOTGLOBAL_TID_:%.*]], ptr noalias noundef [[DOTBOUND_TID_:%.*]]) #[[ATTR1]] {
44 // OMP51-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
45 // OMP51-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
46 // OMP51-NEXT: [[DOTOMP_IV:%.*]] = alloca i32, align 4
47 // OMP51-NEXT: [[TMP:%.*]] = alloca i32, align 4
48 // OMP51-NEXT: [[DOTOMP_LB:%.*]] = alloca i32, align 4
49 // OMP51-NEXT: [[DOTOMP_UB:%.*]] = alloca i32, align 4
50 // OMP51-NEXT: [[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
51 // OMP51-NEXT: [[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
52 // OMP51-NEXT: [[I:%.*]] = alloca i32, align 4
53 // OMP51-NEXT: store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
54 // OMP51-NEXT: store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
55 // OMP51-NEXT: store i32 0, ptr [[DOTOMP_LB]], align 4
56 // OMP51-NEXT: store i32 1, ptr [[DOTOMP_UB]], align 4
57 // OMP51-NEXT: store i32 1, ptr [[DOTOMP_STRIDE]], align 4
58 // OMP51-NEXT: store i32 0, ptr [[DOTOMP_IS_LAST]], align 4
59 // OMP51-NEXT: [[TMP0:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
60 // OMP51-NEXT: [[TMP1:%.*]] = load i32, ptr [[TMP0]], align 4
61 // OMP51-NEXT: call void @__kmpc_for_static_init_4(ptr @[[GLOB1:[0-9]+]], i32 [[TMP1]], i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
62 // OMP51-NEXT: [[TMP2:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
63 // OMP51-NEXT: [[CMP:%.*]] = icmp sgt i32 [[TMP2]], 1
64 // OMP51-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_FALSE:%.*]]
66 // OMP51-NEXT: br label [[COND_END:%.*]]
68 // OMP51-NEXT: [[TMP3:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
69 // OMP51-NEXT: br label [[COND_END]]
71 // OMP51-NEXT: [[COND:%.*]] = phi i32 [ 1, [[COND_TRUE]] ], [ [[TMP3]], [[COND_FALSE]] ]
72 // OMP51-NEXT: store i32 [[COND]], ptr [[DOTOMP_UB]], align 4
73 // OMP51-NEXT: [[TMP4:%.*]] = load i32, ptr [[DOTOMP_LB]], align 4
74 // OMP51-NEXT: store i32 [[TMP4]], ptr [[DOTOMP_IV]], align 4
75 // OMP51-NEXT: br label [[OMP_INNER_FOR_COND:%.*]]
76 // OMP51: omp.inner.for.cond:
77 // OMP51-NEXT: [[TMP5:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
78 // OMP51-NEXT: [[TMP6:%.*]] = load i32, ptr [[DOTOMP_UB]], align 4
79 // OMP51-NEXT: [[CMP1:%.*]] = icmp sle i32 [[TMP5]], [[TMP6]]
80 // OMP51-NEXT: br i1 [[CMP1]], label [[OMP_INNER_FOR_BODY:%.*]], label [[OMP_INNER_FOR_END:%.*]]
81 // OMP51: omp.inner.for.body:
82 // OMP51-NEXT: [[TMP7:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
83 // OMP51-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP7]], 1
84 // OMP51-NEXT: [[ADD:%.*]] = add nsw i32 0, [[MUL]]
85 // OMP51-NEXT: store i32 [[ADD]], ptr [[I]], align 4
86 // OMP51-NEXT: br label [[OMP_BODY_CONTINUE:%.*]]
87 // OMP51: omp.body.continue:
88 // OMP51-NEXT: br label [[OMP_INNER_FOR_INC:%.*]]
89 // OMP51: omp.inner.for.inc:
90 // OMP51-NEXT: [[TMP8:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
91 // OMP51-NEXT: [[ADD2:%.*]] = add nsw i32 [[TMP8]], 1
92 // OMP51-NEXT: store i32 [[ADD2]], ptr [[DOTOMP_IV]], align 4
93 // OMP51-NEXT: br label [[OMP_INNER_FOR_COND]]
94 // OMP51: omp.inner.for.end:
95 // OMP51-NEXT: br label [[OMP_LOOP_EXIT:%.*]]
96 // OMP51: omp.loop.exit:
97 // OMP51-NEXT: call void @__kmpc_for_static_fini(ptr @[[GLOB1]], i32 [[TMP1]])
98 // OMP51-NEXT: ret void
101 // OMP51-LABEL: define internal noundef i32 @.omp_task_entry.
102 // OMP51-SAME: (i32 noundef [[TMP0:%.*]], ptr noalias noundef [[TMP1:%.*]]) #[[ATTR3:[0-9]+]] {
103 // OMP51-NEXT: entry:
104 // OMP51-NEXT: [[DOTGLOBAL_TID__ADDR_I:%.*]] = alloca i32, align 4
105 // OMP51-NEXT: [[DOTPART_ID__ADDR_I:%.*]] = alloca ptr, align 8
106 // OMP51-NEXT: [[DOTPRIVATES__ADDR_I:%.*]] = alloca ptr, align 8
107 // OMP51-NEXT: [[DOTCOPY_FN__ADDR_I:%.*]] = alloca ptr, align 8
108 // OMP51-NEXT: [[DOTTASK_T__ADDR_I:%.*]] = alloca ptr, align 8
109 // OMP51-NEXT: [[__CONTEXT_ADDR_I:%.*]] = alloca ptr, align 8
110 // OMP51-NEXT: [[DOTADDR:%.*]] = alloca i32, align 4
111 // OMP51-NEXT: [[DOTADDR1:%.*]] = alloca ptr, align 8
112 // OMP51-NEXT: store i32 [[TMP0]], ptr [[DOTADDR]], align 4
113 // OMP51-NEXT: store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
114 // OMP51-NEXT: [[TMP2:%.*]] = load i32, ptr [[DOTADDR]], align 4
115 // OMP51-NEXT: [[TMP3:%.*]] = load ptr, ptr [[DOTADDR1]], align 8
116 // OMP51-NEXT: [[TMP4:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T_WITH_PRIVATES:%.*]], ptr [[TMP3]], i32 0, i32 0
117 // OMP51-NEXT: [[TMP5:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T:%.*]], ptr [[TMP4]], i32 0, i32 2
118 // OMP51-NEXT: [[TMP6:%.*]] = getelementptr inbounds nuw [[STRUCT_KMP_TASK_T]], ptr [[TMP4]], i32 0, i32 0
119 // OMP51-NEXT: [[TMP7:%.*]] = load ptr, ptr [[TMP6]], align 8
120 // OMP51-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META5:![0-9]+]])
121 // OMP51-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META8:![0-9]+]])
122 // OMP51-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META10:![0-9]+]])
123 // OMP51-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META12:![0-9]+]])
124 // OMP51-NEXT: store i32 [[TMP2]], ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias [[META14:![0-9]+]]
125 // OMP51-NEXT: store ptr [[TMP5]], ptr [[DOTPART_ID__ADDR_I]], align 8, !noalias [[META14]]
126 // OMP51-NEXT: store ptr null, ptr [[DOTPRIVATES__ADDR_I]], align 8, !noalias [[META14]]
127 // OMP51-NEXT: store ptr null, ptr [[DOTCOPY_FN__ADDR_I]], align 8, !noalias [[META14]]
128 // OMP51-NEXT: store ptr [[TMP3]], ptr [[DOTTASK_T__ADDR_I]], align 8, !noalias [[META14]]
129 // OMP51-NEXT: store ptr [[TMP7]], ptr [[__CONTEXT_ADDR_I]], align 8, !noalias [[META14]]
130 // OMP51-NEXT: [[TMP8:%.*]] = load ptr, ptr [[__CONTEXT_ADDR_I]], align 8, !noalias [[META14]]
131 // OMP51-NEXT: [[TMP9:%.*]] = load i32, ptr [[DOTGLOBAL_TID__ADDR_I]], align 4, !noalias [[META14]]
132 // OMP51-NEXT: call void @__kmpc_set_thread_limit(ptr @[[GLOB2]], i32 [[TMP9]], i32 2)
133 // OMP51-NEXT: call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z33thread_limit_target_parallel_loopv_l14() #[[ATTR2]]
134 // OMP51-NEXT: ret i32 0