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

Conversation

matthias-springer
Copy link
Member

@matthias-springer matthias-springer commented Jan 15, 2025

This commit removes convenience methods from FloatType to make it independent of concrete interface implementations.

See discussion here: https://discourse.llvm.org/t/rethink-on-approach-to-low-precision-fp-types/82361

Note for LLVM integration: Replace FloatType::getF32( with Float32Type::get( etc.

Copy link

github-actions bot commented Jan 15, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@matthias-springer matthias-springer force-pushed the users/matthias-springer/remove_convenience_factories branch from 57e1903 to d14d0e4 Compare January 15, 2025 09:17
@matthias-springer matthias-springer marked this pull request as ready for review January 15, 2025 09:20
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir:llvm mlir:affine mlir flang Flang issues not falling into any other category mlir:ods flang:fir-hlfir flang:codegen labels Jan 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 15, 2025

@llvm/pr-subscribers-mlir-ods
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-mlir-affine

@llvm/pr-subscribers-mlir-llvm

Author: Matthias Springer (matthias-springer)

Changes

This commit removes convenience methods from FloatType to make it independent of concrete interface implementations.

See discussion here: https://discourse.llvm.org/t/rethink-on-approach-to-low-precision-fp-types/82361

Note for LLVM integration: Replace FloatType::getF32( with Float32Type::get( etc.


Patch is 78.51 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/123026.diff

29 Files Affected:

  • (modified) flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h (+5-5)
  • (modified) flang/lib/Lower/ConvertType.cpp (+6-6)
  • (modified) flang/lib/Optimizer/Builder/FIRBuilder.cpp (+6-6)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+19-19)
  • (modified) flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp (+4-4)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Numeric.cpp (+22-22)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Reduction.cpp (+34-34)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Transformational.cpp (+4-4)
  • (modified) flang/lib/Optimizer/CodeGen/Target.cpp (+16-8)
  • (modified) flang/lib/Optimizer/Dialect/FIRType.cpp (+6-6)
  • (modified) flang/unittests/Optimizer/Builder/ComplexTest.cpp (+1-1)
  • (modified) flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp (+4-4)
  • (modified) flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp (+2-2)
  • (modified) flang/unittests/Optimizer/FIRTypesTest.cpp (+3-3)
  • (modified) flang/unittests/Optimizer/FortranVariableTest.cpp (+2-2)
  • (modified) flang/unittests/Optimizer/RTBuilder.cpp (+1-1)
  • (modified) mlir/include/mlir/IR/BuiltinTypeInterfaces.td (-20)
  • (modified) mlir/include/mlir/IR/BuiltinTypes.h (-72)
  • (modified) mlir/lib/CAPI/IR/BuiltinTypes.cpp (+16-16)
  • (modified) mlir/lib/IR/Builders.cpp (+18-24)
  • (modified) mlir/lib/IR/BuiltinTypes.cpp (+5-5)
  • (modified) mlir/lib/Target/LLVMIR/DataLayoutImporter.cpp (+5-5)
  • (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+1-1)
  • (modified) mlir/test/lib/Dialect/Affine/TestVectorizationUtils.cpp (+1-2)
  • (modified) mlir/test/lib/Dialect/Test/TestPatterns.cpp (+3-3)
  • (modified) mlir/test/lib/Transforms/TestDialectConversion.cpp (+1-1)
  • (modified) mlir/tools/tblgen-to-irdl/OpDefinitionsGen.cpp (+14-14)
  • (modified) mlir/unittests/IR/AttributeTest.cpp (+7-7)
  • (modified) mlir/unittests/IR/ShapedTypeTest.cpp (+6-6)
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index 09b49b95fefe57..225326f441bc76 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -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 <>
@@ -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");
   };
 }
@@ -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 <>
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index 037d4335fedf13..2fab520e6c475a 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -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");
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index d01becfe800937..08d4726a539f7c 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -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>");
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index e6d0f044dcf84f..a62259ebaaad95 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1921,7 +1921,7 @@ genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc,
                  Fortran::lower::AbstractConverter *converter) {
   IntrinsicLibrary library{builder, loc, converter};
   return std::visit(
-      [&](auto handler) -> auto {
+      [&](auto handler) -> auto{
         return genIntrinsicCallHelper(handler, resultType, args, library);
       },
       intrinsic.entry);
@@ -1936,7 +1936,7 @@ IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName,
   if (!intrinsic.has_value())
     crashOnMissingIntrinsic(loc, specificName);
   return std::visit(
-      [&](auto handler) -> auto {
+      [&](auto handler) -> auto{
         return genIntrinsicCallHelper(handler, resultType, args, *this);
       },
       intrinsic->entry);
@@ -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});
@@ -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});
@@ -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);
 }
@@ -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);
 }
@@ -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});
@@ -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.
@@ -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();
 
@@ -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 {
@@ -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])) {
@@ -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);
@@ -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(
@@ -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)
@@ -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});
@@ -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});
diff --git a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
index b3b07d18a956ba..fcc91752552c33 100644
--- a/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/PPCIntrinsicCall.cpp
@@ -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))
@@ -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]);
 
