Adding support to the CS preinliner to trim cold base profiles. This makes trimming consistent with the inline decision made by the preinliner. Also disable the existing profile merger when preinliner is on unless explicitly specified.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
271 | I think it's cleaner if we defer all trimming to SampleContextTrimmer. We can add TrimBaseProfileOnly flag to trimAndMergeColdContextProfiles interface, or have a separate interface (will still need to make sure we reuse code). We create SampleContextTrimmer right above anyways. With this change, CSProfMergeColdContext will always be ignored when preinliner is on, but that's not the case before. So alternatively, if TrimBaseProfileOnly is added to the interface, we can call the trimmer outside of preinliner like before, but set TrimBaseProfileOnly to true when preinliner is on. | |
272 | This logging is a bit inconsistent - we don't have logging for this level of activity from SampleContextTrimmer. However if we unify as suggested above, we won't have such inconsistency. I'm not sure if we need such logging though. |
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
271 | Sounds good. I'll defer SampleContextTrimmer to do the trimming. There is a gray area with previous implementation when the preinliner and the trim are both on. In that case the previous check below will accidentally cause the profile merger to run. The profile merger defaulted to on but did not actually run when preilniner was on and neither merger/trimmer switch was given. Turning on the trimmer via the switch caused the merger to run which otherwise would not run. if (!EnableCSPreInliner || CSProfTrimColdContext.getNumOccurrences() || CSProfMergeColdContext.getNumOccurrences()) I think we want to run the trimmer based on the command line switch, regardless of whether preilniner is on. How about the merger? |
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
271 | Maybe we should do this below. That makes sure we don't accidentally run the merging if only trimming is asked for. That is - make preinliner and merging either-or unless explicitly specified, but leave trimming orthogonal. if (EnableCSPreInliner && !CSProfMergeColdContext.getNumOccurrences()) CSProfMergeColdContext = false; |
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
271 | That should work. I was thinking if we should completely disable separate merging for preinliner, since we can tune the hotness cutoff to have preinliner do more merge. |
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
271 | Yeah, that would be the default behavior. But if user asks for merging on top of preinliner, it rarely makes sense but I assume they know what they're doing. | |
272–280 | Sorry if I wasn't clear.
What I meant by the above to do the trimming outside of preinliner. So preinliner does strictly preinlining, and trimming is done at the original place, with TrimBaseProfileOnly set to EnableCSPreInliner. This way we don't have trimming functionality scattered. The setting of CSProfMergeColdContext also better be done outside of preinliner. |
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
272–280 | I found that separating the logic for the preinlining and non-preinlining path is easier to read and less error prone. Don't have a strong preference. Can do what you suggested. |
Addressing Wenlei's comment.
llvm/tools/llvm-profgen/CSPreInliner.cpp | ||
---|---|---|
272–280 | Actually the logic looks better after moving this out. |
llvm/lib/ProfileData/SampleProf.cpp | ||
---|---|---|
335 | what if TrimBaseProfileOnly is true but those two are false, shall we skip the trim? maybe change to if (!TrimColdContext && !MergeColdContext && !TrimBaseProfileOnly) | |
357 | if(MergeColdContext && !TrimBaseProfileOnly) So that MergedProfileMap will be empty for TrimBaseProfileOnly | |
367 | Then we can add an assertion: TrimBaseProfileOnly && MergedProfileMap.empty() |
llvm/lib/ProfileData/SampleProf.cpp | ||
---|---|---|
335 | TrimBaseProfileOnly should only be effective when TrimColdContext is true. Trimming means to trim cold profile. On top of that we can choose to trim all cold profiles or only base cold profiles. Does that make sense? I can add a comment for that. |
llvm/lib/ProfileData/SampleProf.cpp | ||
---|---|---|
335 | Makes sense. I was thinking if we could reuse this for non-CS cold profile trimming(we have that in our internal patch). in that case, it's the same logic as TrimBaseProfileOnly = true. Anyway, that should be another patch. thanks! |
llvm/lib/ProfileData/SampleProf.cpp | ||
---|---|---|
357 | How about this comments? is MergeColdContext always false when TrimBaseProfileOnly is true? |
llvm/lib/ProfileData/SampleProf.cpp | ||
---|---|---|
357 | Sorry for overlooking this comment. MergeColdContext and TrimBaseProfileOnly can be both true when user specifies the switches for both merging and trimming. We were talking about whether to turn off merging for preinliner completely and we agree to let user decide. In that case, I think we should ignore TrimBaseProfileOnly since merging is meant to not honor the preinliner decision. It is a good catch, thanks! |
what if TrimBaseProfileOnly is true but those two are false, shall we skip the trim?
maybe change to if (!TrimColdContext && !MergeColdContext && !TrimBaseProfileOnly)