Skip to content

Commit 57e1903

Browse files
[mlir][IR] Remove factory methods from FloatType
This commit removes convience methods to `FloatType` to make it independent of concrete interface implementations.
1 parent c24ce32 commit 57e1903

29 files changed

+212
-303
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ constexpr TypeBuilderFunc getModel<unsigned long long>() {
320320
template <>
321321
constexpr TypeBuilderFunc getModel<double>() {
322322
return [](mlir::MLIRContext *context) -> mlir::Type {
323-
return mlir::FloatType::getF64(context);
323+
return mlir::Float64Type::get(context);
324324
};
325325
}
326326
template <>
@@ -347,11 +347,11 @@ constexpr TypeBuilderFunc getModel<long double>() {
347347
static_assert(size == 16 || size == 10 || size == 8,
348348
"unsupported long double size");
349349
if constexpr (size == 16)
350-
return mlir::FloatType::getF128(context);
350+
return mlir::Float128Type::get(context);
351351
if constexpr (size == 10)
352-
return mlir::FloatType::getF80(context);
352+
return mlir::Float80Type::get(context);
353353
if constexpr (size == 8)
354-
return mlir::FloatType::getF64(context);
354+
return mlir::Float64Type::get(context);
355355
llvm_unreachable("failed static assert");
356356
};
357357
}
@@ -369,7 +369,7 @@ constexpr TypeBuilderFunc getModel<const long double *>() {
369369
template <>
370370
constexpr TypeBuilderFunc getModel<float>() {
371371
return [](mlir::MLIRContext *context) -> mlir::Type {
372-
return mlir::FloatType::getF32(context);
372+
return mlir::Float16Type::get(context);
373373
};
374374
}
375375
template <>

flang/lib/Lower/ConvertType.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ static mlir::Type genRealType(mlir::MLIRContext *context, int kind) {
3636
Fortran::common::TypeCategory::Real, kind)) {
3737
switch (kind) {
3838
case 2:
39-
return mlir::FloatType::getF16(context);
39+
return mlir::Float16Type::get(context);
4040
case 3:
41-
return mlir::FloatType::getBF16(context);
41+
return mlir::BFloat16Type::get(context);
4242
case 4:
43-
return mlir::FloatType::getF32(context);
43+
return mlir::Float16Type::get(context);
4444
case 8:
45-
return mlir::FloatType::getF64(context);
45+
return mlir::Float64Type::get(context);
4646
case 10:
47-
return mlir::FloatType::getF80(context);
47+
return mlir::Float80Type::get(context);
4848
case 16:
49-
return mlir::FloatType::getF128(context);
49+
return mlir::Float128Type::get(context);
5050
}
5151
}
5252
llvm_unreachable("REAL type translation not implemented");

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ mlir::Type fir::FirOpBuilder::getVarLenSeqTy(mlir::Type eleTy, unsigned rank) {
105105
mlir::Type fir::FirOpBuilder::getRealType(int kind) {
106106
switch (kindMap.getRealTypeID(kind)) {
107107
case llvm::Type::TypeID::HalfTyID:
108-
return mlir::FloatType::getF16(getContext());
108+
return mlir::Float16Type::get(getContext());
109109
case llvm::Type::TypeID::BFloatTyID:
110-
return mlir::FloatType::getBF16(getContext());
110+
return mlir::BFloat16Type::get(getContext());
111111
case llvm::Type::TypeID::FloatTyID:
112-
return mlir::FloatType::getF32(getContext());
112+
return mlir::Float16Type::get(getContext());
113113
case llvm::Type::TypeID::DoubleTyID:
114-
return mlir::FloatType::getF64(getContext());
114+
return mlir::Float64Type::get(getContext());
115115
case llvm::Type::TypeID::X86_FP80TyID:
116-
return mlir::FloatType::getF80(getContext());
116+
return mlir::Float80Type::get(getContext());
117117
case llvm::Type::TypeID::FP128TyID:
118-
return mlir::FloatType::getF128(getContext());
118+
return mlir::Float128Type::get(getContext());
119119
default:
120120
fir::emitFatalError(mlir::UnknownLoc::get(getContext()),
121121
"unsupported type !fir.real<kind>");

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc,
19211921
Fortran::lower::AbstractConverter *converter) {
19221922
IntrinsicLibrary library{builder, loc, converter};
19231923
return std::visit(
1924-
[&](auto handler) -> auto {
1924+
[&](auto handler) -> auto{
19251925
return genIntrinsicCallHelper(handler, resultType, args, library);
19261926
},
19271927
intrinsic.entry);
@@ -1936,7 +1936,7 @@ IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName,
19361936
if (!intrinsic.has_value())
19371937
crashOnMissingIntrinsic(loc, specificName);
19381938
return std::visit(
1939-
[&](auto handler) -> auto {
1939+
[&](auto handler) -> auto{
19401940
return genIntrinsicCallHelper(handler, resultType, args, *this);
19411941
},
19421942
intrinsic->entry);
@@ -2362,7 +2362,7 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType,
23622362
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
23632363
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
23642364
mlir::Value dfactor = builder.createRealConstant(
2365-
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
2365+
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
23662366
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
23672367
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
23682368
return getRuntimeCallGenerator("acos", ftype)(builder, loc, {arg});
@@ -2513,7 +2513,7 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType,
25132513
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
25142514
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
25152515
mlir::Value dfactor = builder.createRealConstant(
2516-
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
2516+
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
25172517
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
25182518
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
25192519
return getRuntimeCallGenerator("asin", ftype)(builder, loc, {arg});
@@ -2539,7 +2539,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType,
25392539
}
25402540
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
25412541
mlir::Value dfactor = builder.createRealConstant(
2542-
loc, mlir::FloatType::getF64(context), llvm::APFloat(180.0) / pi);
2542+
loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi);
25432543
mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
25442544
return builder.create<mlir::arith::MulFOp>(loc, atan, factor);
25452545
}
@@ -2564,7 +2564,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType,
25642564
}
25652565
llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi);
25662566
mlir::Value dfactor =
2567-
builder.createRealConstant(loc, mlir::FloatType::getF64(context), inv_pi);
2567+
builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi);
25682568
mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
25692569
return builder.create<mlir::arith::MulFOp>(loc, atan, factor);
25702570
}
@@ -3119,7 +3119,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType,
31193119
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
31203120
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
31213121
mlir::Value dfactor = builder.createRealConstant(
3122-
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
3122+
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
31233123
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
31243124
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
31253125
return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg});
@@ -4412,12 +4412,12 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType,
44124412
mlir::FloatType yRealType =
44134413
mlir::dyn_cast<mlir::FloatType>(yRealVal.getType());
44144414

