@@ -646,6 +646,10 @@ static constexpr IntrinsicHandler handlers[]{
646
646
{" dim" , asValue},
647
647
{" mask" , asBox, handleDynamicOptional}}},
648
648
/* 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 },
649
653
{" system" ,
650
654
&I::genSystem,
651
655
{{{" command" , asBox}, {" exitstat" , asBox, handleDynamicOptional}}},
@@ -655,6 +659,9 @@ static constexpr IntrinsicHandler handlers[]{
655
659
{{{" count" , asAddr}, {" count_rate" , asAddr}, {" count_max" , asAddr}}},
656
660
/* isElemental=*/ false },
657
661
{" tand" , &I::genTand},
662
+ {" threadfence" , &I::genThreadFence, {}, /* isElemental=*/ false },
663
+ {" threadfence_block" , &I::genThreadFenceBlock, {}, /* isElemental=*/ false },
664
+ {" threadfence_system" , &I::genThreadFenceSystem, {}, /* isElemental=*/ false },
658
665
{" trailz" , &I::genTrailz},
659
666
{" transfer" ,
660
667
&I::genTransfer,
@@ -7437,6 +7444,52 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
7437
7444
resultType, args);
7438
7445
}
7439
7446
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
+
7440
7493
// SYSTEM
7441
7494
fir::ExtendedValue
7442
7495
IntrinsicLibrary::genSystem (std::optional<mlir::Type> resultType,
@@ -7567,6 +7620,38 @@ IntrinsicLibrary::genTranspose(mlir::Type resultType,
7567
7620
return readAndAddCleanUp (resultMutableBox, resultType, " TRANSPOSE" );
7568
7621
}
7569
7622
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
+
7570
7655
// TRIM
7571
7656
fir::ExtendedValue
7572
7657
IntrinsicLibrary::genTrim (mlir::Type resultType,
0 commit comments