Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC]Rename InstrProf::getFuncName{,orExternalSymbol} to getValueName{,orExternalSymbol} #68240

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ template <class FuncRecordTy, support::endianness Endian>
Error getFuncNameViaRef(const FuncRecordTy *Record,
InstrProfSymtab &ProfileNames, StringRef &FuncName) {
uint64_t NameRef = getFuncNameRef<FuncRecordTy, Endian>(Record);
FuncName = ProfileNames.getFuncName(NameRef);
FuncName = ProfileNames.getValueName(NameRef);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make the name clearer: getFuncOrVarName().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

return Error::success();
}

Expand Down
20 changes: 10 additions & 10 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,14 @@ class InstrProfSymtab {
/// an empty string.
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);

/// Return function's PGO name from the name's md5 hash value.
/// If not found, return an empty string.
inline StringRef getFuncName(uint64_t FuncMD5Hash);
/// Return name of functions or global variables from the name's md5 hash
/// value. If not found, return an empty string.
inline StringRef getValueName(uint64_t ValMD5Hash);

/// Just like getFuncName, except that it will return a non-empty StringRef
/// if the function is external to this symbol table. All such cases
/// will be represented using the same StringRef value.
inline StringRef getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash);
/// Just like getValueName, except that it will return a non-empty StringRef
/// if the value (function or global variable) is external to this symbol
/// table. All such cases will be represented using the same StringRef value.
inline StringRef getValueNameOrExternalSymbol(uint64_t ValMD5Hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFuncOrVarNameIfDefined(). Update comment to say 'External Symbol' is returned if not found.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


/// True if Symbol is the value used to represent external symbols.
static bool isExternalSymbol(const StringRef &Symbol) {
Expand Down Expand Up @@ -565,14 +565,14 @@ void InstrProfSymtab::finalizeSymtab() {
Sorted = true;
}

StringRef InstrProfSymtab::getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash) {
StringRef ret = getFuncName(FuncMD5Hash);
StringRef InstrProfSymtab::getValueNameOrExternalSymbol(uint64_t FuncMD5Hash) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FuncMD5Hash -- MD5Hash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

StringRef ret = getValueName(FuncMD5Hash);
if (ret.empty())
return InstrProfSymtab::getExternalSymbol();
return ret;
}

StringRef InstrProfSymtab::getFuncName(uint64_t FuncMD5Hash) {
StringRef InstrProfSymtab::getValueName(uint64_t FuncMD5Hash) {
finalizeSymtab();
auto Result = llvm::lower_bound(MD5NameMap, FuncMD5Hash,
[](const std::pair<uint64_t, StringRef> &LHS,
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/InstrProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class RawInstrProfReader : public InstrProfReader {
}

StringRef getName(uint64_t NameRef) const {
return Symtab->getFuncName(swap(NameRef));
return Symtab->getValueName(swap(NameRef));
}

int getCounterTypeSize() const {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ void InstrProfWriter::writeRecordInText(StringRef Name, uint64_t Hash,
std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
for (uint32_t I = 0; I < ND; I++) {
if (VK == IPVK_IndirectCallTarget)
OS << Symtab.getFuncNameOrExternalSymbol(VD[I].Value) << ":"
OS << Symtab.getValueNameOrExternalSymbol(VD[I].Value) << ":"
<< VD[I].Count << "\n";
else
OS << VD[I].Value << ":" << VD[I].Count << "\n";
Expand Down Expand Up @@ -790,7 +790,7 @@ void InstrProfWriter::writeTextTemporalProfTraceData(raw_fd_ostream &OS,
for (auto &Trace : TemporalProfTraces) {
OS << "# Weight:\n" << Trace.Weight << "\n";
for (auto &NameRef : Trace.FunctionNameRefs)
OS << Symtab.getFuncName(NameRef) << ",";
OS << Symtab.getValueName(NameRef) << ",";
OS << "\n";
}
OS << "\n";
Expand Down
6 changes: 3 additions & 3 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ static void traverseAllValueSites(const InstrProfRecord &Func, uint32_t VK,
if (Symtab == nullptr)
OS << format("%4" PRIu64, VD[V].Value);
else
OS << Symtab->getFuncName(VD[V].Value);
OS << Symtab->getValueName(VD[V].Value);
OS << ", " << format("%10" PRId64, VD[V].Count) << " ] ("
<< format("%.2f%%", (VD[V].Count * 100.0 / SiteSum)) << ")\n";
}
Expand Down Expand Up @@ -2644,7 +2644,7 @@ static int showInstrProfile(
OS << " Temporal Profile Trace " << i << " (weight=" << Traces[i].Weight
<< " count=" << Traces[i].FunctionNameRefs.size() << "):\n";
for (auto &NameRef : Traces[i].FunctionNameRefs)
OS << " " << Reader->getSymtab().getFuncName(NameRef) << "\n";
OS << " " << Reader->getSymtab().getValueName(NameRef) << "\n";
}
}

Expand Down Expand Up @@ -3079,7 +3079,7 @@ static int order_main(int argc, const char *argv[]) {
WithColor::note() << "# Ordered " << Nodes.size() << " functions\n";
for (auto &N : Nodes) {
auto [Filename, ParsedFuncName] =
getParsedIRPGOFuncName(Reader->getSymtab().getFuncName(N.Id));
getParsedIRPGOFuncName(Reader->getSymtab().getValueName(N.Id));
if (!Filename.empty())
OS << "# " << Filename << "\n";
OS << ParsedFuncName << "\n";
Expand Down
46 changes: 24 additions & 22 deletions llvm/unittests/ProfileData/InstrProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,23 +1250,23 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) {
FuncNames.push_back("bar3");
InstrProfSymtab Symtab;
EXPECT_THAT_ERROR(Symtab.create(FuncNames), Succeeded());
StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1"));
StringRef R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func1"));
ASSERT_EQ(StringRef("func1"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func2"));
ASSERT_EQ(StringRef("func2"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func3"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func3"));
ASSERT_EQ(StringRef("func3"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar1"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar1"));
ASSERT_EQ(StringRef("bar1"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar2"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar2"));
ASSERT_EQ(StringRef("bar2"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar3"));
ASSERT_EQ(StringRef("bar3"), R);

// negative tests
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar4"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar4"));
ASSERT_EQ(StringRef(), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("foo4"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("foo4"));
ASSERT_EQ(StringRef(), R);

// Now incrementally update the symtab
Expand All @@ -1275,23 +1275,23 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_test) {
EXPECT_THAT_ERROR(Symtab.addFuncName("blah_3"), Succeeded());

// Check again
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_1"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("blah_1"));
ASSERT_EQ(StringRef("blah_1"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_2"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("blah_2"));
ASSERT_EQ(StringRef("blah_2"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("blah_3"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("blah_3"));
ASSERT_EQ(StringRef("blah_3"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func1"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func1"));
ASSERT_EQ(StringRef("func1"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func2"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func2"));
ASSERT_EQ(StringRef("func2"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("func3"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("func3"));
ASSERT_EQ(StringRef("func3"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar1"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar1"));
ASSERT_EQ(StringRef("bar1"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar2"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar2"));
ASSERT_EQ(StringRef("bar2"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash("bar3"));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash("bar3"));
ASSERT_EQ(StringRef("bar3"), R);
}

Expand Down Expand Up @@ -1331,14 +1331,14 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_module_test) {

std::string IRPGOName = getIRPGOFuncName(*F);
auto IRPGOFuncName =
ProfSymtab.getFuncName(IndexedInstrProf::ComputeHash(IRPGOName));
ProfSymtab.getValueName(IndexedInstrProf::ComputeHash(IRPGOName));
EXPECT_EQ(StringRef(IRPGOName), IRPGOFuncName);
EXPECT_EQ(StringRef(Funcs[I]),
getParsedIRPGOFuncName(IRPGOFuncName).second);
// Ensure we can still read this old record name.
std::string PGOName = getPGOFuncName(*F);
auto PGOFuncName =
ProfSymtab.getFuncName(IndexedInstrProf::ComputeHash(PGOName));
ProfSymtab.getValueName(IndexedInstrProf::ComputeHash(PGOName));
EXPECT_EQ(StringRef(PGOName), PGOFuncName);
EXPECT_THAT(PGOFuncName.str(), EndsWith(Funcs[I].str()));
}
Expand Down Expand Up @@ -1396,9 +1396,10 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {

// Now do the checks:
// First sampling some data points:
StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0]));
StringRef R =
Symtab.getValueName(IndexedInstrProf::ComputeHash(FuncNames1[0]));
ASSERT_EQ(StringRef("func_0"), R);
R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1]));
R = Symtab.getValueName(IndexedInstrProf::ComputeHash(FuncNames1[1]));
ASSERT_EQ(StringRef("f oooooooooooooo_0"), R);
for (int I = 0; I < 3; I++) {
std::string N[4];
Expand All @@ -1407,7 +1408,8 @@ TEST_P(MaybeSparseInstrProfTest, instr_prof_symtab_compression_test) {
N[2] = FuncNames2[2 * I];
N[3] = FuncNames2[2 * I + 1];
for (int J = 0; J < 4; J++) {
StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(N[J]));
StringRef R =
Symtab.getValueName(IndexedInstrProf::ComputeHash(N[J]));
ASSERT_EQ(StringRef(N[J]), R);
}
}
Expand Down