From: Christian Ulmann Date: Thu, 22 Jun 2023 14:53:21 +0000 (+0000) Subject: [mlir][LLVM] Fix empty res attr import X-Git-Tag: upstream/17.0.6~4199 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d3c4ff86652eed86d019b8e17108e94e911fd0f;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index e8ffee3..889555e 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(getBuiltinTypeForAttr(convertType(type)) - ); + return llvm::dyn_cast_if_present( + 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(constant)) { - auto shape = llvm::dyn_cast_if_present(getBuiltinTypeForAttr(convertType(constZero->getType())) - ); + auto shape = llvm::dyn_cast_if_present( + 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 0000000..d7f8400 --- /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()