From 4ba30c6eb6b9b358556563e6b8a0b1dbbba8a2e7 Mon Sep 17 00:00:00 2001 From: Jean-Didier PAILLEUX Date: Mon, 20 Oct 2025 08:00:52 +0200 Subject: [PATCH] [flang][Multi-Image] Moving Mutli-image lowering to PRIF into the MIF dialect (#161179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support for multi-image features has begun to be integrated into LLVM. A new dialect which simplifies lowering to PRIF wil be proposed in this PR. The initial definition of this dialect (MIF) is based only on operations already upstreamed in LLVM and the current lowering will be moved to this dialect. --------- Co-authored-by: Dan Bonachea Co-authored-by: Valentin Clement (バレンタイン クレメン) --- .../flang/Optimizer/Builder/Runtime/Coarray.h | 85 ---- .../flang/Optimizer/Dialect/CMakeLists.txt | 1 + .../include/flang/Optimizer/Dialect/FIRType.h | 3 + .../Optimizer/Dialect/MIF/CMakeLists.txt | 9 + .../flang/Optimizer/Dialect/MIF/MIFDialect.h | 28 ++ .../flang/Optimizer/Dialect/MIF/MIFDialect.td | 38 ++ .../flang/Optimizer/Dialect/MIF/MIFOps.h | 20 + .../flang/Optimizer/Dialect/MIF/MIFOps.td | 268 ++++++++++ .../include/flang/Optimizer/Support/InitFIR.h | 3 +- .../Optimizer/Transforms/MIFOpConversion.h | 27 + .../flang/Optimizer/Transforms/Passes.td | 5 + flang/lib/Frontend/CMakeLists.txt | 2 + flang/lib/Lower/CMakeLists.txt | 2 + flang/lib/Lower/Runtime.cpp | 27 +- flang/lib/Optimizer/Builder/CMakeLists.txt | 3 +- flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 99 +--- .../lib/Optimizer/Builder/Runtime/Coarray.cpp | 228 --------- flang/lib/Optimizer/Builder/Runtime/Main.cpp | 4 +- flang/lib/Optimizer/Dialect/CMakeLists.txt | 1 + flang/lib/Optimizer/Dialect/FIRType.cpp | 7 + .../lib/Optimizer/Dialect/MIF/CMakeLists.txt | 20 + .../lib/Optimizer/Dialect/MIF/MIFDialect.cpp | 24 + flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp | 153 ++++++ flang/lib/Optimizer/Passes/Pipelines.cpp | 1 + flang/lib/Optimizer/Transforms/CMakeLists.txt | 3 + .../Optimizer/Transforms/MIFOpConversion.cpp | 464 ++++++++++++++++++ .../test/Driver/mlir-debug-pass-pipeline.f90 | 1 + flang/test/Driver/mlir-pass-pipeline.f90 | 1 + flang/test/Fir/MIF/co_broadcast.mlir | 137 ++++++ flang/test/Fir/MIF/co_max.mlir | 163 ++++++ flang/test/Fir/MIF/co_min.mlir | 163 ++++++ flang/test/Fir/MIF/co_sum.mlir | 133 +++++ flang/test/Fir/MIF/init.mlir | 24 + flang/test/Fir/MIF/num_images.mlir | 22 + flang/test/Fir/MIF/sync_all.mlir | 45 ++ flang/test/Fir/MIF/sync_images.mlir | 85 ++++ flang/test/Fir/MIF/sync_memory.mlir | 45 ++ flang/test/Fir/MIF/this_image.mlir | 16 + flang/test/Fir/basic-program.fir | 1 + flang/test/Lower/Coarray/co_broadcast.f90 | 92 ---- flang/test/Lower/Coarray/co_max.f90 | 112 ----- flang/test/Lower/Coarray/co_min.f90 | 112 ----- flang/test/Lower/Coarray/co_sum.f90 | 122 ----- flang/test/Lower/Coarray/sync_all.f90 | 37 -- flang/test/Lower/Coarray/sync_images.f90 | 62 --- flang/test/Lower/Coarray/sync_memory.f90 | 37 -- flang/test/Lower/MIF/co_broadcast.f90 | 57 +++ flang/test/Lower/MIF/co_max.f90 | 60 +++ flang/test/Lower/MIF/co_min.f90 | 60 +++ flang/test/Lower/MIF/co_sum.f90 | 51 ++ .../Lower/{Coarray => MIF}/coarray-init.f90 | 4 +- .../Lower/{Coarray => MIF}/num_images.f90 | 6 +- flang/test/Lower/MIF/sync_all.f90 | 27 + flang/test/Lower/MIF/sync_images.f90 | 39 ++ flang/test/Lower/MIF/sync_memory.f90 | 27 + .../Lower/{Coarray => MIF}/this_image.f90 | 4 +- flang/tools/bbc/CMakeLists.txt | 1 + flang/tools/fir-lsp-server/CMakeLists.txt | 3 +- flang/tools/fir-opt/CMakeLists.txt | 1 + flang/tools/tco/CMakeLists.txt | 1 + flang/unittests/Optimizer/CMakeLists.txt | 4 +- 61 files changed, 2287 insertions(+), 993 deletions(-) delete mode 100644 flang/include/flang/Optimizer/Builder/Runtime/Coarray.h create mode 100644 flang/include/flang/Optimizer/Dialect/MIF/CMakeLists.txt create mode 100644 flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.h create mode 100644 flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.td create mode 100644 flang/include/flang/Optimizer/Dialect/MIF/MIFOps.h create mode 100644 flang/include/flang/Optimizer/Dialect/MIF/MIFOps.td create mode 100644 flang/include/flang/Optimizer/Transforms/MIFOpConversion.h delete mode 100644 flang/lib/Optimizer/Builder/Runtime/Coarray.cpp create mode 100644 flang/lib/Optimizer/Dialect/MIF/CMakeLists.txt create mode 100644 flang/lib/Optimizer/Dialect/MIF/MIFDialect.cpp create mode 100644 flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp create mode 100644 flang/lib/Optimizer/Transforms/MIFOpConversion.cpp create mode 100644 flang/test/Fir/MIF/co_broadcast.mlir create mode 100644 flang/test/Fir/MIF/co_max.mlir create mode 100644 flang/test/Fir/MIF/co_min.mlir create mode 100644 flang/test/Fir/MIF/co_sum.mlir create mode 100644 flang/test/Fir/MIF/init.mlir create mode 100644 flang/test/Fir/MIF/num_images.mlir create mode 100644 flang/test/Fir/MIF/sync_all.mlir create mode 100644 flang/test/Fir/MIF/sync_images.mlir create mode 100644 flang/test/Fir/MIF/sync_memory.mlir create mode 100644 flang/test/Fir/MIF/this_image.mlir delete mode 100644 flang/test/Lower/Coarray/co_broadcast.f90 delete mode 100644 flang/test/Lower/Coarray/co_max.f90 delete mode 100644 flang/test/Lower/Coarray/co_min.f90 delete mode 100644 flang/test/Lower/Coarray/co_sum.f90 delete mode 100644 flang/test/Lower/Coarray/sync_all.f90 delete mode 100644 flang/test/Lower/Coarray/sync_images.f90 delete mode 100644 flang/test/Lower/Coarray/sync_memory.f90 create mode 100644 flang/test/Lower/MIF/co_broadcast.f90 create mode 100644 flang/test/Lower/MIF/co_max.f90 create mode 100644 flang/test/Lower/MIF/co_min.f90 create mode 100644 flang/test/Lower/MIF/co_sum.f90 rename flang/test/Lower/{Coarray => MIF}/coarray-init.f90 (57%) rename flang/test/Lower/{Coarray => MIF}/num_images.f90 (60%) create mode 100644 flang/test/Lower/MIF/sync_all.f90 create mode 100644 flang/test/Lower/MIF/sync_images.f90 create mode 100644 flang/test/Lower/MIF/sync_memory.f90 rename flang/test/Lower/{Coarray => MIF}/this_image.f90 (64%) diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Coarray.h b/flang/include/flang/Optimizer/Builder/Runtime/Coarray.h deleted file mode 100644 index 20bfb7c124af..000000000000 --- a/flang/include/flang/Optimizer/Builder/Runtime/Coarray.h +++ /dev/null @@ -1,85 +0,0 @@ -//===-- Coarray.h -- generate Coarray intrinsics runtime calls --*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COARRAY_H -#define FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COARRAY_H - -#include "flang/Lower/AbstractConverter.h" -#include "flang/Optimizer/Support/InternalNames.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" - -namespace fir { -class ExtendedValue; -class FirOpBuilder; -} // namespace fir - -namespace fir::runtime { - -// Get the function type for a prif subroutine with a variable number of -// arguments -#define PRIF_FUNCTYPE(...) \ - mlir::FunctionType::get(builder.getContext(), /*inputs*/ {__VA_ARGS__}, \ - /*result*/ {}) - -// Default prefix for subroutines of PRIF compiled with LLVM -#define PRIFNAME_SUB(fmt) \ - []() { \ - std::ostringstream oss; \ - oss << "prif_" << fmt; \ - return fir::NameUniquer::doProcedure({"prif"}, {}, oss.str()); \ - }() - -#define PRIF_STAT_TYPE builder.getRefType(builder.getI32Type()) -#define PRIF_ERRMSG_TYPE \ - fir::BoxType::get(fir::CharacterType::get(builder.getContext(), 1, \ - fir::CharacterType::unknownLen())) - -/// Generate Call to runtime prif_init -mlir::Value genInitCoarray(fir::FirOpBuilder &builder, mlir::Location loc); - -/// Generate Call to runtime prif_num_images -mlir::Value getNumImages(fir::FirOpBuilder &builder, mlir::Location loc); - -/// Generate Call to runtime prif_num_images_with_team or -/// prif_num_images_with_team_number -mlir::Value getNumImagesWithTeam(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value team); - -/// Generate Call to runtime prif_this_image_no_coarray -mlir::Value getThisImage(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value team = {}); - -/// Generate call to runtime subroutine prif_co_broadcast -void genCoBroadcast(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value A, mlir::Value sourceImage, mlir::Value stat, - mlir::Value errmsg); - -/// Generate call to runtime subroutine prif_co_max and prif_co_max_character -void genCoMax(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value A, - mlir::Value resultImage, mlir::Value stat, mlir::Value errmsg); - -/// Generate call to runtime subroutine prif_co_min or prif_co_min_character -void genCoMin(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value A, - mlir::Value resultImage, mlir::Value stat, mlir::Value errmsg); - -/// Generate call to runtime subroutine prif_co_sum -void genCoSum(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value A, - mlir::Value resultImage, mlir::Value stat, mlir::Value errmsg); - -/// Generate call to runtime subroutine prif_sync_all -void genSyncAllStatement(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value stat, mlir::Value errmsg); -/// Generate call to runtime subroutine prif_sync_memory -void genSyncMemoryStatement(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value stat, mlir::Value errmsg); -/// Generate call to runtime subroutine prif_sync_images -void genSyncImagesStatement(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value imageSet, mlir::Value stat, - mlir::Value errmsg); -} // namespace fir::runtime -#endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COARRAY_H diff --git a/flang/include/flang/Optimizer/Dialect/CMakeLists.txt b/flang/include/flang/Optimizer/Dialect/CMakeLists.txt index adefcfea0b5d..7b1a12932276 100644 --- a/flang/include/flang/Optimizer/Dialect/CMakeLists.txt +++ b/flang/include/flang/Optimizer/Dialect/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(CUF) add_subdirectory(FIRCG) +add_subdirectory(MIF) # This replicates part of the add_mlir_dialect cmake function from MLIR that # cannot be used her because it expects to be run inside MLIR directory which diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h index ceee24af0d20..a94842d82cef 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRType.h +++ b/flang/include/flang/Optimizer/Dialect/FIRType.h @@ -53,6 +53,9 @@ public: /// Unwrap element type from fir.heap, fir.ptr and fir.array. mlir::Type unwrapInnerType() const; + // Get the element type or the fir.array + mlir::Type getElementOrSequenceType() const; + /// Is this the box for an assumed rank? bool isAssumedRank() const; diff --git a/flang/include/flang/Optimizer/Dialect/MIF/CMakeLists.txt b/flang/include/flang/Optimizer/Dialect/MIF/CMakeLists.txt new file mode 100644 index 000000000000..27ba3889c804 --- /dev/null +++ b/flang/include/flang/Optimizer/Dialect/MIF/CMakeLists.txt @@ -0,0 +1,9 @@ +set(LLVM_TARGET_DEFINITIONS MIFDialect.td) +mlir_tablegen(MIFDialect.h.inc -gen-dialect-decls -dialect=mif) +mlir_tablegen(MIFDialect.cpp.inc -gen-dialect-defs -dialect=mif) + +# Add Multi Image Fortran operations +set(LLVM_TARGET_DEFINITIONS MIFOps.td) +mlir_tablegen(MIFOps.h.inc -gen-op-decls) +mlir_tablegen(MIFOps.cpp.inc -gen-op-defs) +add_public_tablegen_target(MIFOpsIncGen) diff --git a/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.h b/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.h new file mode 100644 index 000000000000..2f3ab9c81705 --- /dev/null +++ b/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.h @@ -0,0 +1,28 @@ +//===-- MIF.h - MIF dialect ---------------------------------------*- C++-*-==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_OPTIMIZER_DIALECT_MIF_MIFDIALECT_H +#define FORTRAN_OPTIMIZER_DIALECT_MIF_MIFDIALECT_H + +#include "mlir/Bytecode/BytecodeOpInterface.h" +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/IR/SymbolTable.h" +#include "mlir/Interfaces/CallInterfaces.h" +#include "mlir/Interfaces/InferTypeOpInterface.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" +#include "mlir/Interfaces/VectorInterfaces.h" + +//===----------------------------------------------------------------------===// +// MIFDialect +//===----------------------------------------------------------------------===// + +#include "flang/Optimizer/Dialect/MIF/MIFDialect.h.inc" + +#endif // FORTRAN_OPTIMIZER_DIALECT_MIF_MIFDIALECT_H diff --git a/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.td b/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.td new file mode 100644 index 000000000000..f8be6a86a79f --- /dev/null +++ b/flang/include/flang/Optimizer/Dialect/MIF/MIFDialect.td @@ -0,0 +1,38 @@ +//===-- MIFDialect.td - MIF dialect base definitions - tablegen ---------*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Definition of the Multi-Image Fortran (MIF) dialect +/// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_DIALECT_MIF_MIFDIALECT +#define FORTRAN_DIALECT_MIF_MIFDIALECT + +include "mlir/IR/AttrTypeBase.td" +include "mlir/IR/EnumAttr.td" +include "mlir/IR/OpBase.td" + +def MIFDialect : Dialect { + let name = "mif"; + + let summary = "Multi-Image Fortran dialect"; + + let description = [{ + The "MIF" dialect is designed to contain the basic coarray operations + in Fortran and all multi image operations as descibed in the standard. + This includes synchronization operations, atomic operations, + image queries, teams, criticals, etc. The MIF dialect operations use + the FIR types and are tightly coupled with FIR and HLFIR. + }]; + + let cppNamespace = "::mif"; + let dependentDialects = ["fir::FIROpsDialect"]; +} + +#endif // FORTRAN_DIALECT_MIF_MIFDIALECT diff --git a/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.h b/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.h new file mode 100644 index 000000000000..a9e53c21171c --- /dev/null +++ b/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.h @@ -0,0 +1,20 @@ +//===-- Optimizer/Dialect/MIF/MIFOps.h - MIF operations ---------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_OPTIMIZER_DIALECT_MIF_MIFOPS_H +#define FORTRAN_OPTIMIZER_DIALECT_MIF_MIFOPS_H + +#include "flang/Optimizer/Dialect/FIRType.h" +#include "flang/Optimizer/Dialect/MIF/MIFDialect.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" +#include "mlir/IR/OpDefinition.h" + +#define GET_OP_CLASSES +#include "flang/Optimizer/Dialect/MIF/MIFOps.h.inc" + +#endif // FORTRAN_OPTIMIZER_DIALECT_MIF_MIFOPS_H diff --git a/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.td b/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.td new file mode 100644 index 000000000000..52471d3702b7 --- /dev/null +++ b/flang/include/flang/Optimizer/Dialect/MIF/MIFOps.td @@ -0,0 +1,268 @@ +//===-- MIFOps.td - MIF operation definitions --------------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// Definition of the MIF dialect operations +/// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_DIALECT_MIF_MIF_OPS +#define FORTRAN_DIALECT_MIF_MIF_OPS + +include "flang/Optimizer/Dialect/MIF/MIFDialect.td" +include "flang/Optimizer/Dialect/FIRTypes.td" +include "flang/Optimizer/Dialect/FIRAttr.td" + +class mif_Op traits> + : Op; + +//===----------------------------------------------------------------------===// +// Initialization and Finalization +//===----------------------------------------------------------------------===// + +def mif_InitOp : mif_Op<"init", []> { + let summary = "Initialize the parallel environment"; + let description = [{This operation will initialize the parallel environment}]; + + let results = (outs I32:$stat); + let assemblyFormat = "`->` type($stat) attr-dict"; +} + +//===----------------------------------------------------------------------===// +// Image Queries +//===----------------------------------------------------------------------===// + +def mif_NumImagesOp : mif_Op<"num_images", [AttrSizedOperandSegments]> { + let summary = "Query the number of images in the specified or current team"; + let description = [{ + This operation query the number of images in the specified or current + team and can be called with 3 differents way : + - `num_images()` + - `num_images(team)` + - `num_images(team_number)` + + Arguments: + - `team` : Shall be a scalar of type `team_type` from the `ISO_FORTRAN_ENV` + module with a value that identifies the current or ancestor team. + - `team_number` : Shall be an integer scalar. It shall identify the + initial team or a sibling team of the current team. + + Result Value: The number of images in the specified team, or in the current + team if no team is specified. + }]; + + let arguments = (ins Optional:$team_number, + Optional:$team); + let results = (outs I32:$res); + + let builders = [OpBuilder<(ins CArg<"mlir::Value", "{}">:$teamArg)>]; + + let hasVerifier = 1; + let assemblyFormat = [{ + ( `team_number` $team_number^ )? + ( `team` $team^ )? + attr-dict `:` functional-type(operands, results) + }]; +} + +def mif_ThisImageOp : mif_Op<"this_image", [AttrSizedOperandSegments]> { + let summary = "Determine the image index of the current image"; + let description = [{ + Arguments: + - `coarray` : Shall be a coarray of any type. + - `dim` : Shall be an integer scalar. Its value shall be in the range of + 1 <= DIM <= N, where N is the corank of the coarray. + - `team`(optional) : Shall be a scalar of type `team_type` from + ISO_FORTRAN_ENV. If the `coarray` is present, it shall be + established in that team. + + Results: + - Case(1) : The result of `this_image([team])` is a scalar with a value + equal to the index of the image in the current or specified team. + - Case(2) : The result of `this_image(coarray [,team])` is the sequence of + cosubscript values for `coarray`. + - Case(3) : The result of `this_image(coarray, dim [,team])` is the value of + cosubscript `dim` in the sequence of cosubscript values for `coarray`. + + Example: + ```fortran + REAL :: A[10, 0:9, 0:*] + ``` + If we take a look on the example and we are on image 5, `this_image` has the + value 5, `this_image(A)` has the value [5, 0, 0]. + }]; + + let arguments = (ins Optional:$coarray, + Optional:$dim, Optional:$team); + let results = (outs I32:$res); + + let builders = [OpBuilder<(ins "mlir::Value":$coarray, "mlir::Value":$team)>, + OpBuilder<(ins "mlir::Value":$team)>]; + + let hasVerifier = 1; + let assemblyFormat = [{ + ( `coarray` $coarray^ )? + ( `team` $team^ )? + ( `dim` $dim^ )? + attr-dict `:` functional-type(operands, results) + }]; +} + +//===----------------------------------------------------------------------===// +// Synchronization +//===----------------------------------------------------------------------===// +// NOTE: Every operation in this section corresponds to a Fortran +// "image control statement" (F23 11.7.1). This means they end a Fortran +// "segment" and start another (F23 11.7.2), which affects the memory +// consistency semantics of surrounding accesses in the multi-image execution. +// For now we've modeled this by *deliberately* omitting mlir::MemoryEffects +// on these operations, to ensure analysis treats these ops conservatively. +//===----------------------------------------------------------------------===// + +def mif_SyncAllOp : mif_Op<"sync_all", [AttrSizedOperandSegments]> { + let summary = + "Performs a collective synchronization of all images in the current team"; + + let arguments = (ins Optional:$stat, + Optional:$errmsg); + let assemblyFormat = [{ + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` functional-type(operands, results) + }]; +} + +def mif_SyncImagesOp : mif_Op<"sync_images", [AttrSizedOperandSegments]> { + let summary = "Performs a synchronization of image with each of the other " + "images in the `image_set`"; + let description = [{ + This operation can take an optional argument `⁣image_set`, wich must be an integer expression + and must be scalar or rank one. If `image_set` is omitted from the call, this operation will + adopt the behavior of the Fortran statement `SYNC IMAGES(*)`. + }]; + + let arguments = (ins Optional:$image_set, + Optional:$stat, + Optional:$errmsg); + let hasVerifier = 1; + let assemblyFormat = [{ + (`image_set` $image_set^ )? + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` functional-type(operands, results) + }]; +} + +def mif_SyncMemoryOp : mif_Op<"sync_memory", [AttrSizedOperandSegments]> { + let summary = "Operation that ends one segment and begins another."; + let description = [{ + Operation that ends one segment and begins another; Those two segments can + be ordered by user-defined way with respect to segments on other images. + }]; + + let arguments = (ins Optional:$stat, + Optional:$errmsg); + let assemblyFormat = [{ + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` functional-type(operands, results) + }]; +} + +//===----------------------------------------------------------------------===// +// Collective Operations +//===----------------------------------------------------------------------===// + +def mif_CoBroadcastOp : mif_Op<"co_broadcast", [AttrSizedOperandSegments, + MemoryEffects<[MemWrite]>]> { + let summary = "Broadcast value to images."; + let description = [{ + The co_broadcast operation broadcasts a value from one image to the other images. + }]; + + let arguments = (ins Arg:$a, + AnyIntegerType:$source_image, + Arg, "", [MemWrite]>:$stat, + Arg, "", [MemWrite]>:$errmsg); + + let hasVerifier = 1; + let assemblyFormat = [{ + $a `source` $source_image + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` `(` type(operands) `)` + }]; +} + +def mif_CoMaxOp + : mif_Op<"co_max", [AttrSizedOperandSegments, MemoryEffects<[MemWrite]>]> { + let summary = "Compute maximum value across images."; + let description = [{ + The co_max operation performs the computation of the maximum + across images. + }]; + + let arguments = (ins Arg:$a, + Optional:$result_image, + Arg, "", [MemWrite]>:$stat, + Arg, "", [MemWrite]>:$errmsg); + + let hasVerifier = 1; + let assemblyFormat = [{ + $a (`result` $result_image^ )? + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` `(` type(operands) `)` + }]; +} + +def mif_CoMinOp + : mif_Op<"co_min", [AttrSizedOperandSegments, MemoryEffects<[MemWrite]>]> { + let summary = "Compute minimum value across images."; + let description = [{ + The co_min operation performs the computation of the minimum + across images. + }]; + + let arguments = (ins Arg:$a, + Optional:$result_image, + Arg, "", [MemWrite]>:$stat, + Arg, "", [MemWrite]>:$errmsg); + + let hasVerifier = 1; + let assemblyFormat = [{ + $a (`result` $result_image^ )? + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` `(` type(operands) `)` + }]; +} + +def mif_CoSumOp + : mif_Op<"co_sum", [AttrSizedOperandSegments, MemoryEffects<[MemWrite]>]> { + let summary = "Compute sum across images."; + let description = [{ + The co_sum operation performs the computation of the sum + across images. + }]; + + let arguments = (ins Arg:$a, + Optional:$result_image, + Arg, "", [MemWrite]>:$stat, + Arg, "", [MemWrite]>:$errmsg); + + let hasVerifier = 1; + let assemblyFormat = [{ + $a (`result` $result_image^ )? + (`stat` $stat^ )? + (`errmsg` $errmsg^ )? + attr-dict `:` `(` type(operands) `)` + }]; +} + +#endif // FORTRAN_DIALECT_MIF_MIF_OPS diff --git a/flang/include/flang/Optimizer/Support/InitFIR.h b/flang/include/flang/Optimizer/Support/InitFIR.h index 3e42ffd41591..67e9287ddad4 100644 --- a/flang/include/flang/Optimizer/Support/InitFIR.h +++ b/flang/include/flang/Optimizer/Support/InitFIR.h @@ -16,6 +16,7 @@ #include "flang/Optimizer/Dialect/CUF/CUFDialect.h" #include "flang/Optimizer/Dialect/CUF/CUFToLLVMIRTranslation.h" #include "flang/Optimizer/Dialect/FIRDialect.h" +#include "flang/Optimizer/Dialect/MIF/MIFDialect.h" #include "flang/Optimizer/HLFIR/HLFIRDialect.h" #include "flang/Optimizer/OpenACC/Support/RegisterOpenACCExtensions.h" #include "flang/Optimizer/OpenMP/Support/RegisterOpenMPExtensions.h" @@ -51,7 +52,7 @@ namespace fir::support { mlir::vector::VectorDialect, mlir::math::MathDialect, \ mlir::complex::ComplexDialect, mlir::DLTIDialect, cuf::CUFDialect, \ mlir::NVVM::NVVMDialect, mlir::gpu::GPUDialect, \ - mlir::index::IndexDialect + mlir::index::IndexDialect, mif::MIFDialect #define FLANG_CODEGEN_DIALECT_LIST FIRCodeGenDialect, mlir::LLVM::LLVMDialect diff --git a/flang/include/flang/Optimizer/Transforms/MIFOpConversion.h b/flang/include/flang/Optimizer/Transforms/MIFOpConversion.h new file mode 100644 index 000000000000..93c724748102 --- /dev/null +++ b/flang/include/flang/Optimizer/Transforms/MIFOpConversion.h @@ -0,0 +1,27 @@ +//===------- Optimizer/Transforms/MIFOpToLLVMConversion.h -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_MIFOPCONVERSION_H_ +#define FORTRAN_OPTIMIZER_TRANSFORMS_MIFOPCONVERSION_H_ + +#include "mlir/Conversion/LLVMCommon/Pattern.h" +#include "mlir/Pass/Pass.h" +#include "mlir/Pass/PassRegistry.h" + +namespace fir { +class LLVMTypeConverter; +} + +namespace mif { + +/// Patterns that convert MIF operations to runtime calls. +void populateMIFOpConversionPatterns(mlir::RewritePatternSet &patterns); + +} // namespace mif + +#endif // FORTRAN_OPTIMIZER_TRANSFORMS_MIFOPCONVERSION_H_ diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td index e2ba9c352283..dcff07844347 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -580,4 +580,9 @@ def OptimizeArrayRepacking }]; } +def MIFOpConversion : Pass<"mif-convert", "mlir::ModuleOp"> { + let summary = "Convert some MIF operations to runtime calls"; + let dependentDialects = ["fir::FIROpsDialect", "mlir::LLVM::LLVMDialect"]; +} + #endif // FLANG_OPTIMIZER_TRANSFORMS_PASSES diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt index fa0d5ecfdb9b..2b3bc0e9c226 100644 --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -19,6 +19,7 @@ add_flang_library(flangFrontend FIROptCodeGenPassIncGen FIROptTransformsPassIncGen HLFIRDialect + MIFDialect LINK_LIBS CUFDialect @@ -41,6 +42,7 @@ add_flang_library(flangFrontend FIROpenACCSupport FIROpenMPSupport FlangOpenMPTransforms + MIFDialect LINK_COMPONENTS Passes diff --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt index eb4d57d733dd..3d0b4e4cd82e 100644 --- a/flang/lib/Lower/CMakeLists.txt +++ b/flang/lib/Lower/CMakeLists.txt @@ -45,6 +45,7 @@ add_flang_library(FortranLower FIRDialect FIRTransforms HLFIRDialect + MIFDialect LINK_LIBS CUFAttrs @@ -61,6 +62,7 @@ add_flang_library(FortranLower FortranEvaluate FortranSemantics FortranUtils + MIFDialect LINK_COMPONENTS Support diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp index b19ca0182b4b..cb555249125f 100644 --- a/flang/lib/Lower/Runtime.cpp +++ b/flang/lib/Lower/Runtime.cpp @@ -12,10 +12,10 @@ #include "flang/Lower/OpenMP.h" #include "flang/Lower/StatementContext.h" #include "flang/Optimizer/Builder/FIRBuilder.h" -#include "flang/Optimizer/Builder/Runtime/Coarray.h" #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" #include "flang/Optimizer/Builder/Todo.h" #include "flang/Optimizer/Dialect/FIROpsSupport.h" +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" #include "flang/Parser/parse-tree.h" #include "flang/Runtime/misc-intrinsic.h" #include "flang/Runtime/pointer.h" @@ -52,7 +52,6 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) { static std::pair getStatAndErrmsg( Fortran::lower::AbstractConverter &converter, mlir::Location loc, const std::list &statOrErrList) { - fir::FirOpBuilder &builder = converter.getFirOpBuilder(); Fortran::lower::StatementContext stmtCtx; mlir::Value errMsgExpr, statExpr; @@ -71,16 +70,6 @@ static std::pair getStatAndErrmsg( statOrErr.u); } - if (!statExpr) { - statExpr = fir::AbsentOp::create(builder, loc, - builder.getRefType(builder.getI32Type())); - } - if (!errMsgExpr) { - errMsgExpr = fir::AbsentOp::create( - builder, loc, - fir::BoxType::get(fir::CharacterType::get( - builder.getContext(), 1, fir::CharacterType::unknownLen()))); - } return {statExpr, errMsgExpr}; } @@ -215,7 +204,7 @@ void Fortran::lower::genSyncAllStatement( auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - fir::runtime::genSyncAllStatement(builder, loc, statAddr, errMsgAddr); + mif::SyncAllOp::create(builder, loc, statAddr, errMsgAddr); } void Fortran::lower::genSyncImagesStatement( @@ -244,16 +233,12 @@ void Fortran::lower::genSyncImagesStatement( fir::getBase(converter.genExprBox(loc, *expr, stmtCtx)); }, [&](const Fortran::parser::Star &) { - imageSet = fir::AbsentOp::create( - builder, loc, - fir::BoxType::get(fir::SequenceType::get( - {fir::SequenceType::getUnknownExtent()}, - builder.getI32Type()))); + // Image set is not set. + imageSet = mlir::Value{}; }}, imgSet.u); - fir::runtime::genSyncImagesStatement(builder, loc, imageSet, statAddr, - errMsgAddr); + mif::SyncImagesOp::create(builder, loc, imageSet, statAddr, errMsgAddr); } void Fortran::lower::genSyncMemoryStatement( @@ -267,7 +252,7 @@ void Fortran::lower::genSyncMemoryStatement( auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList); fir::FirOpBuilder &builder = converter.getFirOpBuilder(); - fir::runtime::genSyncMemoryStatement(builder, loc, statAddr, errMsgAddr); + mif::SyncMemoryOp::create(builder, loc, statAddr, errMsgAddr); } void Fortran::lower::genSyncTeamStatement( diff --git a/flang/lib/Optimizer/Builder/CMakeLists.txt b/flang/lib/Optimizer/Builder/CMakeLists.txt index 404afd185fd3..1f95259a857d 100644 --- a/flang/lib/Optimizer/Builder/CMakeLists.txt +++ b/flang/lib/Optimizer/Builder/CMakeLists.txt @@ -16,7 +16,6 @@ add_flang_library(FIRBuilder Runtime/Allocatable.cpp Runtime/ArrayConstructor.cpp Runtime/Assign.cpp - Runtime/Coarray.cpp Runtime/Character.cpp Runtime/Command.cpp Runtime/CUDA/Descriptor.cpp @@ -42,6 +41,7 @@ add_flang_library(FIRBuilder CUFDialect FIRDialect HLFIRDialect + MIFDialect LINK_LIBS CUFAttrs @@ -52,6 +52,7 @@ add_flang_library(FIRBuilder FortranEvaluate FortranSupport HLFIRDialect + MIFDialect MLIR_DEPS ${dialect_libs} diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 01951784fe47..ec0c802fb209 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -25,7 +25,6 @@ #include "flang/Optimizer/Builder/Runtime/Allocatable.h" #include "flang/Optimizer/Builder/Runtime/CUDA/Descriptor.h" #include "flang/Optimizer/Builder/Runtime/Character.h" -#include "flang/Optimizer/Builder/Runtime/Coarray.h" #include "flang/Optimizer/Builder/Runtime/Command.h" #include "flang/Optimizer/Builder/Runtime/Derived.h" #include "flang/Optimizer/Builder/Runtime/Exceptions.h" @@ -40,6 +39,7 @@ #include "flang/Optimizer/Builder/Todo.h" #include "flang/Optimizer/Dialect/FIROps.h" #include "flang/Optimizer/Dialect/FIROpsSupport.h" +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" #include "flang/Optimizer/Dialect/Support/FIRContext.h" #include "flang/Optimizer/HLFIR/HLFIROps.h" #include "flang/Optimizer/Support/FatalError.h" @@ -412,28 +412,28 @@ static constexpr IntrinsicHandler handlers[]{ {"co_broadcast", &I::genCoBroadcast, {{{"a", asBox}, - {"source_image", asAddr}, + {"source_image", asValue}, {"stat", asAddr, handleDynamicOptional}, {"errmsg", asBox, handleDynamicOptional}}}, /*isElemental*/ false}, {"co_max", &I::genCoMax, {{{"a", asBox}, - {"result_image", asAddr, handleDynamicOptional}, + {"result_image", asValue, handleDynamicOptional}, {"stat", asAddr, handleDynamicOptional}, {"errmsg", asBox, handleDynamicOptional}}}, /*isElemental*/ false}, {"co_min", &I::genCoMin, {{{"a", asBox}, - {"result_image", asAddr, handleDynamicOptional}, + {"result_image", asValue, handleDynamicOptional}, {"stat", asAddr, handleDynamicOptional}, {"errmsg", asBox, handleDynamicOptional}}}, /*isElemental*/ false}, {"co_sum", &I::genCoSum, {{{"a", asBox}, - {"result_image", asAddr, handleDynamicOptional}, + {"result_image", asValue, handleDynamicOptional}, {"stat", asAddr, handleDynamicOptional}, {"errmsg", asBox, handleDynamicOptional}}}, /*isElemental*/ false}, @@ -829,7 +829,7 @@ static constexpr IntrinsicHandler handlers[]{ {"null", &I::genNull, {{{"mold", asInquired}}}, /*isElemental=*/false}, {"num_images", &I::genNumImages, - {{{"team", asAddr}, {"team_number", asAddr}}}, + {{{"team_number", asValue}, {"team", asBox}}}, /*isElemental*/ false}, {"pack", &I::genPack, @@ -3795,79 +3795,40 @@ mlir::Value IntrinsicLibrary::genCmplx(mlir::Type resultType, void IntrinsicLibrary::genCoBroadcast(llvm::ArrayRef args) { converter->checkCoarrayEnabled(); assert(args.size() == 4); - mlir::Value sourceImage = fir::getBase(args[1]); - mlir::Value status = - isStaticallyAbsent(args[2]) - ? fir::AbsentOp::create(builder, loc, - builder.getRefType(builder.getI32Type())) - .getResult() - : fir::getBase(args[2]); - mlir::Value errmsg = - isStaticallyAbsent(args[3]) - ? fir::AbsentOp::create(builder, loc, PRIF_ERRMSG_TYPE).getResult() - : fir::getBase(args[3]); - fir::runtime::genCoBroadcast(builder, loc, fir::getBase(args[0]), sourceImage, - status, errmsg); + mif::CoBroadcastOp::create(builder, loc, fir::getBase(args[0]), + /*sourceImage*/ fir::getBase(args[1]), + /*status*/ fir::getBase(args[2]), + /*errmsg*/ fir::getBase(args[3])); } // CO_MAX void IntrinsicLibrary::genCoMax(llvm::ArrayRef args) { converter->checkCoarrayEnabled(); assert(args.size() == 4); - mlir::Value refNone = - fir::AbsentOp::create(builder, loc, - builder.getRefType(builder.getI32Type())) - .getResult(); - mlir::Value resultImage = - isStaticallyAbsent(args[1]) ? refNone : fir::getBase(args[1]); - mlir::Value status = - isStaticallyAbsent(args[2]) ? refNone : fir::getBase(args[2]); - mlir::Value errmsg = - isStaticallyAbsent(args[3]) - ? fir::AbsentOp::create(builder, loc, PRIF_ERRMSG_TYPE).getResult() - : fir::getBase(args[3]); - fir::runtime::genCoMax(builder, loc, fir::getBase(args[0]), resultImage, - status, errmsg); + mif::CoMaxOp::create(builder, loc, fir::getBase(args[0]), + /*resultImage*/ fir::getBase(args[1]), + /*status*/ fir::getBase(args[2]), + /*errmsg*/ fir::getBase(args[3])); } // CO_MIN void IntrinsicLibrary::genCoMin(llvm::ArrayRef args) { converter->checkCoarrayEnabled(); assert(args.size() == 4); - mlir::Value refNone = - fir::AbsentOp::create(builder, loc, - builder.getRefType(builder.getI32Type())) - .getResult(); - mlir::Value resultImage = - isStaticallyAbsent(args[1]) ? refNone : fir::getBase(args[1]); - mlir::Value status = - isStaticallyAbsent(args[2]) ? refNone : fir::getBase(args[2]); - mlir::Value errmsg = - isStaticallyAbsent(args[3]) - ? fir::AbsentOp::create(builder, loc, PRIF_ERRMSG_TYPE).getResult() - : fir::getBase(args[3]); - fir::runtime::genCoMin(builder, loc, fir::getBase(args[0]), resultImage, - status, errmsg); + mif::CoMinOp::create(builder, loc, fir::getBase(args[0]), + /*resultImage*/ fir::getBase(args[1]), + /*status*/ fir::getBase(args[2]), + /*errmsg*/ fir::getBase(args[3])); } // CO_SUM void IntrinsicLibrary::genCoSum(llvm::ArrayRef args) { converter->checkCoarrayEnabled(); assert(args.size() == 4); - mlir::Value absentInt = - fir::AbsentOp::create(builder, loc, - builder.getRefType(builder.getI32Type())) - .getResult(); - mlir::Value resultImage = - isStaticallyAbsent(args[1]) ? absentInt : fir::getBase(args[1]); - mlir::Value status = - isStaticallyAbsent(args[2]) ? absentInt : fir::getBase(args[2]); - mlir::Value errmsg = - isStaticallyAbsent(args[3]) - ? fir::AbsentOp::create(builder, loc, PRIF_ERRMSG_TYPE).getResult() - : fir::getBase(args[3]); - fir::runtime::genCoSum(builder, loc, fir::getBase(args[0]), resultImage, - status, errmsg); + mif::CoSumOp::create(builder, loc, fir::getBase(args[0]), + /*resultImage*/ fir::getBase(args[1]), + /*status*/ fir::getBase(args[2]), + /*errmsg*/ fir::getBase(args[3])); } // COMMAND_ARGUMENT_COUNT @@ -7579,9 +7540,9 @@ IntrinsicLibrary::genNumImages(mlir::Type resultType, assert(args.size() == 0 || args.size() == 1); if (args.size()) - return fir::runtime::getNumImagesWithTeam(builder, loc, - fir::getBase(args[0])); - return fir::runtime::getNumImages(builder, loc); + return mif::NumImagesOp::create(builder, loc, fir::getBase(args[0])) + .getResult(); + return mif::NumImagesOp::create(builder, loc).getResult(); } // CLOCK, CLOCK64, GLOBALTIMER @@ -8659,17 +8620,11 @@ IntrinsicLibrary::genThisImage(mlir::Type resultType, converter->checkCoarrayEnabled(); assert(args.size() >= 1 && args.size() <= 3); const bool coarrayIsAbsent = args.size() == 1; - mlir::Value team = - !isStaticallyAbsent(args, args.size() - 1) - ? fir::getBase(args[args.size() - 1]) - : builder - .create(loc, - fir::BoxType::get(builder.getNoneType())) - .getResult(); + mlir::Value team = fir::getBase(args[args.size() - 1]); if (!coarrayIsAbsent) TODO(loc, "this_image with coarray argument."); - mlir::Value res = fir::runtime::getThisImage(builder, loc, team); + mlir::Value res = mif::ThisImageOp::create(builder, loc, team); return builder.createConvert(loc, resultType, res); } diff --git a/flang/lib/Optimizer/Builder/Runtime/Coarray.cpp b/flang/lib/Optimizer/Builder/Runtime/Coarray.cpp deleted file mode 100644 index 364e7b753c6e..000000000000 --- a/flang/lib/Optimizer/Builder/Runtime/Coarray.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===-- Coarray.cpp -- runtime API for coarray intrinsics -----------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "flang/Optimizer/Builder/Runtime/Coarray.h" -#include "flang/Optimizer/Builder/FIRBuilder.h" -#include "flang/Optimizer/Builder/Runtime/RTBuilder.h" -#include "mlir/Dialect/Func/IR/FuncOps.h" - -using namespace Fortran::runtime; -using namespace Fortran::semantics; - -// Most PRIF functions take `errmsg` and `errmsg_alloc` as two optional -// arguments of intent (out). One is allocatable, the other is not. -// It is the responsibility of the compiler to ensure that the appropriate -// optional argument is passed, and at most one must be provided in a given -// call. -// Depending on the type of `errmsg`, this function will return the pair -// corresponding to (`errmsg`, `errmsg_alloc`). -static std::pair -genErrmsgPRIF(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value errmsg) { - bool isAllocatableErrmsg = fir::isAllocatableType(errmsg.getType()); - - mlir::Value absent = fir::AbsentOp::create(builder, loc, PRIF_ERRMSG_TYPE); - mlir::Value errMsg = isAllocatableErrmsg ? absent : errmsg; - mlir::Value errMsgAlloc = isAllocatableErrmsg ? errmsg : absent; - return {errMsg, errMsgAlloc}; -} - -/// Generate Call to runtime prif_init -mlir::Value fir::runtime::genInitCoarray(fir::FirOpBuilder &builder, - mlir::Location loc) { - mlir::Type i32Ty = builder.getI32Type(); - mlir::Value result = builder.createTemporary(loc, i32Ty); - mlir::FunctionType ftype = PRIF_FUNCTYPE(builder.getRefType(i32Ty)); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("init"), ftype); - llvm::SmallVector args = - fir::runtime::createArguments(builder, loc, ftype, result); - fir::CallOp::create(builder, loc, funcOp, args); - return fir::LoadOp::create(builder, loc, result); -} - -/// Generate Call to runtime prif_num_images -mlir::Value fir::runtime::getNumImages(fir::FirOpBuilder &builder, - mlir::Location loc) { - mlir::Value result = builder.createTemporary(loc, builder.getI32Type()); - mlir::FunctionType ftype = - PRIF_FUNCTYPE(builder.getRefType(builder.getI32Type())); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("num_images"), ftype); - llvm::SmallVector args = - fir::runtime::createArguments(builder, loc, ftype, result); - fir::CallOp::create(builder, loc, funcOp, args); - return fir::LoadOp::create(builder, loc, result); -} - -/// Generate Call to runtime prif_num_images_with_{team|team_number} -mlir::Value fir::runtime::getNumImagesWithTeam(fir::FirOpBuilder &builder, - mlir::Location loc, - mlir::Value team) { - bool isTeamNumber = fir::unwrapPassByRefType(team.getType()).isInteger(); - std::string numImagesName = isTeamNumber - ? PRIFNAME_SUB("num_images_with_team_number") - : PRIFNAME_SUB("num_images_with_team"); - - mlir::Value result = builder.createTemporary(loc, builder.getI32Type()); - mlir::Type refTy = builder.getRefType(builder.getI32Type()); - mlir::FunctionType ftype = - isTeamNumber - ? PRIF_FUNCTYPE(builder.getRefType(builder.getI64Type()), refTy) - : PRIF_FUNCTYPE(fir::BoxType::get(builder.getNoneType()), refTy); - mlir::func::FuncOp funcOp = builder.createFunction(loc, numImagesName, ftype); - - if (!isTeamNumber) - team = builder.createBox(loc, team); - llvm::SmallVector args = - fir::runtime::createArguments(builder, loc, ftype, team, result); - fir::CallOp::create(builder, loc, funcOp, args); - return fir::LoadOp::create(builder, loc, result); -} - -/// Generate Call to runtime prif_this_image_no_coarray -mlir::Value fir::runtime::getThisImage(fir::FirOpBuilder &builder, - mlir::Location loc, mlir::Value team) { - mlir::Type refTy = builder.getRefType(builder.getI32Type()); - mlir::Type boxTy = fir::BoxType::get(builder.getNoneType()); - mlir::FunctionType ftype = PRIF_FUNCTYPE(boxTy, refTy); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("this_image_no_coarray"), ftype); - - mlir::Value result = builder.createTemporary(loc, builder.getI32Type()); - mlir::Value teamArg = - !team ? fir::AbsentOp::create(builder, loc, boxTy) : team; - llvm::SmallVector args = - fir::runtime::createArguments(builder, loc, ftype, teamArg, result); - fir::CallOp::create(builder, loc, funcOp, args); - return fir::LoadOp::create(builder, loc, result); -} - -/// Generate call to collective subroutines except co_reduce -/// A must be lowered as a box -void genCollectiveSubroutine(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value A, mlir::Value rootImage, - mlir::Value stat, mlir::Value errmsg, - std::string coName) { - mlir::Type boxTy = fir::BoxType::get(builder.getNoneType()); - mlir::FunctionType ftype = - PRIF_FUNCTYPE(boxTy, builder.getRefType(builder.getI32Type()), - PRIF_STAT_TYPE, PRIF_ERRMSG_TYPE, PRIF_ERRMSG_TYPE); - mlir::func::FuncOp funcOp = builder.createFunction(loc, coName, ftype); - - auto [errmsgArg, errmsgAllocArg] = genErrmsgPRIF(builder, loc, errmsg); - llvm::SmallVector args = fir::runtime::createArguments( - builder, loc, ftype, A, rootImage, stat, errmsgArg, errmsgAllocArg); - fir::CallOp::create(builder, loc, funcOp, args); -} - -/// Generate call to runtime subroutine prif_co_broadcast -void fir::runtime::genCoBroadcast(fir::FirOpBuilder &builder, - mlir::Location loc, mlir::Value A, - mlir::Value sourceImage, mlir::Value stat, - mlir::Value errmsg) { - genCollectiveSubroutine(builder, loc, A, sourceImage, stat, errmsg, - PRIFNAME_SUB("co_broadcast")); -} - -/// Generate call to runtime subroutine prif_co_max or prif_co_max_character -void fir::runtime::genCoMax(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value A, mlir::Value resultImage, - mlir::Value stat, mlir::Value errmsg) { - mlir::Type argTy = - fir::unwrapSequenceType(fir::unwrapPassByRefType(A.getType())); - if (mlir::isa(argTy)) - genCollectiveSubroutine(builder, loc, A, resultImage, stat, errmsg, - PRIFNAME_SUB("co_max_character")); - else - genCollectiveSubroutine(builder, loc, A, resultImage, stat, errmsg, - PRIFNAME_SUB("co_max")); -} - -/// Generate call to runtime subroutine prif_co_min or prif_co_min_character -void fir::runtime::genCoMin(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value A, mlir::Value resultImage, - mlir::Value stat, mlir::Value errmsg) { - mlir::Type argTy = - fir::unwrapSequenceType(fir::unwrapPassByRefType(A.getType())); - if (mlir::isa(argTy)) - genCollectiveSubroutine(builder, loc, A, resultImage, stat, errmsg, - PRIFNAME_SUB("co_min_character")); - else - genCollectiveSubroutine(builder, loc, A, resultImage, stat, errmsg, - PRIFNAME_SUB("co_min")); -} - -/// Generate call to runtime subroutine prif_co_sum -void fir::runtime::genCoSum(fir::FirOpBuilder &builder, mlir::Location loc, - mlir::Value A, mlir::Value resultImage, - mlir::Value stat, mlir::Value errmsg) { - genCollectiveSubroutine(builder, loc, A, resultImage, stat, errmsg, - PRIFNAME_SUB("co_sum")); -} - -/// Generate call to runtime subroutine prif_sync_all -void fir::runtime::genSyncAllStatement(fir::FirOpBuilder &builder, - mlir::Location loc, mlir::Value stat, - mlir::Value errmsg) { - mlir::FunctionType ftype = - PRIF_FUNCTYPE(PRIF_STAT_TYPE, PRIF_ERRMSG_TYPE, PRIF_ERRMSG_TYPE); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("sync_all"), ftype); - - auto [errmsgArg, errmsgAllocArg] = genErrmsgPRIF(builder, loc, errmsg); - llvm::SmallVector args = fir::runtime::createArguments( - builder, loc, ftype, stat, errmsgArg, errmsgAllocArg); - fir::CallOp::create(builder, loc, funcOp, args); -} - -/// Generate call to runtime subroutine prif_sync_memory -void fir::runtime::genSyncMemoryStatement(fir::FirOpBuilder &builder, - mlir::Location loc, mlir::Value stat, - mlir::Value errmsg) { - mlir::FunctionType ftype = - PRIF_FUNCTYPE(PRIF_STAT_TYPE, PRIF_ERRMSG_TYPE, PRIF_ERRMSG_TYPE); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("sync_memory"), ftype); - - auto [errmsgArg, errmsgAllocArg] = genErrmsgPRIF(builder, loc, errmsg); - llvm::SmallVector args = fir::runtime::createArguments( - builder, loc, ftype, stat, errmsgArg, errmsgAllocArg); - fir::CallOp::create(builder, loc, funcOp, args); -} - -/// Generate call to runtime subroutine prif_sync_images -void fir::runtime::genSyncImagesStatement(fir::FirOpBuilder &builder, - mlir::Location loc, - mlir::Value imageSet, - mlir::Value stat, - mlir::Value errmsg) { - mlir::Type imgSetTy = fir::BoxType::get(fir::SequenceType::get( - {fir::SequenceType::getUnknownExtent()}, builder.getI32Type())); - mlir::FunctionType ftype = PRIF_FUNCTYPE(imgSetTy, PRIF_STAT_TYPE, - PRIF_ERRMSG_TYPE, PRIF_ERRMSG_TYPE); - mlir::func::FuncOp funcOp = - builder.createFunction(loc, PRIFNAME_SUB("sync_images"), ftype); - - // If imageSet is scalar, PRIF require to pass an array of size 1. - if (auto boxTy = mlir::dyn_cast(imageSet.getType())) { - if (!mlir::isa(boxTy.getEleTy())) { - mlir::Value one = - builder.createIntegerConstant(loc, builder.getI32Type(), 1); - mlir::Value shape = fir::ShapeOp::create(builder, loc, one); - imageSet = fir::ReboxOp::create( - builder, loc, - fir::BoxType::get(fir::SequenceType::get({1}, builder.getI32Type())), - imageSet, shape, mlir::Value{}); - } - } - auto [errmsgArg, errmsgAllocArg] = genErrmsgPRIF(builder, loc, errmsg); - llvm::SmallVector args = fir::runtime::createArguments( - builder, loc, ftype, imageSet, stat, errmsgArg, errmsgAllocArg); - fir::CallOp::create(builder, loc, funcOp, args); -} diff --git a/flang/lib/Optimizer/Builder/Runtime/Main.cpp b/flang/lib/Optimizer/Builder/Runtime/Main.cpp index d303e0ad6384..9ce5e172f3cd 100644 --- a/flang/lib/Optimizer/Builder/Runtime/Main.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/Main.cpp @@ -10,11 +10,11 @@ #include "flang/Lower/EnvironmentDefault.h" #include "flang/Optimizer/Builder/BoxValue.h" #include "flang/Optimizer/Builder/FIRBuilder.h" -#include "flang/Optimizer/Builder/Runtime/Coarray.h" #include "flang/Optimizer/Builder/Runtime/EnvironmentDefaults.h" #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" #include "flang/Optimizer/Dialect/FIROps.h" #include "flang/Optimizer/Dialect/FIRType.h" +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" #include "flang/Runtime/CUDA/init.h" #include "flang/Runtime/main.h" #include "flang/Runtime/stop.h" @@ -71,7 +71,7 @@ void fir::runtime::genMain( fir::CallOp::create(builder, loc, initFn); } if (initCoarrayEnv) - fir::runtime::genInitCoarray(builder, loc); + mif::InitOp::create(builder, loc); fir::CallOp::create(builder, loc, qqMainFn); fir::CallOp::create(builder, loc, stopFn); diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt index 4fd4d285341e..65d1f2c02754 100644 --- a/flang/lib/Optimizer/Dialect/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(Support) add_subdirectory(CUF) add_subdirectory(FIRCG) +add_subdirectory(MIF) add_flang_library(FIRDialect FIRAttr.cpp diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index 48e162253e0a..fe35b085405b 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -1427,6 +1427,13 @@ mlir::Type BaseBoxType::unwrapInnerType() const { return fir::unwrapInnerType(getEleTy()); } +mlir::Type BaseBoxType::getElementOrSequenceType() const { + mlir::Type eleTy = getEleTy(); + if (auto seqTy = mlir::dyn_cast(eleTy)) + return seqTy; + return fir::unwrapRefType(eleTy); +} + static mlir::Type changeTypeShape(mlir::Type type, std::optional newShape) { diff --git a/flang/lib/Optimizer/Dialect/MIF/CMakeLists.txt b/flang/lib/Optimizer/Dialect/MIF/CMakeLists.txt new file mode 100644 index 000000000000..d52ab097ddbf --- /dev/null +++ b/flang/lib/Optimizer/Dialect/MIF/CMakeLists.txt @@ -0,0 +1,20 @@ +add_flang_library(MIFDialect + MIFDialect.cpp + MIFOps.cpp + + DEPENDS + MLIRIR + MIFOpsIncGen + + LINK_LIBS + FIRDialect + FIRDialectSupport + FIRSupport + MLIRIR + MLIRTargetLLVMIRExport + + LINK_COMPONENTS + AsmParser + AsmPrinter + Remarks +) diff --git a/flang/lib/Optimizer/Dialect/MIF/MIFDialect.cpp b/flang/lib/Optimizer/Dialect/MIF/MIFDialect.cpp new file mode 100644 index 000000000000..edc723d319aa --- /dev/null +++ b/flang/lib/Optimizer/Dialect/MIF/MIFDialect.cpp @@ -0,0 +1,24 @@ +//===- MIFDialect.cpp - MIF dialect implementation ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// C +//===----------------------------------------------------------------------===// + +#include "flang/Optimizer/Dialect/MIF/MIFDialect.h" +#include "flang/Optimizer/Dialect/FIRDialect.h" +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" + +//===----------------------------------------------------------------------===// +/// Tablegen Definitions +//===----------------------------------------------------------------------===// + +#include "flang/Optimizer/Dialect/MIF/MIFDialect.cpp.inc" + +void mif::MIFDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "flang/Optimizer/Dialect/MIF/MIFOps.cpp.inc" + >(); +} diff --git a/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp b/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp new file mode 100644 index 000000000000..c6cc2e855ff3 --- /dev/null +++ b/flang/lib/Optimizer/Dialect/MIF/MIFOps.cpp @@ -0,0 +1,153 @@ +//===-- MIFOps.cpp - MIF dialect ops implementation -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" +#include "flang/Optimizer/Builder/Todo.h" +#include "flang/Optimizer/Dialect/FIRAttr.h" +#include "flang/Optimizer/Dialect/FIRType.h" +#include "flang/Optimizer/Dialect/MIF/MIFDialect.h" +#include "mlir/IR/Matchers.h" +#include "mlir/IR/PatternMatch.h" +#include "llvm/ADT/SmallVector.h" + +#define GET_OP_CLASSES +#include "flang/Optimizer/Dialect/MIF/MIFOps.cpp.inc" + +//===----------------------------------------------------------------------===// +// NumImagesOp +//===----------------------------------------------------------------------===// + +void mif::NumImagesOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, + mlir::Value teamArg) { + bool isTeamNumber = + teamArg && fir::unwrapPassByRefType(teamArg.getType()).isInteger(); + if (isTeamNumber) + build(builder, result, teamArg, /*team*/ mlir::Value{}); + else + build(builder, result, /*team_number*/ mlir::Value{}, teamArg); +} + +llvm::LogicalResult mif::NumImagesOp::verify() { + if (getTeam() && getTeamNumber()) + return emitOpError( + "team and team_number must not be provided at the same time"); + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// ThisImageOp +//===----------------------------------------------------------------------===// + +void mif::ThisImageOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, mlir::Value coarray, + mlir::Value team) { + build(builder, result, coarray, /*dim*/ mlir::Value{}, team); +} + +void mif::ThisImageOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, mlir::Value team) { + build(builder, result, /*coarray*/ mlir::Value{}, /*dim*/ mlir::Value{}, + team); +} + +llvm::LogicalResult mif::ThisImageOp::verify() { + if (getDim() && !getCoarray()) + return emitOpError( + "`dim` must be provied at the same time as the `coarray` argument."); + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// SyncImagesOp +//===----------------------------------------------------------------------===// + +llvm::LogicalResult mif::SyncImagesOp::verify() { + if (getImageSet()) { + mlir::Type t = getImageSet().getType(); + fir::BoxType boxTy = mlir::dyn_cast(t); + if (auto seqTy = mlir::dyn_cast( + boxTy.getElementOrSequenceType())) { + if (seqTy.getDimension() != 0 && seqTy.getDimension() != 1) + return emitOpError( + "`image_set` must be a boxed integer expression of rank 1."); + if (!fir::isa_integer(seqTy.getElementType())) + return emitOpError("`image_set` must be a boxed array of integer."); + } else if (!fir::isa_integer(boxTy.getElementType())) + return emitOpError( + "`image_set` must be a boxed scalar integer expression."); + } + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// CoBroadcastOp +//===----------------------------------------------------------------------===// + +llvm::LogicalResult mif::CoBroadcastOp::verify() { + fir::BoxType boxTy = mlir::dyn_cast(getA().getType()); + + if (fir::isPolymorphicType(boxTy)) + return emitOpError("`A` cannot be polymorphic."); + else if (auto recTy = + mlir::dyn_cast(boxTy.getElementType())) { + for (auto component : recTy.getTypeList()) { + if (fir::isPolymorphicType(component.second)) + TODO(getLoc(), "`A` with polymorphic subobject component."); + } + } + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// CoMaxOp +//===----------------------------------------------------------------------===// + +llvm::LogicalResult mif::CoMaxOp::verify() { + fir::BoxType boxTy = mlir::dyn_cast(getA().getType()); + mlir::Type elemTy = boxTy.getElementOrSequenceType(); + if (auto seqTy = mlir::dyn_cast(elemTy)) + elemTy = seqTy.getElementType(); + + if (!fir::isa_real(elemTy) && !fir::isa_integer(elemTy) && + !fir::isa_char(elemTy)) + return emitOpError("`A` shall be of type integer, real or character."); + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// CoMinOp +//===----------------------------------------------------------------------===// + +llvm::LogicalResult mif::CoMinOp::verify() { + fir::BoxType boxTy = mlir::dyn_cast(getA().getType()); + mlir::Type elemTy = boxTy.getElementOrSequenceType(); + if (auto seqTy = mlir::dyn_cast(elemTy)) + elemTy = seqTy.getElementType(); + + if (!fir::isa_real(elemTy) && !fir::isa_integer(elemTy) && + !fir::isa_char(elemTy)) + return emitOpError("`A` shall be of type integer, real or character."); + return mlir::success(); +} + +//===----------------------------------------------------------------------===// +// CoSumOp +//===----------------------------------------------------------------------===// + +llvm::LogicalResult mif::CoSumOp::verify() { + fir::BoxType boxTy = mlir::dyn_cast(getA().getType()); + mlir::Type elemTy = boxTy.getElementOrSequenceType(); + if (auto seqTy = mlir::dyn_cast(elemTy)) + elemTy = seqTy.getElementType(); + + if (!fir::isa_real(elemTy) && !fir::isa_integer(elemTy) && + !fir::isa_complex(elemTy)) + return emitOpError("`A` shall be of numeric type."); + return mlir::success(); +} diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index 1ecb6d383f93..6dae39b26976 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -354,6 +354,7 @@ void createDebugPasses(mlir::PassManager &pm, void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm, MLIRToLLVMPassPipelineConfig config, llvm::StringRef inputFilename) { + pm.addPass(fir::createMIFOpConversion()); fir::addBoxedProcedurePass(pm); if (config.OptLevel.isOptimizingForSpeed() && config.AliasAnalysis && !disableFirAliasTags && !useOldAliasTags) diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt index 4ec16274830f..0388439f89a5 100644 --- a/flang/lib/Optimizer/Transforms/CMakeLists.txt +++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt @@ -36,6 +36,7 @@ add_flang_library(FIRTransforms SimplifyFIROperations.cpp OptimizeArrayRepacking.cpp ConvertComplexPow.cpp + MIFOpConversion.cpp DEPENDS CUFAttrs @@ -43,6 +44,7 @@ add_flang_library(FIRTransforms FIRDialect FIROptTransformsPassIncGen HLFIROpsIncGen + MIFDialect LINK_LIBS CUFAttrs @@ -56,6 +58,7 @@ add_flang_library(FIRTransforms FIRSupport FortranSupport HLFIRDialect + MIFDialect MLIR_LIBS MLIRAffineUtils diff --git a/flang/lib/Optimizer/Transforms/MIFOpConversion.cpp b/flang/lib/Optimizer/Transforms/MIFOpConversion.cpp new file mode 100644 index 000000000000..206cb9be0574 --- /dev/null +++ b/flang/lib/Optimizer/Transforms/MIFOpConversion.cpp @@ -0,0 +1,464 @@ +//===-- MIFOpConversion.cpp -----------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "flang/Optimizer/Transforms/MIFOpConversion.h" +#include "flang/Optimizer/Builder/Runtime/RTBuilder.h" +#include "flang/Optimizer/Builder/Todo.h" +#include "flang/Optimizer/CodeGen/TypeConverter.h" +#include "flang/Optimizer/Dialect/FIRDialect.h" +#include "flang/Optimizer/Dialect/FIROps.h" +#include "flang/Optimizer/Dialect/MIF/MIFOps.h" +#include "flang/Optimizer/HLFIR/HLFIROps.h" +#include "flang/Optimizer/Support/DataLayout.h" +#include "flang/Optimizer/Support/InternalNames.h" +#include "mlir/IR/Matchers.h" +#include "mlir/Transforms/DialectConversion.h" +#include "mlir/Transforms/GreedyPatternRewriteDriver.h" + +namespace fir { +#define GEN_PASS_DEF_MIFOPCONVERSION +#include "flang/Optimizer/Transforms/Passes.h.inc" +} // namespace fir + +using namespace mlir; +using namespace Fortran::runtime; + +namespace { + +// Default prefix for subroutines of PRIF compiled with LLVM +static std::string getPRIFProcName(std::string fmt) { + std::ostringstream oss; + oss << "prif_" << fmt; + return fir::NameUniquer::doProcedure({"prif"}, {}, oss.str()); +} + +static mlir::Type getPRIFStatType(fir::FirOpBuilder &builder) { + return builder.getRefType(builder.getI32Type()); +} + +static mlir::Type getPRIFErrmsgType(fir::FirOpBuilder &builder) { + return fir::BoxType::get(fir::CharacterType::get( + builder.getContext(), 1, fir::CharacterType::unknownLen())); +} + +// Most PRIF functions take `errmsg` and `errmsg_alloc` as two optional +// arguments of intent (out). One is allocatable, the other is not. +// It is the responsibility of the compiler to ensure that the appropriate +// optional argument is passed, and at most one must be provided in a given +// call. +// Depending on the type of `errmsg`, this function will return the pair +// corresponding to (`errmsg`, `errmsg_alloc`). +static std::pair +genErrmsgPRIF(fir::FirOpBuilder &builder, mlir::Location loc, + mlir::Value errmsg) { + mlir::Value absent = + fir::AbsentOp::create(builder, loc, getPRIFErrmsgType(builder)); + if (!errmsg) + return {absent, absent}; + + bool isAllocatableErrmsg = fir::isAllocatableType(errmsg.getType()); + mlir::Value errMsg = isAllocatableErrmsg ? absent : errmsg; + mlir::Value errMsgAlloc = isAllocatableErrmsg ? errmsg : absent; + return {errMsg, errMsgAlloc}; +} + +/// Convert mif.init operation to runtime call of 'prif_init' +struct MIFInitOpConversion : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::InitOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + mlir::Type i32Ty = builder.getI32Type(); + mlir::Value result = builder.createTemporary(loc, i32Ty); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {builder.getRefType(i32Ty)}, /*results*/ {}); + mlir::func::FuncOp funcOp = + builder.createFunction(loc, getPRIFProcName("init"), ftype); + llvm::SmallVector args = + fir::runtime::createArguments(builder, loc, ftype, result); + fir::CallOp::create(builder, loc, funcOp, args); + rewriter.replaceOpWithNewOp(op, result); + return mlir::success(); + } +}; + +/// Convert mif.this_image operation to PRIF runtime call +struct MIFThisImageOpConversion + : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::ThisImageOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + if (op.getCoarray()) + TODO(loc, "mif.this_image op with coarray argument."); + else { + mlir::Type i32Ty = builder.getI32Type(); + mlir::Type boxTy = fir::BoxType::get(rewriter.getNoneType()); + mlir::Value result = builder.createTemporary(loc, i32Ty); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {boxTy, builder.getRefType(i32Ty)}, /*results*/ {}); + mlir::Value teamArg = op.getTeam(); + if (!op.getTeam()) + teamArg = fir::AbsentOp::create(builder, loc, boxTy); + + mlir::func::FuncOp funcOp = builder.createFunction( + loc, getPRIFProcName("this_image_no_coarray"), ftype); + llvm::SmallVector args = + fir::runtime::createArguments(builder, loc, ftype, teamArg, result); + fir::CallOp::create(builder, loc, funcOp, args); + rewriter.replaceOpWithNewOp(op, result); + return mlir::success(); + } + } +}; + +/// Convert mif.num_images operation to runtime call of +/// prif_num_images_with_{team|team_number} +struct MIFNumImagesOpConversion + : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::NumImagesOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + mlir::Type i32Ty = builder.getI32Type(); + mlir::Type i64Ty = builder.getI64Type(); + mlir::Type boxTy = fir::BoxType::get(rewriter.getNoneType()); + mlir::Value result = builder.createTemporary(loc, i32Ty); + + mlir::func::FuncOp funcOp; + llvm::SmallVector args; + if (!op.getTeam() && !op.getTeamNumber()) { + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {builder.getRefType(i32Ty)}, /*results*/ {}); + funcOp = + builder.createFunction(loc, getPRIFProcName("num_images"), ftype); + args = fir::runtime::createArguments(builder, loc, ftype, result); + } else { + if (op.getTeam()) { + mlir::FunctionType ftype = + mlir::FunctionType::get(builder.getContext(), + /*inputs*/ + {boxTy, builder.getRefType(i32Ty)}, + /*results*/ {}); + funcOp = builder.createFunction( + loc, getPRIFProcName("num_images_with_team"), ftype); + args = fir::runtime::createArguments(builder, loc, ftype, op.getTeam(), + result); + } else { + mlir::Value teamNumber = builder.createTemporary(loc, i64Ty); + mlir::Value cst = op.getTeamNumber(); + if (op.getTeamNumber().getType() != i64Ty) + cst = fir::ConvertOp::create(builder, loc, i64Ty, op.getTeamNumber()); + fir::StoreOp::create(builder, loc, cst, teamNumber); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {builder.getRefType(i64Ty), builder.getRefType(i32Ty)}, + /*results*/ {}); + funcOp = builder.createFunction( + loc, getPRIFProcName("num_images_with_team_number"), ftype); + args = fir::runtime::createArguments(builder, loc, ftype, teamNumber, + result); + } + } + fir::CallOp::create(builder, loc, funcOp, args); + rewriter.replaceOpWithNewOp(op, result); + return mlir::success(); + } +}; + +/// Convert mif.sync_all operation to runtime call of 'prif_sync_all' +struct MIFSyncAllOpConversion : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::SyncAllOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + mlir::Type errmsgTy = getPRIFErrmsgType(builder); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {getPRIFStatType(builder), errmsgTy, errmsgTy}, + /*results*/ {}); + mlir::func::FuncOp funcOp = + builder.createFunction(loc, getPRIFProcName("sync_all"), ftype); + + auto [errmsgArg, errmsgAllocArg] = + genErrmsgPRIF(builder, loc, op.getErrmsg()); + mlir::Value stat = op.getStat(); + if (!stat) + stat = fir::AbsentOp::create(builder, loc, getPRIFStatType(builder)); + llvm::SmallVector args = fir::runtime::createArguments( + builder, loc, ftype, stat, errmsgArg, errmsgAllocArg); + rewriter.replaceOpWithNewOp(op, funcOp, args); + return mlir::success(); + } +}; + +/// Convert mif.sync_images operation to runtime call of 'prif_sync_images' +struct MIFSyncImagesOpConversion + : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::SyncImagesOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + mlir::Type errmsgTy = getPRIFErrmsgType(builder); + mlir::Type imgSetTy = fir::BoxType::get(fir::SequenceType::get( + {fir::SequenceType::getUnknownExtent()}, builder.getI32Type())); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ + {imgSetTy, getPRIFStatType(builder), errmsgTy, errmsgTy}, + /*results*/ {}); + mlir::func::FuncOp funcOp = + builder.createFunction(loc, getPRIFProcName("sync_images"), ftype); + + // If imageSet is scalar, PRIF require to pass an array of size 1. + mlir::Value imageSet = op.getImageSet(); + if (!imageSet) + imageSet = fir::AbsentOp::create(builder, loc, imgSetTy); + else if (auto boxTy = mlir::dyn_cast(imageSet.getType())) { + if (!mlir::isa(boxTy.getEleTy())) { + mlir::Value one = + builder.createIntegerConstant(loc, builder.getI32Type(), 1); + mlir::Value shape = fir::ShapeOp::create(builder, loc, one); + imageSet = + fir::ReboxOp::create(builder, loc, + fir::BoxType::get(fir::SequenceType::get( + {1}, builder.getI32Type())), + imageSet, shape, mlir::Value{}); + } + } + auto [errmsgArg, errmsgAllocArg] = + genErrmsgPRIF(builder, loc, op.getErrmsg()); + mlir::Value stat = op.getStat(); + if (!stat) + stat = fir::AbsentOp::create(builder, loc, getPRIFStatType(builder)); + llvm::SmallVector args = fir::runtime::createArguments( + builder, loc, ftype, imageSet, stat, errmsgArg, errmsgAllocArg); + rewriter.replaceOpWithNewOp(op, funcOp, args); + return mlir::success(); + } +}; + +/// Convert mif.sync_memory operation to runtime call of 'prif_sync_memory' +struct MIFSyncMemoryOpConversion + : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::SyncMemoryOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + mlir::Type errmsgTy = getPRIFErrmsgType(builder); + mlir::FunctionType ftype = mlir::FunctionType::get( + builder.getContext(), + /*inputs*/ {getPRIFStatType(builder), errmsgTy, errmsgTy}, + /*results*/ {}); + mlir::func::FuncOp funcOp = + builder.createFunction(loc, getPRIFProcName("sync_memory"), ftype); + + auto [errmsgArg, errmsgAllocArg] = + genErrmsgPRIF(builder, loc, op.getErrmsg()); + mlir::Value stat = op.getStat(); + if (!stat) + stat = fir::AbsentOp::create(builder, loc, getPRIFStatType(builder)); + llvm::SmallVector args = fir::runtime::createArguments( + builder, loc, ftype, stat, errmsgArg, errmsgAllocArg); + rewriter.replaceOpWithNewOp(op, funcOp, args); + return mlir::success(); + } +}; + +/// Generate call to collective subroutines except co_reduce +/// A must be lowered as a box +static fir::CallOp genCollectiveSubroutine(fir::FirOpBuilder &builder, + mlir::Location loc, mlir::Value A, + mlir::Value image, mlir::Value stat, + mlir::Value errmsg, + std::string coName) { + mlir::Value rootImage; + mlir::Type i32Ty = builder.getI32Type(); + if (!image) + rootImage = fir::AbsentOp::create(builder, loc, builder.getRefType(i32Ty)); + else { + rootImage = builder.createTemporary(loc, i32Ty); + if (image.getType() != i32Ty) + image = fir::ConvertOp::create(builder, loc, i32Ty, image); + fir::StoreOp::create(builder, loc, image, rootImage); + } + + mlir::Type errmsgTy = getPRIFErrmsgType(builder); + mlir::Type boxTy = fir::BoxType::get(builder.getNoneType()); + mlir::FunctionType ftype = + mlir::FunctionType::get(builder.getContext(), + /*inputs*/ + {boxTy, builder.getRefType(builder.getI32Type()), + getPRIFStatType(builder), errmsgTy, errmsgTy}, + /*results*/ {}); + mlir::func::FuncOp funcOp = builder.createFunction(loc, coName, ftype); + + auto [errmsgArg, errmsgAllocArg] = genErrmsgPRIF(builder, loc, errmsg); + if (!stat) + stat = fir::AbsentOp::create(builder, loc, getPRIFStatType(builder)); + llvm::SmallVector args = fir::runtime::createArguments( + builder, loc, ftype, A, rootImage, stat, errmsgArg, errmsgAllocArg); + return fir::CallOp::create(builder, loc, funcOp, args); +} + +/// Convert mif.co_broadcast operation to runtime call of 'prif_co_broadcast' +struct MIFCoBroadcastOpConversion + : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::CoBroadcastOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + fir::CallOp callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getSourceImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_broadcast")); + rewriter.replaceOp(op, callOp); + return mlir::success(); + } +}; + +/// Convert mif.co_max operation to runtime call of 'prif_co_max' +struct MIFCoMaxOpConversion : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::CoMaxOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + fir::CallOp callOp; + mlir::Type argTy = + fir::unwrapSequenceType(fir::unwrapPassByRefType(op.getA().getType())); + if (mlir::isa(argTy)) + callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getResultImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_max_character")); + else + callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getResultImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_max")); + rewriter.replaceOp(op, callOp); + return mlir::success(); + } +}; + +/// Convert mif.co_min operation to runtime call of 'prif_co_min' +struct MIFCoMinOpConversion : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::CoMinOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + fir::CallOp callOp; + mlir::Type argTy = + fir::unwrapSequenceType(fir::unwrapPassByRefType(op.getA().getType())); + if (mlir::isa(argTy)) + callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getResultImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_min_character")); + else + callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getResultImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_min")); + rewriter.replaceOp(op, callOp); + return mlir::success(); + } +}; + +/// Convert mif.co_sum operation to runtime call of 'prif_co_sum' +struct MIFCoSumOpConversion : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(mif::CoSumOp op, + mlir::PatternRewriter &rewriter) const override { + auto mod = op->template getParentOfType(); + fir::FirOpBuilder builder(rewriter, mod); + mlir::Location loc = op.getLoc(); + + fir::CallOp callOp = genCollectiveSubroutine( + builder, loc, op.getA(), op.getResultImage(), op.getStat(), + op.getErrmsg(), getPRIFProcName("co_sum")); + rewriter.replaceOp(op, callOp); + return mlir::success(); + } +}; + +class MIFOpConversion : public fir::impl::MIFOpConversionBase { +public: + void runOnOperation() override { + auto *ctx = &getContext(); + mlir::RewritePatternSet patterns(ctx); + mlir::ConversionTarget target(*ctx); + + mif::populateMIFOpConversionPatterns(patterns); + + target.addLegalDialect(); + target.addLegalOp(); + + if (mlir::failed(mlir::applyPartialConversion(getOperation(), target, + std::move(patterns)))) { + mlir::emitError(mlir::UnknownLoc::get(ctx), + "error in MIF op conversion\n"); + return signalPassFailure(); + } + } +}; +} // namespace + +void mif::populateMIFOpConversionPatterns(mlir::RewritePatternSet &patterns) { + patterns.insert( + patterns.getContext()); +} diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90 index 5943a3c61c34..eb5165e36c91 100644 --- a/flang/test/Driver/mlir-debug-pass-pipeline.f90 +++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90 @@ -100,6 +100,7 @@ end program ! ALL-NEXT: CSE ! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd ! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd +! ALL-NEXT: MIFOpConversion ! ALL-NEXT: BoxedProcedurePass ! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_reduction', 'omp.private'] diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90 index df558392c5fc..3b6a9d7cda7e 100644 --- a/flang/test/Driver/mlir-pass-pipeline.f90 +++ b/flang/test/Driver/mlir-pass-pipeline.f90 @@ -142,6 +142,7 @@ end program ! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd ! O2-NEXT: 'func.func' Pipeline ! O2-NEXT: SetRuntimeCallAttributes +! ALL-NEXT: MIFOpConversion ! ALL-NEXT: BoxedProcedurePass ! O2-NEXT: AddAliasTags diff --git a/flang/test/Fir/MIF/co_broadcast.mlir b/flang/test/Fir/MIF/co_broadcast.mlir new file mode 100644 index 000000000000..2f5782b2a825 --- /dev/null +++ b/flang/test/Fir/MIF/co_broadcast.mlir @@ -0,0 +1,137 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_CO_BROADCAST"} { + %0 = fir.dummy_scope : !fir.dscope + %c2 = arith.constant 2 : index + %1 = fir.alloca !fir.array<2xcomplex> {bindc_name = "array_c", uniq_name = "_QFEarray_c"} + %2 = fir.shape %c2 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFEarray_c"} : (!fir.ref>>, !fir.shape<1>) -> (!fir.ref>>, !fir.ref>>) + %c2_0 = arith.constant 2 : index + %4 = fir.alloca !fir.array<2xf64> {bindc_name = "array_d", uniq_name = "_QFEarray_d"} + %5 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %6:2 = hlfir.declare %4(%5) {uniq_name = "_QFEarray_d"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_1 = arith.constant 2 : index + %7 = fir.alloca !fir.array<2xi32> {bindc_name = "array_i", uniq_name = "_QFEarray_i"} + %8 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %9:2 = hlfir.declare %7(%8) {uniq_name = "_QFEarray_i"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_2 = arith.constant 2 : index + %10 = fir.alloca !fir.array<2xf32> {bindc_name = "array_r", uniq_name = "_QFEarray_r"} + %11 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %12:2 = hlfir.declare %10(%11) {uniq_name = "_QFEarray_r"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %13 = fir.alloca complex {bindc_name = "c", uniq_name = "_QFEc"} + %14:2 = hlfir.declare %13 {uniq_name = "_QFEc"} : (!fir.ref>) -> (!fir.ref>, !fir.ref>) + %15 = fir.alloca f64 {bindc_name = "d", uniq_name = "_QFEd"} + %16:2 = hlfir.declare %15 {uniq_name = "_QFEd"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %17 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %18:2 = hlfir.declare %17 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %c1 = arith.constant 1 : index + %19 = fir.alloca !fir.char<1> {bindc_name = "message", uniq_name = "_QFEmessage"} + %20:2 = hlfir.declare %19 typeparams %c1 {uniq_name = "_QFEmessage"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %21 = fir.alloca f32 {bindc_name = "r", uniq_name = "_QFEr"} + %22:2 = hlfir.declare %21 {uniq_name = "_QFEr"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %23 = fir.alloca i32 {bindc_name = "status", uniq_name = "_QFEstatus"} + %24:2 = hlfir.declare %23 {uniq_name = "_QFEstatus"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %c1_i32 = arith.constant 1 : i32 + %25 = fir.embox %18#0 : (!fir.ref) -> !fir.box + mif.co_broadcast %25 source %c1_i32 : (!fir.box, i32) + %c1_i32_3 = arith.constant 1 : i32 + %26 = fir.embox %14#0 : (!fir.ref>) -> !fir.box> + mif.co_broadcast %26 source %c1_i32_3 stat %24#0 : (!fir.box>, i32, !fir.ref) + %c1_i32_4 = arith.constant 1 : i32 + %27 = fir.embox %16#0 : (!fir.ref) -> !fir.box + %28 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_broadcast %27 source %c1_i32_4 stat %24#0 errmsg %28 : (!fir.box, i32, !fir.ref, !fir.box>) + %c1_i32_5 = arith.constant 1 : i32 + %29 = fir.embox %22#0 : (!fir.ref) -> !fir.box + %30 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_broadcast %29 source %c1_i32_5 stat %24#0 errmsg %30 : (!fir.box, i32, !fir.ref, !fir.box>) + %c1_i32_6 = arith.constant 1 : i32 + %31 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %32 = fir.embox %9#0(%31) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_broadcast %32 source %c1_i32_6 : (!fir.box>, i32) + %c1_i32_7 = arith.constant 1 : i32 + %33 = fir.shape %c2 : (index) -> !fir.shape<1> + %34 = fir.embox %3#0(%33) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + mif.co_broadcast %34 source %c1_i32_7 : (!fir.box>>, i32) + %c1_i32_8 = arith.constant 1 : i32 + %35 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %36 = fir.embox %6#0(%35) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_broadcast %36 source %c1_i32_8 stat %24#0 : (!fir.box>, i32, !fir.ref) + %c1_i32_9 = arith.constant 1 : i32 + %37 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %38 = fir.embox %12#0(%37) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + %39 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_broadcast %38 source %c1_i32_9 stat %24#0 errmsg %39 : (!fir.box>, i32, !fir.ref, !fir.box>) + return + } +} + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V3]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/co_max.mlir b/flang/test/Fir/MIF/co_max.mlir new file mode 100644 index 000000000000..f74513d862eb --- /dev/null +++ b/flang/test/Fir/MIF/co_max.mlir @@ -0,0 +1,163 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_CO_MAX"} { + %0 = fir.dummy_scope : !fir.dscope + %c1 = arith.constant 1 : index + %c2 = arith.constant 2 : index + %1 = fir.alloca !fir.array<2x!fir.char<1>> {bindc_name = "array_c", uniq_name = "_QFEarray_c"} + %2 = fir.shape %c2 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) typeparams %c1 {uniq_name = "_QFEarray_c"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %c2_0 = arith.constant 2 : index + %4 = fir.alloca !fir.array<2xf64> {bindc_name = "array_d", uniq_name = "_QFEarray_d"} + %5 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %6:2 = hlfir.declare %4(%5) {uniq_name = "_QFEarray_d"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_1 = arith.constant 2 : index + %7 = fir.alloca !fir.array<2xi32> {bindc_name = "array_i", uniq_name = "_QFEarray_i"} + %8 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %9:2 = hlfir.declare %7(%8) {uniq_name = "_QFEarray_i"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_2 = arith.constant 2 : index + %10 = fir.alloca !fir.array<2xf32> {bindc_name = "array_r", uniq_name = "_QFEarray_r"} + %11 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %12:2 = hlfir.declare %10(%11) {uniq_name = "_QFEarray_r"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c1_3 = arith.constant 1 : index + %13 = fir.alloca !fir.char<1> {bindc_name = "c", uniq_name = "_QFEc"} + %14:2 = hlfir.declare %13 typeparams %c1_3 {uniq_name = "_QFEc"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %15 = fir.alloca f64 {bindc_name = "d", uniq_name = "_QFEd"} + %16:2 = hlfir.declare %15 {uniq_name = "_QFEd"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %17 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %18:2 = hlfir.declare %17 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %c1_4 = arith.constant 1 : index + %19 = fir.alloca !fir.char<1> {bindc_name = "message", uniq_name = "_QFEmessage"} + %20:2 = hlfir.declare %19 typeparams %c1_4 {uniq_name = "_QFEmessage"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %21 = fir.alloca f32 {bindc_name = "r", uniq_name = "_QFEr"} + %22:2 = hlfir.declare %21 {uniq_name = "_QFEr"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %23 = fir.alloca i32 {bindc_name = "status", uniq_name = "_QFEstatus"} + %24:2 = hlfir.declare %23 {uniq_name = "_QFEstatus"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %25 = fir.embox %18#0 : (!fir.ref) -> !fir.box + mif.co_max %25 : (!fir.box) + %26 = fir.embox %14#0 : (!fir.ref>) -> !fir.box> + mif.co_max %26 : (!fir.box>) + %27 = fir.embox %16#0 : (!fir.ref) -> !fir.box + mif.co_max %27 : (!fir.box) + %28 = fir.embox %22#0 : (!fir.ref) -> !fir.box + mif.co_max %28 : (!fir.box) + %c1_i32 = arith.constant 1 : i32 + %29 = fir.embox %18#0 : (!fir.ref) -> !fir.box + mif.co_max %29 result %c1_i32 : (!fir.box, i32) + %c1_i32_5 = arith.constant 1 : i32 + %30 = fir.embox %16#0 : (!fir.ref) -> !fir.box + %31 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_max %30 result %c1_i32_5 stat %24#0 errmsg %31 : (!fir.box, i32, !fir.ref, !fir.box>) + %c1_i32_6 = arith.constant 1 : i32 + %32 = fir.embox %22#0 : (!fir.ref) -> !fir.box + %33 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_max %32 result %c1_i32_6 stat %24#0 errmsg %33 : (!fir.box, i32, !fir.ref, !fir.box>) + %34 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %35 = fir.embox %9#0(%34) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_max %35 : (!fir.box>) + %c1_i32_7 = arith.constant 1 : i32 + %36 = fir.shape %c2 : (index) -> !fir.shape<1> + %37 = fir.embox %3#0(%36) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + mif.co_max %37 result %c1_i32_7 : (!fir.box>>, i32) + %c1_i32_8 = arith.constant 1 : i32 + %38 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %39 = fir.embox %6#0(%38) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_max %39 result %c1_i32_8 stat %24#0 : (!fir.box>, i32, !fir.ref) + %c1_i32_9 = arith.constant 1 : i32 + %40 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %41 = fir.embox %12#0(%40) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + %42 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_max %41 result %c1_i32_9 stat %24#0 errmsg %42 : (!fir.box>, i32, !fir.ref, !fir.box>) + return + } +} + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max_character(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max_character(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/co_min.mlir b/flang/test/Fir/MIF/co_min.mlir new file mode 100644 index 000000000000..97806bb376d3 --- /dev/null +++ b/flang/test/Fir/MIF/co_min.mlir @@ -0,0 +1,163 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_CO_MIN"} { + %0 = fir.dummy_scope : !fir.dscope + %c1 = arith.constant 1 : index + %c2 = arith.constant 2 : index + %1 = fir.alloca !fir.array<2x!fir.char<1>> {bindc_name = "array_c", uniq_name = "_QFEarray_c"} + %2 = fir.shape %c2 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) typeparams %c1 {uniq_name = "_QFEarray_c"} : (!fir.ref>>, !fir.shape<1>, index) -> (!fir.ref>>, !fir.ref>>) + %c2_0 = arith.constant 2 : index + %4 = fir.alloca !fir.array<2xf64> {bindc_name = "array_d", uniq_name = "_QFEarray_d"} + %5 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %6:2 = hlfir.declare %4(%5) {uniq_name = "_QFEarray_d"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_1 = arith.constant 2 : index + %7 = fir.alloca !fir.array<2xi32> {bindc_name = "array_i", uniq_name = "_QFEarray_i"} + %8 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %9:2 = hlfir.declare %7(%8) {uniq_name = "_QFEarray_i"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_2 = arith.constant 2 : index + %10 = fir.alloca !fir.array<2xf32> {bindc_name = "array_r", uniq_name = "_QFEarray_r"} + %11 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %12:2 = hlfir.declare %10(%11) {uniq_name = "_QFEarray_r"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c1_3 = arith.constant 1 : index + %13 = fir.alloca !fir.char<1> {bindc_name = "c", uniq_name = "_QFEc"} + %14:2 = hlfir.declare %13 typeparams %c1_3 {uniq_name = "_QFEc"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %15 = fir.alloca f64 {bindc_name = "d", uniq_name = "_QFEd"} + %16:2 = hlfir.declare %15 {uniq_name = "_QFEd"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %17 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %18:2 = hlfir.declare %17 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %c1_4 = arith.constant 1 : index + %19 = fir.alloca !fir.char<1> {bindc_name = "message", uniq_name = "_QFEmessage"} + %20:2 = hlfir.declare %19 typeparams %c1_4 {uniq_name = "_QFEmessage"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %21 = fir.alloca f32 {bindc_name = "r", uniq_name = "_QFEr"} + %22:2 = hlfir.declare %21 {uniq_name = "_QFEr"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %23 = fir.alloca i32 {bindc_name = "status", uniq_name = "_QFEstatus"} + %24:2 = hlfir.declare %23 {uniq_name = "_QFEstatus"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %25 = fir.embox %18#0 : (!fir.ref) -> !fir.box + mif.co_min %25 : (!fir.box) + %26 = fir.embox %14#0 : (!fir.ref>) -> !fir.box> + mif.co_min %26 : (!fir.box>) + %27 = fir.embox %16#0 : (!fir.ref) -> !fir.box + mif.co_min %27 : (!fir.box) + %28 = fir.embox %22#0 : (!fir.ref) -> !fir.box + mif.co_min %28 : (!fir.box) + %c1_i32 = arith.constant 1 : i32 + %29 = fir.embox %18#0 : (!fir.ref) -> !fir.box + mif.co_min %29 result %c1_i32 : (!fir.box, i32) + %c1_i32_5 = arith.constant 1 : i32 + %30 = fir.embox %16#0 : (!fir.ref) -> !fir.box + %31 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_min %30 result %c1_i32_5 stat %24#0 errmsg %31 : (!fir.box, i32, !fir.ref, !fir.box>) + %c1_i32_6 = arith.constant 1 : i32 + %32 = fir.embox %22#0 : (!fir.ref) -> !fir.box + %33 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_min %32 result %c1_i32_6 stat %24#0 errmsg %33 : (!fir.box, i32, !fir.ref, !fir.box>) + %34 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %35 = fir.embox %9#0(%34) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_min %35 : (!fir.box>) + %c1_i32_7 = arith.constant 1 : i32 + %36 = fir.shape %c2 : (index) -> !fir.shape<1> + %37 = fir.embox %3#0(%36) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + mif.co_min %37 result %c1_i32_7 : (!fir.box>>, i32) + %c1_i32_8 = arith.constant 1 : i32 + %38 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %39 = fir.embox %6#0(%38) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_min %39 result %c1_i32_8 stat %24#0 : (!fir.box>, i32, !fir.ref) + %c1_i32_9 = arith.constant 1 : i32 + %40 = fir.shape %c2_2 : (index) -> !fir.shape<1> + %41 = fir.embox %12#0(%40) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + %42 = fir.embox %20#0 : (!fir.ref>) -> !fir.box> + mif.co_min %41 result %c1_i32_9 stat %24#0 errmsg %42 : (!fir.box>, i32, !fir.ref, !fir.box>) + return + } +} + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min_character(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min_character(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/co_sum.mlir b/flang/test/Fir/MIF/co_sum.mlir new file mode 100644 index 000000000000..8afce3582a97 --- /dev/null +++ b/flang/test/Fir/MIF/co_sum.mlir @@ -0,0 +1,133 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_CO_SUM"} { + %0 = fir.dummy_scope : !fir.dscope + %c2 = arith.constant 2 : index + %1 = fir.alloca !fir.array<2xf64> {bindc_name = "array_d", uniq_name = "_QFEarray_d"} + %2 = fir.shape %c2 : (index) -> !fir.shape<1> + %3:2 = hlfir.declare %1(%2) {uniq_name = "_QFEarray_d"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_0 = arith.constant 2 : index + %4 = fir.alloca !fir.array<2xi32> {bindc_name = "array_i", uniq_name = "_QFEarray_i"} + %5 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %6:2 = hlfir.declare %4(%5) {uniq_name = "_QFEarray_i"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %c2_1 = arith.constant 2 : index + %7 = fir.alloca !fir.array<2xf32> {bindc_name = "array_r", uniq_name = "_QFEarray_r"} + %8 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %9:2 = hlfir.declare %7(%8) {uniq_name = "_QFEarray_r"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %10 = fir.alloca f64 {bindc_name = "d", uniq_name = "_QFEd"} + %11:2 = hlfir.declare %10 {uniq_name = "_QFEd"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %12 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %13:2 = hlfir.declare %12 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %c1 = arith.constant 1 : index + %14 = fir.alloca !fir.char<1> {bindc_name = "message", uniq_name = "_QFEmessage"} + %15:2 = hlfir.declare %14 typeparams %c1 {uniq_name = "_QFEmessage"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %16 = fir.alloca f32 {bindc_name = "r", uniq_name = "_QFEr"} + %17:2 = hlfir.declare %16 {uniq_name = "_QFEr"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %18 = fir.alloca i32 {bindc_name = "status", uniq_name = "_QFEstatus"} + %19:2 = hlfir.declare %18 {uniq_name = "_QFEstatus"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %20 = fir.embox %13#0 : (!fir.ref) -> !fir.box + mif.co_sum %20 : (!fir.box) + %21 = fir.embox %11#0 : (!fir.ref) -> !fir.box + mif.co_sum %21 : (!fir.box) + %22 = fir.embox %17#0 : (!fir.ref) -> !fir.box + mif.co_sum %22 : (!fir.box) + %c1_i32 = arith.constant 1 : i32 + %23 = fir.embox %13#0 : (!fir.ref) -> !fir.box + mif.co_sum %23 result %c1_i32 : (!fir.box, i32) + %c1_i32_2 = arith.constant 1 : i32 + %24 = fir.embox %11#0 : (!fir.ref) -> !fir.box + %25 = fir.embox %15#0 : (!fir.ref>) -> !fir.box> + mif.co_sum %24 result %c1_i32_2 stat %19#0 errmsg %25 : (!fir.box, i32, !fir.ref, !fir.box>) + %c1_i32_3 = arith.constant 1 : i32 + %26 = fir.embox %17#0 : (!fir.ref) -> !fir.box + %27 = fir.embox %15#0 : (!fir.ref>) -> !fir.box> + mif.co_sum %26 result %c1_i32_3 stat %19#0 errmsg %27 : (!fir.box, i32, !fir.ref, !fir.box>) + %28 = fir.shape %c2_0 : (index) -> !fir.shape<1> + %29 = fir.embox %6#0(%28) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_sum %29 : (!fir.box>) + %c1_i32_4 = arith.constant 1 : i32 + %30 = fir.shape %c2 : (index) -> !fir.shape<1> + %31 = fir.embox %3#0(%30) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.co_sum %31 result %c1_i32_4 stat %19#0 : (!fir.box>, i32, !fir.ref) + %c1_i32_5 = arith.constant 1 : i32 + %32 = fir.shape %c2_1 : (index) -> !fir.shape<1> + %33 = fir.embox %9#0(%32) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + %34 = fir.embox %15#0 : (!fir.ref>) -> !fir.box> + mif.co_sum %33 result %c1_i32_5 stat %19#0 errmsg %34 : (!fir.box>, i32, !fir.ref, !fir.box>) + return + } +} + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.absent !fir.ref + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[V3]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.absent !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.absent !fir.ref + // CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V4]], %[[V3]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V2:.*]] = fir.absent !fir.box> + // CHECK: %[[V3:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V3]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V2]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + // CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + // CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref + // CHECK: %[[V3:.*]] = fir.absent !fir.box> + // CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box + // CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/init.mlir b/flang/test/Fir/MIF/init.mlir new file mode 100644 index 000000000000..0f1177f92427 --- /dev/null +++ b/flang/test/Fir/MIF/init.mlir @@ -0,0 +1,24 @@ +// RUN: fir-opt --split-input-file --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_INIT"} { + %0 = fir.dummy_scope : !fir.dscope + return + } + func.func private @_FortranAProgramStart(i32, !llvm.ptr, !llvm.ptr, !llvm.ptr) + func.func private @_FortranAProgramEndStatement() + func.func @main(%arg0: i32, %arg1: !llvm.ptr, %arg2: !llvm.ptr) -> i32 { + %0 = fir.zero_bits !fir.ref, !fir.ref>>>>> + fir.call @_FortranAProgramStart(%arg0, %arg1, %arg2, %0) fastmath : (i32, !llvm.ptr, !llvm.ptr, !fir.ref, !fir.ref>>>>>) -> () + %1 = mif.init -> i32 + fir.call @_QQmain() fastmath : () -> () + fir.call @_FortranAProgramEndStatement() fastmath : () -> () + %c0_i32 = arith.constant 0 : i32 + return %c0_i32 : i32 + } +} + + +// CHECK-LABEL: func.func @main +// CHECK: %[[VAL_0:.*]] = fir.alloca i32 +// CHECK: fir.call @_QMprifPprif_init(%[[VAL_0]]) : (!fir.ref) -> () diff --git a/flang/test/Fir/MIF/num_images.mlir b/flang/test/Fir/MIF/num_images.mlir new file mode 100644 index 000000000000..afa33a9063c3 --- /dev/null +++ b/flang/test/Fir/MIF/num_images.mlir @@ -0,0 +1,22 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST"} { + %0 = fir.dummy_scope : !fir.dscope + %1 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %2:2 = hlfir.declare %1 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %3 = fir.alloca i32 {bindc_name = "team_number", uniq_name = "_QFEteam_number"} + %4:2 = hlfir.declare %3 {uniq_name = "_QFEteam_number"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %5 = mif.num_images : () -> i32 + hlfir.assign %5 to %2#0 : i32, !fir.ref + %6 = fir.load %4#0 : !fir.ref + %7 = mif.num_images team_number %6 : (i32) -> i32 + hlfir.assign %7 to %2#0 : i32, !fir.ref + return + } +} + + +// CHECK-LABEL: func.func @_QQmain +// CHECK: fir.call @_QMprifPprif_num_images( +// CHECK: fir.call @_QMprifPprif_num_images_with_team_number( diff --git a/flang/test/Fir/MIF/sync_all.mlir b/flang/test/Fir/MIF/sync_all.mlir new file mode 100644 index 000000000000..b2b98b9aae9e --- /dev/null +++ b/flang/test/Fir/MIF/sync_all.mlir @@ -0,0 +1,45 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_SYNC_ALL"} { + %0 = fir.dummy_scope : !fir.dscope + %1 = fir.address_of(@_QFEerror_message) : !fir.ref> + %c128 = arith.constant 128 : index + %2:2 = hlfir.declare %1 typeparams %c128 {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %3 = fir.alloca i32 {bindc_name = "sync_status", uniq_name = "_QFEsync_status"} + %4:2 = hlfir.declare %3 {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + mif.sync_all : () -> () + mif.sync_all stat %4#0 : (!fir.ref) -> () + %5 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + mif.sync_all errmsg %5 : (!fir.box>) -> () + %6 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + mif.sync_all stat %4#0 errmsg %6 : (!fir.ref, !fir.box>) -> () + return + } + fir.global internal @_QFEerror_message : !fir.char<1,128> { + %0 = fir.zero_bits !fir.char<1,128> + fir.has_value %0 : !fir.char<1,128> + } +} + + +// CHECK: %[[ERRMSG:.*]]:2 = hlfir.declare %[[E:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) +// CHECK: %[[STAT:.*]]:2 = hlfir.declare %[[S:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + +// CHECK: %[[VAL_1:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_2:.*]] = fir.absent !fir.ref +// CHECK: fir.call @_QMprifPprif_sync_all(%[[VAL_2]], %[[VAL_1]], %[[VAL_1]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_3:.*]] = fir.absent !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_all(%[[STAT]]#0, %[[VAL_3]], %[[VAL_3]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_4:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> +// CHECK: %[[VAL_5:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_6:.*]] = fir.absent !fir.ref +// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.box>) -> !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_all(%[[VAL_6]], %[[VAL_7]], %[[VAL_5]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_8:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> +// CHECK: %[[VAL_9:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_8]] : (!fir.box>) -> !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_all(%[[STAT]]#0, %[[VAL_10]], %[[VAL_9]]) : (!fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/sync_images.mlir b/flang/test/Fir/MIF/sync_images.mlir new file mode 100644 index 000000000000..e38fdaa5a4c1 --- /dev/null +++ b/flang/test/Fir/MIF/sync_images.mlir @@ -0,0 +1,85 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_SYNC_IMAGES"} { + %0 = fir.dummy_scope : !fir.dscope + %1 = fir.address_of(@_QFEerror_message) : !fir.ref> + %c128 = arith.constant 128 : index + %2:2 = hlfir.declare %1 typeparams %c128 {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %3 = fir.alloca i32 {bindc_name = "me", uniq_name = "_QFEme"} + %4:2 = hlfir.declare %3 {uniq_name = "_QFEme"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %5 = fir.alloca i32 {bindc_name = "sync_status", uniq_name = "_QFEsync_status"} + %6:2 = hlfir.declare %5 {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %7 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + mif.sync_images stat %6#0 errmsg %7 : (!fir.ref, !fir.box>) -> () + %8 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + %9 = fir.embox %4#0 : (!fir.ref) -> !fir.box + mif.sync_images image_set %9 stat %6#0 errmsg %8 : (!fir.box, !fir.ref, !fir.box>) -> () + %10 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + %11 = fir.address_of(@_QQro.1xi4.0) : !fir.ref> + %c1 = arith.constant 1 : index + %12 = fir.shape %c1 : (index) -> !fir.shape<1> + %13:2 = hlfir.declare %11(%12) {fortran_attrs = #fir.var_attrs, uniq_name = "_QQro.1xi4.0"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %14 = fir.shape %c1 : (index) -> !fir.shape<1> + %15 = fir.embox %13#0(%14) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.sync_images image_set %15 stat %6#0 errmsg %10 : (!fir.box>, !fir.ref, !fir.box>) -> () + mif.sync_images : () -> () + %16 = fir.embox %4#0 : (!fir.ref) -> !fir.box + mif.sync_images image_set %16 : (!fir.box) -> () + %17 = fir.address_of(@_QQro.1xi4.0) : !fir.ref> + %c1_0 = arith.constant 1 : index + %18 = fir.shape %c1_0 : (index) -> !fir.shape<1> + %19:2 = hlfir.declare %17(%18) {fortran_attrs = #fir.var_attrs, uniq_name = "_QQro.1xi4.0"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) + %20 = fir.shape %c1_0 : (index) -> !fir.shape<1> + %21 = fir.embox %19#0(%20) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + mif.sync_images image_set %21 : (!fir.box>) -> () + return + } + fir.global internal @_QFEerror_message : !fir.char<1,128> { + %0 = fir.zero_bits !fir.char<1,128> + fir.has_value %0 : !fir.char<1,128> + } +} + + // CHECK: %[[ERRMSG:.*]]:2 = hlfir.declare %[[E:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + // CHECK: %[[ME:.*]]:2 = hlfir.declare %[[M:.*]] {uniq_name = "_QFEme"} : (!fir.ref) -> (!fir.ref, !fir.ref) + // CHECK: %[[STAT:.*]]:2 = hlfir.declare %[[S:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + + // CHECK: %[[VAL_1:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: %[[VAL_2:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_3:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_2]], %[[STAT]]#0, %[[VAL_4]], %[[VAL_3]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[VAL_5:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: %[[VAL_6:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[VAL_7:.*]] = fir.rebox %[[VAL_6]](%[[SHAPE:.*]]) : (!fir.box, !fir.shape<1>) -> !fir.box> + // CHECK: %[[VAL_8:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_7]] : (!fir.box>) -> !fir.box> + // CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_5]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_9]], %[[STAT]]#0, %[[VAL_10]], %[[VAL_8]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[VAL_11:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + // CHECK: %[[VAL_12:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_1:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[VAL_13:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_12]] : (!fir.box>) -> !fir.box> + // CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_14]], %[[STAT]]#0, %[[VAL_15]], %[[VAL_13]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[VAL_16:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_17:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_18:.*]] = fir.absent !fir.ref + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_16]], %[[VAL_18]], %[[VAL_17]], %[[VAL_17]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[VAL_19:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box + // CHECK: %[[VAL_20:.*]] = fir.rebox %[[VAL_19]](%[[SHAPE_2:.*]]) : (!fir.box, !fir.shape<1>) -> !fir.box> + // CHECK: %[[VAL_21:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_22:.*]] = fir.absent !fir.ref + // CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_20]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_23]], %[[VAL_22]], %[[VAL_21]], %[[VAL_21]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () + + // CHECK: %[[VAL_24:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_3:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + // CHECK: %[[VAL_25:.*]] = fir.absent !fir.box> + // CHECK: %[[VAL_26:.*]] = fir.absent !fir.ref + // CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_24]] : (!fir.box>) -> !fir.box> + // CHECK: fir.call @_QMprifPprif_sync_images(%[[VAL_27]], %[[VAL_26]], %[[VAL_25]], %[[VAL_25]]) : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/sync_memory.mlir b/flang/test/Fir/MIF/sync_memory.mlir new file mode 100644 index 000000000000..d6f24416bc61 --- /dev/null +++ b/flang/test/Fir/MIF/sync_memory.mlir @@ -0,0 +1,45 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST_sync_memory"} { + %0 = fir.dummy_scope : !fir.dscope + %1 = fir.address_of(@_QFEerror_message) : !fir.ref> + %c128 = arith.constant 128 : index + %2:2 = hlfir.declare %1 typeparams %c128 {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + %3 = fir.alloca i32 {bindc_name = "sync_status", uniq_name = "_QFEsync_status"} + %4:2 = hlfir.declare %3 {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + mif.sync_memory : () -> () + mif.sync_memory stat %4#0 : (!fir.ref) -> () + %5 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + mif.sync_memory errmsg %5 : (!fir.box>) -> () + %6 = fir.embox %2#0 : (!fir.ref>) -> !fir.box> + mif.sync_memory stat %4#0 errmsg %6 : (!fir.ref, !fir.box>) -> () + return + } + fir.global internal @_QFEerror_message : !fir.char<1,128> { + %0 = fir.zero_bits !fir.char<1,128> + fir.has_value %0 : !fir.char<1,128> + } +} + + +// CHECK: %[[ERRMSG:.*]]:2 = hlfir.declare %[[E:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) +// CHECK: %[[STAT:.*]]:2 = hlfir.declare %[[S:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + +// CHECK: %[[VAL_1:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_2:.*]] = fir.absent !fir.ref +// CHECK: fir.call @_QMprifPprif_sync_memory(%[[VAL_2]], %[[VAL_1]], %[[VAL_1]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_3:.*]] = fir.absent !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_memory(%[[STAT]]#0, %[[VAL_3]], %[[VAL_3]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_4:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> +// CHECK: %[[VAL_5:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_6:.*]] = fir.absent !fir.ref +// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.box>) -> !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_memory(%[[VAL_6]], %[[VAL_7]], %[[VAL_5]]) : (!fir.ref, !fir.box>, !fir.box>) -> () + +// CHECK: %[[VAL_8:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> +// CHECK: %[[VAL_9:.*]] = fir.absent !fir.box> +// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_8]] : (!fir.box>) -> !fir.box> +// CHECK: fir.call @_QMprifPprif_sync_memory(%[[STAT]]#0, %[[VAL_10]], %[[VAL_9]]) : (!fir.ref, !fir.box>, !fir.box>) -> () diff --git a/flang/test/Fir/MIF/this_image.mlir b/flang/test/Fir/MIF/this_image.mlir new file mode 100644 index 000000000000..25eafc09ef58 --- /dev/null +++ b/flang/test/Fir/MIF/this_image.mlir @@ -0,0 +1,16 @@ +// RUN: fir-opt --mif-convert %s | FileCheck %s + +module attributes {dlti.dl_spec = #dlti.dl_spec = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array, "dlti.stack_alignment" = 128 : i64>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang version 22.0.0 (git@github.com:SiPearl/llvm-project.git 666e4313ebc03587f27774139ad8f780bac15c3e)", llvm.target_triple = "x86_64-unknown-linux-gnu"} { + func.func @_QQmain() attributes {fir.bindc_name = "TEST"} { + %0 = fir.dummy_scope : !fir.dscope + %1 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"} + %2:2 = hlfir.declare %1 {uniq_name = "_QFEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) + %3 = mif.this_image : () -> i32 + hlfir.assign %3 to %2#0 : i32, !fir.ref + return + } +} + + +// CHECK-LABEL: func.func @_QQmain +// CHECK: fir.call @_QMprifPprif_this_image_no_coarray( diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir index 59f6c73ae84e..5159c91dafa5 100644 --- a/flang/test/Fir/basic-program.fir +++ b/flang/test/Fir/basic-program.fir @@ -132,6 +132,7 @@ func.func @_QQmain() { // PASSES-NEXT: (S) 0 num-dce'd - Number of operations DCE'd // PASSES-NEXT: 'func.func' Pipeline // PASSES-NEXT: SetRuntimeCallAttributes +// PASSES-NEXT: MIFOpConversion // PASSES-NEXT: BoxedProcedurePass // PASSES-NEXT: AddAliasTags diff --git a/flang/test/Lower/Coarray/co_broadcast.f90 b/flang/test/Lower/Coarray/co_broadcast.f90 deleted file mode 100644 index be7fdcb99252..000000000000 --- a/flang/test/Lower/Coarray/co_broadcast.f90 +++ /dev/null @@ -1,92 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s - -program test_co_broadcast - integer :: i, array_i(2), status - real :: r, array_r(2) - double precision :: d, array_d(2) - complex :: c, array_c(2) - character(len=1) :: message - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(i, source_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(c, source_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(d, source_image=1, stat=status, errmsg=message) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(r, source_image=1, stat=status, errmsg=message) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(array_i, source_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(array_c, source_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(array_d, source_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_broadcast(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_broadcast(array_r, source_image=1, stat= status, errmsg=message) - -end program diff --git a/flang/test/Lower/Coarray/co_max.f90 b/flang/test/Lower/Coarray/co_max.f90 deleted file mode 100644 index 56d863389d02..000000000000 --- a/flang/test/Lower/Coarray/co_max.f90 +++ /dev/null @@ -1,112 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s - -program test_co_max - integer :: i, array_i(2), status - real :: r, array_r(2) - double precision :: d, array_d(2) - character(len=1) :: c, array_c(2), message - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(i) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max_character(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(c) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(d) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(r) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(i, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(d, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(r, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(array_i) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max_character(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(array_c, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(array_d, result_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_max(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_max(array_r, result_image=1, stat= status, errmsg=message) - -end program diff --git a/flang/test/Lower/Coarray/co_min.f90 b/flang/test/Lower/Coarray/co_min.f90 deleted file mode 100644 index dde878bb14db..000000000000 --- a/flang/test/Lower/Coarray/co_min.f90 +++ /dev/null @@ -1,112 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s - -program test_co_min - integer :: i, array_i(2), status - real :: r, array_r(2) - double precision :: d, array_d(2) - character(len=1) :: c, array_c(2), message - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(i) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min_character(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(c) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(d) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(r) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(i, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(d, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(r, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(array_i) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min_character(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(array_c, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(array_d, result_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_min(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_min(array_r, result_image=1, stat= status, errmsg=message) - -end program diff --git a/flang/test/Lower/Coarray/co_sum.f90 b/flang/test/Lower/Coarray/co_sum.f90 deleted file mode 100644 index 2932b54c60a8..000000000000 --- a/flang/test/Lower/Coarray/co_sum.f90 +++ /dev/null @@ -1,122 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s - -program test_co_sum - integer :: i, array_i(2), status - real :: r, array_r(2) - double precision :: d, array_d(2) - complex :: c, array_c(2) - character(len=1) :: message - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(i) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(c) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(d) - - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(r) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(i, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS:.*]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(c, result_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(d, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(r, result_image=1, stat=status, errmsg=message) - - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[V2]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(array_i) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.ref - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.absent !fir.box> - ! CHECK: %[[V5:.*]] = fir.convert %[[V1]] : (!fir.box>>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V5]], %[[IMAGE_RESULT]], %[[V2]], %[[V3]], %[[V4]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(array_c, result_image=1) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.absent !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V2]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(array_d, result_image=1, stat=status) - - ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 - ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> - ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! CHECK: fir.store %[[C1_i32]] to %[[IMAGE_RESULT:.*]] : !fir.ref - ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> - ! CHECK: %[[V3:.*]] = fir.absent !fir.box> - ! CHECK: %[[V4:.*]] = fir.convert %[[V1]] : (!fir.box>) -> !fir.box - ! CHECK: %[[V5:.*]] = fir.convert %[[V2]] : (!fir.box>) -> !fir.box> - ! CHECK: fir.call @_QMprifPprif_co_sum(%[[V4]], %[[IMAGE_RESULT]], %[[STATUS]], %[[V5]], %[[V3]]) fastmath : (!fir.box, !fir.ref, !fir.ref, !fir.box>, !fir.box>) -> () - call co_sum(array_r, result_image=1, stat= status, errmsg=message) - -end program diff --git a/flang/test/Lower/Coarray/sync_all.f90 b/flang/test/Lower/Coarray/sync_all.f90 deleted file mode 100644 index c2c12d8cdf23..000000000000 --- a/flang/test/Lower/Coarray/sync_all.f90 +++ /dev/null @@ -1,37 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY -! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY - -program test_sync_all - implicit none - ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. - - ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) - ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) - integer sync_status - character(len=128) :: error_message - - ! COARRAY: %[[VAL_3:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_4:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_5:.*]] = fir.absent !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_all(%[[VAL_3]], %[[VAL_4]], %[[VAL_5]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync all - - ! COARRAY: %[[VAL_6:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_7:.*]] = fir.absent !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_all(%[[STAT]]#0, %[[VAL_6]], %[[VAL_7]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync all(stat=sync_status) - - ! COARRAY: %[[VAL_8:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_9:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_10:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_11:.*]] = fir.convert %[[VAL_8]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_all(%[[VAL_9]], %[[VAL_11]], %[[VAL_10]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync all( errmsg=error_message) - - ! COARRAY: %[[VAL_12:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_13:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_14:.*]] = fir.convert %[[VAL_12]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_all(%[[STAT]]#0, %[[VAL_14]], %[[VAL_13]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync all(stat=sync_status, errmsg=error_message) - -end program test_sync_all diff --git a/flang/test/Lower/Coarray/sync_images.f90 b/flang/test/Lower/Coarray/sync_images.f90 deleted file mode 100644 index 0224bf235c36..000000000000 --- a/flang/test/Lower/Coarray/sync_images.f90 +++ /dev/null @@ -1,62 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY -! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY - -program test_sync_images - implicit none - ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. - - ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) - ! COARRAY: %[[ME:.*]]:2 = hlfir.declare %[[VAL_3:.*]] {uniq_name = "_QFEme"} : (!fir.ref) -> (!fir.ref, !fir.ref) - ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) - integer sync_status, me - character(len=128) :: error_message - - ! COARRAY: %[[VAL_1:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_2:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_3:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_2]], %[[STAT]]#0, %[[VAL_4]], %[[VAL_3]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images(*, stat=sync_status, errmsg=error_message) - - ! COARRAY: %[[VAL_5:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_6:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box - ! COARRAY: %[[VAL_7:.*]] = fir.rebox %[[VAL_6]](%[[SHAPE:.*]]) : (!fir.box, !fir.shape<1>) -> !fir.box> - ! COARRAY: %[[VAL_8:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_9:.*]] = fir.convert %[[VAL_7]] : (!fir.box>) -> !fir.box> - ! COARRAY: %[[VAL_10:.*]] = fir.convert %[[VAL_5]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_9]], %[[STAT]]#0, %[[VAL_10]], %[[VAL_8]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images(me, stat=sync_status, errmsg=error_message) - - ! COARRAY: %[[VAL_11:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_12:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_1:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! COARRAY: %[[VAL_13:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_14:.*]] = fir.convert %[[VAL_12]] : (!fir.box>) -> !fir.box> - ! COARRAY: %[[VAL_15:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_14]], %[[STAT]]#0, %[[VAL_15]], %[[VAL_13]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images([1], stat=sync_status, errmsg=error_message) - - ! COARRAY: %[[VAL_17:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_18:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_19:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_20:.*]] = fir.absent !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_19]], %[[VAL_17]], %[[VAL_18]], %[[VAL_20]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images(*) - - ! COARRAY: %[[VAL_23:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_24:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_21:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box - ! COARRAY: %[[VAL_22:.*]] = fir.rebox %[[VAL_21]](%[[SHAPE_2:.*]]) : (!fir.box, !fir.shape<1>) -> !fir.box> - ! COARRAY: %[[VAL_25:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_26:.*]] = fir.convert %[[VAL_22]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_26]], %[[VAL_23]], %[[VAL_24]], %[[VAL_25]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images(me) - - ! COARRAY: %[[VAL_28:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_29:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_27:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_3:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> - ! COARRAY: %[[VAL_30:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_31:.*]] = fir.convert %[[VAL_27]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_images(%[[VAL_31]], %[[VAL_28]], %[[VAL_29]], %[[VAL_30]]) fastmath : (!fir.box>, !fir.ref, !fir.box>, !fir.box>) -> () - sync images([1]) - -end program test_sync_images diff --git a/flang/test/Lower/Coarray/sync_memory.f90 b/flang/test/Lower/Coarray/sync_memory.f90 deleted file mode 100644 index 773cb6fe4efb..000000000000 --- a/flang/test/Lower/Coarray/sync_memory.f90 +++ /dev/null @@ -1,37 +0,0 @@ -! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY -! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY - -program test_sync_memory - implicit none - ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. - - ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) - ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) - integer sync_status - character(len=128) :: error_message - - ! COARRAY: %[[VAL_3:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_4:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_5:.*]] = fir.absent !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_memory(%[[VAL_3]], %[[VAL_4]], %[[VAL_5]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync memory - - ! COARRAY: %[[VAL_6:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_7:.*]] = fir.absent !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_memory(%[[STAT]]#0, %[[VAL_6]], %[[VAL_7]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync memory(stat=sync_status) - - ! COARRAY: %[[VAL_8:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_9:.*]] = fir.absent !fir.ref - ! COARRAY: %[[VAL_10:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_11:.*]] = fir.convert %[[VAL_8]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_memory(%[[VAL_9]], %[[VAL_11]], %[[VAL_10]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync memory( errmsg=error_message) - - ! COARRAY: %[[VAL_12:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> - ! COARRAY: %[[VAL_13:.*]] = fir.absent !fir.box> - ! COARRAY: %[[VAL_14:.*]] = fir.convert %[[VAL_12]] : (!fir.box>) -> !fir.box> - ! COARRAY: fir.call @_QMprifPprif_sync_memory(%[[STAT]]#0, %[[VAL_14]], %[[VAL_13]]) fastmath : (!fir.ref, !fir.box>, !fir.box>) -> () - sync memory(stat=sync_status, errmsg=error_message) - -end program test_sync_memory diff --git a/flang/test/Lower/MIF/co_broadcast.f90 b/flang/test/Lower/MIF/co_broadcast.f90 new file mode 100644 index 000000000000..25e4330ade70 --- /dev/null +++ b/flang/test/Lower/MIF/co_broadcast.f90 @@ -0,0 +1,57 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s + +program test_co_broadcast + integer :: i, array_i(2), status + real :: r, array_r(2) + double precision :: d, array_d(2) + complex :: c, array_c(2) + character(len=1) :: message + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] : (!fir.box, i32) + call co_broadcast(i, source_image=1) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 : (!fir.box>, i32, !fir.ref) + call co_broadcast(c, source_image=1, stat=status) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] stat %[[STATUS]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_broadcast(d, source_image=1, stat=status, errmsg=message) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] stat %[[STATUS]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_broadcast(r, source_image=1, stat=status, errmsg=message) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] : (!fir.box>, i32) + call co_broadcast(array_i, source_image=1) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] : (!fir.box>>, i32) + call co_broadcast(array_c, source_image=1) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 : (!fir.box>, i32, !fir.ref) + call co_broadcast(array_d, source_image=1, stat=status) + + ! CHECK: %[[C1_i32:.*]] = arith.constant 1 : i32 + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_broadcast %[[V1]] source %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box>, i32, !fir.ref, !fir.box>) + call co_broadcast(array_r, source_image=1, stat= status, errmsg=message) + +end program diff --git a/flang/test/Lower/MIF/co_max.f90 b/flang/test/Lower/MIF/co_max.f90 new file mode 100644 index 000000000000..19e65626b50f --- /dev/null +++ b/flang/test/Lower/MIF/co_max.f90 @@ -0,0 +1,60 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s + +program test_co_max + integer :: i, array_i(2), status + real :: r, array_r(2) + double precision :: d, array_d(2) + character(len=1) :: c, array_c(2), message + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_max %[[V1]] : (!fir.box) + call co_max(i) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] : (!fir.box>) + call co_max(c) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_max %[[V1]] : (!fir.box) + call co_max(d) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_max %[[V1]] : (!fir.box) + call co_max(r) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] : (!fir.box, i32) + call co_max(i, result_image=1) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_max(d, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_max(r, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] : (!fir.box>) + call co_max(array_i) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] : (!fir.box>>, i32) + call co_max(array_c, result_image=1) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 : (!fir.box>, i32, !fir.ref) + call co_max(array_d, result_image=1, stat=status) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_R:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_max %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box>, i32, !fir.ref, !fir.box>) + call co_max(array_r, result_image=1, stat= status, errmsg=message) + +end program diff --git a/flang/test/Lower/MIF/co_min.f90 b/flang/test/Lower/MIF/co_min.f90 new file mode 100644 index 000000000000..a7adc6b54014 --- /dev/null +++ b/flang/test/Lower/MIF/co_min.f90 @@ -0,0 +1,60 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s + +program test_co_min + integer :: i, array_i(2), status + real :: r, array_r(2) + double precision :: d, array_d(2) + character(len=1) :: c, array_c(2), message + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_min %[[V1]] : (!fir.box) + call co_min(i) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_C:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] : (!fir.box>) + call co_min(c) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_min %[[V1]] : (!fir.box) + call co_min(d) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_min %[[V1]] : (!fir.box) + call co_min(r) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] : (!fir.box, i32) + call co_min(i, result_image=1) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_min(d, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_min(r, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] : (!fir.box>) + call co_min(array_i) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_C:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.box>> + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] : (!fir.box>>, i32) + call co_min(array_c, result_image=1) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 : (!fir.box>, i32, !fir.ref) + call co_min(array_d, result_image=1, stat=status) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_R:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_min %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box>, i32, !fir.ref, !fir.box>) + call co_min(array_r, result_image=1, stat= status, errmsg=message) + +end program diff --git a/flang/test/Lower/MIF/co_sum.f90 b/flang/test/Lower/MIF/co_sum.f90 new file mode 100644 index 000000000000..0d8a25850ad5 --- /dev/null +++ b/flang/test/Lower/MIF/co_sum.f90 @@ -0,0 +1,51 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s + +program test_co_sum + integer :: i, array_i(2), status + real :: r, array_r(2) + double precision :: d, array_d(2) + character(len=1) :: message + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_sum %[[V1]] : (!fir.box) + call co_sum(i) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_sum %[[V1]] : (!fir.box) + call co_sum(d) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R:.*]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_sum %[[V1]] : (!fir.box) + call co_sum(r) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_I]]#0 : (!fir.ref) -> !fir.box + ! CHECK: mif.co_sum %[[V1]] result %[[C1_i32:.*]] : (!fir.box, i32) + call co_sum(i, result_image=1) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_D]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE:.*]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_sum %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_sum(d, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[V1:.*]] = fir.embox %[[VAR_R]]#0 : (!fir.ref) -> !fir.box + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_sum %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box, i32, !fir.ref, !fir.box>) + call co_sum(r, result_image=1, stat=status, errmsg=message) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_I:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_sum %[[V1]] : (!fir.box>) + call co_sum(array_i) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_D:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: mif.co_sum %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 : (!fir.box>, i32, !fir.ref) + call co_sum(array_d, result_image=1, stat=status) + + ! CHECK: %[[SHAPE_2:.*]] = fir.shape %[[C2_2:.*]] : (index) -> !fir.shape<1> + ! CHECK: %[[V1:.*]] = fir.embox %[[ARRAY_R:.*]]#0(%[[SHAPE_2]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! CHECK: %[[V2:.*]] = fir.embox %[[MESSAGE]]#0 : (!fir.ref>) -> !fir.box> + ! CHECK: mif.co_sum %[[V1]] result %[[C1_i32:.*]] stat %[[STATUS:.*]]#0 errmsg %[[V2]] : (!fir.box>, i32, !fir.ref, !fir.box>) + call co_sum(array_r, result_image=1, stat= status, errmsg=message) + +end program diff --git a/flang/test/Lower/Coarray/coarray-init.f90 b/flang/test/Lower/MIF/coarray-init.f90 similarity index 57% rename from flang/test/Lower/Coarray/coarray-init.f90 rename to flang/test/Lower/MIF/coarray-init.f90 index 055bc0fc4da7..e3544736df28 100644 --- a/flang/test/Lower/Coarray/coarray-init.f90 +++ b/flang/test/Lower/MIF/coarray-init.f90 @@ -7,5 +7,5 @@ end ! ALL-LABEL: func.func @main ! ALL: fir.call @_FortranAProgramStart -! COARRAY: fir.call @_QMprifPprif_init(%[[ARG:.*]]) fastmath : (!fir.ref) -> () -! NOCOARRAY-NOT: fir.call @_QMprifPprif_init(%[[ARG:.*]]) fastmath : (!fir.ref) -> () +! COARRAY: mif.init -> i32 +! NOCOARRAY-NOT: mif.init diff --git a/flang/test/Lower/Coarray/num_images.f90 b/flang/test/Lower/MIF/num_images.f90 similarity index 60% rename from flang/test/Lower/Coarray/num_images.f90 rename to flang/test/Lower/MIF/num_images.f90 index ebfce5db0dbf..a673b6e8120f 100644 --- a/flang/test/Lower/Coarray/num_images.f90 +++ b/flang/test/Lower/MIF/num_images.f90 @@ -6,13 +6,13 @@ program test integer :: team_number type(team_type) :: team - ! CHECK: fir.call @_QMprifPprif_num_images + ! CHECK: mif.num_images : () -> i32 i = num_images() - ! CHECK: fir.call @_QMprifPprif_num_images_with_team_number + ! CHECK: mif.num_images team_number %[[TEAM_NUMBER:.*]] : (i32) -> i32 i = num_images(TEAM_NUMBER=team_number) - ! CHECK: fir.call @_QMprifPprif_num_images_with_team + ! CHECK: mif.num_images team %[[TEAM:.*]]#0 : ({{.*}}) -> i32 i = num_images(TEAM=team) end program diff --git a/flang/test/Lower/MIF/sync_all.f90 b/flang/test/Lower/MIF/sync_all.f90 new file mode 100644 index 000000000000..2b1997c8cc0b --- /dev/null +++ b/flang/test/Lower/MIF/sync_all.f90 @@ -0,0 +1,27 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY +! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY + +program test_sync_all + implicit none + ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. + + ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + integer sync_status + character(len=128) :: error_message + + ! COARRAY: mif.sync_all : () + sync all + + ! COARRAY: mif.sync_all stat %[[STAT]]#0 : (!fir.ref) + sync all(stat=sync_status) + + ! COARRAY: %[[VAL_1:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: mif.sync_all errmsg %[[VAL_1]] : (!fir.box>) + sync all( errmsg=error_message) + + ! COARRAY: %[[VAL_2:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: mif.sync_all stat %[[STAT]]#0 errmsg %[[VAL_2]] : (!fir.ref, !fir.box>) + sync all(stat=sync_status, errmsg=error_message) + +end program test_sync_all diff --git a/flang/test/Lower/MIF/sync_images.f90 b/flang/test/Lower/MIF/sync_images.f90 new file mode 100644 index 000000000000..7ee593613175 --- /dev/null +++ b/flang/test/Lower/MIF/sync_images.f90 @@ -0,0 +1,39 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY +! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY + +program test_sync_images + implicit none + ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. + + ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + ! COARRAY: %[[ME:.*]]:2 = hlfir.declare %[[VAL_3:.*]] {uniq_name = "_QFEme"} : (!fir.ref) -> (!fir.ref, !fir.ref) + ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + integer sync_status, me + character(len=128) :: error_message + + ! COARRAY: %[[VAL_1:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: mif.sync_images stat %[[STAT]]#0 errmsg %[[VAL_1]] : (!fir.ref, !fir.box>) + sync images(*, stat=sync_status, errmsg=error_message) + + ! COARRAY: %[[VAL_2:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: %[[VAL_3:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box + ! COARRAY: mif.sync_images image_set %[[VAL_3]] stat %[[STAT]]#0 errmsg %[[VAL_2]] : (!fir.box, !fir.ref, !fir.box>) + sync images(me, stat=sync_status, errmsg=error_message) + + ! COARRAY: %[[VAL_4:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: %[[VAL_5:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_1:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! COARRAY: mif.sync_images image_set %[[VAL_5]] stat %[[STAT]]#0 errmsg %[[VAL_4]] : (!fir.box>, !fir.ref, !fir.box>) + sync images([1], stat=sync_status, errmsg=error_message) + + ! COARRAY: mif.sync_images : () + sync images(*) + + ! COARRAY: %[[VAL_6:.*]] = fir.embox %[[ME]]#0 : (!fir.ref) -> !fir.box + ! COARRAY: mif.sync_images image_set %[[VAL_6]] : (!fir.box) + sync images(me) + + ! COARRAY: %[[VAL_7:.*]] = fir.embox %[[IMG_SET:.*]]#0(%[[SHAPE_3:.*]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> + ! COARRAY: mif.sync_images image_set %[[VAL_7]] : (!fir.box>) + sync images([1]) + +end program test_sync_images diff --git a/flang/test/Lower/MIF/sync_memory.f90 b/flang/test/Lower/MIF/sync_memory.f90 new file mode 100644 index 000000000000..e6e0fa1e7fdf --- /dev/null +++ b/flang/test/Lower/MIF/sync_memory.f90 @@ -0,0 +1,27 @@ +! RUN: %flang_fc1 -emit-hlfir -fcoarray %s -o - | FileCheck %s --check-prefixes=COARRAY +! RUN: not %flang_fc1 -emit-hlfir %s 2>&1 | FileCheck %s --check-prefixes=NOCOARRAY + +program test_sync_memory + implicit none + ! NOCOARRAY: Not yet implemented: Multi-image features are experimental and are disabled by default, use '-fcoarray' to enable. + + ! COARRAY: %[[ERRMSG:.*]]:2 = hlfir.declare %[[VAL_1:.*]] typeparams %[[C_128:.*]] {uniq_name = "_QFEerror_message"} : (!fir.ref>, index) -> (!fir.ref>, !fir.ref>) + ! COARRAY: %[[STAT:.*]]:2 = hlfir.declare %[[VAL_2:.*]] {uniq_name = "_QFEsync_status"} : (!fir.ref) -> (!fir.ref, !fir.ref) + integer sync_status + character(len=128) :: error_message + + ! COARRAY: mif.sync_memory : () + sync memory + + ! COARRAY: mif.sync_memory stat %[[STAT]]#0 : (!fir.ref) + sync memory(stat=sync_status) + + ! COARRAY: %[[VAL_1:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: mif.sync_memory errmsg %[[VAL_1]] : (!fir.box>) + sync memory( errmsg=error_message) + + ! COARRAY: %[[VAL_2:.*]] = fir.embox %[[ERRMSG]]#0 : (!fir.ref>) -> !fir.box> + ! COARRAY: mif.sync_memory stat %[[STAT]]#0 errmsg %[[VAL_2]] : (!fir.ref, !fir.box>) + sync memory(stat=sync_status, errmsg=error_message) + +end program test_sync_memory diff --git a/flang/test/Lower/Coarray/this_image.f90 b/flang/test/Lower/MIF/this_image.f90 similarity index 64% rename from flang/test/Lower/Coarray/this_image.f90 rename to flang/test/Lower/MIF/this_image.f90 index 143504b5f922..ce729b349e6c 100644 --- a/flang/test/Lower/Coarray/this_image.f90 +++ b/flang/test/Lower/MIF/this_image.f90 @@ -5,10 +5,10 @@ program test integer :: i type(team_type) :: team - ! CHECK: fir.call @_QMprifPprif_this_image_no_coarray + ! CHECK: mif.this_image : () -> i32 i = this_image() - ! CHECK: fir.call @_QMprifPprif_this_image_no_coarray + ! CHECK: mif.this_image team %[[TEAM:.*]] : ({{.*}}) -> i32 i = this_image(TEAM=team) end program diff --git a/flang/tools/bbc/CMakeLists.txt b/flang/tools/bbc/CMakeLists.txt index 7516157731b5..2d0521464a74 100644 --- a/flang/tools/bbc/CMakeLists.txt +++ b/flang/tools/bbc/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(bbc PRIVATE FortranEvaluate FortranSemantics FortranLower + MIFDialect ) mlir_target_link_libraries(bbc PRIVATE diff --git a/flang/tools/fir-lsp-server/CMakeLists.txt b/flang/tools/fir-lsp-server/CMakeLists.txt index 86cde79a6683..17ed948608c3 100644 --- a/flang/tools/fir-lsp-server/CMakeLists.txt +++ b/flang/tools/fir-lsp-server/CMakeLists.txt @@ -13,7 +13,8 @@ target_link_libraries(fir-lsp-server PRIVATE FIRDialect FIROpenACCSupport FIROpenMPSupport - HLFIRDialect) + HLFIRDialect + MIFDialect) mlir_target_link_libraries(fir-lsp-server PRIVATE MLIRLspServerLib diff --git a/flang/tools/fir-opt/CMakeLists.txt b/flang/tools/fir-opt/CMakeLists.txt index 82178c24979d..e735c2c2ff1a 100644 --- a/flang/tools/fir-opt/CMakeLists.txt +++ b/flang/tools/fir-opt/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries(fir-opt PRIVATE FIROpenMPSupport FlangOpenMPTransforms FIRAnalysis + MIFDialect ${test_libs} ) diff --git a/flang/tools/tco/CMakeLists.txt b/flang/tools/tco/CMakeLists.txt index ab2aab2cf99a..5ab8952898a6 100644 --- a/flang/tools/tco/CMakeLists.txt +++ b/flang/tools/tco/CMakeLists.txt @@ -23,6 +23,7 @@ target_link_libraries(tco PRIVATE FIROpenMPSupport FlangOpenMPTransforms FortranSupport + MIFDialect ) mlir_target_link_libraries(tco PRIVATE diff --git a/flang/unittests/Optimizer/CMakeLists.txt b/flang/unittests/Optimizer/CMakeLists.txt index a84d54d96102..3a04008b9b79 100644 --- a/flang/unittests/Optimizer/CMakeLists.txt +++ b/flang/unittests/Optimizer/CMakeLists.txt @@ -13,6 +13,7 @@ set(LIBS FIRDialectSupport FIRSupport HLFIRDialect + MIFDialect ) add_flang_unittest(FlangOptimizerTests @@ -42,7 +43,8 @@ DEPENDS CUFDialect FIRDialect FIRSupport - HLFIRDialect) + HLFIRDialect + MIFDialect) if(NOT FLANG_STANDALONE_BUILD) add_dependencies(FlangOptimizerTests