[BOLT] Remove StringRef from IndirectCallProfile

Summary:
IndirectCallProfile was holding to a StringRef from a profile reader
providing an implicit dependency on the reader.

(cherry picked from FBD21587101)
This commit is contained in:
Maksim Panchenko 2020-05-14 17:34:20 -07:00
parent f91d121eee
commit cce49b9522
7 changed files with 34 additions and 43 deletions

View File

@ -3203,7 +3203,7 @@ MCSymbol *BinaryFunction::addEntryPoint(const BinaryBasicBlock &BB) {
return EntrySymbol;
}
const MCSymbol *BinaryFunction::getSymbolForEntryID(uint64_t EntryID) const {
MCSymbol *BinaryFunction::getSymbolForEntryID(uint64_t EntryID) {
if (EntryID == 0)
return getSymbol();

View File

@ -72,20 +72,17 @@ enum IndirectCallPromotionType : char {
/// Information on a single indirect call to a particular callee.
struct IndirectCallProfile {
bool IsFunction;
MCSymbol *Symbol;
uint32_t Offset;
StringRef Name;
uint64_t Count;
uint64_t Mispreds;
IndirectCallProfile(bool IsFunction, StringRef Name, uint64_t Count,
IndirectCallProfile(MCSymbol *Symbol, uint64_t Count,
uint64_t Mispreds, uint32_t Offset = 0)
: IsFunction(IsFunction), Offset(Offset), Name(Name), Count(Count),
Mispreds(Mispreds) {}
: Symbol(Symbol), Offset(Offset), Count(Count), Mispreds(Mispreds) {}
bool operator==(const IndirectCallProfile &Other) const {
return IsFunction == Other.IsFunction &&
Name == Other.Name &&
return Symbol == Other.Symbol &&
Offset == Other.Offset;
}
};
@ -102,8 +99,8 @@ inline raw_ostream &operator<<(raw_ostream &OS,
uint64_t TotalCount = 0;
uint64_t TotalMispreds = 0;
for (auto &CSP : ICSP) {
SS << Sep << "{ " << (CSP.IsFunction ? CSP.Name : "<unknown>") << ": "
<< CSP.Count << " (" << CSP.Mispreds << " misses) }";
SS << Sep << "{ " << (CSP.Symbol ? CSP.Symbol->getName() : "<unknown>")
<< ": " << CSP.Count << " (" << CSP.Mispreds << " misses) }";
Sep = ",\n ";
TotalCount += CSP.Count;
TotalMispreds += CSP.Mispreds;
@ -1127,7 +1124,10 @@ public:
/// Return MC symbol corresponding to an enumerated entry for multiple-entry
/// functions.
const MCSymbol *getSymbolForEntryID(uint64_t EntryNum) const;
MCSymbol *getSymbolForEntryID(uint64_t EntryNum);
const MCSymbol *getSymbolForEntryID(uint64_t EntryNum) const {
return const_cast<BinaryFunction *>(this)->getSymbolForEntryID(EntryNum);
}
MCSymbol *getColdSymbol() {
if (ColdSymbol)

View File

@ -540,8 +540,13 @@ void BinaryFunction::convertBranchData() {
IndirectCallSiteProfile &CSP =
BC.MIB->getOrCreateAnnotationAs<IndirectCallSiteProfile>(
*Instr, "CallProfile");
CSP.emplace_back(BI.To.IsSymbol, BI.To.Name, BI.Branches,
BI.Mispreds);
MCSymbol *CalleeSymbol{nullptr};
if (BI.To.IsSymbol) {
if (auto *BD = BC.getBinaryDataByName(BI.To.Name)) {
CalleeSymbol = BD->getSymbol();
}
}
CSP.emplace_back(CalleeSymbol, BI.Branches, BI.Mispreds);
} else if (BC.MIB->getConditionalTailCall(*Instr)) {
setOrUpdateAnnotation("CTCTakenCount", BI.Branches);
setOrUpdateAnnotation("CTCMispredCount", BI.Mispreds);

View File

@ -178,11 +178,8 @@ BinaryFunctionCallGraph buildCallGraph(BinaryContext &BC,
const auto &ICSP =
BC.MIB->getAnnotationAs<IndirectCallSiteProfile>(Inst, "CallProfile");
for (const auto &CSI : ICSP) {
if (!CSI.IsFunction)
continue;
if (auto *DstBD = BC.getBinaryDataByName(CSI.Name)) {
Counts.push_back(std::make_pair(DstBD->getSymbol(), CSI.Count));
}
if (CSI.Symbol)
Counts.push_back(std::make_pair(CSI.Symbol, CSI.Count));
}
} else {
const auto Count = BB->getExecutionCount();
@ -204,11 +201,7 @@ BinaryFunctionCallGraph buildCallGraph(BinaryContext &BC,
for (const auto &CSI : Function->getAllCallSites()) {
++TotalCallsites;
if (!CSI.IsFunction)
continue;
auto *DstBD = BC.getBinaryDataByName(CSI.Name);
if (!DstBD)
if (!CSI.Symbol)
continue;
// The computed offset may exceed the hot part of the function; hence,
@ -217,7 +210,7 @@ BinaryFunctionCallGraph buildCallGraph(BinaryContext &BC,
if (Offset > Size)
Offset = Size;
if (!recordCall(DstBD->getSymbol(), CSI.Count)) {
if (!recordCall(CSI.Symbol, CSI.Count)) {
++NotProcessed;
}
}

View File

@ -204,11 +204,9 @@ IndirectCallPromotion::Callsite::Callsite(BinaryFunction &BF,
To(ICP.Offset),
Mispreds(ICP.Mispreds),
Branches(ICP.Count) {
if (ICP.IsFunction) {
if (auto *BD = BF.getBinaryContext().getBinaryDataByName(ICP.Name)) {
To.Sym = BD->getSymbol();
To.Addr = 0;
}
if (ICP.Symbol) {
To.Sym = ICP.Symbol;
To.Addr = 0;
}
}
@ -1301,8 +1299,8 @@ void IndirectCallPromotion::runOnFunctions(BinaryContext &BC) {
for (const auto &BInfo : getCallTargets(BB, Inst)) {
NumCalls += BInfo.Branches;
}
IndirectCalls.push_back(std::make_tuple(NumCalls, &Inst, &Function));
IndirectCalls.push_back(
std::make_tuple(NumCalls, &Inst, &Function));
TotalIndirectCalls += NumCalls;
}
}

View File

@ -122,13 +122,12 @@ ProfileReader::parseFunctionProfile(BinaryFunction &BF,
auto *Callee = YamlCSI.DestId < YamlProfileToFunction.size() ?
YamlProfileToFunction[YamlCSI.DestId] : nullptr;
bool IsFunction = Callee ? true : false;
const MCSymbol *CalleeSymbol = nullptr;
MCSymbol *CalleeSymbol = nullptr;
if (IsFunction) {
CalleeSymbol = Callee->getSymbolForEntryID(YamlCSI.EntryDiscriminator);
}
StringRef Name = CalleeSymbol ? CalleeSymbol->getName() : "<unknown>";
BF.getAllCallSites().emplace_back(
IsFunction, Name, YamlCSI.Count, YamlCSI.Mispreds, YamlCSI.Offset);
CalleeSymbol, YamlCSI.Count, YamlCSI.Mispreds, YamlCSI.Offset);
if (YamlCSI.Offset >= BB.getOriginalSize()) {
if (opts::Verbosity >= 2)
@ -170,7 +169,7 @@ ProfileReader::parseFunctionProfile(BinaryFunction &BF,
IndirectCallSiteProfile &CSP =
BC.MIB->getOrCreateAnnotationAs<IndirectCallSiteProfile>(
*Instr, "CallProfile");
CSP.emplace_back(IsFunction, Name, YamlCSI.Count, YamlCSI.Mispreds);
CSP.emplace_back(CalleeSymbol, YamlCSI.Count, YamlCSI.Mispreds);
} else if (BC.MIB->getConditionalTailCall(*Instr)) {
setAnnotation("CTCTakenCount", YamlCSI.Count);
setAnnotation("CTCMispredCount", YamlCSI.Mispreds);

View File

@ -81,14 +81,10 @@ convert(const BinaryFunction &BF, yaml::bolt::BinaryFunctionProfile &YamlBF) {
for (auto &CSP : ICSP.get()) {
CSI.DestId = 0; // designated for unknown functions
CSI.EntryDiscriminator = 0;
if (CSP.IsFunction) {
const auto *CalleeBD = BC.getBinaryDataByName(CSP.Name);
if (CalleeBD) {
const auto *Callee =
BC.getFunctionForSymbol(CalleeBD->getSymbol());
if (Callee) {
CSI.DestId = Callee->getFunctionNumber();
}
if (CSP.Symbol) {
const auto *Callee = BC.getFunctionForSymbol(CSP.Symbol);
if (Callee) {
CSI.DestId = Callee->getFunctionNumber();
}
}
CSI.Count = CSP.Count;