@@ -642,6 +642,10 @@ static constexpr IntrinsicHandler handlers[]{
642
642
{" dim" , asValue},
643
643
{" mask" , asBox, handleDynamicOptional}}},
644
644
/* 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 },
645
649
{" system" ,
646
650
&I::genSystem,
647
651
{{{" command" , asBox}, {" exitstat" , asBox, handleDynamicOptional}}},
@@ -660,6 +664,9 @@ static constexpr IntrinsicHandler handlers[]{
660
664
&I::genTranspose,
661
665
{{{" matrix" , asAddr}}},
662
666
/* isElemental=*/ false },
667
+ {" threadfence" , &I::genThreadFence, {}, /* isElemental=*/ false },
668
+ {" threadfence_block" , &I::genThreadFenceBlock, {}, /* isElemental=*/ false },
669
+ {" threadfence_system" , &I::genThreadFenceSystem, {}, /* isElemental=*/ false },
663
670
{" trim" , &I::genTrim, {{{" string" , asAddr}}}, /* isElemental=*/ false },
664
671
{" ubound" ,
665
672
&I::genUbound,
@@ -7290,6 +7297,52 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
7290
7297
resultType, args);
7291
7298
}
7292
7299
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
+
7293
7346
// SYSTEM
7294
7347
fir::ExtendedValue
7295
7348
IntrinsicLibrary::genSystem (std::optional<mlir::Type> resultType,
@@ -7420,6 +7473,38 @@ IntrinsicLibrary::genTranspose(mlir::Type resultType,
7420
7473
return readAndAddCleanUp (resultMutableBox, resultType, " TRANSPOSE" );
7421
7474
}
7422
7475
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
+
7423
7508
// TRIM
7424
7509
fir::ExtendedValue
7425
7510
IntrinsicLibrary::genTrim (mlir::Type resultType,
0 commit comments