1!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
2!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect"
3
4!FIRDialect-LABEL: func @_QPparallel_simple
5subroutine parallel_simple()
6   !OMPDialect: omp.parallel
7!$omp parallel
8   !FIRDialect: fir.call
9   call f1()
10!$omp end parallel
11end subroutine parallel_simple
12
13!===============================================================================
14! `if` clause
15!===============================================================================
16
17!FIRDialect-LABEL: func @_QPparallel_if
18subroutine parallel_if(alpha)
19   integer, intent(in) :: alpha
20
21   !OMPDialect: omp.parallel if(%{{.*}} : i1) {
22   !$omp parallel if(alpha .le. 0)
23   !FIRDialect: fir.call
24   call f1()
25   !OMPDialect: omp.terminator
26   !$omp end parallel
27
28   !OMPDialect: omp.parallel if(%{{.*}} : i1) {
29   !$omp parallel if(.false.)
30   !FIRDialect: fir.call
31   call f2()
32   !OMPDialect: omp.terminator
33   !$omp end parallel
34
35   !OMPDialect: omp.parallel if(%{{.*}} : i1) {
36   !$omp parallel if(alpha .ge. 0)
37   !FIRDialect: fir.call
38   call f3()
39   !OMPDialect: omp.terminator
40   !$omp end parallel
41
42   !OMPDialect: omp.parallel if(%{{.*}} : i1) {
43   !$omp parallel if(.true.)
44   !FIRDialect: fir.call
45   call f4()
46   !OMPDialect: omp.terminator
47   !$omp end parallel
48
49end subroutine parallel_if
50
51!===============================================================================
52! `num_threads` clause
53!===============================================================================
54
55!FIRDialect-LABEL: func @_QPparallel_numthreads
56subroutine parallel_numthreads(num_threads)
57   integer, intent(inout) :: num_threads
58
59   !OMPDialect: omp.parallel num_threads(%{{.*}}: i32) {
60   !$omp parallel num_threads(16)
61   !FIRDialect: fir.call
62   call f1()
63   !OMPDialect: omp.terminator
64   !$omp end parallel
65
66   num_threads = 4
67
68   !OMPDialect: omp.parallel num_threads(%{{.*}} : i32) {
69   !$omp parallel num_threads(num_threads)
70   !FIRDialect: fir.call
71   call f2()
72   !OMPDialect: omp.terminator
73   !$omp end parallel
74
75end subroutine parallel_numthreads
76
77!===============================================================================
78! `proc_bind` clause
79!===============================================================================
80
81!FIRDialect-LABEL: func @_QPparallel_proc_bind
82subroutine parallel_proc_bind()
83
84   !OMPDialect: omp.parallel proc_bind(master) {
85   !$omp parallel proc_bind(master)
86   !FIRDialect: fir.call
87   call f1()
88   !OMPDialect: omp.terminator
89   !$omp end parallel
90
91   !OMPDialect: omp.parallel proc_bind(close) {
92   !$omp parallel proc_bind(close)
93   !FIRDialect: fir.call
94   call f2()
95   !OMPDialect: omp.terminator
96   !$omp end parallel
97
98   !OMPDialect: omp.parallel proc_bind(spread) {
99   !$omp parallel proc_bind(spread)
100   !FIRDialect: fir.call
101   call f3()
102   !OMPDialect: omp.terminator
103   !$omp end parallel
104
105end subroutine parallel_proc_bind
106
107!===============================================================================
108! `allocate` clause
109!===============================================================================
110
111!FIRDialect-LABEL: func @_QPparallel_allocate
112subroutine parallel_allocate()
113   use omp_lib
114   integer :: x
115   !OMPDialect: omp.parallel allocate(%{{.+}} : i32 -> %{{.+}} : !fir.ref<i32>) {
116   !$omp parallel allocate(omp_high_bw_mem_alloc: x) private(x)
117   !FIRDialect: arith.addi
118   x = x + 12
119   !OMPDialect: omp.terminator
120   !$omp end parallel
121end subroutine parallel_allocate
122
123!===============================================================================
124! multiple clauses
125!===============================================================================
126
127!FIRDialect-LABEL: func @_QPparallel_multiple_clauses
128subroutine parallel_multiple_clauses(alpha, num_threads)
129   use omp_lib
130   integer, intent(inout) :: alpha
131   integer, intent(in) :: num_threads
132
133   !OMPDialect: omp.parallel if({{.*}} : i1) proc_bind(master) {
134   !$omp parallel if(alpha .le. 0) proc_bind(master)
135   !FIRDialect: fir.call
136   call f1()
137   !OMPDialect: omp.terminator
138   !$omp end parallel
139
140   !OMPDialect: omp.parallel num_threads({{.*}} : i32) proc_bind(close) {
141   !$omp parallel proc_bind(close) num_threads(num_threads)
142   !FIRDialect: fir.call
143   call f2()
144   !OMPDialect: omp.terminator
145   !$omp end parallel
146
147   !OMPDialect: omp.parallel if({{.*}} : i1) num_threads({{.*}} : i32) {
148   !$omp parallel num_threads(num_threads) if(alpha .le. 0)
149   !FIRDialect: fir.call
150   call f3()
151   !OMPDialect: omp.terminator
152   !$omp end parallel
153
154   !OMPDialect: omp.parallel if({{.*}} : i1) num_threads({{.*}} : i32) allocate(%{{.+}} : i32 -> %{{.+}} : !fir.ref<i32>) {
155   !$omp parallel num_threads(num_threads) if(alpha .le. 0) allocate(omp_high_bw_mem_alloc: alpha) private(alpha)
156   !FIRDialect: fir.call
157   call f3()
158   !FIRDialect: arith.addi
159   alpha = alpha + 12
160   !OMPDialect: omp.terminator
161   !$omp end parallel
162
163end subroutine parallel_multiple_clauses
164