Skip to content

[MLIR][LLVM] LLVM import should use is isDSOLocal instead of hasLocalLinkage to set dso_local attribute #124822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

ghehg
Copy link
Contributor

@ghehg ghehg commented Jan 28, 2025

Without this change, function definitions that mostly have external linkage would be missing dso_local attribute during translation.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Guojin (ghehg)

Changes

Function definitions mostly have external linkage thus would be missing dso_local attribute during translation.


Full diff: https://github.com/llvm/llvm-project/pull/124822.diff

2 Files Affected:

  • (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+1-1)
  • (modified) mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll (+10)
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 40d86efe605ad0..414e000356c51f 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -2106,7 +2106,7 @@ LogicalResult ModuleImport::processFunction(llvm::Function *func) {
       iface.isConvertibleIntrinsic(func->getIntrinsicID()))
     return success();
 
-  bool dsoLocal = func->hasLocalLinkage();
+  bool dsoLocal = func->isDSOLocal();
   CConv cconv = convertCConvFromLLVM(func->getCallingConv());
 
   // Insert the function at the end of the module.
diff --git a/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
index d7f8400413b896..a3cf048441e0d5 100644
--- a/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
+++ b/mlir/test/Target/LLVMIR/Import/function-attributes-generic.ll
@@ -7,3 +7,13 @@
 ; CHECK-NOT:  res_attrs
 ; CHECK-SAME:  }>
 declare ptr @func_no_param_attrs()
+
+; Ensure that we have dso_local
+; CHECK: "llvm.func"()
+; CHECK-SAME: <{
+; CHECK-SAME: dso_local
+; CHECK-SAME: "dsolocal_func"
+; CHECK-SAME:  }>
+define dso_local void @dsolocal_func() {
+  ret void
+}

@ghehg ghehg marked this pull request as draft January 28, 2025 19:13
@ghehg ghehg marked this pull request as ready for review January 28, 2025 19:14
Copy link
Contributor

@gysit gysit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

; CHECK-SAME: dso_local
; CHECK-SAME: "dsolocal_func"
; CHECK-SAME: }>
define dso_local void @dsolocal_func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reason to test this using the generic rather than the pretty printed format?

I would prefer to move the test to function-attributes.ll where the other attributes are tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for quick review. Just moved the test.
No, no specific reason other than I thought making size of function-attributes-generics and function-attributes.ll balanced would be good.

Copy link
Contributor

@gysit gysit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving the test! There is one small issue left.

It looks like you do not have commit rights? Should I land the commit for you once the issue is fixed?

@@ -10,6 +10,13 @@ define internal spir_func void @spir_func_internal() {
ret void
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can you move this into a separate split, i.e., can you add ; // ----- above the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. just made its own split

@ghehg
Copy link
Contributor Author

ghehg commented Jan 29, 2025

Thanks for moving the test! There is one small issue left.

It looks like you do not have commit rights? Should I land the commit for you once the issue is fixed?

Yeah, I'm new to llvm main, so would appreciate it if you could help to land once all reviewers satisfied.

@gysit gysit merged commit 4fc514a into llvm:main Jan 29, 2025
8 checks passed
Copy link

@ghehg Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants