diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h --- a/llvm/include/llvm/ProfileData/SampleProf.h +++ b/llvm/include/llvm/ProfileData/SampleProf.h @@ -412,18 +412,18 @@ 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 @@ 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; @@ -598,7 +598,7 @@ ContextStateMask CState = RawContext) { assert(CState != UnknownContext); FullContext = Context; - Name = Context.back().CallerName; + Name = Context.back().FuncName; State = CState; } @@ -621,11 +621,11 @@ 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 @@ 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 --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -269,10 +269,10 @@ 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 @@ 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 --- a/llvm/lib/Transforms/IPO/SampleContextTracker.cpp +++ b/llvm/lib/Transforms/IPO/SampleContextTracker.cpp @@ -511,13 +511,13 @@ 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 --- a/llvm/tools/llvm-profgen/CallContext.h +++ b/llvm/tools/llvm-profgen/CallContext.h @@ -18,12 +18,12 @@ 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 --- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp +++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp @@ -253,15 +253,15 @@ 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 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ // 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 --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -62,8 +62,8 @@ 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 @@ 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 @@ // 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);