@@ -642,6 +642,10 @@ static constexpr IntrinsicHandler handlers[]{
642642 {" dim" , asValue},
643643 {" mask" , asBox, handleDynamicOptional}}},
644644 /* isElemental=*/ false },
645+ {" syncthreads" , &I::genSyncThreads, {}, /* isElemental=*/ false },
646+ {" syncthreads_and" , &I::genSyncThreadsAnd, {}, /* isElemental=*/ false },
647+ {" syncthreads_count" , &I::genSyncThreadsCount, {}, /* isElemental=*/ false },
648+ {" syncthreads_or" , &I::genSyncThreadsOr, {}, /* isElemental=*/ false },
645649 {" system" ,
646650 &I::genSystem,
647651 {{{" command" , asBox}, {" exitstat" , asBox, handleDynamicOptional}}},
@@ -660,6 +664,9 @@ static constexpr IntrinsicHandler handlers[]{
660664 &I::genTranspose,
661665 {{{" matrix" , asAddr}}},
662666 /* isElemental=*/ false },
667+ {" threadfence" , &I::genThreadFence, {}, /* isElemental=*/ false },
668+ {" threadfence_block" , &I::genThreadFenceBlock, {}, /* isElemental=*/ false },
669+ {" threadfence_system" , &I::genThreadFenceSystem, {}, /* isElemental=*/ false },
663670 {" trim" , &I::genTrim, {{{" string" , asAddr}}}, /* isElemental=*/ false },
664671 {" ubound" ,
665672 &I::genUbound,
@@ -7290,6 +7297,52 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
72907297 resultType, args);
72917298}
72927299
7300+ // SYNCTHREADS
7301+ void IntrinsicLibrary::genSyncThreads (llvm::ArrayRef<fir::ExtendedValue> args) {
7302+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0" ;
7303+ mlir::FunctionType funcType =
7304+ mlir::FunctionType::get (builder.getContext (), {}, {});
7305+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7306+ llvm::SmallVector<mlir::Value> noArgs;
7307+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7308+ }
7309+
7310+ // SYNCTHREADS_AND
7311+ mlir::Value
7312+ IntrinsicLibrary::genSyncThreadsAnd (mlir::Type resultType,
7313+ llvm::ArrayRef<mlir::Value> args) {
7314+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.and" ;
7315+ mlir::MLIRContext *context = builder.getContext ();
7316+ mlir::FunctionType ftype =
7317+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7318+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7319+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7320+ }
7321+
7322+ // SYNCTHREADS_COUNT
7323+ mlir::Value
7324+ IntrinsicLibrary::genSyncThreadsCount (mlir::Type resultType,
7325+ llvm::ArrayRef<mlir::Value> args) {
7326+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.popc" ;
7327+ mlir::MLIRContext *context = builder.getContext ();
7328+ mlir::FunctionType ftype =
7329+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7330+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7331+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7332+ }
7333+
7334+ // SYNCTHREADS_OR
7335+ mlir::Value
7336+ IntrinsicLibrary::genSyncThreadsOr (mlir::Type resultType,
7337+ llvm::ArrayRef<mlir::Value> args) {
7338+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.or" ;
7339+ mlir::MLIRContext *context = builder.getContext ();
7340+ mlir::FunctionType ftype =
7341+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7342+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7343+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7344+ }
7345+
72937346// SYSTEM
72947347fir::ExtendedValue
72957348IntrinsicLibrary::genSystem (std::optional<mlir::Type> resultType,
@@ -7420,6 +7473,38 @@ IntrinsicLibrary::genTranspose(mlir::Type resultType,
74207473 return readAndAddCleanUp (resultMutableBox, resultType, " TRANSPOSE" );
74217474}
74227475
7476+ // THREADFENCE
7477+ void IntrinsicLibrary::genThreadFence (llvm::ArrayRef<fir::ExtendedValue> args) {
7478+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.gl" ;
7479+ mlir::FunctionType funcType =
7480+ mlir::FunctionType::get (builder.getContext (), {}, {});
7481+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7482+ llvm::SmallVector<mlir::Value> noArgs;
7483+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7484+ }
7485+
7486+ // THREADFENCE_BLOCK
7487+ void IntrinsicLibrary::genThreadFenceBlock (
7488+ llvm::ArrayRef<fir::ExtendedValue> args) {
7489+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.cta" ;
7490+ mlir::FunctionType funcType =
7491+ mlir::FunctionType::get (builder.getContext (), {}, {});
7492+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7493+ llvm::SmallVector<mlir::Value> noArgs;
7494+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7495+ }
7496+
7497+ // THREADFENCE_SYSTEM
7498+ void IntrinsicLibrary::genThreadFenceSystem (
7499+ llvm::ArrayRef<fir::ExtendedValue> args) {
7500+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.sys" ;
7501+ mlir::FunctionType funcType =
7502+ mlir::FunctionType::get (builder.getContext (), {}, {});
7503+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7504+ llvm::SmallVector<mlir::Value> noArgs;
7505+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7506+ }
7507+
74237508// TRIM
74247509fir::ExtendedValue
74257510IntrinsicLibrary::genTrim (mlir::Type resultType,
0 commit comments