Skip to content

[Pacage CMO] Test updates #76991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2024
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
30 changes: 30 additions & 0 deletions test/IRGen/package-cmo-global-accessor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %empty-directory(%t)

// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -o %t/IR-nonres.ir
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution -o %t/IR-res.ir
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution -wmo -Xfrontend -experimental-allow-non-resilient-access -Xfrontend -experimental-package-cmo -o %t/IR-res-package-cmo.ir

// RUN: %FileCheck %s --check-prefix=CHECK-IR-NONRES < %t/IR-nonres.ir
// RUN: %FileCheck %s --check-prefix=CHECK-IR-RES < %t/IR-res.ir
// RUN: %FileCheck %s --check-prefix=CHECK-IR-RES < %t/IR-res-package-cmo.ir

public struct S {
public static let x = "hello world"
package static let y = "dogs cats"
}

public struct R {
package static let a = "foo"
public static let b = "bar"
}

// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1SV1xSSvau"()
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1SV1ySSvau"()
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1RV1aSSvau"()
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1RV1bSSvau"()

// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1SV1xSSvau"()
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1SV1ySSvau"()
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1RV1aSSvau"()
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1RV1bSSvau"()

65 changes: 65 additions & 0 deletions test/IRGen/package-cmo-serialize-witness-thunk.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-silgen %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-silgen.sil

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-sil %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-sil.sil

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-ir %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-ir.ll -emit-tbd-path %t/Lib-no-pcmo-tbd.tbd -tbd-install_name Lib

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-silgen %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-silgen.sil

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-sil %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-sil.sil

// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-ir %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-ir.ll -emit-tbd-path %t/Lib-tbd.tbd -tbd-install_name Lib

// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-SILGEN < %t/Lib-no-pcmo-silgen.sil
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-SIL < %t/Lib-no-pcmo-sil.sil
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-IR < %t/Lib-no-pcmo-ir.ll
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-TBD < %t/Lib-no-pcmo-tbd.tbd
// RUN: %FileCheck %s --check-prefix=CHECK-SILGEN < %t/Lib-silgen.sil
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/Lib-sil.sil
// RUN: %FileCheck %s --check-prefix=CHECK-IR < %t/Lib-ir.ll
// RUN: %FileCheck %s --check-prefix=CHECK-TBD < %t/Lib-tbd.tbd


/// TEST that a public (or package) protocol witness thunk gets a shared linkage if Package CMO is enabled.
/// It also gets [serialized] in emit-silgen.
///
// protocol witness for Proto.foo.getter in conformance Pub

// CHECK-NO-PCMO-SILGEN-DAG: sil private [transparent] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
// CHECK-SILGEN-DAG: sil shared [transparent] [serialized] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {

// CHECK-NO-PCMO-SIL-DAG: sil private [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
// CHECK-SIL-DAG: sil shared [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {

// CHECK-NO-PCMO-IR-DAG: define internal swiftcc { {{i64|i32}}, ptr } @"$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW"
// CHECK-IR-DAG: define linkonce_odr hidden swiftcc { {{i64|i32}}, ptr } @"$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW"

// protocol witness for Proto.bar(_:) in conformance Pub

// CHECK-NO-PCMO-SILGEN-DAG: sil private [transparent] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
// CHECK-SILGEN-DAG: sil shared [transparent] [serialized] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {

// CHECK-NO-PCMO-SIL-DAG: sil private [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
// CHECK-SIL-DAG: sil shared [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {

// CHECK-NO-PCMO-IR-DAG: define internal swiftcc {{i64|i32}} @"$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW"
// CHECK-IR-DAG: define linkonce_odr hidden swiftcc i64 @"$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW"

// CHECK-NO-PCMO-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW
// CHECK-NO-PCMO-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW
// CHECK-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW
// CHECK-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW

public protocol Proto {
var foo: String { get set }
func bar(_ arg: Int) -> Int
}

public struct Pub: Proto {
public var foo = "foo"
public func bar(_ arg: Int) -> Int {
return arg
}
}
13 changes: 0 additions & 13 deletions test/IRGen/package_global_accessor.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
/// Test 1: They should be deserialized into Client as Lib and Client are in the same package.
// RUN: %FileCheck -check-prefix=CHECK-INPKG %s < %t/InPkgClient.sil

// Pub.init(_:) is removed after getting lined below.
// CHECK-INPKG-NOT: @$s3Lib3PubCyACSicfc

// Pub.__allocating_init(_:)
// CHECK-INPKG: sil public_external @$s3Lib3PubCyACSicfC : $@convention(method) (Int, @thick Pub.Type) -> @owned Pub {
// Pub.init(_:) is inlined in this block, as its body was deserialized.
// CHECK-INPKG: ref_element_addr {{.*}} : $Pub, #Pub.pubVar
// CHECK-INPKG: function_ref @$s3Lib3PubCyACSicfc

// Pub.init(_:)
// CHECK-INPKG: sil @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub

// CHECK-INPKG: sil_vtable Pub {
// CHECK-INPKG: #Pub.pubVar!getter: (Pub) -> () -> Int : @$s3Lib3PubC6pubVarSivg // Pub.pubVar.getter
Expand Down Expand Up @@ -72,11 +71,6 @@

