[Mlir-commits] [mlir] bc60964 - [mlir][LLVM] Add section attribute to LLVMFuncOp
Christian Ulmann
llvmlistbot at llvm.org
Fri Jun 30 07:35:52 PDT 2023
Author: Christian Ulmann
Date: 2023-06-30T14:32:45Z
New Revision: bc6096406c5edbbe177a8c1faab5ada7c729ac03
URL: https://github.com/llvm/llvm-project/commit/bc6096406c5edbbe177a8c1faab5ada7c729ac03
DIFF: https://github.com/llvm/llvm-project/commit/bc6096406c5edbbe177a8c1faab5ada7c729ac03.diff
LOG: [mlir][LLVM] Add section attribute to LLVMFuncOp
This commit adds an optional section attribute to the `LLVMFuncOp` and
adds import and export functionality for it.
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D154219
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ModuleImport.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Target/LLVMIR/Import/function-attributes.ll
mlir/test/Target/LLVMIR/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index e74ec53fe3eebc..43f5b633e251b6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1644,7 +1644,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
OptionalAttr<LLVM_MemoryEffectsAttr>:$memory,
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_,
OptionalAttr<UnitAttr>:$arm_streaming,
- OptionalAttr<UnitAttr>:$arm_locally_streaming
+ OptionalAttr<UnitAttr>:$arm_locally_streaming,
+ OptionalAttr<StrAttr>:$section
);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index e098d14270375d..9adad6e8758c4d 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -1738,6 +1738,9 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
if (func->hasGC())
funcOp.setGarbageCollector(StringRef(func->getGC()));
+ if (func->hasSection())
+ funcOp.setSection(StringRef(func->getSection()));
+
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 62f881171ba229..2cfce47aa1373a 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -904,6 +904,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
if (auto gc = func.getGarbageCollector())
llvmFunc->setGC(gc->str());
+ if (std::optional<StringRef> section = func.getSection())
+ llvmFunc->setSection(*section);
+
if (auto armStreaming = func.getArmStreaming())
llvmFunc->addFnAttr("aarch64_pstate_sm_enabled");
else if (auto armLocallyStreaming = func.getArmLocallyStreaming())
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index 60cdd5864518f2..c9a3cde9ce9c71 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -209,3 +209,11 @@ define void @streaming_func() "aarch64_pstate_sm_enabled" {
define void @locally_streaming_func() "aarch64_pstate_sm_body" {
ret void
}
+
+// -----
+
+; CHECK-LABEL: @section_func
+; CHECK-SAME: attributes {section = ".section.name"}
+define void @section_func() section ".section.name" {
+ ret void
+}
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 9b7dc9d28c229b..eb8bbacf0085ed 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1626,6 +1626,16 @@ llvm.func @hasGCFunction() attributes { garbageCollector = "statepoint-example"
llvm.return
}
+// -----
+
+// CHECK-LABEL: @section_func
+// CHECK-SAME: section ".section.name"
+llvm.func @section_func() attributes { section = ".section.name" } {
+ llvm.return
+}
+
+// -----
+
// CHECK-LABEL: @callFreezeOp
llvm.func @callFreezeOp(%x : i32) {
// CHECK: freeze i32 %{{[0-9]+}}
More information about the Mlir-commits
mailing list