Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file not shown.
Binary file not shown.
33 changes: 0 additions & 33 deletions llvm/test/Transforms/PGOProfile/Inputs/update_memprof_inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,6 @@ rm ${OUTDIR}/memprof.cc
rm ${OUTDIR}/pgo.exe
rm ${OUTDIR}/memprof_pgo.profraw

# Use musttail to simulate a missing leaf debug frame in the profiled binary.
# Note we don't currently match onto explicit ::operator new calls, which is
# why the non-musttail case uses implicit new (which doesn't support musttail).
# Note that changes in the code below which affect relative line number
# offsets of calls from their parent function can affect callsite matching in
# the LLVM IR.
cat > ${OUTDIR}/memprof_missing_leaf.cc << EOF
#include <new>
#ifndef USE_MUSTTAIL
#define USE_MUSTTAIL 0
#endif

// clang::musttail requires that the argument signature matches that of the caller.
void *bar(std::size_t s) {
#if USE_MUSTTAIL
[[clang::musttail]] return ::operator new (s);
#else
return new char[s];
#endif
}

int main() {
char *a = (char *)bar(1);
delete a;
return 0;
}
EOF

${CLANG} ${COMMON_FLAGS} -fmemory-profile -DUSE_MUSTTAIL=1 ${OUTDIR}/memprof_missing_leaf.cc -o ${OUTDIR}/memprof_missing_leaf.exe
env MEMPROF_OPTIONS=log_path=stdout ${OUTDIR}/memprof_missing_leaf.exe > ${OUTDIR}/memprof_missing_leaf.memprofraw

rm ${OUTDIR}/memprof_missing_leaf.cc

cat > ${OUTDIR}/memprof_internal_linkage.cc << EOF
#include <cstring>
#include <unistd.h>
Expand Down
51 changes: 47 additions & 4 deletions llvm/test/Transforms/PGOProfile/memprof_missing_leaf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,58 @@
;; Avoid failures on big-endian systems that can't read the profile properly
; REQUIRES: x86_64-linux

;; TODO: Use text profile inputs once that is available for memprof.
;; # To update the Inputs below, run Inputs/update_memprof_inputs.sh.
;; # To generate below LLVM IR for use in matching.
;; $ clang++ -gmlt -fdebug-info-for-profiling -S memprof_missing_leaf.cc \
;; -O2 -emit-llvm
;;
;; where memprof_missing_leaf.cc is as follows:
;;
;; #include <new>
;;
;; // Use musttail to simulate a missing leaf debug frame in the profiled binary.
;; // Note we don't currently match onto explicit ::operator new calls, which is
;; // why the non-musttail case uses implicit new (which doesn't support musttail).
;; // Note that changes in the code below which affect relative line number
;; // offsets of calls from their parent function can affect callsite matching in
;; // the LLVM IR.
;; #ifndef USE_MUSTTAIL
;; #define USE_MUSTTAIL 0
;; #endif
;;
;; // clang::musttail requires that the argument signature matches that of the caller.
;; void *bar(std::size_t s) {
;; #if USE_MUSTTAIL
;; [[clang::musttail]] return ::operator new (s);
;; #else
;; return new char[s];
;; #endif
;; }
;;
;; int main() {
;; char *a = (char *)bar(1);
;; delete a;
;; return 0;
;;}

; RUN: llvm-profdata merge %S/Inputs/memprof_missing_leaf.memprofraw --profiled-binary %S/Inputs/memprof_missing_leaf.exe -o %t.memprofdata
; RUN: opt < %s -passes='memprof-use<profile-filename=%t.memprofdata>' -S | FileCheck %s
; RUN: split-file %s %t
; RUN: llvm-profdata merge %t/memprof_missing_leaf.yaml -o %t/memprof_missing_leaf.memprofdata
; RUN: opt < %t/memprof_missing_leaf.ll -passes='memprof-use<profile-filename=%t/memprof_missing_leaf.memprofdata>' -S | FileCheck %s

;--- memprof_missing_leaf.yaml
---
HeapProfileRecords:
- GUID: main
AllocSites:
- Callstack:
- { Function: main, LineOffset: 1, Column: 21, IsInlineFrame: false }
MemInfoBlock:
AllocCount: 1
TotalSize: 1
TotalLifetime: 0
TotalLifetimeAccessDensity: 0
CallSites: []
...
;--- memprof_missing_leaf.ll
; CHECK: call {{.*}} @_Znam{{.*}} #[[ATTR:[0-9]+]]
; CHECK: attributes #[[ATTR]] = {{.*}} "memprof"="notcold"

Expand Down
Loading