@@ -397,6 +397,34 @@ static constexpr IntrinsicHandler handlers[]{
397397 {" cmplx" ,
398398 &I::genCmplx,
399399 {{{" x" , asValue}, {" y" , asValue, handleDynamicOptional}}}},
400+ {" co_broadcast" ,
401+ &I::genCoBroadcast,
402+ {{{" a" , asBox},
403+ {" source_image" , asAddr},
404+ {" stat" , asAddr, handleDynamicOptional},
405+ {" errmsg" , asBox, handleDynamicOptional}}},
406+ /* isElemental*/ false },
407+ {" co_max" ,
408+ &I::genCoMax,
409+ {{{" a" , asBox},
410+ {" result_image" , asAddr, handleDynamicOptional},
411+ {" stat" , asAddr, handleDynamicOptional},
412+ {" errmsg" , asBox, handleDynamicOptional}}},
413+ /* isElemental*/ false },
414+ {" co_min" ,
415+ &I::genCoMin,
416+ {{{" a" , asBox},
417+ {" result_image" , asAddr, handleDynamicOptional},
418+ {" stat" , asAddr, handleDynamicOptional},
419+ {" errmsg" , asBox, handleDynamicOptional}}},
420+ /* isElemental*/ false },
421+ {" co_sum" ,
422+ &I::genCoSum,
423+ {{{" a" , asBox},
424+ {" result_image" , asAddr, handleDynamicOptional},
425+ {" stat" , asAddr, handleDynamicOptional},
426+ {" errmsg" , asBox, handleDynamicOptional}}},
427+ /* isElemental*/ false },
400428 {" command_argument_count" , &I::genCommandArgumentCount},
401429 {" conjg" , &I::genConjg},
402430 {" cosd" , &I::genCosd},
@@ -3686,6 +3714,85 @@ mlir::Value IntrinsicLibrary::genCmplx(mlir::Type resultType,
36863714 imag);
36873715}
36883716
3717+ // CO_BROADCAST
3718+ void IntrinsicLibrary::genCoBroadcast (llvm::ArrayRef<fir::ExtendedValue> args) {
3719+ checkCoarrayEnabled ();
3720+ assert (args.size () == 4 );
3721+ mlir::Value sourceImage = fir::getBase (args[1 ]);
3722+ mlir::Value status =
3723+ isStaticallyAbsent (args[2 ])
3724+ ? fir::AbsentOp::create (builder, loc,
3725+ builder.getRefType (builder.getI32Type ()))
3726+ .getResult ()
3727+ : fir::getBase (args[2 ]);
3728+ mlir::Value errmsg =
3729+ isStaticallyAbsent (args[3 ])
3730+ ? fir::AbsentOp::create (builder, loc, PRIF_ERRMSG_TYPE).getResult ()
3731+ : fir::getBase (args[3 ]);
3732+ fir::runtime::genCoBroadcast (builder, loc, fir::getBase (args[0 ]), sourceImage,
3733+ status, errmsg);
3734+ }
3735+
3736+ // CO_MAX
3737+ void IntrinsicLibrary::genCoMax (llvm::ArrayRef<fir::ExtendedValue> args) {
3738+ checkCoarrayEnabled ();
3739+ assert (args.size () == 4 );
3740+ mlir::Value refNone =
3741+ fir::AbsentOp::create (builder, loc,
3742+ builder.getRefType (builder.getI32Type ()))
3743+ .getResult ();
3744+ mlir::Value resultImage =
3745+ isStaticallyAbsent (args[1 ]) ? refNone : fir::getBase (args[1 ]);
3746+ mlir::Value status =
3747+ isStaticallyAbsent (args[2 ]) ? refNone : fir::getBase (args[2 ]);
3748+ mlir::Value errmsg =
3749+ isStaticallyAbsent (args[3 ])
3750+ ? fir::AbsentOp::create (builder, loc, PRIF_ERRMSG_TYPE).getResult ()
3751+ : fir::getBase (args[3 ]);
3752+ fir::runtime::genCoMax (builder, loc, fir::getBase (args[0 ]), resultImage,
3753+ status, errmsg);
3754+ }
3755+
3756+ // CO_MIN
3757+ void IntrinsicLibrary::genCoMin (llvm::ArrayRef<fir::ExtendedValue> args) {
3758+ checkCoarrayEnabled ();
3759+ assert (args.size () == 4 );
3760+ mlir::Value refNone =
3761+ fir::AbsentOp::create (builder, loc,
3762+ builder.getRefType (builder.getI32Type ()))
3763+ .getResult ();
3764+ mlir::Value resultImage =
3765+ isStaticallyAbsent (args[1 ]) ? refNone : fir::getBase (args[1 ]);
3766+ mlir::Value status =
3767+ isStaticallyAbsent (args[2 ]) ? refNone : fir::getBase (args[2 ]);
3768+ mlir::Value errmsg =
3769+ isStaticallyAbsent (args[3 ])
3770+ ? fir::AbsentOp::create (builder, loc, PRIF_ERRMSG_TYPE).getResult ()
3771+ : fir::getBase (args[3 ]);
3772+ fir::runtime::genCoMin (builder, loc, fir::getBase (args[0 ]), resultImage,
3773+ status, errmsg);
3774+ }
3775+
3776+ // CO_SUM
3777+ void IntrinsicLibrary::genCoSum (llvm::ArrayRef<fir::ExtendedValue> args) {
3778+ checkCoarrayEnabled ();
3779+ assert (args.size () == 4 );
3780+ mlir::Value absentInt =
3781+ fir::AbsentOp::create (builder, loc,
3782+ builder.getRefType (builder.getI32Type ()))
3783+ .getResult ();
3784+ mlir::Value resultImage =
3785+ isStaticallyAbsent (args[1 ]) ? absentInt : fir::getBase (args[1 ]);
3786+ mlir::Value status =
3787+ isStaticallyAbsent (args[2 ]) ? absentInt : fir::getBase (args[2 ]);
3788+ mlir::Value errmsg =
3789+ isStaticallyAbsent (args[3 ])
3790+ ? fir::AbsentOp::create (builder, loc, PRIF_ERRMSG_TYPE).getResult ()
3791+ : fir::getBase (args[3 ]);
3792+ fir::runtime::genCoSum (builder, loc, fir::getBase (args[0 ]), resultImage,
3793+ status, errmsg);
3794+ }
3795+
36893796// COMMAND_ARGUMENT_COUNT
36903797fir::ExtendedValue IntrinsicLibrary::genCommandArgumentCount (
36913798 mlir::Type resultType, llvm::ArrayRef<fir::ExtendedValue> args) {
0 commit comments