[Mlir-commits] [mlir] 8d3c4ff - [mlir][LLVM] Fix empty res attr import
Christian Ulmann
llvmlistbot at llvm.org
Thu Jun 22 09:13:13 PDT 2023
Author: Christian Ulmann
Date: 2023-06-22T16:07:23Z
New Revision: 8d3c4ff86652eed86d019b8e17108e94e911fd0f
URL: https://github.com/llvm/llvm-project/commit/8d3c4ff86652eed86d019b8e17108e94e911fd0f
DIFF: https://github.com/llvm/llvm-project/commit/8d3c4ff86652eed86d019b8e17108e94e911fd0f.diff
LOG: [mlir][LLVM] Fix empty res attr import
This commit ensures that an empty list of result attributes is not
imported as an empty `ArrayAttr`. Instead, the attribute is just not
added to the `LLVMFuncOp`.
Reviewed By: gysit
Differential Revision: https://reviews.llvm.org/D153553
Added:
mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
Modified:
mlir/lib/Target/LLVMIR/ModuleImport.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index e8ffee33ea3bc..889555e030495 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -761,8 +761,8 @@ Attribute ModuleImport::getConstantAsAttr(llvm::Constant *constant) {
// Returns the static shape of the provided type if possible.
auto getConstantShape = [&](llvm::Type *type) {
- return llvm::dyn_cast_if_present<ShapedType>(getBuiltinTypeForAttr(convertType(type))
- );
+ return llvm::dyn_cast_if_present<ShapedType>(
+ getBuiltinTypeForAttr(convertType(type)));
};
// Convert one-dimensional constant arrays or vectors that store 1/2/4/8-byte
@@ -829,8 +829,8 @@ Attribute ModuleImport::getConstantAsAttr(llvm::Constant *constant) {
// Convert zero aggregates.
if (auto *constZero = dyn_cast<llvm::ConstantAggregateZero>(constant)) {
- auto shape = llvm::dyn_cast_if_present<ShapedType>(getBuiltinTypeForAttr(convertType(constZero->getType()))
- );
+ auto shape = llvm::dyn_cast_if_present<ShapedType>(
+ getBuiltinTypeForAttr(convertType(constZero->getType())));
if (!shape)
return {};
// Convert zero aggregates with a static shape to splat elements attributes.
@@ -1683,6 +1683,8 @@ void ModuleImport::convertParameterAttributes(llvm::Function *func,
// Convert the result attributes and attach them wrapped in an ArrayAttribute
// to the funcOp.
llvm::AttributeSet llvmResAttr = llvmAttrs.getRetAttrs();
+ if (!llvmResAttr.hasAttributes())
+ return;
funcOp.setResAttrsAttr(
builder.getArrayAttr(convertParameterAttribute(llvmResAttr, builder)));
}
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
new file mode 100644
index 0000000000000..d7f8400413b89
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s --mlir-print-op-generic | FileCheck %s
+
+; Ensure that no empty parameter attribute lists are created.
+; CHECK: "llvm.func"
+; CHECK-SAME: <{
+; CHECK-NOT: arg_attr
+; CHECK-NOT: res_attrs
+; CHECK-SAME: }>
+declare ptr @func_no_param_attrs()
More information about the Mlir-commits
mailing list