Skip to content

Commit f6ae8e8

Browse files
clementvaljeanPeriermleair
committed
[fir] Add fir reduction builder
This patch introduces a bunch of builder functions to create function calls to runtime reduction functions. This patch is part of the upstreaming effort from fir-dev branch. This patch failed previously because a macro was missing. Reviewed By: awarzynski Differential Revision: https://reviews.llvm.org/D114460 Co-authored-by: Jean Perier <[email protected]> Co-authored-by: mleair <[email protected]>
1 parent ce22b7f commit f6ae8e8

File tree

7 files changed

+1416
-0
lines changed

7 files changed

+1416
-0
lines changed

flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ struct RuntimeTableEntry<RuntimeTableKey<KT>, RuntimeIdentifier<Cs...>> {
361361
#undef FirE
362362
#define FirE(L, I) (I < sizeof(L) / sizeof(*L) ? L[I] : 0)
363363
#define FirQuoteKey(X) #X
364+
#define ExpandAndQuoteKey(X) FirQuoteKey(X)
364365
#define FirMacroExpandKey(X) \
365366
FirE(X, 0), FirE(X, 1), FirE(X, 2), FirE(X, 3), FirE(X, 4), FirE(X, 5), \
366367
FirE(X, 6), FirE(X, 7), FirE(X, 8), FirE(X, 9), FirE(X, 10), \
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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/StandardOps/IR/Ops.h"
20+
21+
namespace fir {
22+
class ExtendedValue;
23+
class FirOpBuilder;
24+
} // namespace fir
25+
26+
namespace fir::runtime {
27+
28+
/// Generate call to `all` 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 `any` 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 `all` runtime routine. This version of `all` is specialized
43+
/// for rank 1 mask arguments.
44+
/// This calls the version that returns a scalar logical value.
45+
mlir::Value genAll(fir::FirOpBuilder &builder, mlir::Location loc,
46+
mlir::Value maskBox, mlir::Value dim);
47+
48+
/// Generate call to `any` runtime routine. This version of `any` is specialized
49+
/// for rank 1 mask arguments.
50+
/// This calls the version that returns a scalar logical value.
51+
mlir::Value genAny(fir::FirOpBuilder &builder, mlir::Location loc,
52+
mlir::Value maskBox, mlir::Value dim);
53+
54+
/// Generate call to `count` runtime routine. This routine is a specialized
55+
/// version when mask is a rank one array or the dim argument is not
56+
/// specified by the user.
57+
mlir::Value genCount(fir::FirOpBuilder &builder, mlir::Location loc,
58+
mlir::Value maskBox, mlir::Value dim);
59+
60+
/// Generate call to general CountDim runtime routine. This routine has a
61+
/// descriptor result.
62+
void genCountDim(fir::FirOpBuilder &builder, mlir::Location loc,
63+
mlir::Value resultBox, mlir::Value maskBox, mlir::Value dim,
64+
mlir::Value kind);
65+
66+
/// Generate call to `dot_product` intrinsic runtime routine.
67+
mlir::Value genDotProduct(fir::FirOpBuilder &builder, mlir::Location loc,
68+
mlir::Value vectorABox, mlir::Value vectorBBox,
69+
mlir::Value resultBox);
70+
71+
/// Generate call to `maxloc` intrinsic runtime routine. This is the version
72+
/// that does not take a dim argument.
73+
void genMaxloc(fir::FirOpBuilder &builder, mlir::Location loc,
74+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
75+
mlir::Value kind, mlir::Value back);
76+
77+
/// Generate call to `maxloc` intrinsic runtime routine. This is the version
78+
/// that takes a dim argument.
79+
void genMaxlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
80+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
81+
mlir::Value maskBox, mlir::Value kind, mlir::Value back);
82+
83+
/// Generate call to `minloc` intrinsic runtime routine. This is the version
84+
/// that does not take a dim argument.
85+
void genMinloc(fir::FirOpBuilder &builder, mlir::Location loc,
86+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value maskBox,
87+
mlir::Value kind, mlir::Value back);
88+
89+
/// Generate call to `minloc` intrinsic runtime routine. This is the version
90+
/// that takes a dim argument.
91+
void genMinlocDim(fir::FirOpBuilder &builder, mlir::Location loc,
92+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
93+
mlir::Value maskBox, mlir::Value kind, mlir::Value back);
94+
95+
/// Generate call to `maxval` intrinsic runtime routine. This is the version
96+
/// that does not take a dim argument.
97+
mlir::Value genMaxval(fir::FirOpBuilder &builder, mlir::Location loc,
98+
mlir::Value arrayBox, mlir::Value maskBox);
99+
100+
/// Generate call to `maxval` intrinsic runtime routine. This is the version
101+
/// that that handles 1 dimensional character arrays with no DIM argument.
102+
void genMaxvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
103+
mlir::Value resultBox, mlir::Value arrayBox,
104+
mlir::Value maskBox);
105+
106+
/// Generate call to `maxval` intrinsic runtime routine. This is the version
107+
/// that takes arrays of any rank with a dim argument specified.
108+
void genMaxvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
109+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
110+
mlir::Value maskBox);
111+
112+
/// Generate call to `minval` intrinsic runtime routine. This is the version
113+
/// that does not take a dim argument.
114+
mlir::Value genMinval(fir::FirOpBuilder &builder, mlir::Location loc,
115+
mlir::Value arrayBox, mlir::Value maskBox);
116+
117+
/// Generate call to `minval` intrinsic runtime routine. This is the version
118+
/// that that handles 1 dimensional character arrays with no DIM argument.
119+
void genMinvalChar(fir::FirOpBuilder &builder, mlir::Location loc,
120+
mlir::Value resultBox, mlir::Value arrayBox,
121+
mlir::Value maskBox);
122+
123+
/// Generate call to `minval` intrinsic runtime routine. This is the version
124+
/// that takes arrays of any rank with a dim argument specified.
125+
void genMinvalDim(fir::FirOpBuilder &builder, mlir::Location loc,
126+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
127+
mlir::Value maskBox);
128+
129+
/// Generate call to `product` intrinsic runtime routine. This is the version
130+
/// that does not take a dim argument.
131+
mlir::Value genProduct(fir::FirOpBuilder &builder, mlir::Location loc,
132+
mlir::Value arrayBox, mlir::Value maskBox,
133+
mlir::Value resultBox);
134+
135+
/// Generate call to `product` intrinsic runtime routine. This is the version
136+
/// that takes arrays of any rank with a dim argument specified.
137+
void genProductDim(fir::FirOpBuilder &builder, mlir::Location loc,
138+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
139+
mlir::Value maskBox);
140+
141+
/// Generate call to `sum` intrinsic runtime routine. This is the version
142+
/// that does not take a dim argument.
143+
mlir::Value genSum(fir::FirOpBuilder &builder, mlir::Location loc,
144+
mlir::Value arrayBox, mlir::Value maskBox,
145+
mlir::Value resultBox);
146+
147+
/// Generate call to `sum` intrinsic runtime routine. This is the version
148+
/// that takes arrays of any rank with a dim argument specified.
149+
void genSumDim(fir::FirOpBuilder &builder, mlir::Location loc,
150+
mlir::Value resultBox, mlir::Value arrayBox, mlir::Value dim,
151+
mlir::Value maskBox);
152+
153+
} // namespace fir::runtime
154+
155+
#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_REDUCTION_H

flang/lib/Optimizer/Builder/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_flang_library(FIRBuilder
88
FIRBuilder.cpp
99
MutableBox.cpp
1010
Runtime/Assign.cpp
11+
Runtime/Reduction.cpp
1112
Runtime/Transformational.cpp
1213

1314
DEPENDS

0 commit comments

Comments
 (0)