Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ STATISTIC(NewMergedNodes, "Number of new nodes created during merging");
STATISTIC(NonNewMergedNodes, "Number of non new nodes used during merging");
STATISTIC(MissingAllocForContextId,
"Number of missing alloc nodes for context ids");
STATISTIC(SkippedCallsCloning, "Number of calls skipped during cloning");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this could be more specific to the reason it was skipped? On the other hand, is this case the only place where we may skip calls during cloning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out making it longer and more specific, but figured we'd need to look up the reason in the code if we ever encounter this in the wild anyway (it's a developer-focused stat). Any suggestions for something more specific but not too terse? The other place we might skip is if it required ICP and we couldn't legally perform that. How about "Number of calls skipped during cloning due to unexpected operand" ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the ICP case is good to cover with this statistic too? Then we can keep the name and description as is.

Not a strong opinion, feel free to just update the description as you suggested as an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will update the description for this one as I suggested, since I'd like to know specifically if/when we hit this case. I'll add a separate stat for the other case(s) when I get a chance.


static cl::opt<std::string> DotFilePathPrefix(
"memprof-dot-file-path-prefix", cl::init(""), cl::Hidden,
Expand Down Expand Up @@ -5155,6 +5156,19 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {

assert(!isMemProfClone(*CalledFunction));

// Because we update the cloned calls by calling setCalledOperand (see
// comment below), out of an abundance of caution make sure the called
// function was actually the called operand (or its aliasee). We also
// strip pointer casts when looking for calls (to match behavior during
// summary generation), however, with opaque pointers in theory this
// should not be an issue. Note we still clone the current function
// (containing this call) above, as that could be needed for its callers.
auto *GA = dyn_cast_or_null<GlobalAlias>(CB->getCalledOperand());
if (CalledFunction != CB->getCalledOperand() &&
(!GA || CalledFunction != GA->getAliaseeObject())) {
SkippedCallsCloning++;
return;
}
// Update the calls per the summary info.
// Save orig name since it gets updated in the first iteration
// below.
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/ThinLTO/X86/memprof_callee_type_mismatch.ll
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
;; Test to ensure the call updated to call a clone does not mutate the callee
;; function type. In rare cases we may end up with a callee declaration that
;; does not match the call type, because it was imported from a different
;; Test to ensure the callite when updated to call a clone does not mutate the
;; callee function type. In rare cases we may end up with a callee declaration
;; that does not match the call type, because it was imported from a different
;; module with an incomplete return type (in which case clang gives it a void
;; return type).

; RUN: rm -rf %t && split-file %s %t && cd %t
; RUN: llvm-as src.ll -o src.o
; RUN: llvm-as src.o.thinlto.ll -o src.o.thinlto.bc

; RUN: opt -passes=memprof-context-disambiguation src.o -S -memprof-import-summary=src.o.thinlto.bc | FileCheck %s

;--- src.ll
Expand Down
Loading