File: canonicalize_switch_enum.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 (95 lines) | stat: -rw-r--r-- 2,493 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// RUN: %target-sil-opt -enable-sil-verify-all %s -jumpthread-simplify-cfg | %FileCheck %s

import Builtin
import Swift
import SwiftShims

enum E {
	case A
	case B
	case C
}

enum GenE<T> {
	case A
	case B
	case C(T)
}

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

// CHECK-LABEL: sil @test_switch_enum
sil @test_switch_enum : $@convention(thin) (E) -> Int32 {
bb0(%0 : $E):
  // CHECK: switch_enum %0 : $E, case #E.A!enumelt: bb1, case #E.B!enumelt: bb2, case #E.C!enumelt: bb3
  switch_enum %0 : $E, case #E.A!enumelt: bb1, case #E.B!enumelt: bb2, default bb3

bb1:
  %2 = integer_literal $Builtin.Int32, 10
  br bb4(%2 : $Builtin.Int32)

bb2:
  %21 = function_ref @external_f : $@convention(thin) () -> ()
  %22 = apply %21() : $@convention(thin) () -> ()
  %23 = integer_literal $Builtin.Int32, 20
  br bb4(%23 : $Builtin.Int32)

bb3:
  %6 = integer_literal $Builtin.Int32, 30
  br bb4(%6 : $Builtin.Int32)

bb4(%8 : $Builtin.Int32):
  %9 = struct $Int32 (%8 : $Builtin.Int32)
  return %9 : $Int32
}

// CHECK-LABEL: sil @test_switch_enum_addr
sil @test_switch_enum_addr : $@convention(thin) <T> (@in GenE<T>) -> Int32 {
bb0(%0 : $*GenE<T>):
  %1 = alloc_stack $GenE<T>
  copy_addr %0 to [init] %1 : $*GenE<T>
  // CHECK: switch_enum_addr %1 : $*GenE<T>, case #GenE.A!enumelt: bb1, case #GenE.B!enumelt: bb2, case #GenE.C!enumelt: bb3
  switch_enum_addr %1 : $*GenE<T>, case #GenE.A!enumelt: bb1, case #GenE.B!enumelt: bb2, default bb3

bb1:
  %4 = integer_literal $Builtin.Int32, 10
  br bb4(%4 : $Builtin.Int32)

bb2:
  %6 = integer_literal $Builtin.Int32, 20
  br bb4(%6 : $Builtin.Int32)

bb3:
  destroy_addr %1 : $*GenE<T>
  %9 = integer_literal $Builtin.Int32, 30
  br bb4(%9 : $Builtin.Int32)

bb4(%11 : $Builtin.Int32):
  %12 = struct $Int32 (%11 : $Builtin.Int32)
  dealloc_stack %1 : $*GenE<T>
  destroy_addr %0 : $*GenE<T>
  return %12 : $Int32
}

// CHECK-LABEL: sil @test_no_replace
sil @test_no_replace : $@convention(thin) (@inout E) -> Int32 {
bb0(%0 : $*E):
  %1 = load %0 : $*E
  // CHECK: switch_enum %1 : $E, case #E.A!enumelt: bb1, default bb2
  switch_enum %1 : $E, case #E.A!enumelt: bb1, default bb2

bb1:
  %3 = integer_literal $Builtin.Int32, 10
  br bb3(%3 : $Builtin.Int32)

bb2:
  %21 = function_ref @external_f : $@convention(thin) () -> ()
  %22 = apply %21() : $@convention(thin) () -> ()
  %5 = integer_literal $Builtin.Int32, 30
  br bb3(%5 : $Builtin.Int32)

bb3(%7 : $Builtin.Int32):
  %8 = struct $Int32 (%7 : $Builtin.Int32)
  return %8 : $Int32
}