[Mlir-commits] [mlir] Populate the llvm::GlobalVariable ELF section, with the attribute from the ObjectAttrs (PR #117246)
Renaud Kauffmann
llvmlistbot at llvm.org
Thu Nov 21 14:52:03 PST 2024
https://github.com/Renaud-K updated https://github.com/llvm/llvm-project/pull/117246
>From fa144ca78374b04ac3e86377ab9214bc7e612a81 Mon Sep 17 00:00:00 2001
From: Renaud-K <rkauffmann at nvidia.com>
Date: Thu, 21 Nov 2024 13:59:26 -0800
Subject: [PATCH 1/2] Specifying ELF section on llvm::GlobalVariable if
ObjectAttr attribute exists
---
mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp b/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp
index b023c4c126da30..3aeadeb283ff69 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp
@@ -121,6 +121,13 @@ LogicalResult SelectObjectAttrImpl::embedBinary(
new llvm::GlobalVariable(*module, binary->getType(), true,
llvm::GlobalValue::LinkageTypes::InternalLinkage,
binary, getBinaryIdentifier(op.getName()));
+
+ if (object.getProperties()) {
+ if (auto section = mlir::dyn_cast_or_null<mlir::StringAttr>(
+ object.getProperties().get("section"))) {
+ serializedObj->setSection(section.getValue());
+ }
+ }
serializedObj->setLinkage(llvm::GlobalValue::LinkageTypes::InternalLinkage);
serializedObj->setAlignment(llvm::MaybeAlign(8));
serializedObj->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
>From 5fcf67b4f91784370eaa720a433653093ffb291a Mon Sep 17 00:00:00 2001
From: Renaud-K <rkauffmann at nvidia.com>
Date: Thu, 21 Nov 2024 14:50:57 -0800
Subject: [PATCH 2/2] Adding test
---
mlir/test/Target/LLVMIR/gpu.mlir | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mlir/test/Target/LLVMIR/gpu.mlir b/mlir/test/Target/LLVMIR/gpu.mlir
index 0f41f0b1a59d12..6b7e7fcc71960d 100644
--- a/mlir/test/Target/LLVMIR/gpu.mlir
+++ b/mlir/test/Target/LLVMIR/gpu.mlir
@@ -101,3 +101,11 @@ module attributes {gpu.container_module} {
llvm.return
}
}
+
+// -----
+
+// Checking that ELF section is populated
+module attributes {gpu.container_module} {
+ // CHECK: @cuda_device_mod_bin_cst = internal constant [4 x i8] c"BLOB", section "__nv_rel_fatbin", align 8
+ gpu.binary @cuda_device_mod [#gpu.object<#nvvm.target, properties = {section = "__nv_rel_fatbin"}, "BLOB">]
+}
More information about the Mlir-commits
mailing list