Skip to content

Commit f14c6d5

Browse files
1. use cl::list<std::string> for option type
2. Update `-icp-ignored-base-types` with one base type since this is sufficient
1 parent 2695641 commit f14c6d5

File tree

4 files changed

+28
-58
lines changed

4 files changed

+28
-58
lines changed

llvm/include/llvm/Support/CommandLine.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,26 +1208,6 @@ template <> class parser<char> : public basic_parser<char> {
12081208
void anchor() override;
12091209
};
12101210

1211-
//--------------------------------------------------
1212-
1213-
extern template class basic_parser<DenseSet<StringRef>>;
1214-
1215-
template <>
1216-
class parser<DenseSet<StringRef>> : public basic_parser<DenseSet<StringRef>> {
1217-
public:
1218-
parser(Option &O) : basic_parser(O) {}
1219-
1220-
// Return true on error.
1221-
bool parse(Option &, StringRef, StringRef Arg, DenseSet<StringRef> &Val);
1222-
1223-
StringRef getValueName() const override { return "DenseSet<StringRef>"; }
1224-
1225-
void printOptionDiff(const Option &O, const DenseSet<StringRef> &V,
1226-
OptVal Default, size_t GlobalWidth) const;
1227-
1228-
void anchor() override;
1229-
};
1230-
12311211
//--------------------------------------------------
12321212
// This collection of wrappers is the intermediary between class opt and class
12331213
// parser to handle all the template nastiness.

llvm/lib/Support/CommandLine.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ template class basic_parser<double>;
6666
template class basic_parser<float>;
6767
template class basic_parser<std::string>;
6868
template class basic_parser<char>;
69-
template class basic_parser<DenseSet<StringRef>>;
7069

7170
template class opt<unsigned>;
7271
template class opt<int>;
@@ -94,7 +93,6 @@ void parser<double>::anchor() {}
9493
void parser<float>::anchor() {}
9594
void parser<std::string>::anchor() {}
9695
void parser<char>::anchor() {}
97-
void parser<DenseSet<StringRef>>::anchor() {}
9896

9997
//===----------------------------------------------------------------------===//
10098

@@ -2062,24 +2060,6 @@ bool parser<float>::parse(Option &O, StringRef ArgName, StringRef Arg,
20622060
return false;
20632061
}
20642062

2065-
// parser<DenseSet<StringRef> implementation
2066-
//
2067-
void parser<DenseSet<StringRef>>::printOptionDiff(
2068-
const Option &O, const DenseSet<StringRef> &V,
2069-
OptionValue<DenseSet<StringRef>> D, size_t GlobalWidth) const {}
2070-
2071-
bool parser<DenseSet<StringRef>>::parse(Option &O, StringRef ArgName,
2072-
StringRef Arg,
2073-
DenseSet<StringRef> &Val) {
2074-
SmallVector<StringRef> StrRefs;
2075-
llvm::SplitString(Arg, StrRefs, ",");
2076-
for (const StringRef StrRef : StrRefs)
2077-
if (!Val.insert(StrRef).second)
2078-
return O.error(Arg + " has duplicated strings!");
2079-
2080-
return false;
2081-
}
2082-
20832063
// generic_parser_base implementation
20842064
//
20852065

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

143144
namespace {
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()));

llvm/test/Transforms/PGOProfile/icp_vtable_cmp.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
; RUN: opt < %s -passes='pgo-icall-prom' -pass-remarks=pgo-icall-prom -enable-vtable-profile-use -icp-max-num-vtable-last-candidate=2 -S 2>&1 | FileCheck %s --check-prefixes=VTABLE-COMMON,VTABLE-CMP
44
; RUN: opt < %s -passes='pgo-icall-prom' -pass-remarks=pgo-icall-prom -enable-vtable-profile-use -icp-max-num-vtable-last-candidate=1 -S 2>&1 | FileCheck %s --check-prefixes=VTABLE-COMMON,FUNC-CMP
5-
; RUN: opt < %s -passes='pgo-icall-prom' -pass-remarks=pgo-icall-prom -enable-vtable-profile-use -icp-max-num-vtable-last-candidate=1 -icp-ignored-base-types='Base1,Derived3' -S 2>&1 | FileCheck %s --check-prefixes=VTABLE-COMMON,FUNC-CMP
5+
; RUN: opt < %s -passes='pgo-icall-prom' -pass-remarks=pgo-icall-prom -enable-vtable-profile-use -icp-max-num-vtable-last-candidate=1 -icp-ignored-base-types='Base1' -S 2>&1 | FileCheck %s --check-prefixes=VTABLE-COMMON,FUNC-CMP
66

77
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
88
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)