|
25 | 25 | #include "flang/Optimizer/Builder/Runtime/Allocatable.h"
|
26 | 26 | #include "flang/Optimizer/Builder/Runtime/CUDA/Descriptor.h"
|
27 | 27 | #include "flang/Optimizer/Builder/Runtime/Character.h"
|
| 28 | +#include "flang/Optimizer/Builder/Runtime/Coarray.h" |
28 | 29 | #include "flang/Optimizer/Builder/Runtime/Command.h"
|
29 | 30 | #include "flang/Optimizer/Builder/Runtime/Derived.h"
|
30 | 31 | #include "flang/Optimizer/Builder/Runtime/Exceptions.h"
|
@@ -778,6 +779,10 @@ static constexpr IntrinsicHandler handlers[]{
|
778 | 779 | /*isElemental=*/false},
|
779 | 780 | {"not", &I::genNot},
|
780 | 781 | {"null", &I::genNull, {{{"mold", asInquired}}}, /*isElemental=*/false},
|
| 782 | + {"num_images", |
| 783 | + &I::genNumImages, |
| 784 | + {{{"team", asAddr}, {"team_number", asAddr}}}, |
| 785 | + /*isElemental*/ false}, |
781 | 786 | {"pack",
|
782 | 787 | &I::genPack,
|
783 | 788 | {{{"array", asBox},
|
@@ -947,6 +952,12 @@ static constexpr IntrinsicHandler handlers[]{
|
947 | 952 | {"tand", &I::genTand},
|
948 | 953 | {"tanpi", &I::genTanpi},
|
949 | 954 | {"this_grid", &I::genThisGrid, {}, /*isElemental=*/false},
|
| 955 | + {"this_image", |
| 956 | + &I::genThisImage, |
| 957 | + {{{"coarray", asBox}, |
| 958 | + {"dim", asAddr}, |
| 959 | + {"team", asBox, handleDynamicOptional}}}, |
| 960 | + /*isElemental=*/false}, |
950 | 961 | {"this_thread_block", &I::genThisThreadBlock, {}, /*isElemental=*/false},
|
951 | 962 | {"this_warp", &I::genThisWarp, {}, /*isElemental=*/false},
|
952 | 963 | {"threadfence", &I::genThreadFence, {}, /*isElemental=*/false},
|
@@ -7279,6 +7290,19 @@ IntrinsicLibrary::genNull(mlir::Type, llvm::ArrayRef<fir::ExtendedValue> args) {
|
7279 | 7290 | return fir::MutableBoxValue(boxStorage, mold->nonDeferredLenParams(), {});
|
7280 | 7291 | }
|
7281 | 7292 |
|
| 7293 | +// NUM_IMAGES |
| 7294 | +fir::ExtendedValue |
| 7295 | +IntrinsicLibrary::genNumImages(mlir::Type resultType, |
| 7296 | + llvm::ArrayRef<fir::ExtendedValue> args) { |
| 7297 | + checkCoarrayEnabled(); |
| 7298 | + assert(args.size() == 0 || args.size() == 1); |
| 7299 | + |
| 7300 | + if (args.size()) |
| 7301 | + return fir::runtime::getNumImagesWithTeam(builder, loc, |
| 7302 | + fir::getBase(args[0])); |
| 7303 | + return fir::runtime::getNumImages(builder, loc); |
| 7304 | +} |
| 7305 | + |
7282 | 7306 | // CLOCK, CLOCK64, GLOBALTIMER
|
7283 | 7307 | template <typename OpTy>
|
7284 | 7308 | mlir::Value IntrinsicLibrary::genNVVMTime(mlir::Type resultType,
|
@@ -8329,6 +8353,27 @@ mlir::Value IntrinsicLibrary::genThisGrid(mlir::Type resultType,
|
8329 | 8353 | return res;
|
8330 | 8354 | }
|
8331 | 8355 |
|
| 8356 | +// THIS_IMAGE |
| 8357 | +fir::ExtendedValue |
| 8358 | +IntrinsicLibrary::genThisImage(mlir::Type resultType, |
| 8359 | + llvm::ArrayRef<fir::ExtendedValue> args) { |
| 8360 | + checkCoarrayEnabled(); |
| 8361 | + assert(args.size() >= 1 && args.size() <= 3); |
| 8362 | + const bool coarrayIsAbsent = args.size() == 1; |
| 8363 | + mlir::Value team = |
| 8364 | + !isStaticallyAbsent(args, args.size() - 1) |
| 8365 | + ? fir::getBase(args[args.size() - 1]) |
| 8366 | + : builder |
| 8367 | + .create<fir::AbsentOp>(loc, |
| 8368 | + fir::BoxType::get(builder.getNoneType())) |
| 8369 | + .getResult(); |
| 8370 | + |
| 8371 | + if (!coarrayIsAbsent) |
| 8372 | + TODO(loc, "this_image with coarray argument."); |
| 8373 | + mlir::Value res = fir::runtime::getThisImage(builder, loc, team); |
| 8374 | + return builder.createConvert(loc, resultType, res); |
| 8375 | +} |
| 8376 | + |
8332 | 8377 | // THIS_THREAD_BLOCK
|
8333 | 8378 | mlir::Value
|
8334 | 8379 | IntrinsicLibrary::genThisThreadBlock(mlir::Type resultType,
|
|
0 commit comments