-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[TypeProf][PGO]Support skipping vtable comparisons for a class and its derived ones #110575
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bc43354
[TypeProf][PGO]Support specification of vtables for which type profil…
mingmingl-llvm 2695641
resolve review feedback
mingmingl-llvm f14c6d5
1. use cl::list<std::string> for option type
mingmingl-llvm 255edce
resolve review feedback
mingmingl-llvm 28e2363
1. resolve review feedback 2. Update option description to mention the
mingmingl-llvm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,14 @@ static cl::opt<int> ICPMaxNumVTableLastCandidate( | |
| "icp-max-num-vtable-last-candidate", cl::init(1), cl::Hidden, | ||
| cl::desc("The maximum number of vtable for the last candidate.")); | ||
|
|
||
| static cl::list<std::string> ICPIgnoredBaseTypes( | ||
| "icp-ignored-base-types", cl::Hidden, | ||
| cl::desc( | ||
| "A list of mangled vtable names. Classes specified by the vtables " | ||
| "and their derived ones will not be vtable-ICP'ed. Useful when the " | ||
| "profiled types and actual types in the optimized binary could be " | ||
| "different due to profiling limitations.")); | ||
|
|
||
| namespace { | ||
|
|
||
| // The key is a vtable global variable, and the value is a map. | ||
|
|
@@ -316,6 +324,8 @@ class IndirectCallPromoter { | |
|
|
||
| OptimizationRemarkEmitter &ORE; | ||
|
|
||
| const DenseSet<StringRef> &IgnoredBaseTypes; | ||
|
|
||
| // A struct that records the direct target and it's call count. | ||
| struct PromotionCandidate { | ||
| Function *const TargetFunction; | ||
|
|
@@ -391,10 +401,12 @@ class IndirectCallPromoter { | |
| Function &Func, Module &M, InstrProfSymtab *Symtab, bool SamplePGO, | ||
| const VirtualCallSiteTypeInfoMap &VirtualCSInfo, | ||
| VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal, | ||
| const DenseSet<StringRef> &IgnoredBaseTypes, | ||
| OptimizationRemarkEmitter &ORE) | ||
| : F(Func), M(M), Symtab(Symtab), SamplePGO(SamplePGO), | ||
| VirtualCSInfo(VirtualCSInfo), | ||
| VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE) {} | ||
| VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE), | ||
| IgnoredBaseTypes(IgnoredBaseTypes) {} | ||
| IndirectCallPromoter(const IndirectCallPromoter &) = delete; | ||
| IndirectCallPromoter &operator=(const IndirectCallPromoter &) = delete; | ||
|
|
||
|
|
@@ -851,8 +863,25 @@ bool IndirectCallPromoter::isProfitableToCompareVTables( | |
| LLVM_DEBUG(dbgs() << "\n"); | ||
|
|
||
| uint64_t CandidateVTableCount = 0; | ||
| for (auto &[GUID, Count] : VTableGUIDAndCounts) | ||
|
|
||
| for (auto &[GUID, Count] : VTableGUIDAndCounts) { | ||
| CandidateVTableCount += Count; | ||
| auto *VTableVar = Symtab->getGlobalVariable(GUID); | ||
|
|
||
| assert(VTableVar && | ||
| "VTableVar must exist for GUID in VTableGUIDAndCounts"); | ||
|
|
||
| SmallVector<MDNode *, 2> Types; | ||
| VTableVar->getMetadata(LLVMContext::MD_type, Types); | ||
|
|
||
| for (auto *Type : Types) | ||
| if (auto *TypeId = dyn_cast<MDString>(Type->getOperand(1).get())) | ||
| if (IgnoredBaseTypes.contains(TypeId->getString())) { | ||
| LLVM_DEBUG(dbgs() << " vtable profiles should be ignored. Bail " | ||
| "out vtable comparison."); | ||
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (CandidateVTableCount < Candidate.Count * ICPVTablePercentageThreshold) { | ||
| LLVM_DEBUG( | ||
|
|
@@ -956,9 +985,15 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO, | |
| bool Changed = false; | ||
| VirtualCallSiteTypeInfoMap VirtualCSInfo; | ||
|
|
||
| if (EnableVTableProfileUse) | ||
| DenseSet<StringRef> IgnoredBaseTypes; | ||
|
|
||
| if (EnableVTableProfileUse) { | ||
| computeVirtualCallSiteTypeInfoMap(M, MAM, VirtualCSInfo); | ||
|
|
||
| for (StringRef Str : ICPIgnoredBaseTypes) | ||
| IgnoredBaseTypes.insert(Str); | ||
| } | ||
|
|
||
| // VTableAddressPointOffsetVal stores the vtable address points. The vtable | ||
| // address point of a given <vtable, address point offset> is static (doesn't | ||
| // change after being computed once). | ||
|
|
@@ -977,7 +1012,8 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO, | |
| auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F); | ||
|
|
||
| IndirectCallPromoter CallPromoter(F, M, &Symtab, SamplePGO, VirtualCSInfo, | ||
| VTableAddressPointOffsetVal, ORE); | ||
| VTableAddressPointOffsetVal, | ||
| IgnoredBaseTypes, ORE); | ||
| bool FuncChanged = CallPromoter.processFunction(PSI); | ||
| if (ICPDUMPAFTER && FuncChanged) { | ||
| LLVM_DEBUG(dbgs() << "\n== IR Dump After =="; F.print(dbgs())); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we skip all the new handling when IgnoredBaseTypes is empty?
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 makes sense.
I took the liberty to use a helper function for the new handling, to simplify the control flow (e.g., continue, inner-for-loop and return) inside the outer loop.