[llvm] fb29d81 - [CSSPGO] Rename the field of SampleContextFrame
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 4 19:13:56 PDT 2021
Author: wlei
Date: 2021-10-04T19:06:59-07:00
New Revision: fb29d812e4a536ee1ee81566fd584902f21f4ecb
URL: https://github.com/llvm/llvm-project/commit/fb29d812e4a536ee1ee81566fd584902f21f4ecb
DIFF: https://github.com/llvm/llvm-project/commit/fb29d812e4a536ee1ee81566fd584902f21f4ecb.diff
LOG: [CSSPGO] Rename the field of SampleContextFrame
Differential Revision: https://reviews.llvm.org/D110980
Added:
Modified:
llvm/include/llvm/ProfileData/SampleProf.h
llvm/lib/ProfileData/SampleProfWriter.cpp
llvm/lib/Transforms/IPO/SampleContextTracker.cpp
llvm/tools/llvm-profgen/CallContext.h
llvm/tools/llvm-profgen/ProfileGenerator.cpp
llvm/tools/llvm-profgen/ProfiledBinary.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 2e26c5f676138..3e0753ba14dd5 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -412,18 +412,18 @@ enum ContextAttributeMask {
ContextShouldBeInlined = 0x2, // Leaf of context should be inlined
};
-// Represents a callsite with caller function name and line location
+// Represents a context frame with function name and line location
struct SampleContextFrame {
- StringRef CallerName;
- LineLocation Callsite;
+ StringRef FuncName;
+ LineLocation Location;
- SampleContextFrame() : Callsite(0, 0) {}
+ SampleContextFrame() : Location(0, 0) {}
- SampleContextFrame(StringRef CallerName, LineLocation Callsite)
- : CallerName(CallerName), Callsite(Callsite) {}
+ SampleContextFrame(StringRef FuncName, LineLocation Location)
+ : FuncName(FuncName), Location(Location) {}
bool operator==(const SampleContextFrame &That) const {
- return Callsite == That.Callsite && CallerName == That.CallerName;
+ return Location == That.Location && FuncName == That.FuncName;
}
bool operator!=(const SampleContextFrame &That) const {
@@ -432,19 +432,19 @@ struct SampleContextFrame {
std::string toString(bool OutputLineLocation) const {
std::ostringstream OContextStr;
- OContextStr << CallerName.str();
+ OContextStr << FuncName.str();
if (OutputLineLocation) {
- OContextStr << ":" << Callsite.LineOffset;
- if (Callsite.Discriminator)
- OContextStr << "." << Callsite.Discriminator;
+ OContextStr << ":" << Location.LineOffset;
+ if (Location.Discriminator)
+ OContextStr << "." << Location.Discriminator;
}
return OContextStr.str();
}
};
static inline hash_code hash_value(const SampleContextFrame &arg) {
- return hash_combine(arg.CallerName, arg.Callsite.LineOffset,
- arg.Callsite.Discriminator);
+ return hash_combine(arg.FuncName, arg.Location.LineOffset,
+ arg.Location.Discriminator);
}
using SampleContextFrameVector = SmallVector<SampleContextFrame, 10>;
@@ -598,7 +598,7 @@ class SampleContext {
ContextStateMask CState = RawContext) {
assert(CState != UnknownContext);
FullContext = Context;
- Name = Context.back().CallerName;
+ Name = Context.back().FuncName;
State = CState;
}
@@ -621,11 +621,11 @@ class SampleContext {
while (I < std::min(FullContext.size(), That.FullContext.size())) {
auto &Context1 = FullContext[I];
auto &Context2 = That.FullContext[I];
- auto V = Context1.CallerName.compare(Context2.CallerName);
+ auto V = Context1.FuncName.compare(Context2.FuncName);
if (V)
return V == -1;
- if (Context1.Callsite != Context2.Callsite)
- return Context1.Callsite < Context2.Callsite;
+ if (Context1.Location != Context2.Location)
+ return Context1.Location < Context2.Location;
I++;
}
@@ -645,7 +645,7 @@ class SampleContext {
return false;
ThatContext = ThatContext.take_front(ThisContext.size());
// Compare Leaf frame first
- if (ThisContext.back().CallerName != ThatContext.back().CallerName)
+ if (ThisContext.back().FuncName != ThatContext.back().FuncName)
return false;
// Compare leading context
return ThisContext.drop_back() == ThatContext.drop_back();
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp
index 7fecd0dc7388f..36a0b6f6436bd 100644
--- a/llvm/lib/ProfileData/SampleProfWriter.cpp
+++ b/llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -269,10 +269,10 @@ std::error_code SampleProfileWriterExtBinaryBase::writeCSNameTableSection() {
auto Frames = Context.getContextFrames();
encodeULEB128(Frames.size(), OS);
for (auto &Callsite : Frames) {
- if (std::error_code EC = writeNameIdx(Callsite.CallerName))
+ if (std::error_code EC = writeNameIdx(Callsite.FuncName))
return EC;
- encodeULEB128(Callsite.Callsite.LineOffset, OS);
- encodeULEB128(Callsite.Callsite.Discriminator, OS);
+ encodeULEB128(Callsite.Location.LineOffset, OS);
+ encodeULEB128(Callsite.Location.Discriminator, OS);
}
}
@@ -542,7 +542,7 @@ void SampleProfileWriterExtBinaryBase::addContext(
const SampleContext &Context) {
if (Context.hasContext()) {
for (auto &Callsite : Context.getContextFrames())
- SampleProfileWriterBinary::addName(Callsite.CallerName);
+ SampleProfileWriterBinary::addName(Callsite.FuncName);
CSNameTable.insert(std::make_pair(Context, 0));
} else {
SampleProfileWriterBinary::addName(Context.getName());
diff --git a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
index 2a9a13f2dafaf..028567f0d780c 100644
--- a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
+++ b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp
@@ -511,13 +511,13 @@ SampleContextTracker::getOrCreateContextPath(const SampleContext &Context,
for (auto &Callsite : Context.getContextFrames()) {
// Create child node at parent line/disc location
if (AllowCreate) {
- ContextNode = ContextNode->getOrCreateChildContext(CallSiteLoc,
- Callsite.CallerName);
+ ContextNode =
+ ContextNode->getOrCreateChildContext(CallSiteLoc, Callsite.FuncName);
} else {
ContextNode =
- ContextNode->getChildContext(CallSiteLoc, Callsite.CallerName);
+ ContextNode->getChildContext(CallSiteLoc, Callsite.FuncName);
}
- CallSiteLoc = Callsite.Callsite;
+ CallSiteLoc = Callsite.Location;
}
assert((!AllowCreate || ContextNode) &&
diff --git a/llvm/tools/llvm-profgen/CallContext.h b/llvm/tools/llvm-profgen/CallContext.h
index bb7152a8eaf05..5e552130d03c7 100644
--- a/llvm/tools/llvm-profgen/CallContext.h
+++ b/llvm/tools/llvm-profgen/CallContext.h
@@ -18,12 +18,12 @@ namespace llvm {
namespace sampleprof {
inline std::string getCallSite(const SampleContextFrame &Callsite) {
- std::string CallsiteStr = Callsite.CallerName.str();
+ std::string CallsiteStr = Callsite.FuncName.str();
CallsiteStr += ":";
- CallsiteStr += Twine(Callsite.Callsite.LineOffset).str();
- if (Callsite.Callsite.Discriminator > 0) {
+ CallsiteStr += Twine(Callsite.Location.LineOffset).str();
+ if (Callsite.Location.Discriminator > 0) {
CallsiteStr += ".";
- CallsiteStr += Twine(Callsite.Callsite.Discriminator).str();
+ CallsiteStr += Twine(Callsite.Location.Discriminator).str();
}
return CallsiteStr;
}
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 6e43e53cc6215..0cfe0215b2007 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -253,15 +253,15 @@ void ProfileGeneratorBase::updateBodySamplesforFunctionProfile(
FunctionSamples &FunctionProfile, const SampleContextFrame &LeafLoc,
uint64_t Count) {
// Filter out invalid negative(int type) lineOffset
- if (LeafLoc.Callsite.LineOffset & 0x80000000)
+ if (LeafLoc.Location.LineOffset & 0x80000000)
return;
// Use the maximum count of samples with same line location
ErrorOr<uint64_t> R = FunctionProfile.findSamplesAt(
- LeafLoc.Callsite.LineOffset, LeafLoc.Callsite.Discriminator);
+ LeafLoc.Location.LineOffset, LeafLoc.Location.Discriminator);
uint64_t PreviousCount = R ? R.get() : 0;
if (PreviousCount <= Count) {
- FunctionProfile.addBodySamples(LeafLoc.Callsite.LineOffset,
- LeafLoc.Callsite.Discriminator,
+ FunctionProfile.addBodySamples(LeafLoc.Location.LineOffset,
+ LeafLoc.Location.Discriminator,
Count - PreviousCount);
}
}
@@ -299,16 +299,16 @@ FunctionSamples &ProfileGenerator::getLeafProfileAndAddTotalSamples(
const SampleContextFrameVector &FrameVec, uint64_t Count) {
// Get top level profile
FunctionSamples *FunctionProfile =
- &getTopLevelFunctionProfile(FrameVec[0].CallerName);
+ &getTopLevelFunctionProfile(FrameVec[0].FuncName);
FunctionProfile->addTotalSamples(Count);
for (size_t I = 1; I < FrameVec.size(); I++) {
FunctionSamplesMap &SamplesMap =
- FunctionProfile->functionSamplesAt(FrameVec[I - 1].Callsite);
+ FunctionProfile->functionSamplesAt(FrameVec[I - 1].Location);
auto Ret =
- SamplesMap.emplace(FrameVec[I].CallerName.str(), FunctionSamples());
+ SamplesMap.emplace(FrameVec[I].FuncName.str(), FunctionSamples());
if (Ret.second) {
- SampleContext Context(FrameVec[I].CallerName);
+ SampleContext Context(FrameVec[I].FuncName);
Ret.first->second.setContext(Context);
}
FunctionProfile = &Ret.first->second;
@@ -394,8 +394,8 @@ void ProfileGenerator::populateBoundarySamplesForAllFunctions(
FunctionSamples &FunctionProfile =
getLeafProfileAndAddTotalSamples(FrameVec, Count);
FunctionProfile.addCalledTargetSamples(
- FrameVec.back().Callsite.LineOffset,
- FrameVec.back().Callsite.Discriminator, CalleeName, Count);
+ FrameVec.back().Location.LineOffset,
+ FrameVec.back().Location.Discriminator, CalleeName, Count);
}
// Add head samples for callee.
FunctionSamples &CalleeProfile = getTopLevelFunctionProfile(CalleeName);
@@ -534,13 +534,13 @@ void CSProfileGenerator::populateBoundarySamplesForFunction(
auto LeafLoc = Binary->getInlineLeafFrameLoc(SourceOffset);
if (!LeafLoc.hasValue())
continue;
- FunctionProfile.addCalledTargetSamples(LeafLoc->Callsite.LineOffset,
- LeafLoc->Callsite.Discriminator,
+ FunctionProfile.addCalledTargetSamples(LeafLoc->Location.LineOffset,
+ LeafLoc->Location.Discriminator,
CalleeName, Count);
// Record head sample for called target(callee)
SampleContextFrameVector CalleeCtx(ContextId.begin(), ContextId.end());
- assert(CalleeCtx.back().CallerName == LeafLoc->CallerName &&
+ assert(CalleeCtx.back().FuncName == LeafLoc->FuncName &&
"Leaf function name doesn't match");
CalleeCtx.back() = *LeafLoc;
CalleeCtx.emplace_back(CalleeName, LineLocation(0, 0));
@@ -556,7 +556,7 @@ getCallerContext(SampleContextFrames CalleeContext,
CalleeContext = CalleeContext.drop_back();
CallerContext.assign(CalleeContext.begin(), CalleeContext.end());
SampleContextFrame CallerFrame = CallerContext.back();
- CallerContext.back().Callsite = LineLocation(0, 0);
+ CallerContext.back().Location = LineLocation(0, 0);
return CallerFrame;
}
@@ -595,11 +595,11 @@ void CSProfileGenerator::populateInferredFunctionSamples() {
if (!EstimatedCallCount && !CalleeProfile.getBodySamples().size())
EstimatedCallCount = 1;
CallerProfile.addCalledTargetSamples(
- CallerLeafFrameLoc.Callsite.LineOffset,
- CallerLeafFrameLoc.Callsite.Discriminator,
+ CallerLeafFrameLoc.Location.LineOffset,
+ CallerLeafFrameLoc.Location.Discriminator,
CalleeProfile.getContext().getName(), EstimatedCallCount);
- CallerProfile.addBodySamples(CallerLeafFrameLoc.Callsite.LineOffset,
- CallerLeafFrameLoc.Callsite.Discriminator,
+ CallerProfile.addBodySamples(CallerLeafFrameLoc.Location.LineOffset,
+ CallerLeafFrameLoc.Location.Discriminator,
EstimatedCallCount);
CallerProfile.addTotalSamples(EstimatedCallCount);
}
@@ -734,7 +734,7 @@ void CSProfileGenerator::populateBodySamplesWithProbes(
SampleContextFrameVector CallerContextId;
SampleContextFrame &&CallerLeafFrameLoc =
getCallerContext(CalleeContextId, CallerContextId);
- uint64_t CallerIndex = CallerLeafFrameLoc.Callsite.LineOffset;
+ uint64_t CallerIndex = CallerLeafFrameLoc.Location.LineOffset;
assert(CallerIndex &&
"Inferred caller's location index shouldn't be zero!");
FunctionSamples &CallerProfile =
@@ -795,7 +795,7 @@ FunctionSamples &CSProfileGenerator::getFunctionProfileForLeafProbe(
// frame's probe id, like:
// Inlined stack: [foo:1, bar:2], the ContextId will be "foo:1 @ bar"
auto LeafFrame = NewContextStack.back();
- LeafFrame.Callsite = LineLocation(0, 0);
+ LeafFrame.Location = LineLocation(0, 0);
NewContextStack.pop_back();
// Compress the context string except for the leaf frame
CSProfileGenerator::compressRecursionContext(NewContextStack);
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index aa96f9478afa8..b7a18c2e912e8 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -62,8 +62,8 @@ void BinarySizeContextTracker::addInstructionForContext(
ContextTrieNode *CurNode = &RootContext;
bool IsLeaf = true;
for (const auto &Callsite : reverse(Context)) {
- StringRef CallerName = Callsite.CallerName;
- LineLocation CallsiteLoc = IsLeaf ? LineLocation(0, 0) : Callsite.Callsite;
+ StringRef CallerName = Callsite.FuncName;
+ LineLocation CallsiteLoc = IsLeaf ? LineLocation(0, 0) : Callsite.Location;
CurNode = CurNode->getOrCreateChildContext(CallsiteLoc, CallerName);
IsLeaf = false;
}
@@ -88,7 +88,7 @@ BinarySizeContextTracker::getFuncSizeForContext(const SampleContext &Context) {
const auto &ChildFrame = Frames[I--];
PrevNode = CurrNode;
CurrNode =
- CurrNode->getChildContext(ChildFrame.Callsite, ChildFrame.CallerName);
+ CurrNode->getChildContext(ChildFrame.Location, ChildFrame.FuncName);
if (CurrNode && CurrNode->getFunctionSize().hasValue())
Size = CurrNode->getFunctionSize().getValue();
}
@@ -222,7 +222,7 @@ ProfiledBinary::getExpandedContext(const SmallVectorImpl<uint64_t> &Stack,
// Compress the context string except for the leaf frame
auto LeafFrame = ContextVec.back();
- LeafFrame.Callsite = LineLocation(0, 0);
+ LeafFrame.Location = LineLocation(0, 0);
ContextVec.pop_back();
CSProfileGenerator::compressRecursionContext(ContextVec);
CSProfileGenerator::trimContext(ContextVec);
More information about the llvm-commits
mailing list