48
48
#include " mlir/Dialect/Complex/IR/Complex.h"
49
49
#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
50
50
#include " mlir/Dialect/LLVMIR/LLVMTypes.h"
51
- #include " mlir/Dialect/LLVMIR/NVVMDialect.h"
52
51
#include " mlir/Dialect/Math/IR/Math.h"
53
52
#include " mlir/Dialect/Vector/IR/VectorOps.h"
54
53
#include " llvm/Support/CommandLine.h"
@@ -262,7 +261,7 @@ static constexpr IntrinsicHandler handlers[]{
262
261
{{{" mask" , asAddr}, {" dim" , asValue}}},
263
262
/* isElemental=*/ false },
264
263
{" all_sync" ,
265
- &I::genVoteAllSync ,
264
+ &I::genVoteSync<mlir::NVVM::VoteSyncKind::all> ,
266
265
{{{" mask" , asValue}, {" pred" , asValue}}},
267
266
/* isElemental=*/ false },
268
267
{" allocated" ,
@@ -275,7 +274,7 @@ static constexpr IntrinsicHandler handlers[]{
275
274
{{{" mask" , asAddr}, {" dim" , asValue}}},
276
275
/* isElemental=*/ false },
277
276
{" any_sync" ,
278
- &I::genVoteAnySync ,
277
+ &I::genVoteSync<mlir::NVVM::VoteSyncKind::any> ,
279
278
{{{" mask" , asValue}, {" pred" , asValue}}},
280
279
/* isElemental=*/ false },
281
280
{" asind" , &I::genAsind},
@@ -341,7 +340,7 @@ static constexpr IntrinsicHandler handlers[]{
341
340
{" atomicsubl" , &I::genAtomicSub, {{{" a" , asAddr}, {" v" , asValue}}}, false },
342
341
{" atomicxori" , &I::genAtomicXor, {{{" a" , asAddr}, {" v" , asValue}}}, false },
343
342
{" ballot_sync" ,
344
- &I::genVoteBallotSync ,
343
+ &I::genVoteSync<mlir::NVVM::VoteSyncKind::ballot> ,
345
344
{{{" mask" , asValue}, {" pred" , asValue}}},
346
345
/* isElemental=*/ false },
347
346
{" bessel_jn" ,
@@ -6583,46 +6582,20 @@ IntrinsicLibrary::genMatchAllSync(mlir::Type resultType,
6583
6582
return value;
6584
6583
}
6585
6584
6586
- static mlir::Value genVoteSync (fir::FirOpBuilder &builder, mlir::Location loc,
6587
- llvm::StringRef funcName, mlir::Type resTy,
6588
- llvm::ArrayRef<mlir::Value> args) {
6589
- mlir::MLIRContext *context = builder.getContext ();
6590
- mlir::Type i32Ty = builder.getI32Type ();
6591
- mlir::Type i1Ty = builder.getI1Type ();
6592
- mlir::FunctionType ftype =
6593
- mlir::FunctionType::get (context, {i32Ty, i1Ty}, {resTy});
6594
- auto funcOp = builder.createFunction (loc, funcName, ftype);
6595
- llvm::SmallVector<mlir::Value> filteredArgs;
6596
- return builder.create <fir::CallOp>(loc, funcOp, args).getResult (0 );
6597
- }
6598
-
6599
- // ALL_SYNC
6600
- mlir::Value IntrinsicLibrary::genVoteAllSync (mlir::Type resultType,
6601
- llvm::ArrayRef<mlir::Value> args) {
6602
- assert (args.size () == 2 );
6603
- return genVoteSync (builder, loc, " llvm.nvvm.vote.all.sync" ,
6604
- builder.getI1Type (), args);
6605
- }
6606
-
6607
- // ANY_SYNC
6608
- mlir::Value IntrinsicLibrary::genVoteAnySync (mlir::Type resultType,
6609
- llvm::ArrayRef<mlir::Value> args) {
6610
- assert (args.size () == 2 );
6611
- return genVoteSync (builder, loc, " llvm.nvvm.vote.any.sync" ,
6612
- builder.getI1Type (), args);
6613
- }
6614
-
6615
- // BALLOT_SYNC
6616
- mlir::Value
6617
- IntrinsicLibrary::genVoteBallotSync (mlir::Type resultType,
6618
- llvm::ArrayRef<mlir::Value> args) {
6585
+ // ALL_SYNC, ANY_SYNC, BALLOT_SYNC
6586
+ template <mlir::NVVM::VoteSyncKind kind>
6587
+ mlir::Value IntrinsicLibrary::genVoteSync (mlir::Type resultType,
6588
+ llvm::ArrayRef<mlir::Value> args) {
6619
6589
assert (args.size () == 2 );
6620
6590
mlir::Value arg1 =
6621
6591
builder.create <fir::ConvertOp>(loc, builder.getI1Type (), args[1 ]);
6622
- return builder
6623
- .create <mlir::NVVM::VoteSyncOp>(loc, resultType, args[0 ], arg1,
6624
- mlir::NVVM::VoteSyncKind::ballot)
6625
- .getResult ();
6592
+ mlir::Type resTy = kind == mlir::NVVM::VoteSyncKind::ballot
6593
+ ? builder.getI32Type ()
6594
+ : builder.getI1Type ();
6595
+ auto voteRes =
6596
+ builder.create <mlir::NVVM::VoteSyncOp>(loc, resTy, args[0 ], arg1, kind)
6597
+ .getResult ();
6598
+ return builder.create <fir::ConvertOp>(loc, resultType, voteRes);
6626
6599
}
6627
6600
6628
6601
// MATCH_ANY_SYNC
0 commit comments