1//===- TransformationalTest.cpp -- Transformational intrinsic generation --===//
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#include "flang/Optimizer/Builder/Runtime/Transformational.h"
10#include "RuntimeCallTestBase.h"
11#include "gtest/gtest.h"
12
13void testGenBesselJn(
14 fir::FirOpBuilder &builder, mlir::Type realTy, llvm::StringRef fctName) {
15 mlir::Location loc = builder.getUnknownLoc();
16 mlir::Type i32Ty = builder.getIntegerType(32);
17 mlir::Type seqTy =
18 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), realTy);
19 mlir::Value result = builder.create<fir::UndefOp>(loc, seqTy);
20 mlir::Value n1 = builder.create<fir::UndefOp>(loc, i32Ty);
21 mlir::Value n2 = builder.create<fir::UndefOp>(loc, i32Ty);
22 mlir::Value x = builder.create<fir::UndefOp>(loc, realTy);
23 mlir::Value bn1 = builder.create<fir::UndefOp>(loc, realTy);
24 mlir::Value bn2 = builder.create<fir::UndefOp>(loc, realTy);
25 fir::runtime::genBesselJn(builder, loc, result, n1, n2, x, bn1, bn2);
26 checkCallOpFromResultBox(result, fctName, 6);
27}
28
29TEST_F(RuntimeCallTest, genBesselJnTest) {
30 testGenBesselJn(*firBuilder, f32Ty, "_FortranABesselJn_4");
31 testGenBesselJn(*firBuilder, f64Ty, "_FortranABesselJn_8");
32 testGenBesselJn(*firBuilder, f80Ty, "_FortranABesselJn_10");
33 testGenBesselJn(*firBuilder, f128Ty, "_FortranABesselJn_16");
34}
35
36void testGenBesselJnX0(
37 fir::FirOpBuilder &builder, mlir::Type realTy, llvm::StringRef fctName) {
38 mlir::Location loc = builder.getUnknownLoc();
39 mlir::Type i32Ty = builder.getIntegerType(32);
40 mlir::Type seqTy =
41 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), realTy);
42 mlir::Value result = builder.create<fir::UndefOp>(loc, seqTy);
43 mlir::Value n1 = builder.create<fir::UndefOp>(loc, i32Ty);
44 mlir::Value n2 = builder.create<fir::UndefOp>(loc, i32Ty);
45 fir::runtime::genBesselJnX0(builder, loc, realTy, result, n1, n2);
46 checkCallOpFromResultBox(result, fctName, 3);
47}
48
49TEST_F(RuntimeCallTest, genBesselJnX0Test) {
50 testGenBesselJnX0(*firBuilder, f32Ty, "_FortranABesselJnX0_4");
51 testGenBesselJnX0(*firBuilder, f64Ty, "_FortranABesselJnX0_8");
52 testGenBesselJnX0(*firBuilder, f80Ty, "_FortranABesselJnX0_10");
53 testGenBesselJnX0(*firBuilder, f128Ty, "_FortranABesselJnX0_16");
54}
55
56void testGenBesselYn(
57 fir::FirOpBuilder &builder, mlir::Type realTy, llvm::StringRef fctName) {
58 mlir::Location loc = builder.getUnknownLoc();
59 mlir::Type i32Ty = builder.getIntegerType(32);
60 mlir::Type seqTy =
61 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), realTy);
62 mlir::Value result = builder.create<fir::UndefOp>(loc, seqTy);
63 mlir::Value n1 = builder.create<fir::UndefOp>(loc, i32Ty);
64 mlir::Value n2 = builder.create<fir::UndefOp>(loc, i32Ty);
65 mlir::Value x = builder.create<fir::UndefOp>(loc, realTy);
66 mlir::Value bn1 = builder.create<fir::UndefOp>(loc, realTy);
67 mlir::Value bn2 = builder.create<fir::UndefOp>(loc, realTy);
68 fir::runtime::genBesselYn(builder, loc, result, n1, n2, x, bn1, bn2);
69 checkCallOpFromResultBox(result, fctName, 6);
70}
71
72TEST_F(RuntimeCallTest, genBesselYnTest) {
73 testGenBesselYn(*firBuilder, f32Ty, "_FortranABesselYn_4");
74 testGenBesselYn(*firBuilder, f64Ty, "_FortranABesselYn_8");
75 testGenBesselYn(*firBuilder, f80Ty, "_FortranABesselYn_10");
76 testGenBesselYn(*firBuilder, f128Ty, "_FortranABesselYn_16");
77}
78
79void testGenBesselYnX0(
80 fir::FirOpBuilder &builder, mlir::Type realTy, llvm::StringRef fctName) {
81 mlir::Location loc = builder.getUnknownLoc();
82 mlir::Type i32Ty = builder.getIntegerType(32);
83 mlir::Type seqTy =
84 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), realTy);
85 mlir::Value result = builder.create<fir::UndefOp>(loc, seqTy);
86 mlir::Value n1 = builder.create<fir::UndefOp>(loc, i32Ty);
87 mlir::Value n2 = builder.create<fir::UndefOp>(loc, i32Ty);
88 fir::runtime::genBesselYnX0(builder, loc, realTy, result, n1, n2);
89 checkCallOpFromResultBox(result, fctName, 3);
90}
91
92TEST_F(RuntimeCallTest, genBesselYnX0Test) {
93 testGenBesselYnX0(*firBuilder, f32Ty, "_FortranABesselYnX0_4");
94 testGenBesselYnX0(*firBuilder, f64Ty, "_FortranABesselYnX0_8");
95 testGenBesselYnX0(*firBuilder, f80Ty, "_FortranABesselYnX0_10");
96 testGenBesselYnX0(*firBuilder, f128Ty, "_FortranABesselYnX0_16");
97}
98
99TEST_F(RuntimeCallTest, genCshiftTest) {
100 auto loc = firBuilder->getUnknownLoc();
101 mlir::Type seqTy =
102 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
103 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
104 mlir::Value array = firBuilder->create<fir::UndefOp>(loc, seqTy);
105 mlir::Value shift = firBuilder->create<fir::UndefOp>(loc, seqTy);
106 mlir::Value dim = firBuilder->create<fir::UndefOp>(loc, seqTy);
107 fir::runtime::genCshift(*firBuilder, loc, result, array, shift, dim);
108 checkCallOpFromResultBox(result, "_FortranACshift", 4);
109}
110
111TEST_F(RuntimeCallTest, genCshiftVectorTest) {
112 auto loc = firBuilder->getUnknownLoc();
113 mlir::Type seqTy =
114 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
115 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
116 mlir::Value array = firBuilder->create<fir::UndefOp>(loc, seqTy);
117 mlir::Value shift = firBuilder->create<fir::UndefOp>(loc, seqTy);
118 fir::runtime::genCshiftVector(*firBuilder, loc, result, array, shift);
119 checkCallOpFromResultBox(result, "_FortranACshiftVector", 3);
120}
121
122TEST_F(RuntimeCallTest, genEoshiftTest) {
123 auto loc = firBuilder->getUnknownLoc();
124 mlir::Type seqTy =
125 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
126 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
127 mlir::Value array = firBuilder->create<fir::UndefOp>(loc, seqTy);
128 mlir::Value shift = firBuilder->create<fir::UndefOp>(loc, seqTy);
129 mlir::Value bound = firBuilder->create<fir::UndefOp>(loc, seqTy);
130 mlir::Value dim = firBuilder->create<fir::UndefOp>(loc, seqTy);
131 fir::runtime::genEoshift(*firBuilder, loc, result, array, shift, bound, dim);
132 checkCallOpFromResultBox(result, "_FortranAEoshift", 5);
133}
134
135TEST_F(RuntimeCallTest, genEoshiftVectorTest) {
136 auto loc = firBuilder->getUnknownLoc();
137 mlir::Type seqTy =
138 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
139 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
140 mlir::Value array = firBuilder->create<fir::UndefOp>(loc, seqTy);
141 mlir::Value shift = firBuilder->create<fir::UndefOp>(loc, seqTy);
142 mlir::Value bound = firBuilder->create<fir::UndefOp>(loc, seqTy);
143 fir::runtime::genEoshiftVector(*firBuilder, loc, result, array, shift, bound);
144 checkCallOpFromResultBox(result, "_FortranAEoshiftVector", 4);
145}
146
147TEST_F(RuntimeCallTest, genMatmulTest) {
148 auto loc = firBuilder->getUnknownLoc();
149 mlir::Type seqTy =
150 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
151 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
152 mlir::Value matrixA = firBuilder->create<fir::UndefOp>(loc, seqTy);
153 mlir::Value matrixB = firBuilder->create<fir::UndefOp>(loc, seqTy);
154 fir::runtime::genMatmul(*firBuilder, loc, matrixA, matrixB, result);
155 checkCallOpFromResultBox(result, "_FortranAMatmul", 3);
156}
157
158TEST_F(RuntimeCallTest, genPackTest) {
159 auto loc = firBuilder->getUnknownLoc();
160 mlir::Type seqTy =
161 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
162 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
163 mlir::Value array = firBuilder->create<fir::UndefOp>(loc, seqTy);
164 mlir::Value mask = firBuilder->create<fir::UndefOp>(loc, seqTy);
165 mlir::Value vector = firBuilder->create<fir::UndefOp>(loc, seqTy);
166 fir::runtime::genPack(*firBuilder, loc, result, array, mask, vector);
167 checkCallOpFromResultBox(result, "_FortranAPack", 4);
168}
169
170TEST_F(RuntimeCallTest, genReshapeTest) {
171 auto loc = firBuilder->getUnknownLoc();
172 mlir::Type seqTy =
173 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
174 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
175 mlir::Value source = firBuilder->create<fir::UndefOp>(loc, seqTy);
176 mlir::Value shape = firBuilder->create<fir::UndefOp>(loc, seqTy);
177 mlir::Value pad = firBuilder->create<fir::UndefOp>(loc, seqTy);
178 mlir::Value order = firBuilder->create<fir::UndefOp>(loc, seqTy);
179 fir::runtime::genReshape(*firBuilder, loc, result, source, shape, pad, order);
180 checkCallOpFromResultBox(result, "_FortranAReshape", 5);
181}
182
183TEST_F(RuntimeCallTest, genSpreadTest) {
184 auto loc = firBuilder->getUnknownLoc();
185 mlir::Type seqTy =
186 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
187 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
188 mlir::Value source = firBuilder->create<fir::UndefOp>(loc, seqTy);
189 mlir::Value dim = firBuilder->create<fir::UndefOp>(loc, seqTy);
190 mlir::Value ncopies = firBuilder->create<fir::UndefOp>(loc, seqTy);
191 fir::runtime::genSpread(*firBuilder, loc, result, source, dim, ncopies);
192 checkCallOpFromResultBox(result, "_FortranASpread", 4);
193}
194
195TEST_F(RuntimeCallTest, genTransposeTest) {
196 auto loc = firBuilder->getUnknownLoc();
197 mlir::Type seqTy =
198 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
199 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
200 mlir::Value source = firBuilder->create<fir::UndefOp>(loc, seqTy);
201 fir::runtime::genTranspose(*firBuilder, loc, result, source);
202 checkCallOpFromResultBox(result, "_FortranATranspose", 2);
203}
204
205TEST_F(RuntimeCallTest, genUnpack) {
206 auto loc = firBuilder->getUnknownLoc();
207 mlir::Type seqTy =
208 fir::SequenceType::get(fir::SequenceType::Shape(1, 10), i32Ty);
209 mlir::Value result = firBuilder->create<fir::UndefOp>(loc, seqTy);
210 mlir::Value vector = firBuilder->create<fir::UndefOp>(loc, seqTy);
211 mlir::Value mask = firBuilder->create<fir::UndefOp>(loc, seqTy);
212 mlir::Value field = firBuilder->create<fir::UndefOp>(loc, seqTy);
213 fir::runtime::genUnpack(*firBuilder, loc, result, vector, mask, field);
214 checkCallOpFromResultBox(result, "_FortranAUnpack", 4);
215}
216

source code of flang/unittests/Optimizer/Builder/Runtime/TransformationalTest.cpp