-
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
[PGO]add bitcode-use-sample-profile #66178
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really follow the description of this from the conversation (I think the commit itself also needs a description which seems to be missing here). The change also needs a test case, which would help clarify what problem this is trying to solve.
I've added another reviewer who is more familiar with the sample profiler than I
(@huangjd).
@@ -1886,6 +1891,10 @@ SampleProfileLoader::buildFunctionOrder(Module &M, LazyCallGraph &CG) { | |||
errs() << "WARNING: -use-profiled-call-graph ignored, should be used " | |||
"together with -sample-profile-top-down-load.\n"; | |||
|
|||
for (Function &F : M) | |||
if (!F.isDeclaration() && BitCodeUseSampleProfile) | |||
F.addFnAttr("use-sample-profile"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the starting place the attribute will be used. MatchingManager->runOnModule()
also needs to see the attribute.
I guess you are adding module-level switch to indicate all functions in this module should use profile or not. This may lead to undefined/unexpected behavior for functions imported from other modules when thinLTO mode. In your use case, where does the bitcode come from? Can you set the attribute when the bitcode is generated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the use case either. It seems hacky to bypass the attribute in IR - why is the attribute not present in IR if sample profile is used?
I think this is an issue with LLVM pipeline. Functions are marked as "use-sample-profile" at front end when compiling from C++ source code (At clang::ParseAST -> ... -> CodeGenModule::EmitGlobal), but when compiling LLVM bitcode, it will not go through the parser frontend, instead go directly to optimization passes, so no function attributes will be added to the existing ones from the bitcode. It is a design decision whether it should be allowed to add/override this (or any) attribute in the bitcode |
How was the LLVM bitcode generated? Is it not from a Clang compilation? |
@teresajohnson @WenleiHe @htyu @huangjd
In step 4. Because function doesn't have attribute "use-sample-profile". It can't do pgo's optimation. |
Yeah. Another way is changing |
…rofile-sample-use first
1963ea1
to
507ad6f
Compare
To confirm my understanding, are you saying that you are not doing steps 1 and 2 yourself, but are using an archive of ThinLTO bitcode distributed by a third party? |
Also, if you are going to use an internal attribute, how about using the existing -mllvm -force-attribute=use-sample-profile. The ForceFunctionAttrs pass runs early in the ThinLTO pre-link pipeline, before sample pgo. |
-fprofile-sample-use should also be specified in step 1, otherwise it's too late because IR are not being annotated |
|
I haven't personally tried this option, but the documentation of the option indicates that if no function name is given the attribute gets applied to all functions in the module: static cl::liststd::string ForceAttributes( |
Oh this is a recent change, I didn't noticed it. In this case then just use the force attribute option would resolve the problem. |
I do steps 1,2 and other steps separately. Many third party projects use build tool different from mine, such as cmake,make,autoreconf. It's difficult to migrate third party projects in my project. So I want to do 1,2 steps as apt(advanced package tool) and do 3,4,5 steps in my build system. |
Could you explain why it's too late? |
@lifengxiang1025 |
Yes |
When use bitcode file as input and use "-fprofile-sample-use" first. Function don't has "use-sample-profile" attribute and then "buildFunctionOrder" return empty vector.
When "bitcode-use-sample-profile" enable, add "use-sample-profile" to function and make it can do optimation about pgo.