Skip to content

Commit 04b1853

Browse files
authored
[flang] Cleanup of NYI messages (#73740)
This update makes the user visible messages relating to features that are not yet implemented be more consistent. I also cleaned up some of the code. For NYI messages that refer to intrinsics, I made sure the the message begins with "not yet implemented: intrinsic:" to make them easier to recognize. I created some utility functions for NYI reporting that I put into .../include/Optimizer/Support/Utils.h. These mainly convert MLIR types to their Fortran equivalents. I converted the NYI code to use the newly created utility functions.
1 parent 2273ee0 commit 04b1853

File tree

12 files changed

+178
-140
lines changed

12 files changed

+178
-140
lines changed

flang/include/flang/Optimizer/Support/Utils.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
#define FORTRAN_OPTIMIZER_SUPPORT_UTILS_H
1515

1616
#include "flang/Common/default-kinds.h"
17+
#include "flang/Optimizer/Builder/FIRBuilder.h"
18+
#include "flang/Optimizer/Builder/Todo.h"
1719
#include "flang/Optimizer/Dialect/FIROps.h"
1820
#include "flang/Optimizer/Dialect/FIRType.h"
21+
#include "flang/Optimizer/Support/FatalError.h"
1922
#include "mlir/Dialect/Arith/IR/Arith.h"
2023
#include "mlir/Dialect/Func/IR/FuncOps.h"
2124
#include "mlir/IR/BuiltinAttributes.h"
@@ -70,6 +73,66 @@ fromDefaultKinds(const Fortran::common::IntrinsicTypeDefaultKinds &defKinds) {
7073
static_cast<fir::KindTy>(
7174
defKinds.GetDefaultKind(Fortran::common::TypeCategory::Real))};
7275
}
76+
77+
inline std::string mlirTypeToString(mlir::Type type) {
78+
std::string result{};
79+
llvm::raw_string_ostream sstream(result);
80+
sstream << type;
81+
return result;
82+
}
83+
84+
inline std::string numericMlirTypeToFortran(fir::FirOpBuilder &builder,
85+
mlir::Type type, mlir::Location loc,
86+
const llvm::Twine &name) {
87+
if (type.isF16())
88+
return "REAL(KIND=2)";
89+
else if (type.isBF16())
90+
return "REAL(KIND=3)";
91+
else if (type.isTF32())
92+
return "REAL(KIND=unknown)";
93+
else if (type.isF32())
94+
return "REAL(KIND=4)";
95+
else if (type.isF64())
96+
return "REAL(KIND=8)";
97+
else if (type.isF80())
98+
return "REAL(KIND=10)";
99+
else if (type.isF128())
100+
return "REAL(KIND=16)";
101+
else if (type.isInteger(8))
102+
return "INTEGER(KIND=1)";
103+
else if (type.isInteger(16))
104+
return "INTEGER(KIND=2)";
105+
else if (type.isInteger(32))
106+
return "INTEGER(KIND=4)";
107+
else if (type.isInteger(64))
108+
return "INTEGER(KIND=8)";
109+
else if (type.isInteger(128))
110+
return "INTEGER(KIND=16)";
111+
else if (type == fir::ComplexType::get(builder.getContext(), 2))
112+
return "COMPLEX(KIND=2)";
113+
else if (type == fir::ComplexType::get(builder.getContext(), 3))
114+
return "COMPLEX(KIND=3)";
115+
else if (type == fir::ComplexType::get(builder.getContext(), 4))
116+
return "COMPLEX(KIND=4)";
117+
else if (type == fir::ComplexType::get(builder.getContext(), 8))
118+
return "COMPLEX(KIND=8)";
119+
else if (type == fir::ComplexType::get(builder.getContext(), 10))
120+
return "COMPLEX(KIND=10)";
121+
else if (type == fir::ComplexType::get(builder.getContext(), 16))
122+
return "COMPLEX(KIND=16)";
123+
else
124+
fir::emitFatalError(loc, "unsupported type in " + name + ": " +
125+
fir::mlirTypeToString(type));
126+
}
127+
128+
inline void intrinsicTypeTODO(fir::FirOpBuilder &builder, mlir::Type type,
129+
mlir::Location loc,
130+
const llvm::Twine &intrinsicName) {
131+
TODO(loc,
132+
"intrinsic: " +
133+
fir::numericMlirTypeToFortran(builder, type, loc, intrinsicName) +
134+
" in " + intrinsicName);
135+
}
73136
} // namespace fir
74137

