Skip to content

Commit 21ec110

Browse files
committed
[semantic-arc] Add LLVMSwift.def for metaprogramming Swift Operations in LLVM.
For semantic ARC I need to add an endBorrow entrypoint that will be removed by ARCContract.cpp. In the process I am doing a little bit of cleanup. In this commit, I only use this to generate the enum RT_Kind in LLVMARCOpts.h. I verified it was the same using a diff tool. I am going to do further updates in subsequent commits to make the diff easy to see.
1 parent 2c88a72 commit 21ec110

File tree

2 files changed

+143
-62
lines changed

2 files changed

+143
-62
lines changed

lib/LLVMPasses/LLVMARCOpts.h

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,8 @@
2525
namespace swift {
2626

2727
enum RT_Kind {
28-
/// An instruction with this classification is known to not access (read or
29-
/// write) memory.
30-
RT_NoMemoryAccessed,
31-
32-
/// void swift_retain(SwiftHeapObject *object)
33-
RT_Retain,
34-
35-
/// void swift_retain_n(SwiftHeapObject *object)
36-
RT_RetainN,
37-
38-
/// void swift::swift_retainUnowned(HeapObject *object)
39-
RT_RetainUnowned,
40-
41-
/// void swift_checkUnowned(HeapObject *object)
42-
RT_CheckUnowned,
43-
44-
/// void swift_release(SwiftHeapObject *object)
45-
RT_Release,
46-
47-
/// void swift_release_n(SwiftHeapObject *object)
48-
RT_ReleaseN,
49-
50-
/// SwiftHeapObject *swift_allocObject(SwiftHeapMetadata *metadata,
51-
/// size_t size, size_t alignment)
52-
RT_AllocObject,
53-
54-
/// void objc_release(%objc_object* %P)
55-
RT_ObjCRelease,
56-
57-
/// %objc_object* objc_retain(%objc_object* %P)
58-
RT_ObjCRetain,
59-
60-
/// void swift_unknownRetain(%swift.refcounted* %P)
61-
RT_UnknownRetain,
62-
63-
/// void swift_unknownRetain_n(%swift.refcounted* %P)
64-
RT_UnknownRetainN,
65-
66-
/// void swift_unknownRelease(%swift.refcounted* %P)
67-
RT_UnknownRelease,
68-
69-
/// void swift_unknownRelease_n(%swift.refcounted* %P)
70-
RT_UnknownReleaseN,
71-
72-
/// void __swift_fixLifetime(%swift.refcounted* %P)
73-
RT_FixLifetime,
74-
75-
/// void swift_bridgeRetain(%swift.refcounted* %P)
76-
RT_BridgeRetain,
77-
78-
/// void swift_bridgeRetain_n(%swift.refcounted* %P)
79-
RT_BridgeRetainN,
80-
81-
/// void swift_bridgeRelease(%swift.refcounted* %P)
82-
RT_BridgeRelease,
83-
84-
/// void swift_bridgeRelease_n(%swift.refcounted* %P)
85-
RT_BridgeReleaseN,
86-
87-
/// This is not a runtime function that we support. Maybe it is not a call,
88-
/// or is a call to something we don't care about.
89-
RT_Unknown,
28+
#define KIND(Name, MemBehavior) RT_ ## Name,
29+
#include "LLVMSwift.def"
9030
};
9131

9232
/// classifyInstruction - Take a look at the specified instruction and classify

lib/LLVMPasses/LLVMSwift.def

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//===--- LLVMSwift.def ----------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
// KIND(Name, MemBehavior)
14+
//
15+
// This represents a specific equivalence class of LLVM instructions that have a
16+
// Name and the same MemBehavior from a ModRef perspective.
17+
//
18+
// Name - The name of the kind.
19+
// MemBehavior - One of NoModRef or ModRef.
20+
//
21+
#ifndef KIND
22+
#define KIND(Name, MemBehavior)
23+
#endif
24+
25+
// SWIFT_FUNC(Name, MemBehavior, TextualName)
26+
//
27+
// This defines a special swift function known to the optimizer that may be
28+
// present in either atomic or nonatomic form.
29+
//
30+
// Name - The name of the function
31+
// MemBehavior - The MemBehavior of the instruction that can be known at compile time
32+
// TextualName - The name of the function in the final binary.
33+
#ifndef SWIFT_FUNC
34+
#define SWIFT_FUNC(Name, MemBehavior, TextualName) KIND(Name, MemBehavior)
35+
#endif
36+
37+
// SWIFT_NEVER_NONATOMIC_FUNC(Name, MemBehavior, TextualName)
38+
//
39+
// This defines a special swift function known to the optimizer that does not
40+
// have a nonatomic form.
41+
//
42+
// Name - The name of the function
43+
// MemBehavior - The MemBehavior of the instruction that can be known at compile time
44+
// TextualName - The name of the function in the final binary.
45+
#ifndef SWIFT_NEVER_NONATOMIC_FUNC
46+
#define SWIFT_NEVER_NONATOMIC_FUNC(Name, MemBehavior, TextualName) SWIFT_FUNC(Name, MemBehavior, TextualName)
47+
#endif
48+
49+
// SWIFT_INTERNAL_NEVER_NONATOMIC_FUNC(Name, MemBehavior, TextualName)
50+
//
51+
// This defines a special swift function known to the optimizer that does not
52+
// have a nonatomic form and has an internal prefix (i.e. '__').
53+
//
54+
// Name - The name of the function
55+
// MemBehavior - The MemBehavior of the instruction that can be known at compile time
56+
// TextualName - The name of the function in the final binary.
57+
#ifndef SWIFT_INTERNAL_FUNC_NEVER_NONATOMIC
58+
#define SWIFT_INTERNAL_FUNC_NEVER_NONATOMIC(Name, MemBehavior, TextualName) SWIFT_FUNC(Name, MemBehavior, TextualName)
59+
#endif
60+
61+
// OBJC_FUNC(Name, MemBehavior, TextualName)
62+
//
63+
// This defines a special objc function known to the optimizer that may have an
64+
// atomic and nonatomic form.
65+
//
66+
// Name - The name of the function
67+
// MemBehavior - The MemBehavior of the instruction that can be known at compile time
68+
// TextualName - The name of the function in the final binary.
69+
#ifndef OBJC_FUNC
70+
#define OBJC_FUNC(Name, MemBehavior, TextualName) KIND(Name, MemBehavior)
71+
#endif
72+
73+
/// An instruction with this classification is known to not access (read or
74+
/// write) memory.
75+
KIND(NoMemoryAccessed, NoModRef)
76+
77+
/// void swift_retain(SwiftHeapObject *object)
78+
SWIFT_FUNC(Retain, NoModRef, retain)
79+
80+
/// void swift_retain_n(SwiftHeapObject *object)
81+
SWIFT_FUNC(RetainN, NoModRef, retain_n)
82+
83+
/// void swift::swift_retainUnowned(HeapObject *object)
84+
SWIFT_FUNC(RetainUnowned, NoModRef, retainUnowned)
85+
86+
/// void swift_checkUnowned(HeapObject *object)
87+
SWIFT_FUNC(CheckUnowned, NoModRef, checkUnowned)
88+
89+
/// void swift_release(SwiftHeapObject *object)
90+
SWIFT_FUNC(Release, ModRef, release)
91+
92+
/// void swift_release_n(SwiftHeapObject *object)
93+
SWIFT_FUNC(ReleaseN, ModRef, release_n)
94+
95+
/// SwiftHeapObject *swift_allocObject(SwiftHeapMetadata *metadata,
96+
/// size_t size, size_t alignment)
97+
SWIFT_NEVER_NONATOMIC_FUNC(AllocObject, NoModRef, allocObject)
98+
99+
/// void objc_release(%objc_object* %P)
100+
OBJC_FUNC(ObjCRelease, ModRef, release)
101+
102+
/// %objc_object* objc_retain(%objc_object* %P)
103+
OBJC_FUNC(ObjCRetain, NoModRef, retain)
104+
105+
/// void swift_unknownRetain(%swift.refcounted* %P)
106+
SWIFT_FUNC(UnknownRetain, NoModRef, unknownRetain)
107+
108+
/// void swift_unknownRetain_n(%swift.refcounted* %P)
109+
SWIFT_FUNC(UnknownRetainN, NoModRef, unknownRetain_n)
110+
111+
/// void swift_unknownRelease(%swift.refcounted* %P)
112+
SWIFT_FUNC(UnknownRelease, ModRef, unknownRelease)
113+
114+
/// void swift_unknownRelease_n(%swift.refcounted* %P)
115+
SWIFT_FUNC(UnknownReleaseN, ModRef, unknownRelease_n)
116+
117+
/// void __swift_fixLifetime(%swift.refcounted* %P)
118+
SWIFT_INTERNAL_FUNC_NEVER_NONATOMIC(FixLifetime, NoModRef, fixLifetime)
119+
120+
/// void swift_bridgeObjectRetain(%swift.refcounted* %P)
121+
SWIFT_FUNC(BridgeRetain, NoModRef, bridgeObjectRetain)
122+
123+
/// void swift_bridgeObjectRetain_n(%swift.refcounted* %P)
124+
SWIFT_FUNC(BridgeRetainN, NoModRef, bridgeObjectRetain_n)
125+
126+
/// void swift_bridgeObjectRelease(%swift.refcounted* %P)
127+
SWIFT_FUNC(BridgeRelease, ModRef, bridgeObjectRelease)
128+
129+
/// void swift_bridgeObjectRelease_n(%swift.refcounted* %P)
130+
SWIFT_FUNC(BridgeReleaseN, ModRef, bridgeObjectRelease_n)
131+
132+
/// This is not a runtime function that we support. Maybe it is not a call,
133+
/// or is a call to something we don't care about.
134+
KIND(Unknown, ModRef)
135+
136+
#undef OBJC_NEVER_NONATOMIC_FUNC
137+
#undef SWIFT_INTERNAL_FUNC_NEVER_NONATOMIC
138+
#undef SWIFT_NEVER_NONATOMIC_FUNC
139+
#undef OBJC_FUNC
140+
#undef SWIFT_FUNC
141+
#undef KIND

0 commit comments

Comments
 (0)