3232#include " llvm/Passes/StandardInstrumentations.h"
3333#include " llvm/Support/FileSystem.h"
3434#include " llvm/Support/FileUtilities.h"
35+ #include " llvm/Support/FormatVariadic.h"
3536#include " llvm/Support/MemoryBuffer.h"
3637#include " llvm/Support/Program.h"
3738#include " llvm/Support/TargetSelect.h"
@@ -530,18 +531,6 @@ class CUDATargetBackend final : public TargetBackend {
530531 // Sanitize the function name as PTX has strict requirements.
531532 llvmFunc->setName (sanitizeSymbolName (funcOp.getName ()));
532533
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-
545534 // Mark the entry point as a kernel.
546535 llvmFunc->setCallingConv (llvm::CallingConv::PTX_Kernel);
547536
@@ -560,9 +549,10 @@ class CUDATargetBackend final : public TargetBackend {
560549 maxWorkgroupSize[0 ] = std::max (maxWorkgroupSize[0 ], workgroupSize[0 ]);
561550 maxWorkgroupSize[1 ] = std::max (maxWorkgroupSize[1 ], workgroupSize[1 ]);
562551 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);
566556 }
567557 }
568558
0 commit comments