diff --git a/flang-rt/lib/runtime/execute.cpp b/flang-rt/lib/runtime/execute.cpp index f180da846a32c..da13f74d17884 100644 --- a/flang-rt/lib/runtime/execute.cpp +++ b/flang-rt/lib/runtime/execute.cpp @@ -21,7 +21,9 @@ #include "flang/Common/windows-include.h" #else #include +#ifndef __wasi__ #include +#endif #include #endif @@ -65,6 +67,7 @@ void CheckAndStoreIntToDescriptor( } } +#ifndef __wasi__ // If a condition occurs that would assign a nonzero value to CMDSTAT but // the CMDSTAT variable is not present, error termination is initiated. std::int64_t TerminationCheck(std::int64_t status, const Descriptor *cmdstat, @@ -180,6 +183,7 @@ std::int64_t TerminationCheck(std::int64_t status, const Descriptor *cmdstat, #endif return exitStatusVal; } +#endif void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait, const Descriptor *exitstat, const Descriptor *cmdstat, @@ -202,6 +206,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait, RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg)); } +#ifndef __wasi__ if (wait) { // either wait is not specified or wait is true: synchronous mode std::int64_t status{std::system(newCmd)}; @@ -278,6 +283,9 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait, } #endif } +#else + terminator.Crash("not supported on WASI"); +#endif // Deallocate memory if EnsureNullTerminated dynamically allocated memory if (newCmd != command.OffsetElement()) { FreeMemory(newCmd); diff --git a/flang-rt/lib/runtime/extensions.cpp b/flang-rt/lib/runtime/extensions.cpp index 75195c33a6c21..eb016bd733e0e 100644 --- a/flang-rt/lib/runtime/extensions.cpp +++ b/flang-rt/lib/runtime/extensions.cpp @@ -61,7 +61,7 @@ extern "C" { namespace Fortran::runtime { gid_t RTNAME(GetGID)() { -#ifdef _WIN32 +#if defined(_WIN32) || defined(__wasi__) // Group IDs don't exist on Windows, return 1 to avoid errors return 1; #else @@ -70,7 +70,7 @@ gid_t RTNAME(GetGID)() { } uid_t RTNAME(GetUID)() { -#ifdef _WIN32 +#if defined(_WIN32) || defined(__wasi__) // User IDs don't exist on Windows, return 1 to avoid errors return 1; #else diff --git a/flang-rt/lib/runtime/file.cpp b/flang-rt/lib/runtime/file.cpp index 16e73db488727..8e2bc97ef7dac 100644 --- a/flang-rt/lib/runtime/file.cpp +++ b/flang-rt/lib/runtime/file.cpp @@ -31,6 +31,10 @@ void OpenFile::set_path(OwningPtr &&path, std::size_t bytes) { } static int openfile_mkstemp(IoErrorHandler &handler) { +#ifdef __wasi__ + handler.SignalError("not supported on WASI"); + return -1; +#else #ifdef _WIN32 const unsigned int uUnique{0}; // GetTempFileNameA needs a directory name < MAX_PATH-14 characters in length. @@ -58,6 +62,7 @@ static int openfile_mkstemp(IoErrorHandler &handler) { ::unlink(path); #endif return fd; +#endif } void OpenFile::Open(OpenStatus status, Fortran::common::optional action, diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index 1675c15363868..fe496d34813eb 100644 --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -43,9 +43,28 @@ class BoxValue; inline mlir::Type getIntPtrType(mlir::OpBuilder &builder) { // TODO: Delay the need of such type until codegen or find a way to use // llvm::DataLayout::getPointerSizeInBits here. + // (Note: this is *only* used by MemoryUtils.cpp) return builder.getI64Type(); } +//===----------------------------------------------------------------------===// +// MinimalCTargetInfo +//===----------------------------------------------------------------------===// + +/// Minimal information needed to interface with C code on the target, +/// for generating runtime calls. +struct MinimalCTargetInfo { + unsigned char CharWidth; + unsigned char ShortWidth; + unsigned char IntWidth; + unsigned char LongWidth; + unsigned char LongLongWidth; + unsigned char DataPointerWidth; + unsigned char EnumWidth; + + MinimalCTargetInfo(const llvm::Triple &T); +}; + //===----------------------------------------------------------------------===// // FirOpBuilder //===----------------------------------------------------------------------===// @@ -57,7 +76,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { explicit FirOpBuilder(mlir::Operation *op, fir::KindMapping kindMap, mlir::SymbolTable *symbolTable = nullptr) : OpBuilder{op, /*listener=*/this}, kindMap{std::move(kindMap)}, - symbolTable{symbolTable} { + symbolTable{symbolTable}, + cTargetInfo{fir::getTargetTriple(getModule())} { auto fmi = mlir::dyn_cast(*op); if (fmi) { // Set the builder with FastMathFlags attached to the operation. @@ -67,17 +87,20 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap, mlir::SymbolTable *symbolTable = nullptr) : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)}, - symbolTable{symbolTable} { + symbolTable{symbolTable}, + cTargetInfo{fir::getTargetTriple(getModule())} { setListener(this); } explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod) : OpBuilder(builder), OpBuilder::Listener(), - kindMap{getKindMapping(mod)} { + kindMap{getKindMapping(mod)}, + cTargetInfo{fir::getTargetTriple(getModule())} { setListener(this); } explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap, mlir::Operation *op) - : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} { + : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)}, + cTargetInfo{fir::getTargetTriple(getModule())} { setListener(this); auto fmi = mlir::dyn_cast(*op); if (fmi) { @@ -93,7 +116,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap}, fastMathFlags{other.fastMathFlags}, integerOverflowFlags{other.integerOverflowFlags}, - symbolTable{other.symbolTable} { + symbolTable{other.symbolTable}, + cTargetInfo{other.cTargetInfo} { setListener(this); } @@ -101,7 +125,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { : OpBuilder(other), OpBuilder::Listener(), kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags}, integerOverflowFlags{other.integerOverflowFlags}, - symbolTable{other.symbolTable} { + symbolTable{other.symbolTable}, + cTargetInfo{other.cTargetInfo} { setListener(this); } @@ -160,7 +185,45 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { /// Get the integer type whose bit width corresponds to the width of pointer /// types, or is bigger. - mlir::Type getIntPtrType() { return fir::getIntPtrType(*this); } + mlir::Type getIntPtrType() { + return getIntegerType(cTargetInfo.DataPointerWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// the `char` type in C + mlir::Type getCCharType() { + return getIntegerType(cTargetInfo.CharWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// the `short` type in C + mlir::Type getCShortType() { + return getIntegerType(cTargetInfo.ShortWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// the `int` type in C + mlir::Type getCIntType() { + return getIntegerType(cTargetInfo.IntWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// the `long` type in C + mlir::Type getCLongType() { + return getIntegerType(cTargetInfo.LongWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// the `long long` type in C + mlir::Type getCLongLongType() { + return getIntegerType(cTargetInfo.LongLongWidth); + } + + /// Get the integer type whose bit width corresponds to the width of + /// enums in C + mlir::Type getCEnumType() { + return getIntegerType(cTargetInfo.EnumWidth); + } /// Wrap `str` to a SymbolRefAttr. mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str) { @@ -619,6 +682,8 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener { /// Stored via a unique_ptr rather than an optional so as not to bloat this /// class when most instances won't ever need a data layout. std::unique_ptr dataLayout = nullptr; + + MinimalCTargetInfo cTargetInfo; }; } // namespace fir diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h index 5158abaa31ed1..4021e8149fadf 100644 --- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h +++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h @@ -51,17 +51,18 @@ class DerivedType; namespace fir::runtime { -using TypeBuilderFunc = mlir::Type (*)(mlir::MLIRContext *); -using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *); +using TypeBuilderFunc = mlir::Type (*)(fir::FirOpBuilder &); +using FuncTypeBuilderFunc = mlir::FunctionType (*)(fir::FirOpBuilder &); #define REDUCTION_REF_OPERATION_MODEL(T) \ template <> \ constexpr TypeBuilderFunc \ getModel>() { \ - return [](mlir::MLIRContext *context) -> mlir::Type { \ + return [](fir::FirOpBuilder &builder) -> mlir::Type { \ TypeBuilderFunc f{getModel()}; \ - auto refTy = fir::ReferenceType::get(f(context)); \ - return mlir::FunctionType::get(context, {refTy, refTy}, refTy); \ + auto refTy = fir::ReferenceType::get(f(builder)); \ + return mlir::FunctionType::get(builder.getContext(), {refTy, refTy}, \ + refTy); \ }; \ } @@ -69,11 +70,11 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *); template <> \ constexpr TypeBuilderFunc \ getModel>() { \ - return [](mlir::MLIRContext *context) -> mlir::Type { \ + return [](fir::FirOpBuilder &builder) -> mlir::Type { \ TypeBuilderFunc f{getModel()}; \ - auto refTy = fir::ReferenceType::get(f(context)); \ - return mlir::FunctionType::get(context, {f(context), f(context)}, \ - refTy); \ + auto refTy = fir::ReferenceType::get(f(builder)); \ + return mlir::FunctionType::get(builder.getContext(), \ + {f(builder), f(builder)}, refTy); \ }; \ } @@ -81,16 +82,16 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *); template <> \ constexpr TypeBuilderFunc \ getModel>() { \ - return [](mlir::MLIRContext *context) -> mlir::Type { \ + return [](fir::FirOpBuilder &builder) -> mlir::Type { \ TypeBuilderFunc f{getModel()}; \ auto voidTy = fir::LLVMPointerType::get( \ - context, mlir::IntegerType::get(context, 8)); \ - auto size_tTy = \ - mlir::IntegerType::get(context, 8 * sizeof(std::size_t)); \ - auto refTy = fir::ReferenceType::get(f(context)); \ + builder.getContext(), \ + mlir::IntegerType::get(builder.getContext(), 8)); \ + auto size_tTy = builder.getIntPtrType(); \ + auto refTy = fir::ReferenceType::get(f(builder)); \ return mlir::FunctionType::get( \ - context, {refTy, size_tTy, refTy, refTy, size_tTy, size_tTy}, \ - voidTy); \ + builder.getContext(), \ + {refTy, size_tTy, refTy, refTy, size_tTy, size_tTy}, voidTy); \ }; \ } @@ -98,8 +99,8 @@ using FuncTypeBuilderFunc = mlir::FunctionType (*)(mlir::MLIRContext *); // Type builder models //===----------------------------------------------------------------------===// -// TODO: all usages of sizeof in this file assume build == host == target. -// This will need to be re-visited for cross compilation. +// TODO: not all usages of sizeof have been necessarily correctly audited +// for cross compilation. /// Return a function that returns the type signature model for the type `T` /// when provided an MLIRContext*. This allows one to translate C(++) function @@ -113,21 +114,21 @@ static constexpr TypeBuilderFunc getModel(); template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(unsigned int)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCIntType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(short int)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCShortType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -136,15 +137,15 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(int)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCIntType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -153,15 +154,16 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::IntegerType::get(context, 8)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get( + mlir::IntegerType::get(builder.getContext(), 8)); }; } template <> @@ -170,33 +172,35 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::IntegerType::get(context, 16)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get( + mlir::IntegerType::get(builder.getContext(), 16)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::IntegerType::get(context, 32)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get( + mlir::IntegerType::get(builder.getContext(), 32)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(char)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCCharType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(signed char)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCCharType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -205,69 +209,70 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(char16_t)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::IntegerType::get(builder.getContext(), 16); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(char32_t)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::IntegerType::get(builder.getContext(), 32); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(unsigned char)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCCharType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::LLVMPointerType::get(context, - mlir::IntegerType::get(context, 8)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::LLVMPointerType::get( + builder.getContext(), mlir::IntegerType::get(builder.getContext(), 8)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { return fir::LLVMPointerType::get( - context, - mlir::FunctionType::get(context, /*inputs=*/{}, /*results*/ {})); + builder.getContext(), + mlir::FunctionType::get(builder.getContext(), /*inputs=*/{}, + /*results*/ {})); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get( - fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8))); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get(fir::LLVMPointerType::get( + builder.getContext(), mlir::IntegerType::get(builder.getContext(), 8))); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(long)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCLongType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -280,22 +285,22 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(long long)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCLongLongType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::IntegerType::get(builder.getContext(), 8 * sizeof(Fortran::common::int128_t)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -308,27 +313,27 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(unsigned long)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCLongType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 8 * sizeof(unsigned long long)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCLongLongType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::Float64Type::get(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::Float64Type::get(builder.getContext()); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -341,26 +346,26 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { // See TODO at the top of the file. This is configuring for the host system // - it might be incorrect when cross-compiling! constexpr size_t size = sizeof(long double); static_assert(size == 16 || size == 10 || size == 8, "unsupported long double size"); if constexpr (size == 16) - return mlir::Float128Type::get(context); + return mlir::Float128Type::get(builder.getContext()); if constexpr (size == 10) - return mlir::Float80Type::get(context); + return mlir::Float80Type::get(builder.getContext()); if constexpr (size == 8) - return mlir::Float64Type::get(context); + return mlir::Float64Type::get(builder.getContext()); llvm_unreachable("failed static assert"); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -369,15 +374,15 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::Float32Type::get(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::Float32Type::get(builder.getContext()); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -390,36 +395,38 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, 1); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::IntegerType::get(builder.getContext(), 1); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { + // TODO: This has special signedness semantics? return mlir::IntegerType::get( - context, 8 * sizeof(unsigned short), + builder.getContext(), 8 * sizeof(unsigned short), mlir::IntegerType::SignednessSemantics::Unsigned); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::IntegerType::get(context, 8)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + TypeBuilderFunc f{getModel()}; + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -428,9 +435,9 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get( - mlir::IntegerType::get(context, 8 * sizeof(unsigned short))); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + TypeBuilderFunc f{getModel()}; + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -447,9 +454,9 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get( - mlir::IntegerType::get(context, 8 * sizeof(unsigned long))); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + TypeBuilderFunc f{getModel()}; + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -458,9 +465,9 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get( - mlir::IntegerType::get(context, 8 * sizeof(unsigned long long))); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + TypeBuilderFunc f{getModel()}; + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -473,9 +480,9 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { TypeBuilderFunc f{getModel()}; - return fir::ReferenceType::get(f(context)); + return fir::ReferenceType::get(f(builder)); }; } template <> @@ -496,8 +503,8 @@ constexpr TypeBuilderFunc getModel() { template <> constexpr TypeBuilderFunc getModel &>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type floatTy = getModel()(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type floatTy = getModel()(builder); return fir::ReferenceType::get(mlir::ComplexType::get(floatTy)); }; } @@ -511,8 +518,8 @@ constexpr TypeBuilderFunc getModel *>() { } template <> constexpr TypeBuilderFunc getModel &>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type floatTy = getModel()(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type floatTy = getModel()(builder); return fir::ReferenceType::get(mlir::ComplexType::get(floatTy)); }; } @@ -526,29 +533,29 @@ constexpr TypeBuilderFunc getModel *>() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type floatTy = getModel()(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type floatTy = getModel()(builder); return mlir::ComplexType::get(floatTy); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type floatTy = getModel()(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type floatTy = getModel()(builder); return mlir::ComplexType::get(floatTy); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::BoxType::get(mlir::NoneType::get(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::BoxType::get(mlir::NoneType::get(builder.getContext())); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { return fir::ReferenceType::get( - fir::BoxType::get(mlir::NoneType::get(context))); + fir::BoxType::get(mlir::NoneType::get(builder.getContext()))); }; } template <> @@ -561,29 +568,28 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, - sizeof(Fortran::common::TypeCategory) * 8); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCEnumType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::NoneType::get(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get(mlir::NoneType::get(builder.getContext())); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::NoneType::get(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get(mlir::NoneType::get(builder.getContext())); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::NoneType::get(context); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return mlir::NoneType::get(builder.getContext()); }; } @@ -594,23 +600,22 @@ constexpr TypeBuilderFunc getModel() { } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return mlir::IntegerType::get(context, - 8 * sizeof(Fortran::runtime::io::Iostat)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return builder.getCEnumType(); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::TupleType::get(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get(mlir::TupleType::get(builder.getContext())); }; } template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - return fir::ReferenceType::get(mlir::TupleType::get(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + return fir::ReferenceType::get(mlir::TupleType::get(builder.getContext())); }; } @@ -649,37 +654,37 @@ REDUCTION_VALUE_OPERATION_MODEL(long double) template <> constexpr TypeBuilderFunc getModel>>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type cplx = mlir::ComplexType::get(getModel()(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type cplx = mlir::ComplexType::get(getModel()(builder)); auto refTy = fir::ReferenceType::get(cplx); - return mlir::FunctionType::get(context, {cplx, cplx}, refTy); + return mlir::FunctionType::get(builder.getContext(), {cplx, cplx}, refTy); }; } template <> constexpr TypeBuilderFunc getModel>>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type cplx = mlir::ComplexType::get(getModel()(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type cplx = mlir::ComplexType::get(getModel()(builder)); auto refTy = fir::ReferenceType::get(cplx); - return mlir::FunctionType::get(context, {cplx, cplx}, refTy); + return mlir::FunctionType::get(builder.getContext(), {cplx, cplx}, refTy); }; } template <> constexpr TypeBuilderFunc getModel>>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type cplx = mlir::ComplexType::get(getModel()(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type cplx = mlir::ComplexType::get(getModel()(builder)); auto refTy = fir::ReferenceType::get(cplx); - return mlir::FunctionType::get(context, {refTy, refTy}, refTy); + return mlir::FunctionType::get(builder.getContext(), {refTy, refTy}, refTy); }; } template <> constexpr TypeBuilderFunc getModel< Fortran::runtime::ReferenceReductionOperation>>() { - return [](mlir::MLIRContext *context) -> mlir::Type { - mlir::Type cplx = mlir::ComplexType::get(getModel()(context)); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + mlir::Type cplx = mlir::ComplexType::get(getModel()(builder)); auto refTy = fir::ReferenceType::get(cplx); - return mlir::FunctionType::get(context, {refTy, refTy}, refTy); + return mlir::FunctionType::get(builder.getContext(), {refTy, refTy}, refTy); }; } @@ -690,10 +695,11 @@ REDUCTION_CHAR_OPERATION_MODEL(char32_t) template <> constexpr TypeBuilderFunc getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { - auto voidTy = - fir::LLVMPointerType::get(context, mlir::IntegerType::get(context, 8)); - return mlir::FunctionType::get(context, {voidTy, voidTy, voidTy}, voidTy); + return [](fir::FirOpBuilder &builder) -> mlir::Type { + auto voidTy = fir::LLVMPointerType::get( + builder.getContext(), mlir::IntegerType::get(builder.getContext(), 8)); + return mlir::FunctionType::get(builder.getContext(), + {voidTy, voidTy, voidTy}, voidTy); }; } @@ -702,16 +708,16 @@ struct RuntimeTableKey; template struct RuntimeTableKey { static constexpr FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctxt) { + return [](fir::FirOpBuilder &builder) { TypeBuilderFunc ret = getModel(); std::array args = {getModel()...}; - mlir::Type retTy = ret(ctxt); + mlir::Type retTy = ret(builder); llvm::SmallVector argTys; for (auto f : args) - argTys.push_back(f(ctxt)); + argTys.push_back(f(builder)); if (mlir::isa(retTy)) - return mlir::FunctionType::get(ctxt, argTys, {}); - return mlir::FunctionType::get(ctxt, argTys, {retTy}); + return mlir::FunctionType::get(builder.getContext(), argTys, {}); + return mlir::FunctionType::get(builder.getContext(), argTys, {retTy}); }; } }; @@ -813,7 +819,7 @@ static mlir::func::FuncOp getRuntimeFunc(mlir::Location loc, auto func = builder.getNamedFunction(name); if (func) return func; - auto funTy = RuntimeEntry::getTypeModel()(builder.getContext()); + auto funTy = RuntimeEntry::getTypeModel()(builder); return builder.createRuntimeFunction(loc, name, funTy, isIO); } diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp index 9938bd573d1fa..603505ba129a2 100644 --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -777,7 +777,7 @@ class AllocateStmtHelper { mlir::Value source = sourceExpr ? fir::getBase(sourceExv) : nullptr; // Keep return type the same as a standard AllocatableAllocate call. - mlir::Type retTy = fir::runtime::getModel()(builder.getContext()); + mlir::Type retTy = fir::runtime::getModel()(builder); return builder .create( loc, retTy, box.getAddr(), errmsg, stream, pinned, source, cudaAttr, @@ -846,7 +846,7 @@ static mlir::Value genCudaDeallocate(fir::FirOpBuilder &builder, : errorManager.errMsgAddr; // Keep return type the same as a standard AllocatableAllocate call. - mlir::Type retTy = fir::runtime::getModel()(builder.getContext()); + mlir::Type retTy = fir::runtime::getModel()(builder); return builder .create( loc, retTy, box.getAddr(), errmsg, cudaAttr, diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index 16e6d05bd3b10..280c911b14e2f 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -267,9 +267,9 @@ getNonTbpDefinedIoTableAddr(Fortran::lower::AbstractConverter &converter, mlir::StringAttr linkOnce = builder.createLinkOnceLinkage(); mlir::Type idxTy = builder.getIndexType(); mlir::Type sizeTy = - fir::runtime::getModel()(builder.getContext()); - mlir::Type intTy = fir::runtime::getModel()(builder.getContext()); - mlir::Type boolTy = fir::runtime::getModel()(builder.getContext()); + fir::runtime::getModel()(builder); + mlir::Type intTy = fir::runtime::getModel()(builder); + mlir::Type boolTy = fir::runtime::getModel()(builder); mlir::Type listTy = fir::SequenceType::get( definedIoProcMap.size(), mlir::TupleType::get(context, {refTy, refTy, intTy, boolTy})); @@ -427,7 +427,7 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter, mlir::StringAttr linkOnce = builder.createLinkOnceLinkage(); mlir::Type idxTy = builder.getIndexType(); mlir::Type sizeTy = - fir::runtime::getModel()(builder.getContext()); + fir::runtime::getModel()(builder); mlir::Type charRefTy = fir::ReferenceType::get(builder.getIntegerType(8)); mlir::Type descRefTy = fir::ReferenceType::get(fir::BoxType::get(mlir::NoneType::get(context))); diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index b3d440cedee07..963d816a4d31e 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -33,6 +33,25 @@ #include "llvm/Support/MD5.h" #include +fir::MinimalCTargetInfo::MinimalCTargetInfo(const llvm::Triple &T) { + CharWidth = 8; + ShortWidth = 16; + DataPointerWidth = T.getArchPointerBitWidth(); + // TODO: This will need to be changed for targets such as AVR and MSP430 + IntWidth = 32; + // TODO: flags such as -fshort-enums can change ABI + EnumWidth = IntWidth; + LongLongWidth = 64; + if (T.isArch64Bit() && T.isOSWindows()) { + // Windows uses sizeof(long) = 32 bits + LongWidth = 32; + } else { + // Assumes sizeof(long) == sizeof(ptr) + // (typical for Unix-likes: ILP32 and LP64) + LongWidth = DataPointerWidth; + } +} + static llvm::cl::opt nameLengthHashSize("length-to-hash-string-literal", llvm::cl::desc("string literals that exceed this length" diff --git a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp index 2f46e7605fe91..0949474124f9a 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Intrinsics.cpp @@ -32,13 +32,15 @@ namespace { struct ForcedRandomNumberReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(RandomNumber16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { auto boxTy = - fir::runtime::getModel()(ctx); - auto strTy = fir::runtime::getModel()(ctx); - auto intTy = fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); + auto strTy = fir::runtime::getModel()(builder); + auto intTy = fir::runtime::getModel()(builder); ; - return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy}, {}); + return mlir::FunctionType::get(builder.getContext(), + {boxTy, strTy, intTy}, {}); }; } }; diff --git a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp index 4ff7c86bb0a24..7360077d3fd7f 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Numeric.cpp @@ -26,7 +26,8 @@ using namespace Fortran::runtime; struct ForcedErfcScaled10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ErfcScaled10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -37,7 +38,8 @@ struct ForcedErfcScaled10 { struct ForcedErfcScaled16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ErfcScaled16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -48,7 +50,8 @@ struct ForcedErfcScaled16 { struct ForcedExponent10_4 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent10_4)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float80Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, fltTy, intTy); @@ -59,7 +62,8 @@ struct ForcedExponent10_4 { struct ForcedExponent10_8 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent10_8)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float80Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, fltTy, intTy); @@ -71,7 +75,8 @@ struct ForcedExponent10_8 { struct ForcedExponent16_4 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent16_4)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float128Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, fltTy, intTy); @@ -82,7 +87,8 @@ struct ForcedExponent16_4 { struct ForcedExponent16_8 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Exponent16_8)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float128Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, fltTy, intTy); @@ -94,7 +100,8 @@ struct ForcedExponent16_8 { struct ForcedFraction10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Fraction10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -105,7 +112,8 @@ struct ForcedFraction10 { struct ForcedFraction16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Fraction16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -116,7 +124,8 @@ struct ForcedFraction16 { struct ForcedMod10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); 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)); @@ -130,7 +139,8 @@ struct ForcedMod10 { struct ForcedMod16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); 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)); @@ -144,7 +154,8 @@ struct ForcedMod16 { struct ForcedModulo10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModuloReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); 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)); @@ -158,7 +169,8 @@ struct ForcedModulo10 { struct ForcedModulo16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ModuloReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); 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)); @@ -172,7 +184,8 @@ struct ForcedModulo16 { struct ForcedNearest10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Nearest10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float80Type::get(ctx); auto boolTy = mlir::IntegerType::get(ctx, 1); return mlir::FunctionType::get(ctx, {fltTy, boolTy}, {fltTy}); @@ -184,7 +197,8 @@ struct ForcedNearest10 { struct ForcedNearest16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Nearest16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float128Type::get(ctx); auto boolTy = mlir::IntegerType::get(ctx, 1); return mlir::FunctionType::get(ctx, {fltTy, boolTy}, {fltTy}); @@ -196,7 +210,8 @@ struct ForcedNearest16 { struct ForcedRRSpacing10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(RRSpacing10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -207,7 +222,8 @@ struct ForcedRRSpacing10 { struct ForcedRRSpacing16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(RRSpacing16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -218,7 +234,8 @@ struct ForcedRRSpacing16 { struct ForcedScale10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Scale10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float80Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, {fltTy, intTy}, {fltTy}); @@ -230,7 +247,8 @@ struct ForcedScale10 { struct ForcedScale16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Scale16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float128Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, {fltTy, intTy}, {fltTy}); @@ -242,7 +260,8 @@ struct ForcedScale16 { struct ForcedSetExponent10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SetExponent10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float80Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, {fltTy, intTy}, {fltTy}); @@ -254,7 +273,8 @@ struct ForcedSetExponent10 { struct ForcedSetExponent16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SetExponent16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto fltTy = mlir::Float128Type::get(ctx); auto intTy = mlir::IntegerType::get(ctx, 64); return mlir::FunctionType::get(ctx, {fltTy, intTy}, {fltTy}); @@ -266,7 +286,8 @@ struct ForcedSetExponent16 { struct ForcedSpacing10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Spacing10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; @@ -277,7 +298,8 @@ struct ForcedSpacing10 { struct ForcedSpacing16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Spacing16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); return mlir::FunctionType::get(ctx, {ty}, {ty}); }; diff --git a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp index f778b963c59ca..47b56de12f807 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp @@ -26,10 +26,12 @@ using namespace Fortran::runtime; struct ForcedMaxvalReal10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MaxvalReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -42,10 +44,12 @@ struct ForcedMaxvalReal10 { struct ForcedMaxvalReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MaxvalReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -59,10 +63,12 @@ struct ForcedMaxvalInteger16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MaxvalInteger16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -76,11 +82,13 @@ struct ForcedMaxvalUnsigned16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MaxvalUnsigned16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -93,10 +101,12 @@ struct ForcedMaxvalUnsigned16 { struct ForcedMinvalReal10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MinvalReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -109,10 +119,12 @@ struct ForcedMinvalReal10 { struct ForcedMinvalReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MinvalReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -126,10 +138,12 @@ struct ForcedMinvalInteger16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MinvalInteger16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -143,11 +157,13 @@ struct ForcedMinvalUnsigned16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(MinvalUnsigned16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -172,10 +188,12 @@ using ForcedMinlocUnsigned16 = mkRTKey(MinlocUnsigned16); struct ForcedNorm2Real10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Norm2_10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy}, {ty}); @@ -187,10 +205,12 @@ struct ForcedNorm2Real10 { struct ForcedNorm2Real16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Norm2_16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy}, {ty}); @@ -202,9 +222,11 @@ struct ForcedNorm2Real16 { struct ForcedNorm2DimReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(Norm2DimReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get( @@ -218,10 +240,12 @@ struct ForcedNorm2DimReal16 { struct ForcedProductReal10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ProductReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -234,10 +258,12 @@ struct ForcedProductReal10 { struct ForcedProductReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ProductReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -251,10 +277,12 @@ struct ForcedProductInteger16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ProductInteger16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -268,11 +296,13 @@ struct ForcedProductUnsigned16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ProductUnsigned16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -286,10 +316,12 @@ struct ForcedProductComplex10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppProductComplex10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -304,10 +336,12 @@ struct ForcedProductComplex16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppProductComplex16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -322,10 +356,12 @@ struct ForcedDotProductReal10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(DotProductReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, boxTy, strTy, intTy}, {ty}); @@ -338,10 +374,12 @@ struct ForcedDotProductReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(DotProductReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, boxTy, strTy, intTy}, {ty}); @@ -354,10 +392,12 @@ struct ForcedDotProductComplex10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppDotProductComplex10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -372,10 +412,12 @@ struct ForcedDotProductComplex16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppDotProductComplex16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -390,10 +432,12 @@ struct ForcedDotProductInteger16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(DotProductInteger16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, boxTy, strTy, intTy}, {ty}); @@ -406,11 +450,13 @@ struct ForcedDotProductUnsigned16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(DotProductUnsigned16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, boxTy, strTy, intTy}, {ty}); @@ -422,10 +468,12 @@ struct ForcedDotProductUnsigned16 { struct ForcedSumReal10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SumReal10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -438,10 +486,12 @@ struct ForcedSumReal10 { struct ForcedSumReal16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SumReal16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -454,10 +504,12 @@ struct ForcedSumReal16 { struct ForcedSumInteger16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SumInteger16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -470,11 +522,13 @@ struct ForcedSumInteger16 { struct ForcedSumUnsigned16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(SumUnsigned16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -488,10 +542,12 @@ struct ForcedSumComplex10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppSumComplex10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -506,10 +562,12 @@ struct ForcedSumComplex16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppSumComplex16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); auto resTy = fir::ReferenceType::get(ty); @@ -523,10 +581,12 @@ struct ForcedSumComplex16 { struct ForcedIAll16 { static constexpr const char *name = EXPAND_AND_QUOTE_KEY(IAll16); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -539,10 +599,12 @@ struct ForcedIAll16 { struct ForcedIAny16 { static constexpr const char *name = EXPAND_AND_QUOTE_KEY(IAny16); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -555,10 +617,12 @@ struct ForcedIAny16 { struct ForcedIParity16 { static constexpr const char *name = EXPAND_AND_QUOTE_KEY(IParity16); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 8 * sizeof(int)); return mlir::FunctionType::get(ctx, {boxTy, strTy, intTy, intTy, boxTy}, @@ -572,10 +636,12 @@ struct ForcedReduceReal10Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal10Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -592,10 +658,12 @@ struct ForcedReduceReal10Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal10Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -612,10 +680,12 @@ struct ForcedReduceReal16Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal16Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -632,10 +702,12 @@ struct ForcedReduceReal16Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal16Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -652,10 +724,12 @@ struct ForcedReduceReal10DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal10DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -674,10 +748,12 @@ struct ForcedReduceReal10DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal10DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -696,10 +772,12 @@ struct ForcedReduceReal16DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal16DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -718,10 +796,12 @@ struct ForcedReduceReal16DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceReal16DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -740,10 +820,12 @@ struct ForcedReduceInteger16Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceInteger16Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -760,10 +842,12 @@ struct ForcedReduceUnsigned16Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceUnsigned16Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -780,10 +864,12 @@ struct ForcedReduceInteger16Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceInteger16Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -800,10 +886,12 @@ struct ForcedReduceUnsigned16Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceUnsigned16Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -820,10 +908,12 @@ struct ForcedReduceInteger16DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceInteger16DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -842,11 +932,13 @@ struct ForcedReduceUnsigned16DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceUnsigned16DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -865,10 +957,12 @@ struct ForcedReduceInteger16DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceInteger16DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get(ctx, 128); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -887,11 +981,13 @@ struct ForcedReduceUnsigned16DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(ReduceUnsigned16DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::IntegerType::get( ctx, 128, mlir::IntegerType::SignednessSemantics::Unsigned); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -910,10 +1006,12 @@ struct ForcedReduceComplex10Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex10Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -931,10 +1029,12 @@ struct ForcedReduceComplex10Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex10Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -952,10 +1052,12 @@ struct ForcedReduceComplex10DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex10DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -974,10 +1076,12 @@ struct ForcedReduceComplex10DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex10DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float80Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -996,10 +1100,12 @@ struct ForcedReduceComplex16Ref { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex16Ref)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -1017,10 +1123,12 @@ struct ForcedReduceComplex16Value { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex16Value)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -1038,10 +1146,12 @@ struct ForcedReduceComplex16DimRef { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex16DimRef)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {refTy, refTy}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); @@ -1060,10 +1170,12 @@ struct ForcedReduceComplex16DimValue { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(CppReduceComplex16DimValue)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::ComplexType::get(mlir::Float128Type::get(ctx)); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); auto refTy = fir::ReferenceType::get(ty); auto opTy = mlir::FunctionType::get(ctx, {ty, ty}, refTy); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); diff --git a/flang/lib/Optimizer/Builder/Runtime/Support.cpp b/flang/lib/Optimizer/Builder/Runtime/Support.cpp index b5e9ddb87c7c4..c43df2105b5c4 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Support.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Support.cpp @@ -17,9 +17,9 @@ using namespace Fortran::runtime; template <> constexpr fir::runtime::TypeBuilderFunc fir::runtime::getModel() { - return [](mlir::MLIRContext *context) -> mlir::Type { + return [](fir::FirOpBuilder &builder) -> mlir::Type { return mlir::IntegerType::get( - context, sizeof(Fortran::runtime::LowerBoundModifier) * 8); + builder.getContext(), sizeof(Fortran::runtime::LowerBoundModifier) * 8); }; } diff --git a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp index 978524494af9b..6d8a8c428b736 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Transformational.cpp @@ -24,10 +24,11 @@ using namespace Fortran::runtime; struct ForcedBesselJn_10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselJn_10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get( @@ -40,10 +41,11 @@ struct ForcedBesselJn_10 { struct ForcedBesselJn_16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselJn_16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get( @@ -56,9 +58,10 @@ struct ForcedBesselJn_16 { struct ForcedBesselJnX0_10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselJnX0_10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, {boxTy, intTy, intTy, strTy, intTy}, @@ -71,9 +74,10 @@ struct ForcedBesselJnX0_10 { struct ForcedBesselJnX0_16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselJnX0_16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, {boxTy, intTy, intTy, strTy, intTy}, @@ -86,10 +90,11 @@ struct ForcedBesselJnX0_16 { struct ForcedBesselYn_10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselYn_10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float80Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get( @@ -102,10 +107,11 @@ struct ForcedBesselYn_10 { struct ForcedBesselYn_16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselYn_16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto ty = mlir::Float128Type::get(ctx); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get( @@ -118,9 +124,10 @@ struct ForcedBesselYn_16 { struct ForcedBesselYnX0_10 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselYnX0_10)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, {boxTy, intTy, intTy, strTy, intTy}, @@ -133,9 +140,10 @@ struct ForcedBesselYnX0_10 { struct ForcedBesselYnX0_16 { static constexpr const char *name = ExpandAndQuoteKey(RTNAME(BesselYnX0_16)); static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto strTy = fir::ReferenceType::get(mlir::IntegerType::get(ctx, 8)); auto intTy = mlir::IntegerType::get(ctx, 32); return mlir::FunctionType::get(ctx, {boxTy, intTy, intTy, strTy, intTy}, @@ -324,13 +332,15 @@ void fir::runtime::genEoshiftVector(fir::FirOpBuilder &builder, /// Define ForcedMatmul models. struct ForcedMatmulTypeModel { static constexpr fir::runtime::FuncTypeBuilderFunc getTypeModel() { - return [](mlir::MLIRContext *ctx) { + return [](fir::FirOpBuilder &builder) { + auto ctx = builder.getContext(); auto boxRefTy = - fir::runtime::getModel()(ctx); + fir::runtime::getModel()(builder); auto boxTy = - fir::runtime::getModel()(ctx); - auto strTy = fir::runtime::getModel()(ctx); - auto intTy = fir::runtime::getModel()(ctx); + fir::runtime::getModel()( + builder); + auto strTy = fir::runtime::getModel()(builder); + auto intTy = fir::runtime::getModel()(builder); return mlir::FunctionType::get( ctx, {boxRefTy, boxTy, boxTy, strTy, intTy}, {}); }; diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp index e2f8fb9d239a1..932c5fbcb9b9d 100644 --- a/flang/lib/Optimizer/CodeGen/Target.cpp +++ b/flang/lib/Optimizer/CodeGen/Target.cpp @@ -1816,6 +1816,44 @@ struct TargetLoongArch64 : public GenericTarget { }; } // namespace +//===----------------------------------------------------------------------===// +// WebAssembly (wasm32) target specifics. +//===----------------------------------------------------------------------===// + +namespace { +struct TargetWasm32 : public GenericTarget { + using GenericTarget::GenericTarget; + + static constexpr int defaultWidth = 32; + + CodeGenSpecifics::Marshalling + complexArgumentType(mlir::Location, mlir::Type eleTy) const override { + assert(fir::isa_real(eleTy)); + CodeGenSpecifics::Marshalling marshal; + // Use a type that will be translated into LLVM as: + // { t, t } struct of 2 eleTy, byval, align 4 + auto structTy = + mlir::TupleType::get(eleTy.getContext(), mlir::TypeRange{eleTy, eleTy}); + marshal.emplace_back(fir::ReferenceType::get(structTy), + AT{/*alignment=*/4, /*byval=*/true}); + return marshal; + } + + CodeGenSpecifics::Marshalling + complexReturnType(mlir::Location loc, mlir::Type eleTy) const override { + assert(fir::isa_real(eleTy)); + CodeGenSpecifics::Marshalling marshal; + // Use a type that will be translated into LLVM as: + // { t, t } struct of 2 eleTy, sret, align 4 + auto structTy = mlir::TupleType::get(eleTy.getContext(), + mlir::TypeRange{eleTy, eleTy}); + marshal.emplace_back(fir::ReferenceType::get(structTy), + AT{/*alignment=*/4, /*byval=*/false, /*sret=*/true}); + return marshal; + } +}; +} // namespace + // Instantiate the overloaded target instance based on the triple value. // TODO: Add other targets to this file as needed. std::unique_ptr @@ -1871,6 +1909,9 @@ fir::CodeGenSpecifics::get(mlir::MLIRContext *ctx, llvm::Triple &&trp, case llvm::Triple::ArchType::loongarch64: return std::make_unique( ctx, std::move(trp), std::move(kindMap), targetCPU, targetFeatures, dl); + case llvm::Triple::ArchType::wasm32: + return std::make_unique( + ctx, std::move(trp), std::move(kindMap), targetCPU, targetFeatures, dl); } TODO(mlir::UnknownLoc::get(ctx), "target not implemented"); }