@@ -132,10 +132,13 @@ 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<std::string> ICPKnownUnrepresentativeVTables (
136- " icp-known-unrepresentative-vtables" , cl::init(" " ), cl::Hidden,
137- cl::desc(" A comma-separated list of mangled vtable names for which instrumented
138- profiles are not representative. For instance, the instantiated class is arch or micro-arch specific, while instrumented profiles are collected on one arch." ));
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." ));
139142
140143namespace {
141144
@@ -321,8 +324,6 @@ class IndirectCallPromoter {
321324
322325 OptimizationRemarkEmitter &ORE;
323326
324- const DenseSet<StringRef> &KnownUnrepresentativeBaseTypes;
325-
326327 // A struct that records the direct target and it's call count.
327328 struct PromotionCandidate {
328329 Function *const TargetFunction;
@@ -398,12 +399,10 @@ class IndirectCallPromoter {
398399 Function &Func, Module &M, InstrProfSymtab *Symtab, bool SamplePGO,
399400 const VirtualCallSiteTypeInfoMap &VirtualCSInfo,
400401 VTableAddressPointOffsetValMap &VTableAddressPointOffsetVal,
401- DenseSet<StringRef> &KnownUnrepresentativeTypes,
402402 OptimizationRemarkEmitter &ORE)
403403 : F(Func), M(M), Symtab(Symtab), SamplePGO(SamplePGO),
404404 VirtualCSInfo (VirtualCSInfo),
405- VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE),
406- KnownUnrepresentativeBaseTypes(KnownUnrepresentativeTypes) {}
405+ VTableAddressPointOffsetVal(VTableAddressPointOffsetVal), ORE(ORE) {}
407406 IndirectCallPromoter (const IndirectCallPromoter &) = delete;
408407 IndirectCallPromoter &operator =(const IndirectCallPromoter &) = delete ;
409408
@@ -871,12 +870,13 @@ bool IndirectCallPromoter::isProfitableToCompareVTables(
871870 Types.clear ();
872871 VTableVar->getMetadata (LLVMContext::MD_type, Types);
873872
873+ const DenseSet<StringRef> &VTableSet = ICPIgnoredBaseTypes.getValue ();
874874 for (auto *Type : Types)
875875 if (auto *TypeId = dyn_cast<MDString>(Type->getOperand (1 ).get ()))
876- if (KnownUnrepresentativeBaseTypes .contains (TypeId->getString ())) {
876+ if (VTableSet .contains (TypeId->getString (). str ())) {
877877 LLVM_DEBUG (dbgs ()
878878 << " vtable profiles are known to be "
879- " unrepresentative. Bail out vtable comparison." )
879+ " unrepresentative. Bail out vtable comparison." );
880880 return false ;
881881 }
882882 }
@@ -983,19 +983,9 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO,
983983 bool Changed = false ;
984984 VirtualCallSiteTypeInfoMap VirtualCSInfo;
985985
986- DenseSet<StringRef> KnownUnrepresentativeTypeSet;
987-
988- if (EnableVTableProfileUse) {
986+ if (EnableVTableProfileUse)
989987 computeVirtualCallSiteTypeInfoMap (M, MAM, VirtualCSInfo);
990988
991- SmallVector<StringRef> KnownUnrepresentativeTypes;
992- llvm::SplitString (ICPKnownUnrepresentativeVTables,
993- KnownUnrepresentativeTypes);
994-
995- for (const StringRef Str : KnownUnrepresentativeTypes)
996- KnownUnrepresentativeTypeSet.insert (Str);
997- }
998-
999989 // VTableAddressPointOffsetVal stores the vtable address points. The vtable
1000990 // address point of a given <vtable, address point offset> is static (doesn't
1001991 // change after being computed once).
@@ -1014,8 +1004,7 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO,
10141004 auto &ORE = FAM.getResult <OptimizationRemarkEmitterAnalysis>(F);
10151005
10161006 IndirectCallPromoter CallPromoter (F, M, &Symtab, SamplePGO, VirtualCSInfo,
1017- VTableAddressPointOffsetVal,
1018- KnownUnrepresentativeTypeSet, ORE);
1007+ VTableAddressPointOffsetVal, ORE);
10191008 bool FuncChanged = CallPromoter.processFunction (PSI);
10201009 if (ICPDUMPAFTER && FuncChanged) {
10211010 LLVM_DEBUG (dbgs () << " \n == IR Dump After ==" ; F.print (dbgs ()));
0 commit comments