-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[ThinLTO] Possible missed import of functions for indirect-call-promotion when linkage-name differs from mangled-name for local-linkage functions #74565
Comments
Should this be updated to indicate that it will use ";" once your other patch is in? I.e. to focus the fact that this is not about that difference. Also, you mention importing here, but I would specifically specify this is for ThinLTO, where the ICP target is in a different module. |
I updated the issue description to mention it would be updated to
Added [ThinTLO] in the title, and more details in the description. |
Thanks @minglotus-6 for creating this issue. Could you create a small test case of the missed ICP callees? It would really help me understand the problem. Also, I think you have some typos that I'm a bit confused about: "...it doesn't fix the case when and are different", "while the difference of and might exist". |
Test case Transforms/PGOProfile/thinlto_indirect_call_promotion.ll in PR/74008 showcases one type of missed function import when semicolon/colon cause MD5 hash differences between pgo func names and global identifiers. Hopefully this showcases the problem how missed imports happens. The key thing in getting a test case here is to get a executable (thereby raw profiles) where a function's Some findings while trying to do construct a test case:
I'm wondering if you come across source code examples where IR functions are generated with private linkage (therefore difference between mangled name and linkage-name) in objective-c++ or swift (for the function-ordering use case). If yes, that could be a start to construct the test case.
Fixed it now (It seems content inside a pair of angled bracket (i.e., < >) won't render but surrounding them with backticks would.) |
Ah I see. I hope you don't mind I fixed this in other areas too. |
Of course not. Thanks for the correction! |
I took another attempt only to find out it isn't very practical to synthesis an executable that contains functions with specific microsoft-faststdcall-mangling, on many (x86-64 or arm64) windows machines. Here are some uninteresting details and how I come to this finding
|
Based on our discussion in #74008 (comment) it seems like one solution could be to change
It does, however, have the linkage. After briefly looking at llvm-project/llvm/lib/IR/Mangler.cpp Lines 119 to 184 in 1638657
So my main question is: are we ok with changing the behavior of |
I think changing
Yes |
I had hoped that we could pass a |
I'm not sure of a good path forward, but I'll list some options I can think of.
|
Change the format of IRPGO counter names to `[<filepath>;]<mangled-name>` which is computed by `GlobalValue::getGlobalIdentifier()` to fix llvm#74565. In fe05193 (https://reviews.llvm.org/D156569) the format of IRPGO counter names was changed to be `[<filepath>;]<linkage-name>` where `<linkage-name>` is `F.getName()` with some prefix, e.g., `_` or `l_` on Mach-O (it is confusing that `<linkage-name>` is computed with `Mangler().getNameWithPrefix()` while `<mangled-name>` is just `F.getName()`). We discovered in llvm#74565 that this causes some missed import issues on some targets and llvm#74008 is a partial fix. Since `<mangled-name>` may not match the `<linkage-name>` on some targets like Mach-O, we will need to post-process the output of `llvm-profdata order` before passing to the linker via `-order_file`. Profiles generated after fe05193 will become stale after this diff, but I think this is acceptable since that patch after the LLVM 18 cut which has not been released yet.
Change the format of IRPGO counter names to `[<filepath>;]<mangled-name>` which is computed by `GlobalValue::getGlobalIdentifier()` to fix #74565. In fe05193 (https://reviews.llvm.org/D156569) the format of IRPGO counter names was changed to be `[<filepath>;]<linkage-name>` where `<linkage-name>` is basically `F.getName()` with some prefix, e.g., `_` or `l_` on Mach-O (yes, it is confusing that `<linkage-name>` is computed with `Mangler().getNameWithPrefix()` while `<mangled-name>` is just `F.getName()`). We discovered in #74565 that this causes some missed import issues on some targets and #74008 is a partial fix. Since `<mangled-name>` may not match the `<linkage-name>` on some targets like Mach-O, we will need to post-process the output of `llvm-profdata order` before passing to the linker via `-order_file`. Profiles generated after fe05193 will become stale after this diff, but I think this is acceptable since that patch landed after the LLVM 18 cut which hasn't been released yet.
Global identifiers has the format
[filename:]<mangled-name>
, and its MD5 hash are known as GUIDs to compute the import of referenced symbols in ThinLTO.When the referenced symbols is a callee of indirect call (whether the callee is in the same IR module as caller, or from a different IR module), the reference edge comes from PGO profiles as the MD5 hash of IRPGO function names, which has the format
[filename;]<linkage-name>
(more details)PR/74008 would update the delimiter to be
;
, but it doesn't fix the case when<mangled-name>
and<linkage-name>
are different. Note[filename;]
prefix exists for local-linkage functions only, while the difference of<mangled-name>
and<linkage-name>
might exist for external functions according to the Mangler impl.Looking at the code (Mangler used to compute IRPGO names),
<linkage-name>
(e.g., considering linkage and calling-convention) and<mangled-name>
(e.g., emitted by Clang for C++) could be different. This difference means possible missed import of functions as indirect-call-promotion callees (or when reference edge needs to be deduced from raw profiles using a similar approach to ICP).Create this issue so the missed import issue (and thereby missed opt) is tracked.
The text was updated successfully, but these errors were encountered: