[Mlir-commits] [mlir] 10417b1 - [mlir][LLVM] Add unnamed_addr to LLVMFuncOp
Christian Ulmann
llvmlistbot at llvm.org
Mon Jul 3 22:50:54 PDT 2023
Author: Christian Ulmann
Date: 2023-07-04T05:41:27Z
New Revision: 10417b1359c2ba7cde2c40e61530f7de30b6d199
URL: https://github.com/llvm/llvm-project/commit/10417b1359c2ba7cde2c40e61530f7de30b6d199
DIFF: https://github.com/llvm/llvm-project/commit/10417b1359c2ba7cde2c40e61530f7de30b6d199.diff
LOG: [mlir][LLVM] Add unnamed_addr to LLVMFuncOp
This commit adds LLVM's unnamed_addr enum to LLVMFuncOp.
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D154360
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
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 993748fe629264..1b1b0043bd9980 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1647,7 +1647,8 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
DefaultValuedAttr<Visibility, "mlir::LLVM::Visibility::Default">:$visibility_,
OptionalAttr<UnitAttr>:$arm_streaming,
OptionalAttr<UnitAttr>:$arm_locally_streaming,
- OptionalAttr<StrAttr>:$section
+ OptionalAttr<StrAttr>:$section,
+ OptionalAttr<UnnamedAddr>:$unnamed_addr
);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index f914c044d7e75a..82cbee3d548d1f 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1785,7 +1785,8 @@ void GlobalOp::print(OpAsmPrinter &p) {
getGlobalTypeAttrName(), getConstantAttrName(),
getValueAttrName(), getLinkageAttrName(),
getUnnamedAddrAttrName(), getThreadLocal_AttrName(),
- getVisibility_AttrName(), getComdatAttrName()});
+ getVisibility_AttrName(), getComdatAttrName(),
+ getUnnamedAddrAttrName()});
// Print the trailing type unless it's a string global.
if (llvm::dyn_cast_or_null<StringAttr>(getValueOrNull()))
@@ -2246,6 +2247,12 @@ ParseResult LLVMFuncOp::parse(OpAsmParser &parser, OperationState &result) {
parseOptionalLLVMKeyword<LLVM::Visibility, int64_t>(
parser, result, LLVM::Visibility::Default)));
+ // Parse optional UnnamedAddr, default to None.
+ result.addAttribute(getUnnamedAddrAttrName(result.name),
+ parser.getBuilder().getI64IntegerAttr(
+ parseOptionalLLVMKeyword<UnnamedAddr, int64_t>(
+ parser, result, LLVM::UnnamedAddr::None)));
+
// Default to C Calling Convention if no keyword is provided.
result.addAttribute(
getCConvAttrName(result.name),
@@ -2309,6 +2316,11 @@ void LLVMFuncOp::print(OpAsmPrinter &p) {
StringRef visibility = stringifyVisibility(getVisibility_());
if (!visibility.empty())
p << visibility << ' ';
+ if (auto unnamedAddr = getUnnamedAddr()) {
+ StringRef str = stringifyUnnamedAddr(*unnamedAddr);
+ if (!str.empty())
+ p << str << ' ';
+ }
if (getCConv() != LLVM::CConv::C)
p << stringifyCConv(getCConv()) << ' ';
@@ -2336,7 +2348,7 @@ void LLVMFuncOp::print(OpAsmPrinter &p) {
p, *this,
{getFunctionTypeAttrName(), getArgAttrsAttrName(), getResAttrsAttrName(),
getLinkageAttrName(), getCConvAttrName(), getVisibility_AttrName(),
- getComdatAttrName()});
+ getComdatAttrName(), getUnnamedAddrAttrName()});
// Print the body if this is not an external function.
Region &body = getBody();
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 9adad6e8758c4d..efa1fc3b4ac720 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->hasAtLeastLocalUnnamedAddr())
+ funcOp.setUnnamedAddr(convertUnnamedAddrFromLLVM(func->getUnnamedAddr()));
+
if (func->hasSection())
funcOp.setSection(StringRef(func->getSection()));
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 9f806957d42f04..62b7ec4619d129 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1041,6 +1041,9 @@ LogicalResult ModuleTranslation::convertFunctionSignatures() {
if (auto gc = function.getGarbageCollector())
llvmFunc->setGC(gc->str());
+
+ if (auto unnamedAddr = function.getUnnamedAddr())
+ llvmFunc->setUnnamedAddr(convertUnnamedAddrToLLVM(*unnamedAddr));
}
return success();
diff --git a/mlir/test/Dialect/LLVMIR/func.mlir b/mlir/test/Dialect/LLVMIR/func.mlir
index 466f7d1eb70d8b..491234a44ee42f 100644
--- a/mlir/test/Dialect/LLVMIR/func.mlir
+++ b/mlir/test/Dialect/LLVMIR/func.mlir
@@ -205,6 +205,11 @@ module {
llvm.return
}
+ // CHECK-LABEL: local_unnamed_addr @local_unnamed_addr_func
+ llvm.func local_unnamed_addr @local_unnamed_addr_func() {
+ llvm.return
+ }
+
// CHECK: llvm.comdat @__llvm_comdat
llvm.comdat @__llvm_comdat {
// CHECK: llvm.comdat_selector @any any
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes.ll b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
index c9a3cde9ce9c71..034933f64671de 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes.ll
@@ -217,3 +217,15 @@ define void @locally_streaming_func() "aarch64_pstate_sm_body" {
define void @section_func() section ".section.name" {
ret void
}
+
+// -----
+
+; CHECK-LABEL: local_unnamed_addr @local_unnamed_addr_func
+define void @local_unnamed_addr_func() local_unnamed_addr {
+ ret void
+}
+
+// -----
+
+; CHECK-LABEL: unnamed_addr @unnamed_addr_func
+declare void @unnamed_addr_func() unnamed_addr
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 1f9c438a8e1d84..bb2cf218bd9532 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1642,6 +1642,20 @@ llvm.func @section_func() attributes { section = ".section.name" } {
// -----
+// CHECK-LABEL: @local_unnamed_addr_func
+// CHECK-SAME: local_unnamed_addr
+llvm.func local_unnamed_addr @local_unnamed_addr_func() {
+ llvm.return
+}
+
+// -----
+
+// CHECK-LABEL: @unnamed_addr_func
+// CHECK-SAME: unnamed_addr
+llvm.func unnamed_addr @unnamed_addr_func()
+
+// -----
+
// CHECK-LABEL: @callFreezeOp
llvm.func @callFreezeOp(%x : i32) {
// CHECK: freeze i32 %{{[0-9]+}}
More information about the Mlir-commits
mailing list