Skip to content
Open
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
7 changes: 7 additions & 0 deletions llvm/lib/Transforms/IPO/ExpandVariadics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ bool ExpandVariadics::runOnFunction(Module &M, IRBuilder<> &Builder,
assert(VariadicWrapperDefine == VariadicWrapper);
assert(!VariadicWrapper->isDeclaration());

// Add the prof metadata from the original function to the wrapper. Because
// FixedArityReplacement is the owner of original function's prof metadata
// after the splice, we need to transfer it to VariadicWrapper.
VariadicWrapper->setMetadata(LLVMContext::MD_prof, FixedArityReplacement->getMetadata(LLVMContext::MD_prof))
FixedArityReplacement->getMetadata(LLVMContext::MD_prof))
VariadicWrapper->setMetadata(LLVMContext::MD_prof, ProfMD);

// We now have:
// 1. the original function, now as a declaration with no uses
// 2. a variadic function that unconditionally calls a fixed arity replacement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature --check-globals
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s --check-prefixes=OPT
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s --check-prefixes=ABI
; REQUIRES: webassembly-registered-target
Expand All @@ -21,8 +21,8 @@ declare void @llvm.va_start(ptr)
declare void @llvm.va_end(ptr)

declare void @decl_simple(...)
define void @defn_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_simple(...) {
define void @defn_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_simple(...) !prof !0 {
; OPT-NEXT: entry:
; OPT-NEXT: %va_start = alloca ptr, align 4
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
Expand All @@ -32,7 +32,7 @@ define void @defn_simple(...) {
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -46,8 +46,8 @@ define void @defn_simple(...) {
}

; no declare for private
define private void @defn_private_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_private_simple(...) {
define private void @defn_private_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_private_simple(...) !prof !0 {
; OPT-NEXT: entry:
; OPT-NEXT: %va_start = alloca ptr, align 4
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
Expand All @@ -57,7 +57,7 @@ define private void @defn_private_simple(...) {
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_private_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_private_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -71,8 +71,8 @@ define private void @defn_private_simple(...) {
}

; no declare for internal
define internal void @defn_internal_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_internal_simple(...) {
define internal void @defn_internal_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_internal_simple(...) !prof !0 {
; OPT-NEXT: entry:
; OPT-NEXT: %va_start = alloca ptr, align 4
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
Expand All @@ -82,7 +82,7 @@ define internal void @defn_internal_simple(...) {
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_internal_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_internal_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -96,14 +96,14 @@ define internal void @defn_internal_simple(...) {
}

; no declare for available_externally
define available_externally void @available_externally_simple(...) {
; OPT-LABEL: define {{[^@]+}}@available_externally_simple(...) {
define available_externally void @available_externally_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@available_externally_simple(...) !prof !0 {
; OPT-NEXT: %va = alloca ptr, align 4
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
; OPT-NEXT: call void @sink_valist(ptr %va)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@available_externally_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@available_externally_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -117,14 +117,14 @@ define available_externally void @available_externally_simple(...) {
}

; no declare for linkonce
define linkonce void @defn_linkonce_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_simple(...) {
define linkonce void @defn_linkonce_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_simple(...) !prof !0 {
; OPT-NEXT: %va = alloca ptr, align 4
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
; OPT-NEXT: call void @sink_valist(ptr %va)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -138,14 +138,14 @@ define linkonce void @defn_linkonce_simple(...) {
}

; no declare for weak
define weak void @defn_weak_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_weak_simple(...) {
define weak void @defn_weak_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_weak_simple(...) !prof !0 {
; OPT-NEXT: %va = alloca ptr, align 4
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
; OPT-NEXT: call void @sink_valist(ptr %va)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_weak_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_weak_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -165,14 +165,14 @@ declare extern_weak void @decl_extern_weak_simple(...)
; no define for extern_weak

; no declare for linkonce_odr
define linkonce_odr void @defn_linkonce_odr_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(...) {
define linkonce_odr void @defn_linkonce_odr_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(...) !prof !0 {
; OPT-NEXT: %va = alloca ptr, align 4
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
; OPT-NEXT: call void @sink_valist(ptr %va)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_linkonce_odr_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -186,14 +186,14 @@ define linkonce_odr void @defn_linkonce_odr_simple(...) {
}

; no declare for weak_odr
define weak_odr void @defn_weak_odr_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_weak_odr_simple(...) {
define weak_odr void @defn_weak_odr_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_weak_odr_simple(...) !prof !0 {
; OPT-NEXT: %va = alloca ptr, align 4
; OPT-NEXT: call void @llvm.va_start.p0(ptr %va)
; OPT-NEXT: call void @sink_valist(ptr %va)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_weak_odr_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_weak_odr_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -207,8 +207,8 @@ define weak_odr void @defn_weak_odr_simple(...) {
}

declare external void @decl_external_simple(...)
define external void @defn_external_simple(...) {
; OPT-LABEL: define {{[^@]+}}@defn_external_simple(...) {
define external void @defn_external_simple(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@defn_external_simple(...) !prof !0 {
; OPT-NEXT: entry:
; OPT-NEXT: %va_start = alloca ptr, align 4
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
Expand All @@ -218,7 +218,7 @@ define external void @defn_external_simple(...) {
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
; OPT-NEXT: ret void
;
; ABI-LABEL: define {{[^@]+}}@defn_external_simple(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@defn_external_simple(ptr %varargs) !prof !0 {
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
; ABI-NEXT: call void @sink_valist(ptr %va)
Expand All @@ -230,3 +230,15 @@ define external void @defn_external_simple(...) {
call void @llvm.va_end(ptr %va)
ret void
}

!0 = !{!"function_entry_count", i64 1000}
;.
; OPT: attributes #0 = { nocallback nofree nosync nounwind willreturn }
; OPT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
;.
; ABI: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
;.
; OPT: !0 = !{!"function_entry_count", i64 1000}
;.
; ABI: !0 = !{!"function_entry_count", i64 1000}
;.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: -p --function-signature --check-globals
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s --check-prefixes=OPT
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s --check-prefixes=ABI
; REQUIRES: webassembly-registered-target

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

define i32 @variadic_int_double_get_firstz(...) {
; OPT-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(...) {
define i32 @variadic_int_double_get_firstz(...) !prof !0 {
; OPT-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(...) !prof !0 {
; OPT-NEXT: entry:
; OPT-NEXT: %va_start = alloca ptr, align 4
; OPT-NEXT: call void @llvm.lifetime.start.p0(ptr %va_start)
Expand All @@ -17,7 +17,7 @@ define i32 @variadic_int_double_get_firstz(...) {
; OPT-NEXT: call void @llvm.lifetime.end.p0(ptr %va_start)
; OPT-NEXT: ret i32 %1
;
; ABI-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(ptr %varargs) {
; ABI-LABEL: define {{[^@]+}}@variadic_int_double_get_firstz(ptr %varargs) !prof !0 {
; ABI-NEXT: entry:
; ABI-NEXT: %va = alloca ptr, align 4
; ABI-NEXT: store ptr %varargs, ptr %va, align 4
Expand Down Expand Up @@ -212,3 +212,15 @@ declare void @variadic_without_callers(...)

declare void @llvm.va_start.p0(ptr)
declare void @llvm.va_end.p0(ptr)

!0 = !{!"function_entry_count", i64 1000}
;.
; OPT: attributes #0 = { nocallback nofree nosync nounwind willreturn }
; OPT: attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
;.
; ABI: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
;.
; OPT: !0 = !{!"function_entry_count", i64 1000}
;.
; ABI: !0 = !{!"function_entry_count", i64 1000}
;.
18 changes: 16 additions & 2 deletions llvm/test/Transforms/ExpandVariadics/intrinsics.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=optimize < %s | FileCheck %s -check-prefixes=CHECK,OPT
; RUN: opt -mtriple=wasm32-unknown-unknown -S --passes=expand-variadics --expand-variadics-override=lowering < %s | FileCheck %s -check-prefixes=CHECK,ABI
; REQUIRES: webassembly-registered-target
Expand All @@ -16,7 +16,7 @@ declare void @llvm.va_start.p0(ptr)
declare void @llvm.va_end.p0(ptr)


define void @start_once(...) {
define void @start_once(...) !prof !0 {
; OPT-LABEL: @start_once(
; OPT-NEXT: entry:
; OPT-NEXT: [[VA_START:%.*]] = alloca ptr, align 4
Expand Down Expand Up @@ -118,3 +118,17 @@ entry:
call void @llvm.lifetime.end.p0(ptr nonnull %cp)
ret void
}

!0 = !{!"function_entry_count", i64 1000}
;.
; OPT: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
; OPT: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn }
; OPT: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
;.
; ABI: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
; ABI: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
;.
; OPT: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
;.
; ABI: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
;.
Loading