[Mlir-commits] [mlir] [mlir][nvvm]Add support for grid_constant attribute on LLVM function arguments (PR #78228)

Rishi Surendran llvmlistbot at llvm.org
Tue Jan 16 17:07:41 PST 2024


================
@@ -201,6 +201,63 @@ class NVVMDialectLLVMIRTranslationInterface
     }
     return success();
   }
+
+  LogicalResult
+  convertParameterAttr(LLVMFuncOp funcOp, int argIdx, NamedAttribute attribute,
+                       LLVM::ModuleTranslation &moduleTranslation) const final {
+
+    llvm::LLVMContext &llvmContext = moduleTranslation.getLLVMContext();
+    llvm::Function *llvmFunc =
+        moduleTranslation.lookupFunction(funcOp.getName());
+    auto nvvmAnnotations =
+        moduleTranslation.getOrInsertNamedModuleMetadata("nvvm.annotations");
+
+    if (attribute.getName() == NVVM::NVVMDialect::getGridConstantAttrName()) {
+      llvm::MDNode *gridConstantMetaData = nullptr;
+
+      // Check if a 'grid_constant' metadata node exists for the given function
+      for (int i = nvvmAnnotations->getNumOperands() - 1; i >= 0; --i) {
----------------
rishisurendran wrote:

The loop is written this way for efficiency since a common case is to append to the last metadata node. If you prefer the range-based loop I will revise.

https://github.com/llvm/llvm-project/pull/78228


More information about the Mlir-commits mailing list