forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge_object.sil
89 lines (79 loc) · 4.47 KB
/
bridge_object.sil
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
// RUN: %swift -emit-ir -target x86_64-apple-macosx10.9 %s | FileCheck --check-prefix=X86_64 %s
// RUN: %swift -emit-ir -target arm64-apple-ios8.0 %s | FileCheck --check-prefix=ARM64 %s
// RUN: %swift -emit-ir -target armv7-apple-ios8.0 %s | FileCheck --check-prefix=ARMV7 %s
sil_stage canonical
import Builtin
class C {}
sil_vtable C {}
@objc protocol ObjC {}
// X86_64-LABEL: define void @retain_release_bridge_object
// X86_64: call [[BRIDGE:%swift.bridge\*]] @swift_bridgeObjectRetain
// X86_64: call void @swift_bridgeObjectRelease
sil @retain_release_bridge_object : $(Builtin.BridgeObject) -> () {
entry(%b : $Builtin.BridgeObject):
strong_retain %b : $Builtin.BridgeObject
strong_release %b : $Builtin.BridgeObject
return undef : $()
}
// X86_64-LABEL: define %swift.bridge* @convert_to_bridge_object
// X86_64: [[REFBITS:%.*]] = ptrtoint [[C:%C13bridge_object1C\*]] %0 to i64
// X86_64: [[OR:%.*]] = or i64 [[REFBITS]], %1
// X86_64: inttoptr i64 [[OR]] to [[BRIDGE]]
sil @convert_to_bridge_object : $(C, Builtin.Word) -> Builtin.BridgeObject {
entry(%c : $C, %w : $Builtin.Word):
%b = ref_to_bridge_object %c : $C, %w : $Builtin.Word
return %b : $Builtin.BridgeObject
}
// X86_64-LABEL: define { %objc_object*, i64 } @convert_from_bridge_object
// X86_64: [[BOBITS:%.*]] = ptrtoint [[BRIDGE]] %0 to i64
// -- 0x8000_0000_0000_0001
// X86_64: [[TAGBITS:%.*]] = and i64 [[BOBITS]], -9223372036854775807
// X86_64: [[TAGGED:%.*]] = icmp eq i64 [[TAGBITS]], 0
// X86_64: br i1 [[TAGGED]], label %not-tagged-pointer, label %tagged-pointer
// X86_64: tagged-pointer:
// X86_64: [[TAGGED_RESULT:%.*]] = bitcast [[BRIDGE]] %0 to [[C:%objc_object\*]]
// X86_64: br label %tagged-cont
// X86_64: not-tagged-pointer:
// -- 0x00ff_ffff_ffff_fff8
// X86_64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
// X86_64: [[MASKED_RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C]]
// X86_64: br label %tagged-cont
// X86_64: tagged-cont:
// X86_64: phi [[C]] [ [[TAGGED_RESULT]], %tagged-pointer ], [ [[MASKED_RESULT]], %not-tagged-pointer ]
// ARM64-LABEL: define { %objc_object*, i64 } @convert_from_bridge_object
// ARM64: [[BOBITS:%.*]] = ptrtoint [[BRIDGE:%swift.bridge\*]] %0 to i64
// -- 0x8000_0000_0000_0000
// ARM64: [[TAGBITS:%.*]] = and i64 [[BOBITS]], -9223372036854775808
// ARM64: [[TAGGED:%.*]] = icmp eq i64 [[TAGBITS]], 0
// ARM64: br i1 [[TAGGED]], label %not-tagged-pointer, label %tagged-pointer
// ARM64: tagged-pointer:
// ARM64: [[TAGGED_RESULT:%.*]] = bitcast [[BRIDGE]] %0 to [[C:%objc_object\*]]
// ARM64: br label %tagged-cont
// ARM64: not-tagged-pointer:
// -- 0x00ff_ffff_ffff_fff8
// ARM64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
// ARM64: [[MASKED_RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C]]
// ARM64: br label %tagged-cont
// ARM64: tagged-cont:
// ARM64: phi [[C]] [ [[TAGGED_RESULT]], %tagged-pointer ], [ [[MASKED_RESULT]], %not-tagged-pointer ]
// ARMV7-LABEL: define { %objc_object*, i32 } @convert_from_bridge_object
// ARMV7: [[BOBITS:%.*]] = ptrtoint [[BRIDGE:%swift.bridge\*]] %0 to i32
// ARMV7: [[MASKED_BITS:%.*]] = and i32 [[BOBITS]], -4
// ARMV7: inttoptr i32 [[MASKED_BITS]] to [[C:%objc_object\*]]
sil @convert_from_bridge_object : $Builtin.BridgeObject -> (ObjC, Builtin.Word) {
entry(%b : $Builtin.BridgeObject):
%c = bridge_object_to_ref %b : $Builtin.BridgeObject to $ObjC
%w = bridge_object_to_word %b : $Builtin.BridgeObject to $Builtin.Word
%t = tuple (%c : $ObjC, %w : $Builtin.Word)
return %t : $(ObjC, Builtin.Word)
}
// X86_64-LABEL: define %C13bridge_object1C* @convert_from_native_bridge_object
// X86_64: [[BOBITS:%.*]] = ptrtoint %swift.bridge* %0 to i64
// X86_64: [[MASKED_BITS:%.*]] = and i64 [[BOBITS]], 72057594037927928
// X86_64: [[RESULT:%.*]] = inttoptr i64 [[MASKED_BITS]] to [[C:%C13bridge_object1C\*]]
// X86_64: ret %C13bridge_object1C* [[RESULT]]
sil @convert_from_native_bridge_object : $Builtin.BridgeObject -> C {
entry(%b : $Builtin.BridgeObject):
%c = bridge_object_to_ref %b : $Builtin.BridgeObject to $C
return %c : $C
}