[mlir][LLVM] Add section attribute to LLVMFuncOp
authorChristian Ulmann <christian.ulmann@nextsilicon.com>
Fri, 30 Jun 2023 14:19:31 +0000 (14:19 +0000)
committerChristian Ulmann <christian.ulmann@nextsilicon.com>
Fri, 30 Jun 2023 14:32:45 +0000 (14:32 +0000)
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

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

index e74ec53..43f5b63 100644 (file)
@@ -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);
index e098d14..9adad6e 100644 (file)
@@ -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())
index 62f8811..2cfce47 100644 (file)
@@ -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())
index 60cdd58..c9a3cde 100644 (file)
@@ -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
+}
index 9b7dc9d..eb8bbac 100644 (file)
@@ -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]+}}