Skip to content

Commit 00eb087

Browse files
[memprof] Test the memprof-use pass with a YAML
This patch adds a test to verify that the call site that allocates cold bytes is annotated as such. The test is the first of its kind integrating the memprof-use pass and YAML.
1 parent 81dcbef commit 00eb087

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; Make sure that we can ingest the MemProf profile in YAML and
2+
; annotate a call to new as cold.
3+
4+
; REQUIRES: x86_64-linux
5+
6+
; RUN: split-file %s %t
7+
; RUN: llvm-profdata merge %t/memprof_annotate_yaml.yaml -o %t/memprof_annotate_yaml.memprofdata
8+
; RUN: opt < %t/memprof_annotate_yaml.ll -passes='memprof-use<profile-filename=%t/memprof_annotate_yaml.memprofdata>' -S 2>&1 | FileCheck %s
9+
10+
;--- memprof_annotate_yaml.yaml
11+
---
12+
HeapProfileRecords:
13+
- GUID: _Z3foov
14+
AllocSites:
15+
- Callstack:
16+
- { Function: _Z3foov, LineOffset: 0, Column: 22, IsInlineFrame: false }
17+
- { Function: main, LineOffset: 2, Column: 5, IsInlineFrame: false }
18+
MemInfoBlock:
19+
TotalSize: 400
20+
AllocCount: 1
21+
TotalLifetimeAccessDensity: 1
22+
TotalLifetime: 1000000
23+
CallSites: []
24+
...
25+
;--- memprof_annotate_yaml.ll
26+
define dso_local ptr @_Z3foov() !dbg !4 {
27+
entry:
28+
%call = call ptr @_Znam(i64 4) #0, !dbg !5
29+
; CHECK: call ptr @_Znam(i64 4) [[ATTR:#[0-9]+]],
30+
ret ptr %call
31+
}
32+
33+
declare ptr @_Znam(i64)
34+
35+
attributes #0 = { builtin allocsize(0) }
36+
; CHECK: attributes [[ATTR]] = {{.*}} "memprof"="cold"
37+
38+
!llvm.module.flags = !{!2, !3}
39+
40+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1)
41+
!1 = !DIFile(filename: "t", directory: "/")
42+
!2 = !{i32 7, !"Dwarf Version", i32 5}
43+
!3 = !{i32 2, !"Debug Info Version", i32 3}
44+
!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 1, unit: !0)
45+
!5 = !DILocation(line: 1, column: 22, scope: !4)

0 commit comments

Comments
 (0)