Files
swift-mirror/test/SILOptimizer/set.swift
Erik Eckstein 7839b54b8a GenericSpecializer: drop metatype arguments in specialized functions
And replace them with explicit `metatype` instruction in the entry block.
This allows such metatype instructions to be deleted if they are dead.

This was already done for performance-annotated functions. But now do this for all functions.

It is essential that performance-annotated functions are specialized in the same way as other functions.
Because otherwise it can happen that the same specialization has different performance characteristics in different modules.
And it's up to the linker to select one of those ODR functions when linking.

Also, dropping metatype arguments is good for performance and code size in general.

This change also contains a few bug fixes for dropping metatype arguments.

rdar://110509780
2023-06-15 21:42:01 +02:00

33 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -parse-as-library -primary-file %s -O -sil-verify-all -module-name=test -Xllvm -sil-disable-pass=function-signature-opts -emit-sil | %FileCheck %s
// RUN: %target-swift-frontend -parse-as-library -primary-file %s -Osize -sil-verify-all -module-name=test -Xllvm -sil-disable-pass=function-signature-opts -emit-sil | %FileCheck %s
// REQUIRES: swift_stdlib_no_asserts,optimized_stdlib
// REQUIRES: swift_in_compiler
// Test optimal code generation for creating empty sets.
// CHECK-LABEL: sil {{.*}}@$s4test30createEmptySetFromArrayLiteralShySiGyF
// CHECK: global_addr @_swiftEmptySetSingleton
// CHECK-NOT: apply
// CHECK: } // end sil function '$s4test30createEmptySetFromArrayLiteralShySiGyF'
public func createEmptySetFromArrayLiteral() -> Set<Int> {
return []
}
// CHECK-LABEL: sil {{.*}}@$s4test29createEmptySetWithInitializerShySiGyF
// CHECK: global_addr @_swiftEmptySetSingleton
// CHECK-NOT: apply
// CHECK: } // end sil function '$s4test29createEmptySetWithInitializerShySiGyF'
public func createEmptySetWithInitializer() -> Set<Int> {
return Set<Int>()
}
// CHECK-LABEL: sil {{.*}}@$s4test17createNonEmptySetShySiGyF
// CHECK: global_value
// CHECK: [[F:%[0-9]+]] = function_ref @$sSh21_nonEmptyArrayLiteralShyxGSayxG_tcfCSi_Tgm5
// CHECK: apply [[F]]
// CHECK: } // end sil function '$s4test17createNonEmptySetShySiGyF'
public func createNonEmptySet() -> Set<Int> {
return [1, 2, 3]
}