[Mlir-commits] [mlir] c55a886 - [mlir][LLVM] Add alignment to LLVMFuncOp
Christian Ulmann
llvmlistbot at llvm.org
Mon Jul 3 23:34:13 PDT 2023
Author: Christian Ulmann
Date: 2023-07-04T06:33:36Z
New Revision: c55a8861f439f3a4ab07e565bc670edc91fe2598
URL: https://github.com/llvm/llvm-project/commit/c55a8861f439f3a4ab07e565bc670edc91fe2598
DIFF: https://github.com/llvm/llvm-project/commit/c55a8861f439f3a4ab07e565bc670edc91fe2598.diff
LOG: [mlir][LLVM] Add alignment to LLVMFuncOp
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D154410
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ModuleImport.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Dialect/LLVMIR/func.mlir
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 1b1b0043bd9980..98f5b844047070 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1648,7 +1648,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
OptionalAttr<UnitAttr>:$arm_streaming,
OptionalAttr<UnitAttr>:$arm_locally_streaming,
OptionalAttr<StrAttr>:$section,
- OptionalAttr<UnnamedAddr>:$unnamed_addr
+ OptionalAttr<UnnamedAddr>:$unnamed_addr,
+ OptionalAttr<I64Attr>:$alignment
);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index efa1fc3b4ac720..f23dad679e0ae8 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -1749,6 +1749,9 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
if (func->hasComdat())
funcOp.setComdatAttr(comdatMapping.lookup(func->getComdat()));
+ if (llvm::MaybeAlign maybeAlign = func->getAlign())
+ funcOp.setAlignment(maybeAlign->value());
+
// Handle Function attributes.
processFunctionAttributes(func, funcOp);
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 62b7ec4619d129..5ba9a6eaaa0141 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1044,6 +1044,9 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() {
if (auto unnamedAddr = function.getUnnamedAddr())
llvmFunc->setUnnamedAddr(convertUnnamedAddrToLLVM(*unnamedAddr));
+
+ if (auto alignment = function.getAlignment())
+ llvmFunc->setAlignment(llvm::MaybeAlign(*alignment));
}
return success();
diff --git a/mlir/test/Dialect/LLVMIR/func.mlir b/mlir/test/Dialect/LLVMIR/func.mlir
index 491234a44ee42f..c0da9fc40e16fa 100644
--- a/mlir/test/Dialect/LLVMIR/func.mlir
+++ b/mlir/test/Dialect/LLVMIR/func.mlir
@@ -207,7 +207,13 @@ module {
// CHECK-LABEL: local_unnamed_addr @local_unnamed_addr_func
llvm.func local_unnamed_addr @local_unnamed_addr_func() {
- llvm.return
+ llvm.return
+ }
+
+ // CHECK-LABEL: @align_func
+ // CHECK-SAME: attributes {alignment = 2 : i64}
+ llvm.func @align_func() attributes {alignment = 2 : i64} {
+ llvm.return
}
// CHECK: llvm.comdat @__llvm_comdat
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index 034933f64671de..bf9d746f6c0b6d 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -229,3 +229,17 @@ define void @local_unnamed_addr_func() local_unnamed_addr {
; CHECK-LABEL: unnamed_addr @unnamed_addr_func
declare void @unnamed_addr_func() unnamed_addr
+
+// -----
+
+; CHECK-LABEL: @align_func
+; CHECK-SAME: attributes {alignment = 2 : i64}
+define void @align_func() align 2 {
+ ret void
+}
+
+// -----
+
+; CHECK-LABEL: @align_decl
+; CHECK-SAME: attributes {alignment = 64 : i64}
+declare void @align_decl() align 64
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index bb2cf218bd9532..f37ed750412a3a 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1656,6 +1656,20 @@ llvm.func unnamed_addr @unnamed_addr_func()
// -----
+// CHECK-LABEL: @align_func
+// CHECK-SAME: align 2
+llvm.func @align_func() attributes {alignment = 2 : i64} {
+ llvm.return
+}
+
+// -----
+
+// CHECK-LABEL: @align_decl
+// CHECK-SAME: align 64
+llvm.func @align_decl() attributes {alignment = 64 : i64}
+
+// -----
+
// CHECK-LABEL: @callFreezeOp
llvm.func @callFreezeOp(%x : i32) {
// CHECK: freeze i32 %{{[0-9]+}}
More information about the Mlir-commits
mailing list