[Mlir-commits] [mlir] [MLIR][LLVM] Add support for translation of partition attribute (PR #109114)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Sep 18 02:43:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-llvm
Author: lemon (lemoncmd)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/109114.diff
7 Files Affected:
- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td (+2)
- (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+5)
- (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+6)
- (modified) mlir/test/Dialect/LLVMIR/global.mlir (+3)
- (modified) mlir/test/Target/LLVMIR/Import/function-attributes.ll (+8)
- (modified) mlir/test/Target/LLVMIR/Import/global-variables.ll (+8)
- (modified) mlir/test/Target/LLVMIR/llvmir.mlir (+15)
``````````diff
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index d956d7f27f784d..90698abf5d644c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1126,6 +1126,7 @@ def LLVM_GlobalOp : LLVM_Op<"mlir.global",
DefaultValuedAttr<ConfinedAttr<I32Attr, [IntNonNegative]>, "0">:$addr_space,
OptionalAttr<UnnamedAddr>:$unnamed_addr,
OptionalAttr<StrAttr>:$section,
+ OptionalAttr<StrAttr>:$partition,
OptionalAttr<SymbolRefAttr>:$comdat,
DefaultValuedAttr<LLVM_DIGlobalVariableExpressionAttr, "{}">:$dbg_expr,
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_
@@ -1437,6 +1438,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
OptionalAttr<UnitAttr>:$arm_inout_za,
OptionalAttr<UnitAttr>:$arm_preserves_za,
OptionalAttr<StrAttr>:$section,
+ OptionalAttr<StrAttr>:$partition,
OptionalAttr<UnnamedAddr>:$unnamed_addr,
OptionalAttr<I64Attr>:$alignment,
OptionalAttr<LLVM_VScaleRangeAttr>:$vscale_range,
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 21f2050cbceb9c..1f0cb3dcc8ba01 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -947,6 +947,8 @@ LogicalResult ModuleImport::convertGlobal(llvm::GlobalVariable *globalVar) {
}
if (globalVar->hasSection())
globalOp.setSection(globalVar->getSection());
+ if (globalVar->hasPartition())
+ globalOp.setPartition(globalVar->getPartition());
globalOp.setVisibility_(
convertVisibilityFromLLVM(globalVar->getVisibility()));
@@ -1997,6 +1999,9 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
if (func->hasSection())
funcOp.setSection(StringRef(func->getSection()));
+ if (func->hasPartition())
+ funcOp.setPartition(StringRef(func->getPartition()));
+
funcOp.setVisibility_(convertVisibilityFromLLVM(func->getVisibility()));
if (func->hasComdat())
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index fcb329eb7a92c1..4963c456c26c68 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1050,6 +1050,9 @@ LogicalResult ModuleTranslation::convertGlobals() {
if (op.getSection().has_value())
var->setSection(*op.getSection());
+ if (op.getPartition().has_value())
+ var->setPartition(*op.getPartition());
+
addRuntimePreemptionSpecifier(op.getDsoLocal(), var);
std::optional<uint64_t> alignment = op.getAlignment();
@@ -1347,6 +1350,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
if (std::optional<StringRef> section = func.getSection())
llvmFunc->setSection(*section);
+ if (std::optional<StringRef> partition = func.getPartition())
+ llvmFunc->setPartition(*partition);
+
if (func.getArmStreaming())
llvmFunc->addFnAttr("aarch64_pstate_sm_enabled");
else if (func.getArmLocallyStreaming())
diff --git a/mlir/test/Dialect/LLVMIR/global.mlir b/mlir/test/Dialect/LLVMIR/global.mlir
index 3fa7636d4dd686..7f356815c665be 100644
--- a/mlir/test/Dialect/LLVMIR/global.mlir
+++ b/mlir/test/Dialect/LLVMIR/global.mlir
@@ -95,6 +95,9 @@ llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64
// CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {addr_space = 0 : i32, section = ".mysection"}
llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}: !llvm.array<10 x i8>
+// CHECK: llvm.mlir.global internal constant @partitionvar("teststring") {addr_space = 0 : i32, partition = "part1"}
+llvm.mlir.global internal constant @partitionvar("teststring") {partition = "part1"}: !llvm.array<10 x i8>
+
// CHECK: llvm.mlir.global internal thread_local constant @thread_local(42 : i32)
llvm.mlir.global internal thread_local constant @thread_local(42 : i32) : i32
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index 912f448657baa7..4d3f09a0797e34 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -260,6 +260,14 @@ define void @section_func() section ".section.name" {
// -----
+; CHECK-LABEL: @partition_func
+; CHECK-SAME: attributes {partition = "part1"}
+define void @partition_func() partition "part1" {
+ ret void
+}
+
+// -----
+
; CHECK-LABEL: local_unnamed_addr @local_unnamed_addr_func
define void @local_unnamed_addr_func() local_unnamed_addr {
ret void
diff --git a/mlir/test/Target/LLVMIR/Import/global-variables.ll b/mlir/test/Target/LLVMIR/Import/global-variables.ll
index cac7411431ae35..7bf2899a7a1664 100644
--- a/mlir/test/Target/LLVMIR/Import/global-variables.ll
+++ b/mlir/test/Target/LLVMIR/Import/global-variables.ll
@@ -155,6 +155,14 @@
; // -----
+; partition attribute.
+
+; CHECK: llvm.mlir.global internal constant @partitionvar("hello world")
+; CHECK-SAME: {addr_space = 0 : i32, dso_local, partition = "part1"}
+ at partitionvar = internal constant [11 x i8] c"hello world", partition "part1"
+
+; // -----
+
; Sequential constants.
; CHECK: llvm.mlir.global internal constant @vector_constant
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 7eca1a40373054..c77e1a85e69709 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -186,6 +186,13 @@ llvm.mlir.global thread_local @has_thr_local(42 : i64) : i64
// CHECK: @sectionvar = internal constant [10 x i8] c"teststring", section ".mysection"
llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}: !llvm.array<10 x i8>
+//
+// Partition attribute.
+//
+
+// CHECK: @partitionvar = internal constant [10 x i8] c"teststring", partition "part1"
+llvm.mlir.global internal constant @partitionvar("teststring") {partition = "part1"}: !llvm.array<10 x i8>
+
//
// Declarations of the allocation functions to be linked against. These are
// inserted before other functions in the module.
@@ -1688,6 +1695,14 @@ llvm.func @section_func() attributes { section = ".section.name" } {
// -----
+// CHECK-LABEL: @partition_func
+// CHECK-SAME: partition "part1"
+llvm.func @partition_func() attributes { partition = "part1" } {
+ llvm.return
+}
+
+// -----
+
// CHECK-LABEL: @local_unnamed_addr_func
// CHECK-SAME: local_unnamed_addr
llvm.func local_unnamed_addr @local_unnamed_addr_func() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/109114
More information about the Mlir-commits
mailing list