File: closure_specialize_and_cfg.sil

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 (49 lines) | stat: -rw-r--r-- 1,990 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
// RUN: %target-sil-opt -sil-verify-without-invalidation -enable-sil-verify-all -simplify-cfg -closure-specialize %s

// Test if the ClosureSpecializer correctly invalidates the dominator tree
// even if there are no functions specialized.
// The test just checks if the compiler does not crash.
// First running SimplifyCFG creates the dominator tree, which should then be
// invalidated by the ClosureSpecializer.
// If this is not done correctly the verification will complain that the
// dominator tree is not up to date.

import Builtin
import Swift

sil @closure : $@convention(thin) () -> ()

sil @use_closure : $@convention(thin) (@owned @callee_owned () -> ()) -> ()

sil hidden [noinline] @use_closure2 : $@convention(thin) (@owned @callee_owned () -> (), @owned @callee_owned () -> ()) -> () {
bb0(%0 : $@callee_owned () -> (), %1 : $@callee_owned () -> ()):
  %2 = apply %0() : $@callee_owned () -> ()
  %3 = apply %1() : $@callee_owned () -> ()
  %4 = tuple ()
  return %3 : $()
}

sil @insert_release_in_liverange_exit_block : $@convention(thin) () -> () {
bb0:
  %2 = function_ref @closure : $@convention(thin) () -> ()
  %3 = partial_apply %2() : $@convention(thin) () -> ()
  %8 = function_ref @use_closure : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
  %5 = partial_apply %8(%3) : $@convention(thin) (@owned @callee_owned () -> ()) -> ()

  // There is a critical edge from bb0 to bb2 which is broken by ValueLifetimeAnalysis.
  cond_br undef, bb2, bb1

bb1:
  strong_retain %3 : $@callee_owned () -> ()
  strong_retain %3 : $@callee_owned () -> ()
  %10 = function_ref @use_closure2 : $@convention(thin) (@owned @callee_owned () -> (), @owned @callee_owned () -> ()) -> ()

  // Passing two closures actually prevents closure specialization.
  %17 = apply %10(%3, %3) : $@convention(thin) (@owned @callee_owned () -> (), @owned @callee_owned () -> ()) -> ()
  br bb2

bb2:
  strong_release %5 : $@callee_owned () -> ()
  %11 = tuple ()
  return %11 : $()
}