File: closure_specialize_and_cfg.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
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_liferange_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 : $()
}