diff --git a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp --- a/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp @@ -255,11 +255,22 @@ rewriter.getNamedAttr(function_like_impl::getArgDictAttrName(), rewriter.getArrayAttr(newArgAttrs))); } + for (auto pair : llvm::enumerate(attributes)) { + if (pair.value().first == "llvm.linkage") { + attributes.erase(attributes.begin() + pair.index()); + break; + } + } // Create an LLVM function, use external linkage by default until MLIR // functions have linkage. + LLVM::Linkage linkage = LLVM::Linkage::External; + if (funcOp->hasAttr("llvm.linkage")) { + linkage = funcOp->getAttr("llvm.linkage") + .cast().getLinkage(); + } auto newFuncOp = rewriter.create( - funcOp.getLoc(), funcOp.getName(), llvmType, LLVM::Linkage::External, + funcOp.getLoc(), funcOp.getName(), llvmType, linkage, /*dsoLocal*/ false, attributes); rewriter.inlineRegionBefore(funcOp.getBody(), newFuncOp.getBody(), newFuncOp.end()); diff --git a/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir b/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir --- a/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir +++ b/mlir/test/Conversion/StandardToLLVM/convert-funcs.mlir @@ -37,6 +37,9 @@ return %bbarg : () -> () } +// CHECK-LABEL: llvm.func extern_weak @llvmlinkage(i32) +func private @llvmlinkage(i32) attributes { "llvm.linkage" = #llvm.linkage } + // CHECK-LABEL: llvm.func @body(i32) func private @body(i32)