@@ -67,17 +67,6 @@ class SILBuilderContext {
67
67
// / only by SILGen or SIL deserializers.
68
68
SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr ;
69
69
70
- // / True if this SILBuilder is being used for parsing.
71
- // /
72
- // / This is important since in such a case, we want to not perform any
73
- // / Ownership Verification in SILBuilder. This functionality is very useful
74
- // / for determining if qualified or unqualified instructions are being created
75
- // / in appropriate places, but prevents us from inferring ownership
76
- // / qualification of functions when parsing. The ability to perform this
77
- // / inference is important since otherwise, we would need to update all SIL
78
- // / test cases while bringing up SIL ownership.
79
- bool isParsing = false ;
80
-
81
70
public:
82
71
explicit SILBuilderContext (
83
72
SILModule &M, SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
@@ -130,10 +119,6 @@ class SILBuilder {
130
119
// / can store the SILGlobalVariable here as well.
131
120
SILFunction *F;
132
121
133
- // / If the current block that we are inserting into must assume that
134
- // / the current context we are in has ownership.
135
- bool hasOwnership;
136
-
137
122
// / If this is non-null, the instruction is inserted in the specified
138
123
// / basic block, at the specified InsertPt. If null, created instructions
139
124
// / are not auto-inserted.
@@ -143,21 +128,17 @@ class SILBuilder {
143
128
Optional<SILLocation> CurDebugLocOverride = None;
144
129
145
130
public:
146
- explicit SILBuilder (SILFunction &F, bool isParsing = false )
147
- : TempContext(F.getModule()), C(TempContext), F(&F),
148
- hasOwnership(F.hasOwnership()), BB(0 ) {
149
- C.isParsing = isParsing;
150
- }
131
+ explicit SILBuilder (SILFunction &F)
132
+ : TempContext(F.getModule()), C(TempContext), F(&F), BB(nullptr ) {}
151
133
152
134
SILBuilder (SILFunction &F, SmallVectorImpl<SILInstruction *> *InsertedInstrs)
153
135
: TempContext(F.getModule(), InsertedInstrs), C(TempContext), F(&F),
154
- hasOwnership (F.hasOwnership()), BB(0 ) {}
136
+ BB (nullptr ) {}
155
137
156
138
explicit SILBuilder (SILInstruction *I,
157
139
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
158
140
: TempContext(I->getFunction ()->getModule(), InsertedInstrs),
159
- C(TempContext), F(I->getFunction ()),
160
- hasOwnership(F->hasOwnership ()) {
141
+ C(TempContext), F(I->getFunction ()) {
161
142
setInsertionPoint (I);
162
143
}
163
144
@@ -168,8 +149,7 @@ class SILBuilder {
168
149
explicit SILBuilder (SILBasicBlock *BB,
169
150
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
170
151
: TempContext(BB->getParent ()->getModule(), InsertedInstrs),
171
- C(TempContext), F(BB->getParent ()),
172
- hasOwnership(F->hasOwnership ()) {
152
+ C(TempContext), F(BB->getParent ()) {
173
153
setInsertionPoint (BB);
174
154
}
175
155
@@ -179,8 +159,7 @@ class SILBuilder {
179
159
SILBuilder (SILBasicBlock *BB, SILBasicBlock::iterator InsertPt,
180
160
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
181
161
: TempContext(BB->getParent ()->getModule(), InsertedInstrs),
182
- C(TempContext), F(BB->getParent ()),
183
- hasOwnership(F->hasOwnership ()) {
162
+ C(TempContext), F(BB->getParent ()) {
184
163
setInsertionPoint (BB, InsertPt);
185
164
}
186
165
@@ -189,8 +168,7 @@ class SILBuilder {
189
168
// /
190
169
// / SILBuilderContext must outlive this SILBuilder instance.
191
170
SILBuilder (SILInstruction *I, const SILDebugScope *DS, SILBuilderContext &C)
192
- : TempContext(C.getModule()), C(C), F(I->getFunction ()),
193
- hasOwnership(F->hasOwnership ()) {
171
+ : TempContext(C.getModule()), C(C), F(I->getFunction ()) {
194
172
assert (DS && " instruction has no debug scope" );
195
173
setCurrentDebugScope (DS);
196
174
setInsertionPoint (I);
@@ -201,8 +179,7 @@ class SILBuilder {
201
179
// /
202
180
// / SILBuilderContext must outlive this SILBuilder instance.
203
181
SILBuilder (SILBasicBlock *BB, const SILDebugScope *DS, SILBuilderContext &C)
204
- : TempContext(C.getModule()), C(C), F(BB->getParent ()),
205
- hasOwnership(F->hasOwnership ()) {
182
+ : TempContext(C.getModule()), C(C), F(BB->getParent ()) {
206
183
assert (DS && " block has no debug scope" );
207
184
setCurrentDebugScope (DS);
208
185
setInsertionPoint (BB);
@@ -260,15 +237,13 @@ class SILBuilder {
260
237
return SILDebugLocation (overriddenLoc, Scope);
261
238
}
262
239
263
- // / Allow for users to override has ownership if necessary.
264
- // /
265
- // / This is only used in the SILParser since it sets whether or not ownership
266
- // / is qualified after the SILBuilder is constructed due to the usage of
267
- // / AssumeUnqualifiedOwnershipWhenParsing.
268
- // /
269
- // / TODO: Once we start printing [ossa] on SILFunctions to indicate ownership
270
- // / and get rid of this global option, this can go away.
271
- void setHasOwnership (bool newHasOwnership) { hasOwnership = newHasOwnership; }
240
+ // / If we have a SILFunction, return SILFunction::hasOwnership(). If we have a
241
+ // / SILGlobalVariable, just return false.
242
+ bool hasOwnership () const {
243
+ if (F)
244
+ return F->hasOwnership ();
245
+ return false ;
246
+ }
272
247
273
248
// ===--------------------------------------------------------------------===//
274
249
// Insertion Point Management
@@ -683,7 +658,7 @@ class SILBuilder {
683
658
LoadInst *createTrivialLoadOr (SILLocation Loc, SILValue LV,
684
659
LoadOwnershipQualifier Qualifier,
685
660
bool SupportUnqualifiedSIL = false ) {
686
- if (SupportUnqualifiedSIL && !getFunction (). hasOwnership ()) {
661
+ if (SupportUnqualifiedSIL && !hasOwnership ()) {
687
662
assert (
688
663
Qualifier != LoadOwnershipQualifier::Copy &&
689
664
" In unqualified SIL, a copy must be done separately form the load" );
@@ -699,11 +674,9 @@ class SILBuilder {
699
674
LoadInst *createLoad (SILLocation Loc, SILValue LV,
700
675
LoadOwnershipQualifier Qualifier) {
701
676
assert ((Qualifier != LoadOwnershipQualifier::Unqualified) ||
702
- !getFunction ().hasOwnership () &&
703
- " Unqualified inst in qualified function" );
677
+ !hasOwnership () && " Unqualified inst in qualified function" );
704
678
assert ((Qualifier == LoadOwnershipQualifier::Unqualified) ||
705
- getFunction ().hasOwnership () &&
706
- " Qualified inst in unqualified function" );
679
+ hasOwnership () && " Qualified inst in unqualified function" );
707
680
assert (LV->getType ().isLoadableOrOpaque (getModule ()));
708
681
return insert (new (getModule ())
709
682
LoadInst (getSILDebugLocation (Loc), LV, Qualifier));
@@ -757,7 +730,7 @@ class SILBuilder {
757
730
SILValue DestAddr,
758
731
StoreOwnershipQualifier Qualifier,
759
732
bool SupportUnqualifiedSIL = false ) {
760
- if (SupportUnqualifiedSIL && !getFunction (). hasOwnership ()) {
733
+ if (SupportUnqualifiedSIL && !hasOwnership ()) {
761
734
assert (
762
735
Qualifier != StoreOwnershipQualifier::Assign &&
763
736
" In unqualified SIL, assigns must be represented via 2 instructions" );
@@ -773,11 +746,9 @@ class SILBuilder {
773
746
StoreInst *createStore (SILLocation Loc, SILValue Src, SILValue DestAddr,
774
747
StoreOwnershipQualifier Qualifier) {
775
748
assert ((Qualifier != StoreOwnershipQualifier::Unqualified) ||
776
- !getFunction ().hasOwnership () &&
777
- " Unqualified inst in qualified function" );
749
+ !hasOwnership () && " Unqualified inst in qualified function" );
778
750
assert ((Qualifier == StoreOwnershipQualifier::Unqualified) ||
779
- getFunction ().hasOwnership () &&
780
- " Qualified inst in unqualified function" );
751
+ hasOwnership () && " Qualified inst in unqualified function" );
781
752
return insert (new (getModule ()) StoreInst (getSILDebugLocation (Loc), Src,
782
753
DestAddr, Qualifier));
783
754
}
@@ -1128,22 +1099,22 @@ class SILBuilder {
1128
1099
1129
1100
RetainValueInst *createRetainValue (SILLocation Loc, SILValue operand,
1130
1101
Atomicity atomicity) {
1131
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1102
+ assert (! hasOwnership ());
1132
1103
assert (operand->getType ().isLoadableOrOpaque (getModule ()));
1133
1104
return insert (new (getModule ()) RetainValueInst (getSILDebugLocation (Loc),
1134
1105
operand, atomicity));
1135
1106
}
1136
1107
1137
1108
RetainValueAddrInst *createRetainValueAddr (SILLocation Loc, SILValue operand,
1138
1109
Atomicity atomicity) {
1139
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1110
+ assert (! hasOwnership ());
1140
1111
return insert (new (getModule ()) RetainValueAddrInst (
1141
1112
getSILDebugLocation (Loc), operand, atomicity));
1142
1113
}
1143
1114
1144
1115
ReleaseValueInst *createReleaseValue (SILLocation Loc, SILValue operand,
1145
1116
Atomicity atomicity) {
1146
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1117
+ assert (! hasOwnership ());
1147
1118
assert (operand->getType ().isLoadableOrOpaque (getModule ()));
1148
1119
return insert (new (getModule ()) ReleaseValueInst (getSILDebugLocation (Loc),
1149
1120
operand, atomicity));
@@ -1152,15 +1123,15 @@ class SILBuilder {
1152
1123
ReleaseValueAddrInst *createReleaseValueAddr (SILLocation Loc,
1153
1124
SILValue operand,
1154
1125
Atomicity atomicity) {
1155
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1126
+ assert (! hasOwnership ());
1156
1127
return insert (new (getModule ()) ReleaseValueAddrInst (
1157
1128
getSILDebugLocation (Loc), operand, atomicity));
1158
1129
}
1159
1130
1160
1131
UnmanagedRetainValueInst *createUnmanagedRetainValue (SILLocation Loc,
1161
1132
SILValue operand,
1162
1133
Atomicity atomicity) {
1163
- assert (getFunction (). hasOwnership ());
1134
+ assert (hasOwnership ());
1164
1135
assert (operand->getType ().isLoadableOrOpaque (getModule ()));
1165
1136
return insert (new (getModule ()) UnmanagedRetainValueInst (
1166
1137
getSILDebugLocation (Loc), operand, atomicity));
@@ -1169,7 +1140,7 @@ class SILBuilder {
1169
1140
UnmanagedReleaseValueInst *createUnmanagedReleaseValue (SILLocation Loc,
1170
1141
SILValue operand,
1171
1142
Atomicity atomicity) {
1172
- assert (getFunction (). hasOwnership ());
1143
+ assert (hasOwnership ());
1173
1144
assert (operand->getType ().isLoadableOrOpaque (getModule ()));
1174
1145
return insert (new (getModule ()) UnmanagedReleaseValueInst (
1175
1146
getSILDebugLocation (Loc), operand, atomicity));
@@ -1201,21 +1172,21 @@ class SILBuilder {
1201
1172
unsigned NumBaseElements) {
1202
1173
return insert (ObjectInst::create (getSILDebugLocation (Loc), Ty, Elements,
1203
1174
NumBaseElements, getModule (),
1204
- hasOwnership));
1175
+ hasOwnership () ));
1205
1176
}
1206
1177
1207
1178
StructInst *createStruct (SILLocation Loc, SILType Ty,
1208
1179
ArrayRef<SILValue> Elements) {
1209
1180
assert (Ty.isLoadableOrOpaque (getModule ()));
1210
1181
return insert (StructInst::create (getSILDebugLocation (Loc), Ty, Elements,
1211
- getModule (), hasOwnership));
1182
+ getModule (), hasOwnership () ));
1212
1183
}
1213
1184
1214
1185
TupleInst *createTuple (SILLocation Loc, SILType Ty,
1215
1186
ArrayRef<SILValue> Elements) {
1216
1187
assert (Ty.isLoadableOrOpaque (getModule ()));
1217
1188
return insert (TupleInst::create (getSILDebugLocation (Loc), Ty, Elements,
1218
- getModule (), hasOwnership));
1189
+ getModule (), hasOwnership () ));
1219
1190
}
1220
1191
1221
1192
TupleInst *createTuple (SILLocation loc, ArrayRef<SILValue> elts);
@@ -1296,7 +1267,7 @@ class SILBuilder {
1296
1267
assert (Ty.isLoadableOrOpaque (getModule ()));
1297
1268
return insert (SelectEnumInst::create (
1298
1269
getSILDebugLocation (Loc), Operand, Ty, DefaultValue, CaseValues,
1299
- getModule (), CaseCounts, DefaultCount, hasOwnership));
1270
+ getModule (), CaseCounts, DefaultCount, hasOwnership () ));
1300
1271
}
1301
1272
1302
1273
SelectEnumAddrInst *createSelectEnumAddr (
@@ -1314,7 +1285,7 @@ class SILBuilder {
1314
1285
ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResults) {
1315
1286
return insert (SelectValueInst::create (getSILDebugLocation (Loc), Operand, Ty,
1316
1287
DefaultResult, CaseValuesAndResults,
1317
- getModule (), hasOwnership));
1288
+ getModule (), hasOwnership () ));
1318
1289
}
1319
1290
1320
1291
TupleExtractInst *createTupleExtract (SILLocation Loc, SILValue Operand,
@@ -1501,7 +1472,7 @@ class SILBuilder {
1501
1472
OpenExistentialRefInst *
1502
1473
createOpenExistentialRef (SILLocation Loc, SILValue Operand, SILType Ty) {
1503
1474
auto *I = insert (new (getModule ()) OpenExistentialRefInst (
1504
- getSILDebugLocation (Loc), Operand, Ty, hasOwnership));
1475
+ getSILDebugLocation (Loc), Operand, Ty, hasOwnership () ));
1505
1476
if (C.OpenedArchetypesTracker )
1506
1477
C.OpenedArchetypesTracker ->registerOpenedArchetypes (I);
1507
1478
return I;
@@ -1637,13 +1608,13 @@ class SILBuilder {
1637
1608
1638
1609
StrongRetainInst *createStrongRetain (SILLocation Loc, SILValue Operand,
1639
1610
Atomicity atomicity) {
1640
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1611
+ assert (! hasOwnership ());
1641
1612
return insert (new (getModule ()) StrongRetainInst (getSILDebugLocation (Loc),
1642
1613
Operand, atomicity));
1643
1614
}
1644
1615
StrongReleaseInst *createStrongRelease (SILLocation Loc, SILValue Operand,
1645
1616
Atomicity atomicity) {
1646
- assert (C. isParsing || ! getFunction (). hasOwnership ());
1617
+ assert (! hasOwnership ());
1647
1618
return insert (new (getModule ()) StrongReleaseInst (
1648
1619
getSILDebugLocation (Loc), Operand, atomicity));
1649
1620
}
0 commit comments