-
Notifications
You must be signed in to change notification settings - Fork 14.1k
[MemProf] Emit remarks when hinting allocations not needing cloning #141859
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||
//===----------------------------------------------------------------------===// | ||||
|
||||
#include "llvm/Analysis/MemoryProfileInfo.h" | ||||
#include "llvm/Analysis/OptimizationRemarkEmitter.h" | ||||
#include "llvm/IR/Constants.h" | ||||
#include "llvm/Support/CommandLine.h" | ||||
#include "llvm/Support/Compiler.h" | ||||
|
@@ -145,13 +146,6 @@ std::string llvm::memprof::getAllocTypeAttributeString(AllocationType Type) { | |||
llvm_unreachable("invalid alloc type"); | ||||
} | ||||
|
||||
static void addAllocTypeAttribute(LLVMContext &Ctx, CallBase *CI, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was only one call to this so I inlined it for simplicity and so we have easier access to the AllocTypeString for the remark. |
||||
AllocationType AllocType) { | ||||
auto AllocTypeString = getAllocTypeAttributeString(AllocType); | ||||
auto A = llvm::Attribute::get(Ctx, "memprof", AllocTypeString); | ||||
CI->addFnAttr(A); | ||||
} | ||||
|
||||
bool llvm::memprof::hasSingleAllocType(uint8_t AllocTypes) { | ||||
const unsigned NumAllocTypes = llvm::popcount(AllocTypes); | ||||
assert(NumAllocTypes != 0); | ||||
|
@@ -475,7 +469,9 @@ bool CallStackTrie::buildMIBNodes(CallStackTrieNode *Node, LLVMContext &Ctx, | |||
|
||||
void CallStackTrie::addSingleAllocTypeAttribute(CallBase *CI, AllocationType AT, | ||||
StringRef Descriptor) { | ||||
addAllocTypeAttribute(CI->getContext(), CI, AT); | ||||
auto AllocTypeString = getAllocTypeAttributeString(AT); | ||||
auto A = llvm::Attribute::get(CI->getContext(), "memprof", AllocTypeString); | ||||
CI->addFnAttr(A); | ||||
if (MemProfReportHintedSizes) { | ||||
std::vector<ContextTotalSize> ContextSizeInfo; | ||||
collectContextSizeInfo(Alloc, ContextSizeInfo); | ||||
|
@@ -485,6 +481,12 @@ void CallStackTrie::addSingleAllocTypeAttribute(CallBase *CI, AllocationType AT, | |||
<< getAllocTypeAttributeString(AT) << ": " << TotalSize << "\n"; | ||||
} | ||||
} | ||||
if (ORE) | ||||
ORE->emit(OptimizationRemark(DEBUG_TYPE, "MemprofAttribute", CI) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we associate this annotation back to what was in the profile? Is it possible to associate a non-context sensitive hint to (a set of) context ids? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are for the user so have the allocation file and line like other remarks. I wasn't planning to emit context ids which are more for compiler developers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I.e. here is an example of the equivalent message emitted during cloning:
|
||||
<< ore::NV("AllocationCall", CI) << " in function " | ||||
<< ore::NV("Caller", CI->getFunction()) | ||||
<< " marked with memprof allocation attribute " | ||||
<< ore::NV("Attribute", AllocTypeString)); | ||||
} | ||||
|
||||
// Build and attach the minimal necessary MIB metadata. If the alloc has a | ||||
|
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.
Are you planning to switch all the other messages to ORE too in the future?
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.
Which messages? I wasn't planning to switch e.g. the matching and hinted byte reporting messages that are more for compiler developers at this point