diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h --- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h +++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h @@ -463,6 +463,99 @@ MathGeneratorTy funcGenerator; }; +// Enum of most supported intrinsic argument or return types. +// Used by getTypeHelper to help generate most intrinsic function types. +enum class Ty { + Void, + Integer, + Real, + Complex, +}; + +// Helper function that generates most types that are supported for intrinsic +// arguments and return type. Used by `genFuncType` to generate function +// types for most of the intrinsics. +static inline mlir::Type getTypeHelper(mlir::MLIRContext *context, Ty ty, + int bits) { + mlir::Type r; + switch (ty) { + case Ty::Void: + llvm::report_fatal_error("can not get type of void"); + break; + case Ty::Integer: + assert((bits == 8 || bits == 16 || bits == 32 || bits == 64) && + "unsupported integer bit width"); + r = mlir::IntegerType::get(context, bits); + break; + case Ty::Real: + if (bits == 32) + r = mlir::FloatType::getF32(context); + else if (bits == 64) + r = mlir::FloatType::getF64(context); + else if (bits == 80) + r = mlir::FloatType::getF80(context); + else if (bits == 128) + r = mlir::FloatType::getF128(context); + else + llvm::report_fatal_error("unsupported float bit width"); + break; + case Ty::Complex: + r = fir::ComplexType::get(context, bits / 8); + break; + } + return r; +} + +// Generic function type generator that supports most of the function types +// used by intrinsics with upto 4 arguments. +template // arg4 +static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context) { + llvm::SmallVector types = {ty1, ty2, ty3, ty4}; + llvm::SmallVector bits = {eleBits1, eleBits2, eleBits3, eleBits4}; + llvm::SmallVector argTypes; + + for (size_t i = 0; i < types.size(); i++) { + // ignore void arguments + if (types[i] != Ty::Void) + argTypes.push_back(getTypeHelper(context, types[i], bits[i])); + } + + if (tyR == Ty::Void) { + return mlir::FunctionType::get(context, argTypes, std::nullopt); + } else { + auto resType = getTypeHelper(context, tyR, eleBitsR); + return mlir::FunctionType::get(context, argTypes, {resType}); + } +} + +template // arg3 +static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context) { + return genFuncType(context); +} + +template // arg2 +static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context) { + return genFuncType(context); +} + +template // arg1 +static inline mlir::FunctionType genFuncType(mlir::MLIRContext *context) { + return genFuncType(context); +} + /// Return argument lowering rules for an intrinsic. /// Returns a nullptr if all the intrinsic arguments should be lowered by value. const IntrinsicArgumentLoweringRules * diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -580,152 +580,6 @@ "dialect to lower complex operations"), llvm::cl::init(false)); -static mlir::FunctionType genF32F32FuncType(mlir::MLIRContext *context) { - mlir::Type t = mlir::FloatType::getF32(context); - return mlir::FunctionType::get(context, {t}, {t}); -} - -static mlir::FunctionType genF64F64FuncType(mlir::MLIRContext *context) { - mlir::Type t = mlir::FloatType::getF64(context); - return mlir::FunctionType::get(context, {t}, {t}); -} - -static mlir::FunctionType genF80F80FuncType(mlir::MLIRContext *context) { - mlir::Type t = mlir::FloatType::getF80(context); - return mlir::FunctionType::get(context, {t}, {t}); -} - -static mlir::FunctionType genF128F128FuncType(mlir::MLIRContext *context) { - mlir::Type t = mlir::FloatType::getF128(context); - return mlir::FunctionType::get(context, {t}, {t}); -} - -static mlir::FunctionType genF32F32F32FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF32(context); - return mlir::FunctionType::get(context, {t, t}, {t}); -} - -static mlir::FunctionType genF64F64F64FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF64(context); - return mlir::FunctionType::get(context, {t, t}, {t}); -} - -static mlir::FunctionType genF80F80F80FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF80(context); - return mlir::FunctionType::get(context, {t, t}, {t}); -} - -static mlir::FunctionType genF128F128F128FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF128(context); - return mlir::FunctionType::get(context, {t, t}, {t}); -} - -static mlir::FunctionType genF32F32F32F32FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF32(context); - return mlir::FunctionType::get(context, {t, t, t}, {t}); -} - -static mlir::FunctionType genF64F64F64F64FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF64(context); - return mlir::FunctionType::get(context, {t, t, t}, {t}); -} - -template -static mlir::FunctionType genVoidIntF64FuncType(mlir::MLIRContext *context) { - auto t = mlir::IntegerType::get(context, Bits); - auto u = mlir::FloatType::getF64(context); - return mlir::FunctionType::get(context, {t, u}, std::nullopt); -} - -template -static mlir::FunctionType genVoidIntIntFuncType(mlir::MLIRContext *context) { - auto t = mlir::IntegerType::get(context, BitsA); - auto u = mlir::IntegerType::get(context, BitsB); - return mlir::FunctionType::get(context, {t, u}, std::nullopt); -} - -template -static mlir::FunctionType genIntF64FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF64(context); - auto r = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {t}, {r}); -} - -template -static mlir::FunctionType genIntF32FuncType(mlir::MLIRContext *context) { - auto t = mlir::FloatType::getF32(context); - auto r = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {t}, {r}); -} - -template -static mlir::FunctionType genF64F64IntFuncType(mlir::MLIRContext *context) { - auto ftype = mlir::FloatType::getF64(context); - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {ftype, itype}, {ftype}); -} - -template -static mlir::FunctionType genF32F32IntFuncType(mlir::MLIRContext *context) { - auto ftype = mlir::FloatType::getF32(context); - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {ftype, itype}, {ftype}); -} - -template -static mlir::FunctionType genF64IntF64FuncType(mlir::MLIRContext *context) { - auto ftype = mlir::FloatType::getF64(context); - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {itype, ftype}, {ftype}); -} - -template -static mlir::FunctionType genF32IntF32FuncType(mlir::MLIRContext *context) { - auto ftype = mlir::FloatType::getF32(context); - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {itype, ftype}, {ftype}); -} - -template -static mlir::FunctionType genIntIntIntFuncType(mlir::MLIRContext *context) { - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {itype, itype}, {itype}); -} - -template -static mlir::FunctionType -genComplexComplexFuncType(mlir::MLIRContext *context) { - auto ctype = fir::ComplexType::get(context, Kind); - return mlir::FunctionType::get(context, {ctype}, {ctype}); -} - -template -static mlir::FunctionType -genComplexComplexComplexFuncType(mlir::MLIRContext *context) { - auto ctype = fir::ComplexType::get(context, Kind); - return mlir::FunctionType::get(context, {ctype, ctype}, {ctype}); -} - -static mlir::FunctionType genF32ComplexFuncType(mlir::MLIRContext *context) { - auto ctype = fir::ComplexType::get(context, 4); - auto ftype = mlir::FloatType::getF32(context); - return mlir::FunctionType::get(context, {ctype}, {ftype}); -} - -static mlir::FunctionType genF64ComplexFuncType(mlir::MLIRContext *context) { - auto ctype = fir::ComplexType::get(context, 8); - auto ftype = mlir::FloatType::getF64(context); - return mlir::FunctionType::get(context, {ctype}, {ftype}); -} - -template -static mlir::FunctionType -genComplexComplexIntFuncType(mlir::MLIRContext *context) { - auto ctype = fir::ComplexType::get(context, Kind); - auto itype = mlir::IntegerType::get(context, Bits); - return mlir::FunctionType::get(context, {ctype, itype}, {ctype}); -} - static mlir::Value genLibCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::StringRef libFuncName, mlir::FunctionType libFuncType, @@ -924,217 +778,332 @@ /// See https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gfortran/\ /// Intrinsic-Procedures.html for a reference. static constexpr MathOperation mathOperations[] = { - {"abs", "fabsf", genF32F32FuncType, genMathOp}, - {"abs", "fabs", genF64F64FuncType, genMathOp}, - {"abs", "llvm.fabs.f128", genF128F128FuncType, + {"abs", "fabsf", genFuncType, + genMathOp}, + {"abs", "fabs", genFuncType, genMathOp}, - {"abs", "cabsf", genF32ComplexFuncType, + {"abs", "llvm.fabs.f128", genFuncType, + genMathOp}, + {"abs", "cabsf", genFuncType, genComplexMathOp}, - {"abs", "cabs", genF64ComplexFuncType, + {"abs", "cabs", genFuncType, genComplexMathOp}, - {"acos", "acosf", genF32F32FuncType, genLibCall}, - {"acos", "acos", genF64F64FuncType, genLibCall}, - {"acos", "cacosf", genComplexComplexFuncType<4>, genLibCall}, - {"acos", "cacos", genComplexComplexFuncType<8>, genLibCall}, - {"acosh", "acoshf", genF32F32FuncType, genLibCall}, - {"acosh", "acosh", genF64F64FuncType, genLibCall}, - {"acosh", "cacoshf", genComplexComplexFuncType<4>, genLibCall}, - {"acosh", "cacosh", genComplexComplexFuncType<8>, genLibCall}, + {"acos", "acosf", genFuncType, genLibCall}, + {"acos", "acos", genFuncType, genLibCall}, + {"acos", "cacosf", genFuncType, + genLibCall}, + {"acos", "cacos", genFuncType, + genLibCall}, + {"acosh", "acoshf", genFuncType, genLibCall}, + {"acosh", "acosh", genFuncType, genLibCall}, + {"acosh", "cacoshf", genFuncType, + genLibCall}, + {"acosh", "cacosh", genFuncType, + genLibCall}, // llvm.trunc behaves the same way as libm's trunc. - {"aint", "llvm.trunc.f32", genF32F32FuncType, genLibCall}, - {"aint", "llvm.trunc.f64", genF64F64FuncType, genLibCall}, - {"aint", "llvm.trunc.f80", genF80F80FuncType, genLibCall}, + {"aint", "llvm.trunc.f32", genFuncType, + genLibCall}, + {"aint", "llvm.trunc.f64", genFuncType, + genLibCall}, + {"aint", "llvm.trunc.f80", genFuncType, + genLibCall}, // llvm.round behaves the same way as libm's round. - {"anint", "llvm.round.f32", genF32F32FuncType, + {"anint", "llvm.round.f32", genFuncType, genMathOp}, - {"anint", "llvm.round.f64", genF64F64FuncType, + {"anint", "llvm.round.f64", genFuncType, genMathOp}, - {"anint", "llvm.round.f80", genF80F80FuncType, + {"anint", "llvm.round.f80", genFuncType, genMathOp}, - {"asin", "asinf", genF32F32FuncType, genLibCall}, - {"asin", "asin", genF64F64FuncType, genLibCall}, - {"asin", "casinf", genComplexComplexFuncType<4>, genLibCall}, - {"asin", "casin", genComplexComplexFuncType<8>, genLibCall}, - {"asinh", "asinhf", genF32F32FuncType, genLibCall}, - {"asinh", "asinh", genF64F64FuncType, genLibCall}, - {"asinh", "casinhf", genComplexComplexFuncType<4>, genLibCall}, - {"asinh", "casinh", genComplexComplexFuncType<8>, genLibCall}, - {"atan", "atanf", genF32F32FuncType, genMathOp}, - {"atan", "atan", genF64F64FuncType, genMathOp}, - {"atan", "catanf", genComplexComplexFuncType<4>, genLibCall}, - {"atan", "catan", genComplexComplexFuncType<8>, genLibCall}, - {"atan2", "atan2f", genF32F32F32FuncType, genMathOp}, - {"atan2", "atan2", genF64F64F64FuncType, genMathOp}, - {"atanh", "atanhf", genF32F32FuncType, genLibCall}, - {"atanh", "atanh", genF64F64FuncType, genLibCall}, - {"atanh", "catanhf", genComplexComplexFuncType<4>, genLibCall}, - {"atanh", "catanh", genComplexComplexFuncType<8>, genLibCall}, - {"bessel_j0", "j0f", genF32F32FuncType, genLibCall}, - {"bessel_j0", "j0", genF64F64FuncType, genLibCall}, - {"bessel_j1", "j1f", genF32F32FuncType, genLibCall}, - {"bessel_j1", "j1", genF64F64FuncType, genLibCall}, - {"bessel_jn", "jnf", genF32IntF32FuncType<32>, genLibCall}, - {"bessel_jn", "jn", genF64IntF64FuncType<32>, genLibCall}, - {"bessel_y0", "y0f", genF32F32FuncType, genLibCall}, - {"bessel_y0", "y0", genF64F64FuncType, genLibCall}, - {"bessel_y1", "y1f", genF32F32FuncType, genLibCall}, - {"bessel_y1", "y1", genF64F64FuncType, genLibCall}, - {"bessel_yn", "ynf", genF32IntF32FuncType<32>, genLibCall}, - {"bessel_yn", "yn", genF64IntF64FuncType<32>, genLibCall}, + {"asin", "asinf", genFuncType, genLibCall}, + {"asin", "asin", genFuncType, genLibCall}, + {"asin", "casinf", genFuncType, + genLibCall}, + {"asin", "casin", genFuncType, + genLibCall}, + {"asinh", "asinhf", genFuncType, genLibCall}, + {"asinh", "asinh", genFuncType, genLibCall}, + {"asinh", "casinhf", genFuncType, + genLibCall}, + {"asinh", "casinh", genFuncType, + genLibCall}, + {"atan", "atanf", genFuncType, + genMathOp}, + {"atan", "atan", genFuncType, + genMathOp}, + {"atan", "catanf", genFuncType, + genLibCall}, + {"atan", "catan", genFuncType, + genLibCall}, + {"atan2", "atan2f", genFuncType, + genMathOp}, + {"atan2", "atan2", genFuncType, + genMathOp}, + {"atanh", "atanhf", genFuncType, genLibCall}, + {"atanh", "atanh", genFuncType, genLibCall}, + {"atanh", "catanhf", genFuncType, + genLibCall}, + {"atanh", "catanh", genFuncType, + genLibCall}, + {"bessel_j0", "j0f", genFuncType, genLibCall}, + {"bessel_j0", "j0", genFuncType, genLibCall}, + {"bessel_j1", "j1f", genFuncType, genLibCall}, + {"bessel_j1", "j1", genFuncType, genLibCall}, + {"bessel_jn", "jnf", + genFuncType, genLibCall}, + {"bessel_jn", "jn", + genFuncType, genLibCall}, + {"bessel_y0", "y0f", genFuncType, genLibCall}, + {"bessel_y0", "y0", genFuncType, genLibCall}, + {"bessel_y1", "y1f", genFuncType, genLibCall}, + {"bessel_y1", "y1", genFuncType, genLibCall}, + {"bessel_yn", "ynf", + genFuncType, genLibCall}, + {"bessel_yn", "yn", + genFuncType, genLibCall}, // math::CeilOp returns a real, while Fortran CEILING returns integer. - {"ceil", "ceilf", genF32F32FuncType, genMathOp}, - {"ceil", "ceil", genF64F64FuncType, genMathOp}, - {"cos", "cosf", genF32F32FuncType, genMathOp}, - {"cos", "cos", genF64F64FuncType, genMathOp}, - {"cos", "ccosf", genComplexComplexFuncType<4>, + {"ceil", "ceilf", genFuncType, + genMathOp}, + {"ceil", "ceil", genFuncType, + genMathOp}, + {"cos", "cosf", genFuncType, + genMathOp}, + {"cos", "cos", genFuncType, + genMathOp}, + {"cos", "ccosf", genFuncType, genComplexMathOp}, - {"cos", "ccos", genComplexComplexFuncType<8>, + {"cos", "ccos", genFuncType, genComplexMathOp}, - {"cosh", "coshf", genF32F32FuncType, genLibCall}, - {"cosh", "cosh", genF64F64FuncType, genLibCall}, - {"cosh", "ccoshf", genComplexComplexFuncType<4>, genLibCall}, - {"cosh", "ccosh", genComplexComplexFuncType<8>, genLibCall}, + {"cosh", "coshf", genFuncType, genLibCall}, + {"cosh", "cosh", genFuncType, genLibCall}, + {"cosh", "ccoshf", genFuncType, + genLibCall}, + {"cosh", "ccosh", genFuncType, + genLibCall}, {"divc", {}, - genComplexComplexComplexFuncType<2>, + genFuncType, genComplexMathOp}, {"divc", {}, - genComplexComplexComplexFuncType<3>, + genFuncType, genComplexMathOp}, - {"divc", "__divsc3", genComplexComplexComplexFuncType<4>, + {"divc", "__divsc3", + genFuncType, genLibSplitComplexArgsCall}, - {"divc", "__divdc3", genComplexComplexComplexFuncType<8>, + {"divc", "__divdc3", + genFuncType, genLibSplitComplexArgsCall}, - {"divc", "__divxc3", genComplexComplexComplexFuncType<10>, + {"divc", "__divxc3", + genFuncType, genLibSplitComplexArgsCall}, - {"divc", "__divtc3", genComplexComplexComplexFuncType<16>, + {"divc", "__divtc3", + genFuncType, genLibSplitComplexArgsCall}, - {"erf", "erff", genF32F32FuncType, genMathOp}, - {"erf", "erf", genF64F64FuncType, genMathOp}, - {"erfc", "erfcf", genF32F32FuncType, genLibCall}, - {"erfc", "erfc", genF64F64FuncType, genLibCall}, - {"exp", "expf", genF32F32FuncType, genMathOp}, - {"exp", "exp", genF64F64FuncType, genMathOp}, - {"exp", "cexpf", genComplexComplexFuncType<4>, + {"erf", "erff", genFuncType, + genMathOp}, + {"erf", "erf", genFuncType, + genMathOp}, + {"erfc", "erfcf", genFuncType, genLibCall}, + {"erfc", "erfc", genFuncType, genLibCall}, + {"exp", "expf", genFuncType, + genMathOp}, + {"exp", "exp", genFuncType, + genMathOp}, + {"exp", "cexpf", genFuncType, genComplexMathOp}, - {"exp", "cexp", genComplexComplexFuncType<8>, + {"exp", "cexp", genFuncType, genComplexMathOp}, // math::FloorOp returns a real, while Fortran FLOOR returns integer. - {"floor", "floorf", genF32F32FuncType, genMathOp}, - {"floor", "floor", genF64F64FuncType, genMathOp}, - {"gamma", "tgammaf", genF32F32FuncType, genLibCall}, - {"gamma", "tgamma", genF64F64FuncType, genLibCall}, - {"hypot", "hypotf", genF32F32F32FuncType, genLibCall}, - {"hypot", "hypot", genF64F64F64FuncType, genLibCall}, - {"log", "logf", genF32F32FuncType, genMathOp}, - {"log", "log", genF64F64FuncType, genMathOp}, - {"log", "clogf", genComplexComplexFuncType<4>, + {"floor", "floorf", genFuncType, + genMathOp}, + {"floor", "floor", genFuncType, + genMathOp}, + {"gamma", "tgammaf", genFuncType, genLibCall}, + {"gamma", "tgamma", genFuncType, genLibCall}, + {"hypot", "hypotf", genFuncType, + genLibCall}, + {"hypot", "hypot", genFuncType, + genLibCall}, + {"log", "logf", genFuncType, + genMathOp}, + {"log", "log", genFuncType, + genMathOp}, + {"log", "clogf", genFuncType, genComplexMathOp}, - {"log", "clog", genComplexComplexFuncType<8>, + {"log", "clog", genFuncType, genComplexMathOp}, - {"log10", "log10f", genF32F32FuncType, genMathOp}, - {"log10", "log10", genF64F64FuncType, genMathOp}, - {"log_gamma", "lgammaf", genF32F32FuncType, genLibCall}, - {"log_gamma", "lgamma", genF64F64FuncType, genLibCall}, + {"log10", "log10f", genFuncType, + genMathOp}, + {"log10", "log10", genFuncType, + genMathOp}, + {"log_gamma", "lgammaf", genFuncType, + genLibCall}, + {"log_gamma", "lgamma", genFuncType, + genLibCall}, // llvm.lround behaves the same way as libm's lround. - {"nint", "llvm.lround.i64.f64", genIntF64FuncType<64>, genLibCall}, - {"nint", "llvm.lround.i64.f32", genIntF32FuncType<64>, genLibCall}, - {"nint", "llvm.lround.i32.f64", genIntF64FuncType<32>, genLibCall}, - {"nint", "llvm.lround.i32.f32", genIntF32FuncType<32>, genLibCall}, - {"pow", {}, genIntIntIntFuncType<8>, genMathOp}, - {"pow", {}, genIntIntIntFuncType<16>, genMathOp}, - {"pow", {}, genIntIntIntFuncType<32>, genMathOp}, - {"pow", {}, genIntIntIntFuncType<64>, genMathOp}, - {"pow", "powf", genF32F32F32FuncType, genMathOp}, - {"pow", "pow", genF64F64F64FuncType, genMathOp}, - {"pow", "cpowf", genComplexComplexComplexFuncType<4>, + {"nint", "llvm.lround.i64.f64", genFuncType, + genLibCall}, + {"nint", "llvm.lround.i64.f32", genFuncType, + genLibCall}, + {"nint", "llvm.lround.i32.f64", genFuncType, + genLibCall}, + {"nint", "llvm.lround.i32.f32", genFuncType, + genLibCall}, + {"pow", + {}, + genFuncType, + genMathOp}, + {"pow", + {}, + genFuncType, + genMathOp}, + {"pow", + {}, + genFuncType, + genMathOp}, + {"pow", + {}, + genFuncType, + genMathOp}, + {"pow", "powf", genFuncType, + genMathOp}, + {"pow", "pow", genFuncType, + genMathOp}, + {"pow", "cpowf", + genFuncType, genComplexMathOp}, - {"pow", "cpow", genComplexComplexComplexFuncType<8>, + {"pow", "cpow", + genFuncType, genComplexMathOp}, - {"pow", RTNAME_STRING(FPow4i), genF32F32IntFuncType<32>, + {"pow", RTNAME_STRING(FPow4i), + genFuncType, genMathOp}, - {"pow", RTNAME_STRING(FPow8i), genF64F64IntFuncType<32>, + {"pow", RTNAME_STRING(FPow8i), + genFuncType, genMathOp}, - {"pow", RTNAME_STRING(FPow4k), genF32F32IntFuncType<64>, + {"pow", RTNAME_STRING(FPow4k), + genFuncType, genMathOp}, - {"pow", RTNAME_STRING(FPow8k), genF64F64IntFuncType<64>, + {"pow", RTNAME_STRING(FPow8k), + genFuncType, genMathOp}, - {"pow", RTNAME_STRING(cpowi), genComplexComplexIntFuncType<4, 32>, + {"pow", RTNAME_STRING(cpowi), + genFuncType, genLibCall}, - {"pow", RTNAME_STRING(zpowi), genComplexComplexIntFuncType<8, 32>, + {"pow", RTNAME_STRING(zpowi), + genFuncType, genLibCall}, - {"pow", RTNAME_STRING(cpowk), genComplexComplexIntFuncType<4, 64>, + {"pow", RTNAME_STRING(cpowk), + genFuncType, genLibCall}, - {"pow", RTNAME_STRING(zpowk), genComplexComplexIntFuncType<8, 64>, + {"pow", RTNAME_STRING(zpowk), + genFuncType, genLibCall}, - {"sign", "copysignf", genF32F32F32FuncType, + {"sign", "copysignf", genFuncType, genMathOp}, - {"sign", "copysign", genF64F64F64FuncType, + {"sign", "copysign", genFuncType, genMathOp}, - {"sign", "copysignl", genF80F80F80FuncType, + {"sign", "copysignl", genFuncType, genMathOp}, - {"sign", "llvm.copysign.f128", genF128F128F128FuncType, + {"sign", "llvm.copysign.f128", + genFuncType, genMathOp}, - {"sin", "sinf", genF32F32FuncType, genMathOp}, - {"sin", "sin", genF64F64FuncType, genMathOp}, - {"sin", "csinf", genComplexComplexFuncType<4>, + {"sin", "sinf", genFuncType, + genMathOp}, + {"sin", "sin", genFuncType, + genMathOp}, + {"sin", "csinf", genFuncType, genComplexMathOp}, - {"sin", "csin", genComplexComplexFuncType<8>, + {"sin", "csin", genFuncType, genComplexMathOp}, - {"sinh", "sinhf", genF32F32FuncType, genLibCall}, - {"sinh", "sinh", genF64F64FuncType, genLibCall}, - {"sinh", "csinhf", genComplexComplexFuncType<4>, genLibCall}, - {"sinh", "csinh", genComplexComplexFuncType<8>, genLibCall}, - {"sqrt", "sqrtf", genF32F32FuncType, genMathOp}, - {"sqrt", "sqrt", genF64F64FuncType, genMathOp}, - {"sqrt", "csqrtf", genComplexComplexFuncType<4>, + {"sinh", "sinhf", genFuncType, genLibCall}, + {"sinh", "sinh", genFuncType, genLibCall}, + {"sinh", "csinhf", genFuncType, + genLibCall}, + {"sinh", "csinh", genFuncType, + genLibCall}, + {"sqrt", "sqrtf", genFuncType, + genMathOp}, + {"sqrt", "sqrt", genFuncType, + genMathOp}, + {"sqrt", "csqrtf", genFuncType, genComplexMathOp}, - {"sqrt", "csqrt", genComplexComplexFuncType<8>, + {"sqrt", "csqrt", genFuncType, genComplexMathOp}, - {"tan", "tanf", genF32F32FuncType, genMathOp}, - {"tan", "tan", genF64F64FuncType, genMathOp}, - {"tan", "ctanf", genComplexComplexFuncType<4>, + {"tan", "tanf", genFuncType, + genMathOp}, + {"tan", "tan", genFuncType, + genMathOp}, + {"tan", "ctanf", genFuncType, genComplexMathOp}, - {"tan", "ctan", genComplexComplexFuncType<8>, + {"tan", "ctan", genFuncType, genComplexMathOp}, - {"tanh", "tanhf", genF32F32FuncType, genMathOp}, - {"tanh", "tanh", genF64F64FuncType, genMathOp}, - {"tanh", "ctanhf", genComplexComplexFuncType<4>, + {"tanh", "tanhf", genFuncType, + genMathOp}, + {"tanh", "tanh", genFuncType, + genMathOp}, + {"tanh", "ctanhf", genFuncType, genComplexMathOp}, - {"tanh", "ctanh", genComplexComplexFuncType<8>, + {"tanh", "ctanh", genFuncType, genComplexMathOp}, }; static constexpr MathOperation ppcMathOperations[] = { // fcfi is just another name for fcfid, there is no llvm.ppc.fcfi. - {"__ppc_fcfi", "llvm.ppc.fcfid", genF64F64FuncType, genLibCall}, - {"__ppc_fcfid", "llvm.ppc.fcfid", genF64F64FuncType, genLibCall}, - {"__ppc_fcfud", "llvm.ppc.fcfud", genF64F64FuncType, genLibCall}, - {"__ppc_fctid", "llvm.ppc.fctid", genF64F64FuncType, genLibCall}, - {"__ppc_fctidz", "llvm.ppc.fctidz", genF64F64FuncType, genLibCall}, - {"__ppc_fctiw", "llvm.ppc.fctiw", genF64F64FuncType, genLibCall}, - {"__ppc_fctiwz", "llvm.ppc.fctiwz", genF64F64FuncType, genLibCall}, - {"__ppc_fctudz", "llvm.ppc.fctudz", genF64F64FuncType, genLibCall}, - {"__ppc_fctuwz", "llvm.ppc.fctuwz", genF64F64FuncType, genLibCall}, - {"__ppc_fmadd", "llvm.fma.f32", genF32F32F32F32FuncType, + {"__ppc_fcfi", "llvm.ppc.fcfid", genFuncType, + genLibCall}, + {"__ppc_fcfid", "llvm.ppc.fcfid", genFuncType, + genLibCall}, + {"__ppc_fcfud", "llvm.ppc.fcfud", genFuncType, + genLibCall}, + {"__ppc_fctid", "llvm.ppc.fctid", genFuncType, + genLibCall}, + {"__ppc_fctidz", "llvm.ppc.fctidz", genFuncType, + genLibCall}, + {"__ppc_fctiw", "llvm.ppc.fctiw", genFuncType, + genLibCall}, + {"__ppc_fctiwz", "llvm.ppc.fctiwz", genFuncType, + genLibCall}, + {"__ppc_fctudz", "llvm.ppc.fctudz", genFuncType, + genLibCall}, + {"__ppc_fctuwz", "llvm.ppc.fctuwz", genFuncType, + genLibCall}, + {"__ppc_fmadd", "llvm.fma.f32", + genFuncType, genMathOp}, - {"__ppc_fmadd", "llvm.fma.f64", genF64F64F64F64FuncType, + {"__ppc_fmadd", "llvm.fma.f64", + genFuncType, genMathOp}, - {"__ppc_fmsub", "llvm.ppc.fmsubs", genF32F32F32F32FuncType, genLibCall}, - {"__ppc_fmsub", "llvm.ppc.fmsub", genF64F64F64F64FuncType, genLibCall}, - {"__ppc_fnabs", "llvm.ppc.fnabss", genF32F32FuncType, genLibCall}, - {"__ppc_fnabs", "llvm.ppc.fnabs", genF64F64FuncType, genLibCall}, - {"__ppc_fnmadd", "llvm.ppc.fnmadds", genF32F32F32F32FuncType, genLibCall}, - {"__ppc_fnmadd", "llvm.ppc.fnmadd", genF64F64F64F64FuncType, genLibCall}, - {"__ppc_fnmsub", "llvm.ppc.fnmsub.f32", genF32F32F32F32FuncType, + {"__ppc_fmsub", "llvm.ppc.fmsubs", + genFuncType, + genLibCall}, + {"__ppc_fmsub", "llvm.ppc.fmsub", + genFuncType, + genLibCall}, + {"__ppc_fnabs", "llvm.ppc.fnabss", genFuncType, + genLibCall}, + {"__ppc_fnabs", "llvm.ppc.fnabs", genFuncType, + genLibCall}, + {"__ppc_fnmadd", "llvm.ppc.fnmadds", + genFuncType, + genLibCall}, + {"__ppc_fnmadd", "llvm.ppc.fnmadd", + genFuncType, + genLibCall}, + {"__ppc_fnmsub", "llvm.ppc.fnmsub.f32", + genFuncType, + genLibCall}, + {"__ppc_fnmsub", "llvm.ppc.fnmsub.f64", + genFuncType, + genLibCall}, + {"__ppc_fre", "llvm.ppc.fre", genFuncType, genLibCall}, - {"__ppc_fnmsub", "llvm.ppc.fnmsub.f64", genF64F64F64F64FuncType, + {"__ppc_fres", "llvm.ppc.fres", genFuncType, genLibCall}, - {"__ppc_fre", "llvm.ppc.fre", genF64F64FuncType, genLibCall}, - {"__ppc_fres", "llvm.ppc.fres", genF32F32FuncType, genLibCall}, - {"__ppc_frsqrte", "llvm.ppc.frsqrte", genF64F64FuncType, genLibCall}, - {"__ppc_frsqrtes", "llvm.ppc.frsqrtes", genF32F32FuncType, genLibCall}, + {"__ppc_frsqrte", "llvm.ppc.frsqrte", + genFuncType, genLibCall}, + {"__ppc_frsqrtes", "llvm.ppc.frsqrtes", + genFuncType, genLibCall}, }; // This helper class computes a "distance" between two function types. @@ -5270,10 +5239,12 @@ mlir::FunctionType libFuncType; mlir::func::FuncOp funcOp; if (isImm) { - libFuncType = genVoidIntIntFuncType<32, 32>(builder.getContext()); + libFuncType = genFuncType(builder.getContext()); funcOp = builder.addNamedFunction(loc, "llvm.ppc.mtfsfi", libFuncType); } else { - libFuncType = genVoidIntF64FuncType<32>(builder.getContext()); + libFuncType = genFuncType(builder.getContext()); funcOp = builder.addNamedFunction(loc, "llvm.ppc.mtfsf", libFuncType); } builder.create(loc, funcOp, scalarArgs);