75138
#endif // FORTRAN_OPTIMIZER_SUPPORT_UTILS_H

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ searchMathOperation(fir::FirOpBuilder &builder, llvm::StringRef name,
12351235
static void checkPrecisionLoss(llvm::StringRef name,
12361236
mlir::FunctionType funcType,
12371237
const FunctionDistance &distance,
1238-
mlir::Location loc) {
1238+
fir::FirOpBuilder &builder, mlir::Location loc) {
12391239
if (!distance.isLosingPrecision())
12401240
return;
12411241

@@ -1249,13 +1249,20 @@ static void checkPrecisionLoss(llvm::StringRef name,
12491249
llvm::raw_string_ostream sstream(message);
12501250
if (name == "pow") {
12511251
assert(funcType.getNumInputs() == 2 && "power operator has two arguments");
1252-
sstream << funcType.getInput(0) << " ** " << funcType.getInput(1);
1252+
std::string displayName{" ** "};
1253+
sstream << numericMlirTypeToFortran(builder, funcType.getInput(0), loc,
1254+
displayName)
1255+
<< displayName
1256+
<< numericMlirTypeToFortran(builder, funcType.getInput(1), loc,
1257+
displayName);
12531258
} else {
1254-
sstream << name << "(";
1259+
sstream << name.upper() << "(";
12551260
if (funcType.getNumInputs() > 0)
1256-
sstream << funcType.getInput(0);
1257-
for (mlir::Type argType : funcType.getInputs().drop_front())
1258-
sstream << ", " << argType;
1261+
sstream << numericMlirTypeToFortran(builder, funcType.getInput(0), loc,
1262+
name);
1263+
for (mlir::Type argType : funcType.getInputs().drop_front()) {
1264+
sstream << ", " << numericMlirTypeToFortran(builder, argType, loc, name);
1265+
}
12591266
sstream << ")";
12601267
}
12611268
sstream << "'";
@@ -1373,7 +1380,7 @@ void crashOnMissingIntrinsic(mlir::Location loc, llvm::StringRef name) {
13731380
else if (isCoarrayIntrinsic(name))
13741381
TODO(loc, "coarray: intrinsic " + llvm::Twine(name));
13751382
else
1376-
TODO(loc, "intrinsic: " + llvm::Twine(name));
1383+
TODO(loc, "intrinsic: " + llvm::Twine(name.upper()));
13771384
}
13781385

13791386
template <typename GeneratorType>
@@ -1756,7 +1763,7 @@ IntrinsicLibrary::getRuntimeCallGenerator(llvm::StringRef name,
17561763
if (!mathOp && bestNearMatch) {
17571764
// Use the best near match, optionally issuing an error,
17581765
// if types conversions cause precision loss.
1759-
checkPrecisionLoss(name, soughtFuncType, bestMatchDistance, loc);
1766+
checkPrecisionLoss(name, soughtFuncType, bestMatchDistance, builder, loc);
17601767
mathOp = bestNearMatch;
17611768
}
17621769

@@ -4373,7 +4380,7 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType,
43734380
// Real case
43744381
if (resultType == mlir::FloatType::getF128(builder.getContext()))
43754382

4376-
TODO(loc, "intrinsic: modulo for floating point of KIND=16");
4383+
TODO(loc, "REAL(KIND=16): in MODULO intrinsic");
43774384
auto remainder = builder.create<mlir::arith::RemFOp>(loc, args[0], args[1]);
43784385
mlir::Value zero = builder.createRealZeroConstant(loc, remainder.getType());
43794386
auto remainderIsNotZero = builder.create<mlir::arith::CmpFOp>(

flang/lib/Optimizer/Builder/Runtime/Numeric.cpp

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "flang/Optimizer/Builder/Character.h"
1212
#include "flang/Optimizer/Builder/FIRBuilder.h"
1313
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
14-
#include "flang/Optimizer/Builder/Todo.h"
14+
#include "flang/Optimizer/Support/Utils.h"
1515
#include "flang/Runtime/numeric.h"
1616
#include "mlir/Dialect/Func/IR/FuncOps.h"
1717

@@ -240,10 +240,7 @@ mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder,
240240
mlir::Value x) {
241241
mlir::func::FuncOp func;
242242
mlir::Type fltTy = x.getType();
243-
244-
if (fltTy.isF16()) {
245-
TODO(loc, "support for REAL with KIND = 2 in EXPONENT");
246-
} else if (fltTy.isF32()) {
243+
if (fltTy.isF32()) {
247244
if (resultType.isInteger(32))
248245
func = fir::runtime::getRuntimeFunc<mkRTKey(Exponent4_4)>(loc, builder);
249246
else if (resultType.isInteger(64))
@@ -264,7 +261,7 @@ mlir::Value fir::runtime::genExponent(fir::FirOpBuilder &builder,
264261
else if (resultType.isInteger(64))
265262
func = fir::runtime::getRuntimeFunc<ForcedExponent16_8>(loc, builder);
266263
} else
267-
fir::emitFatalError(loc, "unsupported REAL kind in EXPONENT");
264+
fir::intrinsicTypeTODO(builder, fltTy, loc, "EXPONENT");
268265

269266
auto funcTy = func.getFunctionType();
270267
llvm::SmallVector<mlir::Value> args = {
@@ -278,9 +275,7 @@ mlir::Value fir::runtime::genFraction(fir::FirOpBuilder &builder,
278275
mlir::Location loc, mlir::Value x) {
279276
mlir::func::FuncOp func;
280277
mlir::Type fltTy = x.getType();
281-
if (fltTy.isF16())
282-
TODO(loc, "support for REAL with KIND = 2 in FRACTION");
283-
else if (fltTy.isF32())
278+
if (fltTy.isF32())
284279
func = fir::runtime::getRuntimeFunc<mkRTKey(Fraction4)>(loc, builder);
285280
else if (fltTy.isF64())
286281
func = fir::runtime::getRuntimeFunc<mkRTKey(Fraction8)>(loc, builder);
@@ -289,7 +284,7 @@ mlir::Value fir::runtime::genFraction(fir::FirOpBuilder &builder,
289284
else if (fltTy.isF128())
290285
func = fir::runtime::getRuntimeFunc<ForcedFraction16>(loc, builder);
291286
else
292-
fir::emitFatalError(loc, "unsupported REAL kind in FRACTION");
287+
fir::intrinsicTypeTODO(builder, fltTy, loc, "FRACTION");
293288

294289
auto funcTy = func.getFunctionType();
295290
llvm::SmallVector<mlir::Value> args = {
@@ -307,9 +302,7 @@ mlir::Value fir::runtime::genMod(fir::FirOpBuilder &builder, mlir::Location loc,
307302
if (fltTy != p.getType())
308303
fir::emitFatalError(loc, "arguments type mismatch in MOD");
309304

310-
if (fltTy.isF16())
311-
TODO(loc, "support for REAL with KIND = 2 in MOD");
312-
else if (fltTy.isF32())
305+
if (fltTy.isF32())
313306
func = fir::runtime::getRuntimeFunc<mkRTKey(ModReal4)>(loc, builder);
314307
else if (fltTy.isF64())
315308
func = fir::runtime::getRuntimeFunc<mkRTKey(ModReal8)>(loc, builder);
@@ -318,7 +311,7 @@ mlir::Value fir::runtime::genMod(fir::FirOpBuilder &builder, mlir::Location loc,
318311
else if (fltTy.isF128())
319312
func = fir::runtime::getRuntimeFunc<ForcedMod16>(loc, builder);
320313
else
321-
fir::emitFatalError(loc, "unsupported REAL kind in MOD");
314+
fir::intrinsicTypeTODO(builder, fltTy, loc, "MOD");
322315

323316
auto funcTy = func.getFunctionType();
324317
auto sourceFile = fir::factory::locationToFilename(builder, loc);
@@ -337,9 +330,7 @@ mlir::Value fir::runtime::genNearest(fir::FirOpBuilder &builder,
337330
mlir::func::FuncOp func;
338331
mlir::Type fltTy = x.getType();
339332

340-
if (fltTy.isF16())
341-
TODO(loc, "support for REAL with KIND = 2 in NEAREST");
342-
else if (fltTy.isF32())
333+
if (fltTy.isF32())
343334
func = fir::runtime::getRuntimeFunc<mkRTKey(Nearest4)>(loc, builder);
344335
else if (fltTy.isF64())
345336
func = fir::runtime::getRuntimeFunc<mkRTKey(Nearest8)>(loc, builder);
@@ -348,7 +339,7 @@ mlir::Value fir::runtime::genNearest(fir::FirOpBuilder &builder,
348339
else if (fltTy.isF128())
349340
func = fir::runtime::getRuntimeFunc<ForcedNearest16>(loc, builder);
350341
else
351-
fir::emitFatalError(loc, "unsupported REAL kind in NEAREST");
342+
fir::intrinsicTypeTODO(builder, fltTy, loc, "NEAREST");
352343

353344
auto funcTy = func.getFunctionType();
354345

@@ -374,9 +365,7 @@ mlir::Value fir::runtime::genRRSpacing(fir::FirOpBuilder &builder,
374365
mlir::func::FuncOp func;
375366
mlir::Type fltTy = x.getType();
376367

377-
if (fltTy.isF16())
378-
TODO(loc, "support for REAL with KIND = 2 in RRSPACING");
379-
else if (fltTy.isF32())
368+
if (fltTy.isF32())
380369
func = fir::runtime::getRuntimeFunc<mkRTKey(RRSpacing4)>(loc, builder);
381370
else if (fltTy.isF64())
382371
func = fir::runtime::getRuntimeFunc<mkRTKey(RRSpacing8)>(loc, builder);
@@ -385,7 +374,7 @@ mlir::Value fir::runtime::genRRSpacing(fir::FirOpBuilder &builder,
385374
else if (fltTy.isF128())
386375
func = fir::runtime::getRuntimeFunc<ForcedRRSpacing16>(loc, builder);
387376
else
388-
fir::emitFatalError(loc, "unsupported REAL kind in RRSPACING");
377+
fir::intrinsicTypeTODO(builder, fltTy, loc, "RRSPACING");
389378

390379
auto funcTy = func.getFunctionType();
391380
llvm::SmallVector<mlir::Value> args = {
@@ -401,9 +390,7 @@ mlir::Value fir::runtime::genScale(fir::FirOpBuilder &builder,
401390
mlir::func::FuncOp func;
402391
mlir::Type fltTy = x.getType();
403392

404-
if (fltTy.isF16())
405-
TODO(loc, "support for REAL with KIND = 2 in SCALE");
406-
else if (fltTy.isF32())
393+
if (fltTy.isF32())
407394
func = fir::runtime::getRuntimeFunc<mkRTKey(Scale4)>(loc, builder);
408395
else if (fltTy.isF64())
409396
func = fir::runtime::getRuntimeFunc<mkRTKey(Scale8)>(loc, builder);
@@ -412,7 +399,7 @@ mlir::Value fir::runtime::genScale(fir::FirOpBuilder &builder,
412399
else if (fltTy.isF128())
413400
func = fir::runtime::getRuntimeFunc<ForcedScale16>(loc, builder);
414401
else
415-
fir::emitFatalError(loc, "unsupported REAL kind in SCALE");
402+
fir::intrinsicTypeTODO(builder, fltTy, loc, "SCALE");
416403

417404
auto funcTy = func.getFunctionType();
418405
auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i);
@@ -480,9 +467,7 @@ mlir::Value fir::runtime::genSetExponent(fir::FirOpBuilder &builder,
480467
mlir::func::FuncOp func;
481468
mlir::Type fltTy = x.getType();
482469

483-
if (fltTy.isF16())
484-
TODO(loc, "support for REAL with KIND = 2 in FRACTION");
485-
else if (fltTy.isF32())
470+
if (fltTy.isF32())
486471
func = fir::runtime::getRuntimeFunc<mkRTKey(SetExponent4)>(loc, builder);
487472
else if (fltTy.isF64())
488473
func = fir::runtime::getRuntimeFunc<mkRTKey(SetExponent8)>(loc, builder);
@@ -491,7 +476,7 @@ mlir::Value fir::runtime::genSetExponent(fir::FirOpBuilder &builder,
491476
else if (fltTy.isF128())
492477
func = fir::runtime::getRuntimeFunc<ForcedSetExponent16>(loc, builder);
493478
else
494-
fir::emitFatalError(loc, "unsupported REAL kind in FRACTION");
479+
fir::intrinsicTypeTODO(builder, fltTy, loc, "SET_EXPONENT");
495480

496481
auto funcTy = func.getFunctionType();
497482
auto args = fir::runtime::createArguments(builder, loc, funcTy, x, i);
@@ -505,9 +490,7 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
505490
mlir::func::FuncOp func;
506491
mlir::Type fltTy = x.getType();
507492

508-
if (fltTy.isF16())
509-
TODO(loc, "support for REAL with KIND = 2 in SPACING");
510-
else if (fltTy.isF32())
493+
if (fltTy.isF32())
511494
func = fir::runtime::getRuntimeFunc<mkRTKey(Spacing4)>(loc, builder);
512495
else if (fltTy.isF64())
513496
func = fir::runtime::getRuntimeFunc<mkRTKey(Spacing8)>(loc, builder);
@@ -516,7 +499,7 @@ mlir::Value fir::runtime::genSpacing(fir::FirOpBuilder &builder,
516499
else if (fltTy.isF128())
517500
func = fir::runtime::getRuntimeFunc<ForcedSpacing16>(loc, builder);
518501
else
519-
fir::emitFatalError(loc, "unsupported REAL kind in SPACING");
502+
fir::intrinsicTypeTODO(builder, fltTy, loc, "SPACING");
520503

521504
auto funcTy = func.getFunctionType();
522505
llvm::SmallVector<mlir::Value> args = {

0 commit comments

Comments
 (0)