xref: /llvm-project/flang/include/flang/Optimizer/Builder/Runtime/Reduction.h (revision 38fd0181a065784afdf9b170fe3988aff01aab66)
1 //===-- Reduction.h -- generate calls to reduction runtime API --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // The runtime routines generated in this file are generally storing the result
10 // in a descriptor (represented as a `box` in FIR). Some function might
11 // have a specialization where the value is returned as a scalar value, e.g.
12 // `genAll` is a specialization of `genAllDescriptor`.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H
17 #define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H
18 
19 #include "mlir/Dialect/Func/IR/FuncOps.h"
20 
21 namespace fir {
22 class ExtendedValue;
23 class FirOpBuilder;
24 } // namespace fir
25 
26 namespace fir::runtime {
27 
28 /// Generate call to `AllDim` runtime routine.
29 /// This calls the descriptor based runtime call implementation of the `all`
30 /// intrinsic.
31 void genAllDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
32                       mlir::Value resultBox, mlir::Value maskBox,
33                       mlir::Value dim);
34 
35 /// Generate call to `AnyDim` runtime routine.
36 /// This calls the descriptor based runtime call implementation of the `any`
37 /// intrinsic.
38 void genAnyDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
39                       mlir::Value resultBox, mlir::Value maskBox,
40                       mlir::Value dim);
41 
42 /// Generate call to `ParityDim` runtime routine.
43 /// This calls the descriptor based runtime call implementation of the `parity`
44 /// intrinsic.
45 void genParityDescriptor(fir::FirOpBuilder &builder, mlir::Location loc,
46                          mlir::Value resultBox, mlir::Value maskBox,
47                          mlir::Value dim);
48 
49 /// Generate call to `All` runtime routine. This version of `all` is specialized
50 /// for rank 1 mask arguments.
51 /// This calls the version that returns a scalar logical value.
52 mlir::Value genAll(fir::FirOpBuilder &builder, mlir::Location loc,
53                    mlir::Value maskBox, mlir::Value dim);
54 
55 /// Generate call to `Any` runtime routine. This version of `any` is specialized
56 /// for rank 1 mask arguments.
57 /// This calls the version that returns a scalar logical value.
58 mlir::Value genAny(fir::FirOpBuilder &builder, mlir::Location loc,
59                    mlir::Value maskBox, mlir::Value dim);
60 
61 /// Generate call to `Count` runtime routine. This routine is a specialized
62 /// version when mask is a rank one array or the dim argument is not
63 /// specified by the user.
64 mlir::Value genCount(fir::FirOpBuilder &builder, mlir::Location loc,
65                      mlir::Value maskBox, mlir::Value dim);
66 
67 /// Generate call to general `CountDim` runtime routine. This routine has a
68 /// descriptor result.
69 void genCountDim(fir::FirOpBuilder &builder, mlir::Location loc,
70                  mlir::Value resultBox, mlir::Value maskBox, mlir::Value dim,
71                  mlir::Value kind);
72 
73 /// Generate call to `DotProduct` intrinsic runtime routine.
74 mlir::Value genDotProduct(fir::FirOpBuilder &builder, mlir::Location loc,
75                           mlir::Value vectorABox, mlir::Value vectorBBox,
76                           mlir::Value resultBox);
77 
78 /// Generate call to `Findloc` intrinsic runtime routine. This is the version
79 /// that does not take a dim argument.
80 void genFindloc(fir::FirOpBuilder &builder, mlir::Location loc,
81                 mlir::Value resultBox, mlir::Value arrayBox, mlir::Value val,
82                 mlir::Value maskBox, mlir::Value kind, mlir::Value back);
83 
84 /// Generate call to `FindlocDim` intrinsic runtime routine. This is the version
85 /// that takes a dim argument.
86 void genFindlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
87                    mlir::Value resultBox, mlir::Value arrayBox, mlir::Value val,
88                    mlir::Value dim, mlir::Value maskBox, mlir::Value kind,
89                    mlir::Value back);
90 
91 /// Generate call to `Maxloc` intrinsic runtime routine. This is the version
92 /// that does not take a dim argument.
93 void genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
94                mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
95                mlir::Value kind, mlir::Value back);
96 
97 /// Generate call to `MaxlocDim` intrinsic runtime routine. This is the version
98 /// that takes a dim argument.
99 void genMaxlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
100                   mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
101                   mlir::Value maskBox, mlir::Value kind, mlir::Value back);
102 
103 /// Generate call to `Minloc` intrinsic runtime routine. This is the version
104 /// that does not take a dim argument.
105 void genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
106                mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
107                mlir::Value kind, mlir::Value back);
108 
109 /// Generate call to `MinlocDim` intrinsic runtime routine. This is the version
110 /// that takes a dim argument.
111 void genMinlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
112                   mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
113                   mlir::Value maskBox, mlir::Value kind, mlir::Value back);
114 
115 /// Generate call to `Maxval` intrinsic runtime routine. This is the version
116 /// that does not take a dim argument.
117 mlir::Value genMaxval(fir::FirOpBuilder &builder, mlir::Location loc,
118                       mlir::Value arrayBox, mlir::Value maskBox);
119 
120 /// Generate call to `MaxvalCharacter` intrinsic runtime routine. This is the
121 /// version hat that handles 1 dimensional character arrays  with no DIM
122 /// argument.
123 void genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
124                    mlir::Value resultBox, mlir::Value arrayBox,
125                    mlir::Value maskBox);
126 
127 /// Generate call to `MaxvalDim` intrinsic runtime routine. This is the version
128 /// that takes arrays of any rank with a dim argument specified.
129 void genMaxvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
130                   mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
131                   mlir::Value maskBox);
132 
133 /// Generate call to `Minval` intrinsic runtime routine. This is the version
134 /// that does not take a dim argument.
135 mlir::Value genMinval(fir::FirOpBuilder &builder, mlir::Location loc,
136                       mlir::Value arrayBox, mlir::Value maskBox);
137 
138 /// Generate call to `MinvalCharacter` intrinsic runtime routine. This is the
139 /// version that handles 1 dimensional character arrays with no DIM
140 /// argument.
141 void genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
142                    mlir::Value resultBox, mlir::Value arrayBox,
143                    mlir::Value maskBox);
144 
145 /// Generate call to `MinvalDim` intrinsic runtime routine. This is the version
146 /// that takes arrays of any rank with a dim argument specified.
147 void genMinvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
148                   mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
149                   mlir::Value maskBox);
150 
151 /// Generate call to `Norm2` intrinsic runtime routine. This is the version
152 /// that does not take a dim argument.
153 mlir::Value genNorm2(fir::FirOpBuilder &builder, mlir::Location loc,
154                      mlir::Value arrayBox);
155 
156 /// Generate call to `Norm2Dim` intrinsic runtime routine. This is the version
157 /// that takes a dim argument.
158 void genNorm2Dim(fir::FirOpBuilder &builder, mlir::Location loc,
159                  mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim);
160 
161 /// Generate call to `Parity` runtime routine. This version of `parity` is
162 /// specialized for rank 1 mask arguments.
163 /// This calls the version that returns a scalar logical value.
164 mlir::Value genParity(fir::FirOpBuilder &builder, mlir::Location loc,
165                       mlir::Value maskBox, mlir::Value dim);
166 
167 /// Generate call to `Product` intrinsic runtime routine. This is the version
168 /// that does not take a dim argument.
169 mlir::Value genProduct(fir::FirOpBuilder &builder, mlir::Location loc,
170                        mlir::Value arrayBox, mlir::Value maskBox,
171                        mlir::Value resultBox);
172 
173 /// Generate call to `ProductDim` intrinsic runtime routine. This is the version
174 /// that takes arrays of any rank with a dim argument specified.
175 void genProductDim(fir::FirOpBuilder &builder, mlir::Location loc,
176                    mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
177                    mlir::Value maskBox);
178 
179 /// Generate call to `Sum` intrinsic runtime routine. This is the version
180 /// that does not take a dim argument.
181 mlir::Value genSum(fir::FirOpBuilder &builder, mlir::Location loc,
182                    mlir::Value arrayBox, mlir::Value maskBox,
183                    mlir::Value resultBox);
184 
185 /// Generate call to `SumDim` intrinsic runtime routine. This is the version
186 /// that takes arrays of any rank with a dim argument specified.
187 void genSumDim(fir::FirOpBuilder &builder, mlir::Location loc,
188                mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
189                mlir::Value maskBox);
190 
191 /// Generate call to `IAll` intrinsic runtime routine. This is the version
192 /// that does not take a dim argument.
193 mlir::Value genIAll(fir::FirOpBuilder &builder, mlir::Location loc,
194                     mlir::Value arrayBox, mlir::Value maskBox,
195                     mlir::Value resultBox);
196 
197 /// Generate call to `IAllDim` intrinsic runtime routine. This is the version
198 /// that takes arrays of any rank with a dim argument specified.
199 void genIAllDim(fir::FirOpBuilder &builder, mlir::Location loc,
200                 mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
201                 mlir::Value maskBox);
202 
203 /// Generate call to `IAny` intrinsic runtime routine. This is the version
204 /// that does not take a dim argument.
205 mlir::Value genIAny(fir::FirOpBuilder &builder, mlir::Location loc,
206                     mlir::Value arrayBox, mlir::Value maskBox,
207                     mlir::Value resultBox);
208 
209 /// Generate call to `IAnyDim` intrinsic runtime routine. This is the version
210 /// that takes arrays of any rank with a dim argument specified.
211 void genIAnyDim(fir::FirOpBuilder &builder, mlir::Location loc,
212                 mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
213                 mlir::Value maskBox);
214 
215 /// Generate call to `IParity` intrinsic runtime routine. This is the version
216 /// that does not take a dim argument.
217 mlir::Value genIParity(fir::FirOpBuilder &builder, mlir::Location loc,
218                        mlir::Value arrayBox, mlir::Value maskBox,
219                        mlir::Value resultBox);
220 
221 /// Generate call to `IParityDim` intrinsic runtime routine. This is the version
222 /// that takes arrays of any rank with a dim argument specified.
223 void genIParityDim(fir::FirOpBuilder &builder, mlir::Location loc,
224                    mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
225                    mlir::Value maskBox);
226 
227 /// Generate call to `Reduce` intrinsic runtime routine. This is the version
228 /// that does not take a dim argument and store the result in the provided
229 /// result value. This is used for COMPLEX, CHARACTER and DERIVED TYPES.
230 void genReduce(fir::FirOpBuilder &builder, mlir::Location loc,
231                mlir::Value arrayBox, mlir::Value operation, mlir::Value maskBox,
232                mlir::Value identity, mlir::Value ordered, mlir::Value resultBox,
233                bool argByRef);
234 
235 /// Generate call to `Reduce` intrinsic runtime routine. This is the version
236 /// that does not take a dim argument and return a scalare result. This is used
237 /// for REAL, INTEGER and LOGICAL TYPES.
238 mlir::Value genReduce(fir::FirOpBuilder &builder, mlir::Location loc,
239                       mlir::Value arrayBox, mlir::Value operation,
240                       mlir::Value maskBox, mlir::Value identity,
241                       mlir::Value ordered, bool argByRef);
242 
243 /// Generate call to `Reduce` intrinsic runtime routine. This is the version
244 /// that takes arrays of any rank with a dim argument specified.
245 void genReduceDim(fir::FirOpBuilder &builder, mlir::Location loc,
246                   mlir::Value arrayBox, mlir::Value operation, mlir::Value dim,
247                   mlir::Value maskBox, mlir::Value identity,
248                   mlir::Value ordered, mlir::Value resultBox, bool argByRef);
249 
250 } // namespace fir::runtime
251 
252 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H
253