Skip to content

[mlir][IR] Remove factory methods from FloatType #123026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ constexpr TypeBuilderFunc getModel<unsigned long long>() {
template <>
constexpr TypeBuilderFunc getModel<double>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
return mlir::FloatType::getF64(context);
return mlir::Float64Type::get(context);
};
}
template <>
Expand All @@ -347,11 +347,11 @@ constexpr TypeBuilderFunc getModel<long double>() {
static_assert(size == 16 || size == 10 || size == 8,
"unsupported long double size");
if constexpr (size == 16)
return mlir::FloatType::getF128(context);
return mlir::Float128Type::get(context);
if constexpr (size == 10)
return mlir::FloatType::getF80(context);
return mlir::Float80Type::get(context);
if constexpr (size == 8)
return mlir::FloatType::getF64(context);
return mlir::Float64Type::get(context);
llvm_unreachable("failed static assert");
};
}
Expand All @@ -369,7 +369,7 @@ constexpr TypeBuilderFunc getModel<const long double *>() {
template <>
constexpr TypeBuilderFunc getModel<float>() {
return [](mlir::MLIRContext *context) -> mlir::Type {
return mlir::FloatType::getF32(context);
return mlir::Float32Type::get(context);
};
}
template <>
Expand Down
12 changes: 6 additions & 6 deletions flang/lib/Lower/ConvertType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ static mlir::Type genRealType(mlir::MLIRContext *context, int kind) {
Fortran::common::TypeCategory::Real, kind)) {
switch (kind) {
case 2:
return mlir::FloatType::getF16(context);
return mlir::Float16Type::get(context);
case 3:
return mlir::FloatType::getBF16(context);
return mlir::BFloat16Type::get(context);
case 4:
return mlir::FloatType::getF32(context);
return mlir::Float32Type::get(context);
case 8:
return mlir::FloatType::getF64(context);
return mlir::Float64Type::get(context);
case 10:
return mlir::FloatType::getF80(context);
return mlir::Float80Type::get(context);
case 16:
return mlir::FloatType::getF128(context);
return mlir::Float128Type::get(context);
}
}
llvm_unreachable("REAL type translation not implemented");
Expand Down
12 changes: 6 additions & 6 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ mlir::Type fir::FirOpBuilder::getVarLenSeqTy(mlir::Type eleTy, unsigned rank) {
mlir::Type fir::FirOpBuilder::getRealType(int kind) {
switch (kindMap.getRealTypeID(kind)) {
case llvm::Type::TypeID::HalfTyID:
return mlir::FloatType::getF16(getContext());
return mlir::Float16Type::get(getContext());
case llvm::Type::TypeID::BFloatTyID:
return mlir::FloatType::getBF16(getContext());
return mlir::BFloat16Type::get(getContext());
case llvm::Type::TypeID::FloatTyID:
return mlir::FloatType::getF32(getContext());
return mlir::Float32Type::get(getContext());
case llvm::Type::TypeID::DoubleTyID:
return mlir::FloatType::getF64(getContext());
return mlir::Float64Type::get(getContext());
case llvm::Type::TypeID::X86_FP80TyID:
return mlir::FloatType::getF80(getContext());
return mlir::Float80Type::get(getContext());
case llvm::Type::TypeID::FP128TyID:
return mlir::FloatType::getF128(getContext());
return mlir::Float128Type::get(getContext());
default:
fir::emitFatalError(mlir::UnknownLoc::get(getContext()),
"unsupported type !fir.real<kind>");
Expand Down
34 changes: 17 additions & 17 deletions flang/lib/Optimizer/Builder/IntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,7 @@ mlir::Value IntrinsicLibrary::genAcosd(mlir::Type resultType,
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
return getRuntimeCallGenerator("acos", ftype)(builder, loc, {arg});
Expand Down Expand Up @@ -2513,7 +2513,7 @@ mlir::Value IntrinsicLibrary::genAsind(mlir::Type resultType,
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
return getRuntimeCallGenerator("asin", ftype)(builder, loc, {arg});
Expand All @@ -2539,7 +2539,7 @@ mlir::Value IntrinsicLibrary::genAtand(mlir::Type resultType,
}
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), llvm::APFloat(180.0) / pi);
loc, mlir::Float64Type::get(context), llvm::APFloat(180.0) / pi);
mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
return builder.create<mlir::arith::MulFOp>(loc, atan, factor);
}
Expand All @@ -2564,7 +2564,7 @@ mlir::Value IntrinsicLibrary::genAtanpi(mlir::Type resultType,
}
llvm::APFloat inv_pi = llvm::APFloat(llvm::numbers::inv_pi);
mlir::Value dfactor =
builder.createRealConstant(loc, mlir::FloatType::getF64(context), inv_pi);
builder.createRealConstant(loc, mlir::Float64Type::get(context), inv_pi);
mlir::Value factor = builder.createConvert(loc, resultType, dfactor);
return builder.create<mlir::arith::MulFOp>(loc, atan, factor);
}
Expand Down Expand Up @@ -3119,7 +3119,7 @@ mlir::Value IntrinsicLibrary::genCosd(mlir::Type resultType,
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
return getRuntimeCallGenerator("cos", ftype)(builder, loc, {arg});
Expand Down Expand Up @@ -4412,12 +4412,12 @@ IntrinsicLibrary::genIeeeCopySign(mlir::Type resultType,
mlir::FloatType yRealType =
mlir::dyn_cast<mlir::FloatType>(yRealVal.getType());

if (yRealType == mlir::FloatType::getBF16(builder.getContext())) {
if (yRealType == mlir::BFloat16Type::get(builder.getContext())) {
// Workaround: CopySignOp and BitcastOp don't work for kind 3 arg Y.
// This conversion should always preserve the sign bit.
yRealVal = builder.createConvert(
loc, mlir::FloatType::getF32(builder.getContext()), yRealVal);
yRealType = mlir::FloatType::getF32(builder.getContext());
loc, mlir::Float32Type::get(builder.getContext()), yRealVal);
yRealType = mlir::Float32Type::get(builder.getContext());
}

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

assert(args.size() == 2);
mlir::Type i1Ty = builder.getI1Type();
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext());
mlir::Value a = args[0];
mlir::Type aType = a.getType();

Expand Down Expand Up @@ -5140,7 +5140,7 @@ mlir::Value IntrinsicLibrary::genIeeeRem(mlir::Type resultType,
mlir::Value x = args[0];
mlir::Value y = args[1];
if (mlir::dyn_cast<mlir::FloatType>(resultType).getWidth() < 32) {
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext());
x = builder.create<fir::ConvertOp>(loc, f32Ty, x);
y = builder.create<fir::ConvertOp>(loc, f32Ty, y);
} else {
Expand Down Expand Up @@ -5174,7 +5174,7 @@ mlir::Value IntrinsicLibrary::genIeeeRint(mlir::Type resultType,
}
if (mlir::cast<mlir::FloatType>(resultType).getWidth() == 16)
a = builder.create<fir::ConvertOp>(
loc, mlir::FloatType::getF32(builder.getContext()), a);
loc, mlir::Float32Type::get(builder.getContext()), a);
mlir::Value result = builder.create<fir::ConvertOp>(
loc, resultType, genRuntimeCall("nearbyint", a.getType(), a));
if (isStaticallyPresent(args[1])) {
Expand Down Expand Up @@ -5259,10 +5259,10 @@ mlir::Value IntrinsicLibrary::genIeeeSignbit(mlir::Type resultType,
mlir::Value realVal = args[0];
mlir::FloatType realType = mlir::dyn_cast<mlir::FloatType>(realVal.getType());
int bitWidth = realType.getWidth();
if (realType == mlir::FloatType::getBF16(builder.getContext())) {
if (realType == mlir::BFloat16Type::get(builder.getContext())) {
// Workaround: can't bitcast or convert real(3) to integer(2) or real(2).
realVal = builder.createConvert(
loc, mlir::FloatType::getF32(builder.getContext()), realVal);
loc, mlir::Float32Type::get(builder.getContext()), realVal);
bitWidth = 32;
}
mlir::Type intType = builder.getIntegerType(bitWidth);
Expand Down Expand Up @@ -6026,7 +6026,7 @@ mlir::Value IntrinsicLibrary::genModulo(mlir::Type resultType,
auto fastMathFlags = builder.getFastMathFlags();
// F128 arith::RemFOp may be lowered to a runtime call that may be unsupported
// on the target, so generate a call to Fortran Runtime's ModuloReal16.
if (resultType == mlir::FloatType::getF128(builder.getContext()) ||
if (resultType == mlir::Float128Type::get(builder.getContext()) ||
(fastMathFlags & mlir::arith::FastMathFlags::ninf) ==
mlir::arith::FastMathFlags::none)
return builder.createConvert(
Expand Down Expand Up @@ -6215,7 +6215,7 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType,
mlir::FloatType yType = mlir::dyn_cast<mlir::FloatType>(args[1].getType());
const unsigned yBitWidth = yType.getWidth();
if (xType != yType) {
mlir::Type f32Ty = mlir::FloatType::getF32(builder.getContext());
mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext());
if (xBitWidth < 32)
x1 = builder.createConvert(loc, f32Ty, x1);
if (yBitWidth > 32 && yBitWidth > xBitWidth)
Expand Down Expand Up @@ -7166,7 +7166,7 @@ mlir::Value IntrinsicLibrary::genSind(mlir::Type resultType,
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
return getRuntimeCallGenerator("sin", ftype)(builder, loc, {arg});
Expand Down Expand Up @@ -7247,7 +7247,7 @@ mlir::Value IntrinsicLibrary::genTand(mlir::Type resultType,
mlir::FunctionType::get(context, {resultType}, {args[0].getType()});
llvm::APFloat pi = llvm::APFloat(llvm::numbers::pi);
mlir::Value dfactor = builder.createRealConstant(
loc, mlir::FloatType::getF64(context), pi / llvm::APFloat(180.0));
loc, mlir::Float64Type::get(context), pi / llvm::APFloat(180.0));
mlir::Value factor = builder.createConvert(loc, args[0].getType(), dfactor);
mlir::Value arg = builder.create<mlir::arith::MulFOp>(loc, args[0], factor);
return getRuntimeCallGenerator("tan", ftype)(builder, loc, {arg});
Expand Down
8 changes: 4 additions & 4 deletions flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ PPCIntrinsicLibrary::genVecConvert(mlir::Type resultType,

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

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

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

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

auto mArg0{builder.createConvert(loc, mlirTy, argBases[0])};
auto mArg1{builder.createConvert(loc, mlirTy, argBases[1])};
Expand Down
Loading
Loading