Skip to content

Commit 2e9f80f

Browse files
author
Jin Huang
committed
[profcheck] Propagate profile metadata to Wrapper in ExpandVariadics optimize mode
1 parent 3705921 commit 2e9f80f

File tree

4 files changed

+79
-34
lines changed

4 files changed

+79
-34
lines changed

llvm/lib/Transforms/IPO/ExpandVariadics.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ bool ExpandVariadics::runOnFunction(Module &M, IRBuilder<> &Builder,
422422
assert(VariadicWrapperDefine == VariadicWrapper);
423423
assert(!VariadicWrapper->isDeclaration());
424424

425+
// Add the prof metadata from the original function to the wrapper. Because
426+
// FixedArityReplacement is the owner of original function's prof metadata
427+
// after the splice, we need to transfer it to VariadicWrapper.
428+
VariadicWrapper->setMetadata(
429+
LLVMContext::MD_prof,
430+
FixedArityReplacement->getMetadata(LLVMContext::MD_prof));
431+
425432
// We now have:
426433
// 1. the original function, now as a declaration with no uses
427434
// 2. a variadic function that unconditionally calls a fixed arity replacement

llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-linkage.ll

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature --check-globals
22
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s --check-prefixes=OPT
33
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s --check-prefixes=ABI
44
; REQUIRES: webassembly-registered-target
@@ -21,8 +21,8 @@ declare void @llvm.va_start(ptr)
2121
declare void @llvm.va_end(ptr)
2222

2323
declare void @decl_simple(...)
24-
define void @defn_simple(...) {
25-
; OPT-LABEL: define {{[^@]+}}@defn_simple(...) {
24+
define void @defn_simple(...) !prof !0 {
25+
; OPT-LABEL: define {{[^@]+}}@defn_simple(...) !prof !0 {
2626
; OPT-NEXT: entry:
2727
; OPT-NEXT: %va_start = alloca ptr, align 4
2828
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
@@ -32,7 +32,7 @@ define void @defn_simple(...) {
3232
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
3333
; OPT-NEXT: ret void
3434
;
35-
; ABI-LABEL: define {{[^@]+}}@defn_simple(ptr %varargs) {
35+
; ABI-LABEL: define {{[^@]+}}@defn_simple(ptr %varargs) !prof !0 {
3636
; ABI-NEXT: %va = alloca ptr, align 4
3737
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
3838
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -46,8 +46,8 @@ define void @defn_simple(...) {
4646
}
4747

4848
; no declare for private
49-
define private void @defn_private_simple(...) {
50-
; OPT-LABEL: define {{[^@]+}}@defn_private_simple(...) {
49+
define private void @defn_private_simple(...) !prof !0 {
50+
; OPT-LABEL: define {{[^@]+}}@defn_private_simple(...) !prof !0 {
5151
; OPT-NEXT: entry:
5252
; OPT-NEXT: %va_start = alloca ptr, align 4
5353
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
@@ -57,7 +57,7 @@ define private void @defn_private_simple(...) {
5757
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
5858
; OPT-NEXT: ret void
5959
;
60-
; ABI-LABEL: define {{[^@]+}}@defn_private_simple(ptr %varargs) {
60+
; ABI-LABEL: define {{[^@]+}}@defn_private_simple(ptr %varargs) !prof !0 {
6161
; ABI-NEXT: %va = alloca ptr, align 4
6262
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
6363
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -71,8 +71,8 @@ define private void @defn_private_simple(...) {
7171
}
7272

7373
; no declare for internal
74-
define internal void @defn_internal_simple(...) {
75-
; OPT-LABEL: define {{[^@]+}}@defn_internal_simple(...) {
74+
define internal void @defn_internal_simple(...) !prof !0 {
75+
; OPT-LABEL: define {{[^@]+}}@defn_internal_simple(...) !prof !0 {
7676
; OPT-NEXT: entry:
7777
; OPT-NEXT: %va_start = alloca ptr, align 4
7878
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
@@ -82,7 +82,7 @@ define internal void @defn_internal_simple(...) {
8282
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
8383
; OPT-NEXT: ret void
8484
;
85-
; ABI-LABEL: define {{[^@]+}}@defn_internal_simple(ptr %varargs) {
85+
; ABI-LABEL: define {{[^@]+}}@defn_internal_simple(ptr %varargs) !prof !0 {
8686
; ABI-NEXT: %va = alloca ptr, align 4
8787
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
8888
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -96,14 +96,14 @@ define internal void @defn_internal_simple(...) {
9696
}
9797

9898
; no declare for available_externally
99-
define available_externally void @available_externally_simple(...) {
100-
; OPT-LABEL: define {{[^@]+}}@available_externally_simple(...) {
99+
define available_externally void @available_externally_simple(...) !prof !0 {
100+
; OPT-LABEL: define {{[^@]+}}@available_externally_simple(...) !prof !0 {
101101
; OPT-NEXT: %va = alloca ptr, align 4
102102
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
103103
; OPT-NEXT: call void @sink_valist(ptr %va)
104104
; OPT-NEXT: ret void
105105
;
106-
; ABI-LABEL: define {{[^@]+}}@available_externally_simple(ptr %varargs) {
106+
; ABI-LABEL: define {{[^@]+}}@available_externally_simple(ptr %varargs) !prof !0 {
107107
; ABI-NEXT: %va = alloca ptr, align 4
108108
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
109109
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -117,14 +117,14 @@ define available_externally void @available_externally_simple(...) {
117117
}
118118

119119
; no declare for linkonce
120-
define linkonce void @defn_linkonce_simple(...) {
121-
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_simple(...) {
120+
define linkonce void @defn_linkonce_simple(...) !prof !0 {
121+
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_simple(...) !prof !0 {
122122
; OPT-NEXT: %va = alloca ptr, align 4
123123
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
124124
; OPT-NEXT: call void @sink_valist(ptr %va)
125125
; OPT-NEXT: ret void
126126
;
127-
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_simple(ptr %varargs) {
127+
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_simple(ptr %varargs) !prof !0 {
128128
; ABI-NEXT: %va = alloca ptr, align 4
129129
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
130130
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -138,14 +138,14 @@ define linkonce void @defn_linkonce_simple(...) {
138138
}
139139

140140
; no declare for weak
141-
define weak void @defn_weak_simple(...) {
142-
; OPT-LABEL: define {{[^@]+}}@defn_weak_simple(...) {
141+
define weak void @defn_weak_simple(...) !prof !0 {
142+
; OPT-LABEL: define {{[^@]+}}@defn_weak_simple(...) !prof !0 {
143143
; OPT-NEXT: %va = alloca ptr, align 4
144144
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
145145
; OPT-NEXT: call void @sink_valist(ptr %va)
146146
; OPT-NEXT: ret void
147147
;
148-
; ABI-LABEL: define {{[^@]+}}@defn_weak_simple(ptr %varargs) {
148+
; ABI-LABEL: define {{[^@]+}}@defn_weak_simple(ptr %varargs) !prof !0 {
149149
; ABI-NEXT: %va = alloca ptr, align 4
150150
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
151151
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -165,14 +165,14 @@ declare extern_weak void @decl_extern_weak_simple(...)
165165
; no define for extern_weak
166166

167167
; no declare for linkonce_odr
168-
define linkonce_odr void @defn_linkonce_odr_simple(...) {
169-
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(...) {
168+
define linkonce_odr void @defn_linkonce_odr_simple(...) !prof !0 {
169+
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(...) !prof !0 {
170170
; OPT-NEXT: %va = alloca ptr, align 4
171171
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
172172
; OPT-NEXT: call void @sink_valist(ptr %va)
173173
; OPT-NEXT: ret void
174174
;
175-
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(ptr %varargs) {
175+
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(ptr %varargs) !prof !0 {
176176
; ABI-NEXT: %va = alloca ptr, align 4
177177
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
178178
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -186,14 +186,14 @@ define linkonce_odr void @defn_linkonce_odr_simple(...) {
186186
}
187187

188188
; no declare for weak_odr
189-
define weak_odr void @defn_weak_odr_simple(...) {
190-
; OPT-LABEL: define {{[^@]+}}@defn_weak_odr_simple(...) {
189+
define weak_odr void @defn_weak_odr_simple(...) !prof !0 {
190+
; OPT-LABEL: define {{[^@]+}}@defn_weak_odr_simple(...) !prof !0 {
191191
; OPT-NEXT: %va = alloca ptr, align 4
192192
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
193193
; OPT-NEXT: call void @sink_valist(ptr %va)
194194
; OPT-NEXT: ret void
195195
;
196-
; ABI-LABEL: define {{[^@]+}}@defn_weak_odr_simple(ptr %varargs) {
196+
; ABI-LABEL: define {{[^@]+}}@defn_weak_odr_simple(ptr %varargs) !prof !0 {
197197
; ABI-NEXT: %va = alloca ptr, align 4
198198
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
199199
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -207,8 +207,8 @@ define weak_odr void @defn_weak_odr_simple(...) {
207207
}
208208

209209
declare external void @decl_external_simple(...)
210-
define external void @defn_external_simple(...) {
211-
; OPT-LABEL: define {{[^@]+}}@defn_external_simple(...) {
210+
define external void @defn_external_simple(...) !prof !0 {
211+
; OPT-LABEL: define {{[^@]+}}@defn_external_simple(...) !prof !0 {
212212
; OPT-NEXT: entry:
213213
; OPT-NEXT: %va_start = alloca ptr, align 4
214214
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
@@ -218,7 +218,7 @@ define external void @defn_external_simple(...) {
218218
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
219219
; OPT-NEXT: ret void
220220
;
221-
; ABI-LABEL: define {{[^@]+}}@defn_external_simple(ptr %varargs) {
221+
; ABI-LABEL: define {{[^@]+}}@defn_external_simple(ptr %varargs) !prof !0 {
222222
; ABI-NEXT: %va = alloca ptr, align 4
223223
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
224224
; ABI-NEXT: call void @sink_valist(ptr %va)
@@ -230,3 +230,15 @@ define external void @defn_external_simple(...) {
230230
call void @llvm.va_end(ptr %va)
231231
ret void
232232
}
233+
234+
!0 = !{!"function_entry_count", i64 1000}
235+
;.
236+
; OPT: attributes #0 = { nocallback nofree nosync nounwind willreturn }
237+
; OPT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
238+
;.
239+
; ABI: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
240+
;.
241+
; OPT: !0 = !{!"function_entry_count", i64 1000}
242+
;.
243+
; ABI: !0 = !{!"function_entry_count", i64 1000}
244+
;.

llvm/test/Transforms/ExpandVariadics/expand-va-intrinsic-split-simple.ll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature --check-globals
22
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s --check-prefixes=OPT
33
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s --check-prefixes=ABI
44
; REQUIRES: webassembly-registered-target
55

66
; Examples are variadic functions that return the first or the second of an int and a double
77
; Split the functions into an internal equivalent that takes a va_list and a ABI preserving wrapper
88

9-
define i32 @variadic_int_double_get_firstz(...) {
10-
; OPT-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(...) {
9+
define i32 @variadic_int_double_get_firstz(...) !prof !0 {
10+
; OPT-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(...) !prof !0 {
1111
; OPT-NEXT: entry:
1212
; OPT-NEXT: %va_start = alloca ptr, align 4
1313
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
@@ -17,7 +17,7 @@ define i32 @variadic_int_double_get_firstz(...) {
1717
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
1818
; OPT-NEXT: ret i32 %1
1919
;
20-
; ABI-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(ptr %varargs) {
20+
; ABI-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(ptr %varargs) !prof !0 {
2121
; ABI-NEXT: entry:
2222
; ABI-NEXT: %va = alloca ptr, align 4
2323
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
@@ -212,3 +212,15 @@ declare void @variadic_without_callers(...)
212212

213213
declare void @llvm.va_start.p0(ptr)
214214
declare void @llvm.va_end.p0(ptr)
215+
216+
!0 = !{!"function_entry_count", i64 1000}
217+
;.
218+
; OPT: attributes #0 = { nocallback nofree nosync nounwind willreturn }
219+
; OPT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
220+
;.
221+
; ABI: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
222+
;.
223+
; OPT: !0 = !{!"function_entry_count", i64 1000}
224+
;.
225+
; ABI: !0 = !{!"function_entry_count", i64 1000}
226+
;.

llvm/test/Transforms/ExpandVariadics/intrinsics.ll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s -check-prefixes=CHECK,OPT
33
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s -check-prefixes=CHECK,ABI
44
; REQUIRES: webassembly-registered-target
@@ -16,7 +16,7 @@ declare void @llvm.va_start.p0(ptr)
1616
declare void @llvm.va_end.p0(ptr)
1717

1818

19-
define void @start_once(...) {
19+
define void @start_once(...) !prof !0 {
2020
; OPT-LABEL: @start_once(
2121
; OPT-NEXT: entry:
2222
; OPT-NEXT: [[VA_START:%.*]] = alloca ptr, align 4
@@ -118,3 +118,17 @@ entry:
118118
call void @llvm.lifetime.end.p0(ptr nonnull %cp)
119119
ret void
120120
}
121+
122+
!0 = !{!"function_entry_count", i64 1000}
123+
;.
124+
; OPT: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
125+
; OPT: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn }
126+
; OPT: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
127+
;.
128+
; ABI: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
129+
; ABI: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
130+
;.
131+
; OPT: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
132+
;.
133+
; ABI: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
134+
;.

0 commit comments

Comments
 (0)