Skip to content

Commit b0f4b30

Browse files
committed
Address comments
1 parent ceca3b4 commit b0f4b30

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ STATISTIC(NewMergedNodes, "Number of new nodes created during merging");
9595
STATISTIC(NonNewMergedNodes, "Number of non new nodes used during merging");
9696
STATISTIC(MissingAllocForContextId,
9797
"Number of missing alloc nodes for context ids");
98+
STATISTIC(SkippedCallsCloning, "Number of calls skipped during cloning");
9899

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

51565157
assert(!isMemProfClone(*CalledFunction));
51575158

5159+
// Because we update the cloned calls by calling setCalledOperand (see
5160+
// comment below), out of an abundance of caution make sure the called
5161+
// function was actually the called operand (or its aliasee). We also
5162+
// strip pointer casts when looking for calls (to match behavior during
5163+
// summary generation), however, with opaque pointers in theory this
5164+
// should not be an issue. Note we still clone the current function
5165+
// (containing this call) above, as that could be needed for its callers.
5166+
auto *GA = dyn_cast_or_null<GlobalAlias>(CB->getCalledOperand());
5167+
if (CalledFunction != CB->getCalledOperand() &&
5168+
(!GA || CalledFunction != GA->getAliaseeObject())) {
5169+
SkippedCallsCloning++;
5170+
return;
5171+
}
51585172
// Update the calls per the summary info.
51595173
// Save orig name since it gets updated in the first iteration
51605174
// below.

llvm/test/ThinLTO/X86/memprof_callee_type_mismatch.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
;; Test to ensure the call updated to call a clone does not mutate the callee
2-
;; function type. In rare cases we may end up with a callee declaration that
3-
;; does not match the call type, because it was imported from a different
1+
;; Test to ensure the callite when updated to call a clone does not mutate the
2+
;; callee function type. In rare cases we may end up with a callee declaration
3+
;; that does not match the call type, because it was imported from a different
44
;; module with an incomplete return type (in which case clang gives it a void
55
;; return type).
66

77
; RUN: rm -rf %t && split-file %s %t && cd %t
88
; RUN: llvm-as src.ll -o src.o
99
; RUN: llvm-as src.o.thinlto.ll -o src.o.thinlto.bc
10-
1110
; RUN: opt -passes=memprof-context-disambiguation src.o -S -memprof-import-summary=src.o.thinlto.bc | FileCheck %s
1211

1312
;--- src.ll

0 commit comments

Comments
 (0)