Skip to content

Commit 2695641

Browse files
resolve review feedback
1 parent bc43354 commit 2695641

File tree

4 files changed

+54
-25
lines changed

4 files changed

+54
-25
lines changed

llvm/include/llvm/Support/CommandLine.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,26 @@ 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+
12111231
//--------------------------------------------------
12121232
// This collection of wrappers is the intermediary between class opt and class
12131233
// parser to handle all the template nastiness.

llvm/lib/Support/CommandLine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ 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>>;
6970

7071
template class opt<unsigned>;
7172
template class opt<int>;
@@ -93,6 +94,7 @@ void parser<double>::anchor() {}
9394
void parser<float>::anchor() {}
9495
void parser<std::string>::anchor() {}
9596
void parser<char>::anchor() {}
97+
void parser<DenseSet<StringRef>>::anchor() {}
9698

9799
//===----------------------------------------------------------------------===//
98100

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

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+
20632083
// generic_parser_base implementation
20642084
//
20652085

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

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

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

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-known-unrepresentative-vtables='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,Derived3' -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)