@@ -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"
@@ -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])};
diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
index d0092add0118f1..4ff7c86bb0a24a 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp
@@ -27,7 +27,7 @@ struct ForcedErfcScaled10 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ErfcScaled10));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto ty = mlir::FloatType::getF80(ctx);
+      auto ty = mlir::Float80Type::get(ctx);
       return mlir::FunctionType::get(ctx, {ty}, {ty});
     };
   }
@@ -38,7 +38,7 @@ struct ForcedErfcScaled16 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ErfcScaled16));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto ty = mlir::FloatType::getF128(ctx);
+      auto ty = mlir::Float128Type::get(ctx);
       return mlir::FunctionType::get(ctx, {ty}, {ty});
     };
   }
@@ -49,7 +49,7 @@ struct ForcedExponent10_4 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent10_4));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF80(ctx);
+      auto fltTy = mlir::Float80Type::get(ctx);
       auto intTy = mlir::IntegerType::get(ctx, 32);
       return mlir::FunctionType::get(ctx, fltTy, intTy);
     };
@@ -60,7 +60,7 @@ struct ForcedExponent10_8 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent10_8));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF80(ctx);
+      auto fltTy = mlir::Float80Type::get(ctx);
       auto intTy = mlir::IntegerType::get(ctx, 64);
       return mlir::FunctionType::get(ctx, fltTy, intTy);
     };
@@ -72,7 +72,7 @@ struct ForcedExponent16_4 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent16_4));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF128(ctx);
+      auto fltTy = mlir::Float128Type::get(ctx);
       auto intTy = mlir::IntegerType::get(ctx, 32);
       return mlir::FunctionType::get(ctx, fltTy, intTy);
     };
@@ -83,7 +83,7 @@ struct ForcedExponent16_8 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent16_8));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF128(ctx);
+      auto fltTy = mlir::Float128Type::get(ctx);
       auto intTy = mlir::IntegerType::get(ctx, 64);
       return mlir::FunctionType::get(ctx, fltTy, intTy);
     };
@@ -95,7 +95,7 @@ struct ForcedFraction10 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Fraction10));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto ty = mlir::FloatType::getF80(ctx);
+      auto ty = mlir::Float80Type::get(ctx);
       return mlir::FunctionType::get(ctx, {ty}, {ty});
     };
   }
@@ -106,7 +106,7 @@ struct ForcedFraction16 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Fraction16));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto ty = mlir::FloatType::getF128(ctx);
+      auto ty = mlir::Float128Type::get(ctx);
       return mlir::FunctionType::get(ctx, {ty}, {ty});
     };
   }
@@ -117,7 +117,7 @@ struct ForcedMod10 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModReal10));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF80(ctx);
+      auto fltTy = mlir::Float80Type::get(ctx);
       auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8));
       auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int));
       return mlir::FunctionType::get(ctx, {fltTy, fltTy, strTy, intTy},
@@ -131,7 +131,7 @@ struct ForcedMod16 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModReal16));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF128(ctx);
+      auto fltTy = mlir::Float128Type::get(ctx);
       auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8));
       auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int));
       return mlir::FunctionType::get(ctx, {fltTy, fltTy, strTy, intTy},
@@ -145,7 +145,7 @@ struct ForcedModulo10 {
   static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModuloReal10));
   static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() {
     return [](mlir::MLIRContext *ctx) {
-      auto fltTy = mlir::FloatType::getF80(ctx);
+      auto fltTy = mlir::Float80Type::get(ctx);
       auto strTy = fi...
[truncated]

This commit removes convience methods to `FloatType` to make it independent of concrete interface implementations.
@matthias-springer matthias-springer force-pushed the users/matthias-springer/remove_convenience_factories branch from d14d0e4 to 9b6f3c2 Compare January 15, 2025 09:38
Copy link
Contributor

@River707 River707 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@matthias-springer matthias-springer merged commit f023da1 into main Jan 16, 2025
8 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/remove_convenience_factories branch January 16, 2025 07:56
@Endilll
Copy link
Contributor

Endilll commented Jan 16, 2025

It seems that MSVC is running out of memory since this patch landed: https://lab.llvm.org/buildbot/#/builders/35/builds/6250

@matthias-springer
Copy link
Member Author

matthias-springer commented Jan 16, 2025

Looking at the history of that build bot, this is not the first time this is happening. E.g.: https://lab.llvm.org/buildbot/#/builders/35/builds/6227 or https://lab.llvm.org/buildbot/#/builders/35/builds/6121

This commit removes some functions, so I'd actually expect less memory usage.

I ran into build problems with Flang in the past on my workstation. But during linking time. What helped was reducing the amount of parallelism during the build. In the end, I upgraded the RAM from 128 GB to 256 GB, that also fixed the problem.

I think we should try one of these options:

  • Deactivate Flang build on this build bot.
  • Get a bigger VM.
  • Reduce the amount of parallelism during the build.

@matthias-springer
Copy link
Member Author

Looks like the most recent build was successful: https://lab.llvm.org/buildbot/#/builders/35/builds/6258

nirvedhmeshram added a commit to iree-org/torch-mlir that referenced this pull request Jan 20, 2025
peterbell10 pushed a commit to triton-lang/triton that referenced this pull request Jan 29, 2025
makslevental added a commit to makslevental/triton that referenced this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:codegen flang:fir-hlfir flang Flang issues not falling into any other category mlir:affine mlir:core MLIR Core Infrastructure mlir:llvm mlir:ods mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants