-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[MemProf] Refactor context node creation into a new helper (NFC) #108408
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
Merged
teresajohnson
merged 1 commit into
llvm:main
from
teresajohnson:memprof_refactor_node_creation
Sep 27, 2024
Merged
[MemProf] Refactor context node creation into a new helper (NFC) #108408
teresajohnson
merged 1 commit into
llvm:main
from
teresajohnson:memprof_refactor_node_creation
Sep 27, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simplify code by refactoring some common handling for node creation into a helper function.
@llvm/pr-subscribers-llvm-transforms Author: Teresa Johnson (teresajohnson) ChangesSimplify code by refactoring some common handling for node creation into Full diff: https://github.com/llvm/llvm-project/pull/108408.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index fa25baee2ba032..42c9faf0445563 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -587,6 +587,16 @@ class CallsiteContextGraph {
return static_cast<const DerivedCCG *>(this)->getLabel(Func, Call, CloneNo);
}
+ // Create and return a new ContextNode.
+ ContextNode *createNewNode(bool IsAllocation, const FuncTy *F = nullptr,
+ CallInfo C = CallInfo()) {
+ NodeOwner.push_back(std::make_unique<ContextNode>(IsAllocation, C));
+ auto *NewNode = NodeOwner.back().get();
+ if (F)
+ NodeToCallingFunc[NewNode] = F;
+ return NewNode;
+ }
+
/// Helpers to find the node corresponding to the given call or stackid.
ContextNode *getNodeForInst(const CallInfo &C);
ContextNode *getNodeForAlloc(const CallInfo &C);
@@ -1023,11 +1033,8 @@ typename CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextNode *
CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::addAllocNode(
CallInfo Call, const FuncTy *F) {
assert(!getNodeForAlloc(Call));
- NodeOwner.push_back(
- std::make_unique<ContextNode>(/*IsAllocation=*/true, Call));
- ContextNode *AllocNode = NodeOwner.back().get();
+ ContextNode *AllocNode = createNewNode(/*IsAllocation=*/true, F, Call);
AllocationCallToContextNodeMap[Call] = AllocNode;
- NodeToCallingFunc[AllocNode] = F;
// Use LastContextId as a uniq id for MIB allocation nodes.
AllocNode->OrigStackOrAllocId = LastContextId;
// Alloc type should be updated as we add in the MIBs. We should assert
@@ -1084,9 +1091,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::addStackNodesForMIB(
auto StackId = getStackId(*ContextIter);
ContextNode *StackNode = getNodeForStackId(StackId);
if (!StackNode) {
- NodeOwner.push_back(
- std::make_unique<ContextNode>(/*IsAllocation=*/false));
- StackNode = NodeOwner.back().get();
+ StackNode = createNewNode(/*IsAllocation=*/false);
StackEntryIdToContextNodeMap[StackId] = StackNode;
StackNode->OrigStackOrAllocId = StackId;
}
@@ -1371,10 +1376,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
continue;
// Create new context node.
- NodeOwner.push_back(
- std::make_unique<ContextNode>(/*IsAllocation=*/false, Call));
- ContextNode *NewNode = NodeOwner.back().get();
- NodeToCallingFunc[NewNode] = Func;
+ ContextNode *NewNode = createNewNode(/*IsAllocation=*/false, Func, Call);
NonAllocationCallToContextNodeMap[Call] = NewNode;
NewNode->AllocTypes = computeAllocType(SavedContextIds);
@@ -2083,10 +2085,7 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
} else {
FuncToCallsWithMetadata[Func].push_back({NewCall});
// Create Node and record node info.
- NodeOwner.push_back(
- std::make_unique<ContextNode>(/*IsAllocation=*/false, NewCall));
- NewNode = NodeOwner.back().get();
- NodeToCallingFunc[NewNode] = Func;
+ NewNode = createNewNode(/*IsAllocation=*/false, Func, NewCall);
TailCallToContextNodeMap[NewCall] = NewNode;
NewNode->AllocTypes = Edge->AllocTypes;
}
@@ -2655,13 +2654,11 @@ CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::moveEdgeToNewCalleeClone(
const std::shared_ptr<ContextEdge> &Edge, EdgeIter *CallerEdgeI,
DenseSet<uint32_t> ContextIdsToMove) {
ContextNode *Node = Edge->Callee;
- NodeOwner.push_back(
- std::make_unique<ContextNode>(Node->IsAllocation, Node->Call));
- ContextNode *Clone = NodeOwner.back().get();
+ assert(NodeToCallingFunc.count(Node));
+ ContextNode *Clone =
+ createNewNode(Node->IsAllocation, NodeToCallingFunc[Node], Node->Call);
Node->addClone(Clone);
Clone->MatchingCalls = Node->MatchingCalls;
- assert(NodeToCallingFunc.count(Node));
- NodeToCallingFunc[Clone] = NodeToCallingFunc[Node];
moveEdgeToExistingCalleeClone(Edge, Clone, CallerEdgeI, /*NewClone=*/true,
ContextIdsToMove);
return Clone;
|
snehasish
approved these changes
Sep 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Sterling-Augustine
pushed a commit
to Sterling-Augustine/llvm-project
that referenced
this pull request
Sep 27, 2024
…m#108408) Simplify code by refactoring some common handling for node creation into a helper function.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Simplify code by refactoring some common handling for node creation into
a helper function.