@@ -132,13 +132,14 @@ static cl::opt<int> ICPMaxNumVTableLastCandidate(
132132 " icp-max-num-vtable-last-candidate" , cl::init(1 ), cl::Hidden,
133133 cl::desc(" The maximum number of vtable for the last candidate." ));
134134
135- static cl::opt<DenseSet<StringRef>> ICPIgnoredBaseTypes (
136- " icp-ignored-base-types" , cl::Hidden, cl::init(DenseSet<StringRef>()),
137- cl::desc(" A comma-separated list of mangled vtable names. Classes "
138- " specified by the vtables and their derived ones will not be "
139- " vtable-ICP'ed. Useful when the profiled types and actual types "
140- " in the optimized binary could be different due to profiling "
141- " limitations." ));
135+ static cl::list<std::string> ICPIgnoredBaseTypes (
136+ " icp-ignored-base-types" , cl::Hidden,
137+ cl::desc (
138+ " A list of mangled vtable names. Classes specified by the vtables "
139+ " and their derived ones will not be vtable-ICP'ed. Useful when the "
140+ " profiled types and actual types in the optimized binary could be "
141+ " different due to profiling "
142+ " limitations." ));
142143
143144namespace {
144145
@@ -324,6 +325,8 @@ class IndirectCallPromoter {
324325
325326 OptimizationRemarkEmitter &ORE;
326327
328+ const DenseSet<StringRef> &IgnoredBaseTypes;
329+
327330 // A struct that records the direct target and it's call count.
328331 struct PromotionCandidate {
329332 Function *const TargetFunction;
@@ -399,10 +402,12 @@ class IndirectCallPromoter {
399402 Function &Func, Module &M, InstrProfSymtab *Symtab, bool SamplePGO,
400403 const VirtualCallSiteTypeInfoMap &VirtualCSInfo,
401404 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal,
405+ const DenseSet<StringRef> &IgnoredBaseTypes,
402406 OptimizationRemarkEmitter &ORE)
403407 : F(Func), M(M), Symtab(Symtab), SamplePGO(SamplePGO),
404408 VirtualCSInfo (VirtualCSInfo),
405- VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE) {}
409+ VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE),
410+ IgnoredBaseTypes(IgnoredBaseTypes) {}
406411 IndirectCallPromoter (const IndirectCallPromoter &) = delete;
407412 IndirectCallPromoter &operator =(const IndirectCallPromoter &) = delete ;
408413
@@ -859,24 +864,22 @@ bool IndirectCallPromoter::isProfitableToCompareVTables(
859864 LLVM_DEBUG (dbgs () << " \n " );
860865
861866 uint64_t CandidateVTableCount = 0 ;
862- SmallVector<MDNode *, 2 > Types;
867+
863868 for (auto &[GUID, Count] : VTableGUIDAndCounts) {
864869 CandidateVTableCount += Count;
865870 auto *VTableVar = Symtab->getGlobalVariable (GUID);
866871
867872 assert (VTableVar &&
868873 " VTableVar must exist for GUID in VTableGUIDAndCounts" );
869874
870- Types. clear () ;
875+ SmallVector<MDNode *, 2 > Types;
871876 VTableVar->getMetadata (LLVMContext::MD_type, Types);
872877
873- const DenseSet<StringRef> &VTableSet = ICPIgnoredBaseTypes.getValue ();
874878 for (auto *Type : Types)
875879 if (auto *TypeId = dyn_cast<MDString>(Type->getOperand (1 ).get ()))
876- if (VTableSet.contains (TypeId->getString ().str ())) {
877- LLVM_DEBUG (dbgs ()
878- << " vtable profiles are known to be "
879- " unrepresentative. Bail out vtable comparison." );
880+ if (IgnoredBaseTypes.contains (TypeId->getString ())) {
881+ LLVM_DEBUG (dbgs () << " vtable profiles should be ignored. Bail "
882+ " out vtable comparison." );
880883 return false ;
881884 }
882885 }
@@ -983,9 +986,15 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO,
983986 bool Changed = false ;
984987 VirtualCallSiteTypeInfoMap VirtualCSInfo;
985988
986- if (EnableVTableProfileUse)
989+ DenseSet<StringRef> IgnoredBaseTypes;
990+
991+ if (EnableVTableProfileUse) {
987992 computeVirtualCallSiteTypeInfoMap (M, MAM, VirtualCSInfo);
988993
994+ for (StringRef Str : ICPIgnoredBaseTypes)
995+ IgnoredBaseTypes.insert (Str);
996+ }
997+
989998 // VTableAddressPointOffsetVal stores the vtable address points. The vtable
990999 // address point of a given <vtable, address point offset> is static (doesn't
9911000 // change after being computed once).
@@ -1004,7 +1013,8 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO,
10041013 auto &ORE = FAM.getResult <OptimizationRemarkEmitterAnalysis>(F);
10051014
10061015 IndirectCallPromoter CallPromoter (F, M, &Symtab, SamplePGO, VirtualCSInfo,
1007- VTableAddressPointOffsetVal, ORE);
1016+ VTableAddressPointOffsetVal,
1017+ IgnoredBaseTypes, ORE);
10081018 bool FuncChanged = CallPromoter.processFunction (PSI);
10091019 if (ICPDUMPAFTER && FuncChanged) {
10101020 LLVM_DEBUG (dbgs () << " \n == IR Dump After ==" ; F.print (dbgs ()));
0 commit comments