4415-
if (yRealType == mlir::FloatType::getBF16(builder.getContext())) {
4415+
if (yRealType == mlir::BFloat16Type::get(builder.getContext())) {
44164416
// Workaround: CopySignOp and BitcastOp don't work for kind 3 arg Y.
44174417
// This conversion should always preserve the sign bit.
44184418
yRealVal = builder.createConvert(
4419-
loc, mlir::FloatType::getF32(builder.getContext()), yRealVal);
4420-
yRealType = mlir::FloatType::getF32(builder.getContext());
4419+
loc, mlir::Float16Type::get(builder.getContext()), yRealVal);
4420+
yRealType = mlir::Float16Type::get(builder.getContext());
44214421
}
44224422

44234423
// Args have the same type.
@@ -4940,7 +4940,7 @@ mlir::Value IntrinsicLibrary::genIeeeReal(mlir::Type resultType,
49404940

49414941
assert(args.size() == 2);
49424942
mlir::Type i1Ty = builder.getI1Type();
4943-
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
4943+
mlir::Type f32Ty = mlir::Float16Type::get(builder.getContext());
49444944
mlir::Value a = args[0];
49454945
mlir::Type aType = a.getType();
49464946

@@ -5140,7 +5140,7 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType,
51405140
mlir::Value x = args[0];
51415141
mlir::Value y = args[1];
51425142
if (mlir::dyn_cast<mlir::FloatType>(resultType).getWidth() < 32) {
5143-
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
5143+
mlir::Type f32Ty = mlir::Float16Type::get(builder.getContext());
51445144
x = builder.create<fir::ConvertOp>(loc, f32Ty, x);
51455145
y = builder.create<fir::ConvertOp>(loc, f32Ty, y);
51465146
} else {
@@ -5174,7 +5174,7 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType,
51745174
}
51755175
if (mlir::cast<mlir::FloatType>(resultType).getWidth() == 16)
51765176
a = builder.create<fir::ConvertOp>(
5177-
loc, mlir::FloatType::getF32(builder.getContext()), a);
5177+
loc, mlir::Float16Type::get(builder.getContext()), a);
51785178
mlir::Value result = builder.create<fir::ConvertOp>(
51795179
loc, resultType, genRuntimeCall("nearbyint", a.getType(), a));
51805180
if (isStaticallyPresent(args[1])) {
@@ -5259,10 +5259,10 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType,
52595259
mlir::Value realVal = args[0];
52605260
mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(realVal.getType());
52615261
int bitWidth = realType.getWidth();
5262-
if (realType == mlir::FloatType::getBF16(builder.getContext())) {
5262+
if (realType == mlir::BFloat16Type::get(builder.getContext())) {
52635263
// Workaround: can't bitcast or convert real(3) to integer(2) or real(2).
52645264
realVal = builder.createConvert(
5265-
loc, mlir::FloatType::getF32(builder.getContext()), realVal);
5265+
loc, mlir::Float16Type::get(builder.getContext()), realVal);
52665266
bitWidth = 32;
52675267
}
52685268
mlir::Type intType = builder.getIntegerType(bitWidth);
@@ -6026,7 +6026,7 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType,
60266026
auto fastMathFlags = builder.getFastMathFlags();
60276027
// F128 arith::RemFOp may be lowered to a runtime call that may be unsupported
60286028
// on the target, so generate a call to Fortran Runtime's ModuloReal16.
6029-
if (resultType == mlir::FloatType::getF128(builder.getContext()) ||
6029+
if (resultType == mlir::Float128Type::get(builder.getContext()) ||
60306030
(fastMathFlags & mlir::arith::FastMathFlags::ninf) ==
60316031
mlir::arith::FastMathFlags::none)
60326032
return builder.createConvert(
@@ -6215,7 +6215,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType,
62156215
mlir::FloatType yType = mlir::dyn_cast<mlir::FloatType>(args[1].getType());
62166216
const unsigned yBitWidth = yType.getWidth();
62176217
if (xType != yType) {
6218-
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
6218+
mlir::Type f32Ty = mlir::Float16Type::get(builder.getContext());
62196219
if (xBitWidth < 32)
62206220
x1 = builder.createConvert(loc, f32Ty, x1);
62216221
if (yBitWidth > 32 && yBitWidth > xBitWidth)
@@ -7166,7 +7166,7 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType,
71667166
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
71677167
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
71687168
mlir::Value dfactor = builder.createRealConstant(
7169-
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
7169+
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
71707170
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
71717171
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
71727172
return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
@@ -7247,7 +7247,7 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType,
72477247
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
72487248
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
72497249
mlir::Value dfactor = builder.createRealConstant(
7250-
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
7250+
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
72517251
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
72527252
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
72537253
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});

flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType,
15791579

15801580
return callOp.getResult(0);
15811581
} else if (width == 64) {
1582-
auto fTy{mlir::FloatType::getF64(context)};
1582+
auto fTy{mlir::Float64Type::get(context)};
15831583
auto ty{mlir::VectorType::get(2, fTy)};
15841584

15851585
// vec_vtf(arg1, arg2) = fmul(1.0 / (1 << arg2), llvm.sitofp(arg1))
@@ -1639,7 +1639,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType,
16391639
newArgs[0] =
16401640
builder.create<fir::CallOp>(loc, funcOp, newArgs).getResult(0);
16411641
auto fvf32Ty{newArgs[0].getType()};
1642-
auto f32type{mlir::FloatType::getF32(context)};
1642+
auto f32type{mlir::Float16Type::get(context)};
16431643
auto mvf32Ty{mlir::VectorType::get(4, f32type)};
16441644
newArgs[0] = builder.createConvert(loc, mvf32Ty, newArgs[0]);
16451645

@@ -1949,7 +1949,7 @@ PPCIntrinsicLibrary::genVecLdCallGrp(mlir::Type resultType,
19491949
fname = isBEVecElemOrderOnLE() ? "llvm.ppc.vsx.lxvd2x.be"
19501950
: "llvm.ppc.vsx.lxvd2x";
19511951
// llvm.ppc.altivec.lxvd2x* returns <2 x double>
1952-
intrinResTy = mlir::VectorType::get(2, mlir::FloatType::getF64(context));
1952+
intrinResTy = mlir::VectorType::get(2, mlir::Float64Type::get(context));
19531953
} break;
19541954
case VecOp::Xlw4:
19551955
fname = isBEVecElemOrderOnLE() ? "llvm.ppc.vsx.lxvw4x.be"
@@ -2092,7 +2092,7 @@ PPCIntrinsicLibrary::genVecPerm(mlir::Type resultType,
20922092
auto mlirTy{vecTyInfo.toMlirVectorType(context)};
20932093

20942094
auto vi32Ty{mlir::VectorType::get(4, mlir::IntegerType::get(context, 32))};
2095-
auto vf64Ty{mlir::VectorType::get(2, mlir::FloatType::getF64(context))};
2095+
auto vf64Ty{mlir::VectorType::get(2, mlir::Float64Type::get(context))};
20962096

20972097
auto mArg0{builder.createConvert(loc, mlirTy, argBases[0])};
20982098
auto mArg1{builder.createConvert(loc, mlirTy, argBases[1])};

0 commit comments

Comments
 (0)