File: sil_combine_nocanonicalize_ossa.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 (106 lines) | stat: -rw-r--r-- 4,475 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
96
97
98
99
100
101
102
103
104
105
106
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -sil-combine-canonicalize=false | %FileCheck %s
//
// Run sil-combine without canonicalization to test specific patterns
// in isolation.

sil_stage canonical

import Swift
import Builtin

class Klass {}

class KlassWithTailAllocatedElems {
  var x : Builtin.NativeObject
  init()
}

// Test conversion from address_to_pointer->pointer_to_address to
// unchecked_addr_cast when the base is a borrowed box.
//
// The box is not an interior pointer, so RAUW should not try to clone
// the begin_borrow, which would fail.
//
// CHECK-LABEL: sil [ossa] @unchecked_addr_cast_borrowed_box : $@convention(thin) () -> Builtin.Int64 {
// CHECK: [[BOX:%.*]] = alloc_box ${ var Builtin.Int64 }
// CHECK: [[BORROW:%.*]] = begin_borrow [[BOX]]
// CHECK: [[PROJ:%.*]] = project_box [[BORROW]]
// CHECK-NOT: pointer_to_address
// CHECK-NOT: address_to_pointer
// CHECK: [[CAST_RESULT:%.*]] = unchecked_addr_cast [[PROJ]]
// CHECK-NOT: pointer_to_address
// CHECK-NOT: address_to_pointer
// CHECK: load [trivial] [[CAST_RESULT]]
// CHECK: end_borrow [[BORROW]]
// CHECK: destroy_value [[BOX]]
// CHECK-LABEL: } // end sil function 'unchecked_addr_cast_borrowed_box'
sil [ossa] @unchecked_addr_cast_borrowed_box : $@convention(thin) () -> Builtin.Int64 {
bb0:
  %0 = integer_literal $Builtin.Int64, 0
  %1 = alloc_box ${ var Builtin.Int64 }
  %1a = project_box %1 : ${ var Builtin.Int64 }, 0
  store %0 to [trivial] %1a : $*Builtin.Int64
  %borrow = begin_borrow %1 : ${ var Builtin.Int64 }
  %1b = project_box %borrow : ${ var Builtin.Int64 }, 0
  %1c = address_to_pointer %1b : $*Builtin.Int64 to $Builtin.RawPointer
  %2 = pointer_to_address %1c : $Builtin.RawPointer to [strict] $*Builtin.Int64
  %3 = load [trivial] %2 : $*Builtin.Int64
  end_borrow %borrow : ${ var Builtin.Int64 }
  destroy_value %1 : ${ var Builtin.Int64 }
  return %3 : $Builtin.Int64
}

// CHECK-LABEL: sil [ossa] @unchecked_addr_cast_mark_dependence : $@convention(thin) () -> Builtin.Word {
// CHECK: [[BORROW:%.*]] = begin_borrow
// CHECK: [[TAIL_ADDR:%.*]] = ref_tail_addr
// CHECK-NOT: unchecked_addr_cast
// CHECK: [[MD:%.*]] = mark_dependence [[TAIL_ADDR]]
// CHECK-NOT: unchecked_addr_cast
// CHECK: [[PTR:%.*]] = address_to_pointer [[MD]]
// CHECK-NOT: unchecked_addr_cast
// CHECK: end_borrow [[BORROW]]
// CHECK-NOT: unchecked_addr_cast
// CHECK: destroy_value {{.*}} : $Klass
// CHECK-NOT: unchecked_addr_cast
// CHECK: [[ADR:%.*]] = pointer_to_address [[PTR]]
// CHECK: load [trivial] [[ADR]]
// CHECK: destroy_value {{.*}} : $KlassWithTailAllocatedElems
// CHECK-LABEL: } // end sil function 'unchecked_addr_cast_mark_dependence'
sil [ossa] @unchecked_addr_cast_mark_dependence : $@convention(thin) () -> Builtin.Word {
bb0:
  %parent = alloc_ref $Klass
  %one = integer_literal $Builtin.Word, 1
  %obj = alloc_ref [tail_elems $(Builtin.NativeObject) * %one : $Builtin.Word] $KlassWithTailAllocatedElems
  %borrow = begin_borrow %obj : $KlassWithTailAllocatedElems
  %addr = ref_tail_addr %borrow : $KlassWithTailAllocatedElems, $Builtin.NativeObject
  %md = mark_dependence %addr : $*Builtin.NativeObject on %parent : $Klass
  %ptr = address_to_pointer %md : $*Builtin.NativeObject to $Builtin.RawPointer
  end_borrow %borrow : $KlassWithTailAllocatedElems
  destroy_value %parent : $Klass
  %adr = pointer_to_address %ptr : $Builtin.RawPointer to [strict] $*Builtin.Word
  %val = load [trivial] %adr : $*Builtin.Word
  destroy_value %obj : $KlassWithTailAllocatedElems
  return %val : $Builtin.Word
}

sil @get_native_object : $@convention(thin) () -> @owned Builtin.NativeObject

// CHECK-LABEL: sil [ossa] @bitwise_combines_guaranteed :
// CHECK: unchecked_ref_cast
// CHECK-LABEL: } // end sil function 'bitwise_combines_guaranteed'
sil [ossa] @bitwise_combines_guaranteed : $@convention(thin) () -> @owned Optional<Builtin.NativeObject> {
bb0:
  %f = function_ref @get_native_object : $@convention(thin) () -> @owned Builtin.NativeObject
  %0 = apply %f() : $@convention(thin) () -> @owned Builtin.NativeObject
  %b = begin_borrow [lexical] %0 : $Builtin.NativeObject
  br bb1

bb1:
  %2 = unchecked_trivial_bit_cast %b : $Builtin.NativeObject to $Builtin.Word
  %3 = unchecked_bitwise_cast %2 : $Builtin.Word to $Optional<Builtin.NativeObject>
  %c = copy_value %3 : $Optional<Builtin.NativeObject>
  end_borrow %b : $Builtin.NativeObject
  destroy_value %0 : $Builtin.NativeObject
  return %c : $Optional<Builtin.NativeObject>
}