// CHECK-LIB: sil [serialized] [exact_self_class] [canonical] @$s3Lib3PubCyACSicfC : $@convention(method) (Int, @thick Pub.Type) -> @owned Pub {
// CHECK-LIB: function_ref @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub
// Pub.init(_:)

// CHECK-LIB: sil [serialized_for_package] [canonical] @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub {
// CHECK-LIB: ref_element_addr {{.*}} : $Pub, #Pub.pubVar
// Pub.__allocating_init(_:)

// Pub.pkgVar.getter
// CHECK-LIB: sil package [serialized_for_package] [canonical] @$s3Lib3PubC6pkgVarSivg : $@convention(method) (@guaranteed Pub) -> Int {
Expand Down Expand Up @@ -106,21 +100,35 @@ public protocol PubProto {
public class Pub: PubProto {
public var pubVar: Int = 1
package var pkgVar: Int = 2
var internalVar: Int = 3
public init(_ arg: Int) {
pubVar = arg
pkgVar = arg
}
public func pubFunc(_ arg: Pub) {
print(arg.pubVar)
}
}

public class SubPub: Pub {
override public func pubFunc(_ arg: Pub) {
print(arg.pubVar, arg.internalVar)
}
}

//--- Client.swift
import Lib

public func test(_ arg: Int) -> Int {
public func test1(_ arg: Int) -> Int {
let x = Pub(arg)
x.pubVar = 3
return x.run()
}

public func test2(_ arg: Int) {
SubPub(arg).pubFunc(Pub(arg))
}

public extension PubProto {
func run() -> Int {
return pubVar
Expand Down
53 changes: 53 additions & 0 deletions test/SILOptimizer/package-cmo-inlining-pass.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend %s \
// RUN: -emit-sil -module-name=Lib -package-name Pkg \
// RUN: -package-cmo -allow-non-resilient-access \
// RUN: -O -wmo -enable-library-evolution \
// RUN: -Xllvm -sil-print-function=s3Lib3fooyS2iF 2>&1 | %FileCheck %s

/// TEST that accessing PkgStruct in the following functions gets inlined after perf inlining pass.
public func bar(_ arg: Int) -> Int {
let p = PkgStruct(1, 2)
return arg > 0 ? p.field1 : p.field2
}

package func foo(_ arg: Int) -> Int {
let p = PkgStruct(1, 2)
return arg > 0 ? p.field1 : p.field2
}

package struct PkgStruct {
package let field1: Int
package let field2: Int
package init(_ arg1: Int, _ arg2: Int) {
field1 = arg1
field2 = arg2
}
}

/// BEFORE perf inlining pass.
// CHECK: sil package @$s3Lib3fooyS2iF : $@convention(thin) (Int) -> Int {
// CHECK: [[PKG_STACK:%.*]] = alloc_stack $PkgStruct
// CHECK: [[FUNC_REF:%.*]] = function_ref @$s3Lib9PkgStructVyACSi_SitcfC : $@convention(method) (Int, Int, @thin PkgStruct.Type) -> @out PkgStruct
// CHECK: apply [[FUNC_REF]]
// CHECK: [[F1:%.*]] = struct_element_addr [[PKG_STACK]] : $*PkgStruct, #PkgStruct.field1
// CHECK: load [[F1]] : $*Int
// CHECK: [[F2:%.*]] = struct_element_addr [[PKG_STACK]] : $*PkgStruct, #PkgStruct.field2
// CHECK: load [[F2]] : $*Int

/// AFTER perf inlining pass; body of `@$s3Lib9PkgStructVyACSi_SitcfC` gets inlined.
// CHECK: *** SIL function after {{.*}} EarlyPerfInliner (early-inline)
// CHECK: sil package @$s3Lib3fooyS2iF : $@convention(thin) (Int) -> Int {
// CHECK: [[PKG_ALLOC:%.*]] = alloc_stack $PkgStruct
// CHECK: [[PKG_INIT:%.*]] = alloc_stack [var_decl] $PkgStruct, var, name "self"
// CHECK: [[FIELD1_IVAR:%.*]] = struct_element_addr [[PKG_INIT]] : $*PkgStruct, #PkgStruct.field1
// CHECK: store {{.*}} to [[FIELD1_IVAR]] : $*Int
// CHECK: [[FIELD2_IVAR:%.*]] = struct_element_addr [[PKG_INIT]] : $*PkgStruct, #PkgStruct.field2
// CHECK: store {{.*}} to [[FIELD2_IVAR]] : $*Int
// CHECK: [[PKG_STR:%.*]] = struct $PkgStruct
// CHECK: store [[PKG_STR]] to [[PKG_ALLOC]] : $*PkgStruct
// CHECK: [[FIELD1:%.*]] = struct_element_addr [[PKG_ALLOC]] : $*PkgStruct, #PkgStruct.field1
// CHECK: load [[FIELD1]] : $*Int
// CHECK: [[FIELD2:%.*]] = struct_element_addr [[PKG_ALLOC]] : $*PkgStruct, #PkgStruct.field2
// CHECK: load [[FIELD2]] : $*Int
Loading