File: package-cmo-inlining-pass.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (53 lines) | stat: -rw-r--r-- 2,400 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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