summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormingmingl <mingmingl@google.com>2025-07-07 21:37:03 -0700
committermingmingl <mingmingl@google.com>2025-07-07 21:37:03 -0700
commit1bc148813f845484a4c4b3941616ceb764dc3ded (patch)
tree9221ff50d87cd752c45bfebd475f9f230f0e3662
parentef1ca26e45479b0c64642fbd51fb5f25ad1464da (diff)
-rw-r--r--llvm/tools/llvm-profgen/PerfReader.cpp14
-rw-r--r--llvm/tools/llvm-profgen/ProfileGenerator.cpp29
-rw-r--r--llvm/tools/llvm-profgen/ProfiledBinary.h14
3 files changed, 13 insertions, 44 deletions
diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp
index 4756b971e9e0..b84152e47a19 100644
--- a/llvm/tools/llvm-profgen/PerfReader.cpp
+++ b/llvm/tools/llvm-profgen/PerfReader.cpp
@@ -387,8 +387,6 @@ void PerfReaderBase::parseDataAccessPerfTraces(
if (EC)
exitWithError("Failed to open perf trace file: " + DataAccessPerfTraceFile);
- DenseMap<uint64_t, DenseMap<StringRef, uint64_t>> IpDataAccessCount;
-
assert(!SampleCounters.empty() && "Sample counters should not be empty!");
SampleCounter &Counter = SampleCounters.begin()->second;
line_iterator LineIt(*BufferOrErr.get(), true);
@@ -417,22 +415,16 @@ void PerfReaderBase::parseDataAccessPerfTraces(
if (matches.size() != 5)
continue;
- uint64_t DataAddress = std::stoull(matches[4].str(), nullptr, 16);
-
- // Skip addresses out of the specified PT_LOAD section for data sections.
- if (!Binary->InRange(DataAddress))
- continue;
-
- int32_t PID = std::stoi(matches[1].str());
+ const int32_t PID = std::stoi(matches[1].str());
if (PIDFilter && *PIDFilter != PID) {
continue;
}
- uint64_t IP = std::stoull(matches[3].str(), nullptr, 16);
-
+ const uint64_t DataAddress = std::stoull(matches[4].str(), nullptr, 16);
StringRef DataSymbol = Binary->symbolizeDataAddress(
Binary->CanonicalizeNonTextAddress(DataAddress));
if (DataSymbol.starts_with("_ZTV")) {
+ const uint64_t IP = std::stoull(matches[3].str(), nullptr, 16);
Counter.recordDataAccessCount(Binary->canonicalizeVirtualAddress(IP),
DataSymbol, 1);
}
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 44c76e630851..760efcfc0f86 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -542,32 +542,19 @@ void ProfileGenerator::generateLineNumBasedProfile() {
// Fill in boundary sample counts as well as call site samples for calls
populateBoundarySamplesForAllFunctions(SC.BranchCounter);
- // Process data access counters.
- const auto &DataAccessCounters = SC.DataAccessCounter;
- for (const auto &Entry : DataAccessCounters) {
- uint64_t InstAddr = Entry.first.first;
- StringRef DataSymbol = Entry.first.second;
-
- FunctionId DataSymbolName(DataSymbol);
- // If the symbol is not a valid address, skip it.
-
- // symbolize vtable here.
- uint64_t Count = Entry.second;
+ // For each instruction with vtable accesses, get its symbolized inline
+ // stack, and add the vtable counters to the function samples.
+ for (const auto &[IpData, Count] : SC.DataAccessCounter) {
+ uint64_t InstAddr = IpData.first;
const SampleContextFrameVector &FrameVec =
Binary->getCachedFrameLocationStack(InstAddr, false);
-
if (!FrameVec.empty()) {
- // If the leaf function sample has only one of body sample or call site
- // sample, use one of them.
FunctionSamples &FunctionProfile =
getLeafProfileAndAddTotalSamples(FrameVec, 0);
- LineLocation Loc(FrameVec.back().Location.LineOffset,
- getBaseDiscriminator(FrameVec.back().Location.Discriminator));
-
- // Assume inlined callsites and call targets have different
- // discriminators.
-
- FunctionProfile.getTypeSamplesAt(Loc)[DataSymbolName] += Count;
+ LineLocation Loc(
+ FrameVec.back().Location.LineOffset,
+ getBaseDiscriminator(FrameVec.back().Location.Discriminator));
+ FunctionProfile.getTypeSamplesAt(Loc)[FunctionId(IpData.second)] += Count;
}
}
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 7efcace7b46f..02df7628b0d3 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -630,22 +630,12 @@ public:
return ProbeDecoder.getInlinerDescForProbe(Probe);
}
- bool InRange(uint64_t Address, const MMapEvent &MMap) const {
- return Address >= MMap.Address && Address < MMap.Address + MMap.Size;
- }
-
- bool InRange(uint64_t Address) const {
- for (const auto &MMap : MMapNonTextEvents) {
- if (InRange(Address, MMap))
- return true;
- }
- return false;
- }
-
void addMMapNonTextEvent(MMapEvent MMap) {
MMapNonTextEvents.push_back(MMap);
}
+ // Given a runtime address, canonicalize it to the virtual address in the
+ // binary.
uint64_t CanonicalizeNonTextAddress(uint64_t Address);
bool getTrackFuncContextSize() { return TrackFuncContextSize; }