32
32
#include " llvm/Passes/StandardInstrumentations.h"
33
33
#include " llvm/Support/FileSystem.h"
34
34
#include " llvm/Support/FileUtilities.h"
35
+ #include " llvm/Support/FormatVariadic.h"
35
36
#include " llvm/Support/MemoryBuffer.h"
36
37
#include " llvm/Support/Program.h"
37
38
#include " llvm/Support/TargetSelect.h"
@@ -530,18 +531,6 @@ class CUDATargetBackend final : public TargetBackend {
530
531
// Sanitize the function name as PTX has strict requirements.
531
532
llvmFunc->setName (sanitizeSymbolName (funcOp.getName ()));
532
533
533
- auto *annotations =
534
- llvmModule->getOrInsertNamedMetadata (" nvvm.annotations" );
535
- auto setMetadataValueI32 = [&](StringRef name, int value) {
536
- llvm::Metadata *llvmMetadata[] = {
537
- llvm::ValueAsMetadata::get (llvmFunc),
538
- llvm::MDString::get (llvmModule->getContext (), name),
539
- llvm::ValueAsMetadata::get (llvm::ConstantInt::get (
540
- llvm::Type::getInt32Ty (llvmModule->getContext ()), value))};
541
- annotations->addOperand (
542
- llvm::MDNode::get (llvmModule->getContext (), llvmMetadata));
543
- };
544
-
545
534
// Mark the entry point as a kernel.
546
535
llvmFunc->setCallingConv (llvm::CallingConv::PTX_Kernel);
547
536
@@ -560,9 +549,10 @@ class CUDATargetBackend final : public TargetBackend {
560
549
maxWorkgroupSize[0 ] = std::max (maxWorkgroupSize[0 ], workgroupSize[0 ]);
561
550
maxWorkgroupSize[1 ] = std::max (maxWorkgroupSize[1 ], workgroupSize[1 ]);
562
551
maxWorkgroupSize[2 ] = std::max (maxWorkgroupSize[2 ], workgroupSize[2 ]);
563
- setMetadataValueI32 (" maxntidx" , workgroupSize[0 ]);
564
- setMetadataValueI32 (" maxntidy" , workgroupSize[1 ]);
565
- setMetadataValueI32 (" maxntidz" , workgroupSize[2 ]);
552
+ std::string maxntid = llvm::formatv (
553
+ " {0},{1},{2}" , llvm::utostr (workgroupSize[0 ]),
554
+ llvm::utostr (workgroupSize[1 ]), llvm::utostr (workgroupSize[2 ]));
555
+ llvmFunc->addFnAttr (" nvvm.maxntid" , maxntid);
566
556
}
567
557
}
568
558
0 commit comments