@@ -646,6 +646,10 @@ static constexpr IntrinsicHandler handlers[]{
646646 {" dim" , asValue},
647647 {" mask" , asBox, handleDynamicOptional}}},
648648 /* isElemental=*/ false },
649+ {" syncthreads" , &I::genSyncThreads, {}, /* isElemental=*/ false },
650+ {" syncthreads_and" , &I::genSyncThreadsAnd, {}, /* isElemental=*/ false },
651+ {" syncthreads_count" , &I::genSyncThreadsCount, {}, /* isElemental=*/ false },
652+ {" syncthreads_or" , &I::genSyncThreadsOr, {}, /* isElemental=*/ false },
649653 {" system" ,
650654 &I::genSystem,
651655 {{{" command" , asBox}, {" exitstat" , asBox, handleDynamicOptional}}},
@@ -655,6 +659,9 @@ static constexpr IntrinsicHandler handlers[]{
655659 {{{" count" , asAddr}, {" count_rate" , asAddr}, {" count_max" , asAddr}}},
656660 /* isElemental=*/ false },
657661 {" tand" , &I::genTand},
662+ {" threadfence" , &I::genThreadFence, {}, /* isElemental=*/ false },
663+ {" threadfence_block" , &I::genThreadFenceBlock, {}, /* isElemental=*/ false },
664+ {" threadfence_system" , &I::genThreadFenceSystem, {}, /* isElemental=*/ false },
658665 {" trailz" , &I::genTrailz},
659666 {" transfer" ,
660667 &I::genTransfer,
@@ -7437,6 +7444,52 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
74377444 resultType, args);
74387445}
74397446
7447+ // SYNCTHREADS
7448+ void IntrinsicLibrary::genSyncThreads (llvm::ArrayRef<fir::ExtendedValue> args) {
7449+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0" ;
7450+ mlir::FunctionType funcType =
7451+ mlir::FunctionType::get (builder.getContext (), {}, {});
7452+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7453+ llvm::SmallVector<mlir::Value> noArgs;
7454+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7455+ }
7456+
7457+ // SYNCTHREADS_AND
7458+ mlir::Value
7459+ IntrinsicLibrary::genSyncThreadsAnd (mlir::Type resultType,
7460+ llvm::ArrayRef<mlir::Value> args) {
7461+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.and" ;
7462+ mlir::MLIRContext *context = builder.getContext ();
7463+ mlir::FunctionType ftype =
7464+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7465+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7466+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7467+ }
7468+
7469+ // SYNCTHREADS_COUNT
7470+ mlir::Value
7471+ IntrinsicLibrary::genSyncThreadsCount (mlir::Type resultType,
7472+ llvm::ArrayRef<mlir::Value> args) {
7473+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.popc" ;
7474+ mlir::MLIRContext *context = builder.getContext ();
7475+ mlir::FunctionType ftype =
7476+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7477+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7478+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7479+ }
7480+
7481+ // SYNCTHREADS_OR
7482+ mlir::Value
7483+ IntrinsicLibrary::genSyncThreadsOr (mlir::Type resultType,
7484+ llvm::ArrayRef<mlir::Value> args) {
7485+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.barrier0.or" ;
7486+ mlir::MLIRContext *context = builder.getContext ();
7487+ mlir::FunctionType ftype =
7488+ mlir::FunctionType::get (context, {resultType}, {args[0 ].getType ()});
7489+ auto funcOp = builder.createFunction (loc, funcName, ftype);
7490+ return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
7491+ }
7492+
74407493// SYSTEM
74417494fir::ExtendedValue
74427495IntrinsicLibrary::genSystem (std::optional<mlir::Type> resultType,
@@ -7567,6 +7620,38 @@ IntrinsicLibrary::genTranspose(mlir::Type resultType,
75677620 return readAndAddCleanUp (resultMutableBox, resultType, " TRANSPOSE" );
75687621}
75697622
7623+ // THREADFENCE
7624+ void IntrinsicLibrary::genThreadFence (llvm::ArrayRef<fir::ExtendedValue> args) {
7625+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.gl" ;
7626+ mlir::FunctionType funcType =
7627+ mlir::FunctionType::get (builder.getContext (), {}, {});
7628+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7629+ llvm::SmallVector<mlir::Value> noArgs;
7630+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7631+ }
7632+
7633+ // THREADFENCE_BLOCK
7634+ void IntrinsicLibrary::genThreadFenceBlock (
7635+ llvm::ArrayRef<fir::ExtendedValue> args) {
7636+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.cta" ;
7637+ mlir::FunctionType funcType =
7638+ mlir::FunctionType::get (builder.getContext (), {}, {});
7639+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7640+ llvm::SmallVector<mlir::Value> noArgs;
7641+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7642+ }
7643+
7644+ // THREADFENCE_SYSTEM
7645+ void IntrinsicLibrary::genThreadFenceSystem (
7646+ llvm::ArrayRef<fir::ExtendedValue> args) {
7647+ constexpr llvm::StringLiteral funcName = " llvm.nvvm.membar.sys" ;
7648+ mlir::FunctionType funcType =
7649+ mlir::FunctionType::get (builder.getContext (), {}, {});
7650+ auto funcOp = builder.createFunction (loc, funcName, funcType);
7651+ llvm::SmallVector<mlir::Value> noArgs;
7652+ builder.create <fir::CallOp>(loc, funcOp, noArgs);
7653+ }
7654+
75707655// TRIM
75717656fir::ExtendedValue
75727657IntrinsicLibrary::genTrim (mlir::Type resultType,
0 commit comments