@@ -121,8 +121,19 @@ class SILBuilder {
121
121
// / Reference to the provided SILBuilderContext.
122
122
SILBuilderContext &C;
123
123
124
+ // / The SILFunction that we are currently inserting into if we have one.
125
+ // /
126
+ // / If we are building into a block associated with a SILGlobalVariable this
127
+ // / will be a nullptr.
128
+ // /
129
+ // / TODO: This can be made cleaner by using a PointerUnion or the like so we
130
+ // / can store the SILGlobalVariable here as well.
124
131
SILFunction *F;
125
132
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
+
126
137
// / If this is non-null, the instruction is inserted in the specified
127
138
// / basic block, at the specified InsertPt. If null, created instructions
128
139
// / are not auto-inserted.
@@ -133,18 +144,20 @@ class SILBuilder {
133
144
134
145
public:
135
146
explicit SILBuilder (SILFunction &F, bool isParsing = false )
136
- : TempContext(F.getModule()), C(TempContext), F(&F), BB(0 ) {
147
+ : TempContext(F.getModule()), C(TempContext), F(&F),
148
+ hasOwnership(F.hasQualifiedOwnership()), BB(0 ) {
137
149
C.isParsing = isParsing;
138
150
}
139
151
140
152
SILBuilder (SILFunction &F, SmallVectorImpl<SILInstruction *> *InsertedInstrs)
141
153
: TempContext(F.getModule(), InsertedInstrs), C(TempContext), F(&F),
142
- BB (0 ) {}
154
+ hasOwnership (F.hasQualifiedOwnership()), BB(0 ) {}
143
155
144
156
explicit SILBuilder (SILInstruction *I,
145
157
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
146
158
: TempContext(I->getFunction ()->getModule(), InsertedInstrs),
147
- C(TempContext), F(I->getFunction ()) {
159
+ C(TempContext), F(I->getFunction ()),
160
+ hasOwnership(F->hasQualifiedOwnership ()) {
148
161
setInsertionPoint (I);
149
162
}
150
163
@@ -155,7 +168,8 @@ class SILBuilder {
155
168
explicit SILBuilder (SILBasicBlock *BB,
156
169
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
157
170
: TempContext(BB->getParent ()->getModule(), InsertedInstrs),
158
- C(TempContext), F(BB->getParent ()) {
171
+ C(TempContext), F(BB->getParent ()),
172
+ hasOwnership(F->hasQualifiedOwnership ()) {
159
173
setInsertionPoint (BB);
160
174
}
161
175
@@ -165,7 +179,8 @@ class SILBuilder {
165
179
SILBuilder (SILBasicBlock *BB, SILBasicBlock::iterator InsertPt,
166
180
SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
167
181
: TempContext(BB->getParent ()->getModule(), InsertedInstrs),
168
- C(TempContext), F(BB->getParent ()) {
182
+ C(TempContext), F(BB->getParent ()),
183
+ hasOwnership(F->hasQualifiedOwnership ()) {
169
184
setInsertionPoint (BB, InsertPt);
170
185
}
171
186
@@ -174,7 +189,8 @@ class SILBuilder {
174
189
// /
175
190
// / SILBuilderContext must outlive this SILBuilder instance.
176
191
SILBuilder (SILInstruction *I, const SILDebugScope *DS, SILBuilderContext &C)
177
- : TempContext(C.getModule()), C(C), F(I->getFunction ()) {
192
+ : TempContext(C.getModule()), C(C), F(I->getFunction ()),
193
+ hasOwnership(F->hasQualifiedOwnership ()) {
178
194
assert (DS && " instruction has no debug scope" );
179
195
setCurrentDebugScope (DS);
180
196
setInsertionPoint (I);
@@ -185,7 +201,8 @@ class SILBuilder {
185
201
// /
186
202
// / SILBuilderContext must outlive this SILBuilder instance.
187
203
SILBuilder (SILBasicBlock *BB, const SILDebugScope *DS, SILBuilderContext &C)
188
- : TempContext(C.getModule()), C(C), F(BB->getParent ()) {
204
+ : TempContext(C.getModule()), C(C), F(BB->getParent ()),
205
+ hasOwnership(F->hasQualifiedOwnership ()) {
189
206
assert (DS && " block has no debug scope" );
190
207
setCurrentDebugScope (DS);
191
208
setInsertionPoint (BB);
@@ -243,6 +260,16 @@ class SILBuilder {
243
260
return SILDebugLocation (overriddenLoc, Scope);
244
261
}
245
262
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; }
272
+
246
273
// ===--------------------------------------------------------------------===//
247
274
// Insertion Point Management
248
275
// ===--------------------------------------------------------------------===//
@@ -1187,25 +1214,23 @@ class SILBuilder {
1187
1214
ObjectInst *createObject (SILLocation Loc, SILType Ty,
1188
1215
ArrayRef<SILValue> Elements,
1189
1216
unsigned NumBaseElements) {
1190
- return insert (
1191
- ObjectInst::create ( getSILDebugLocation (Loc), Ty, Elements ,
1192
- NumBaseElements, getModule () ));
1217
+ return insert (ObjectInst::create ( getSILDebugLocation (Loc), Ty, Elements,
1218
+ NumBaseElements, getModule () ,
1219
+ hasOwnership ));
1193
1220
}
1194
1221
1195
1222
StructInst *createStruct (SILLocation Loc, SILType Ty,
1196
1223
ArrayRef<SILValue> Elements) {
1197
1224
assert (Ty.isLoadableOrOpaque (getModule ()));
1198
- return insert (
1199
- StructInst::create (getSILDebugLocation (Loc), Ty, Elements,
1200
- getModule ()));
1225
+ return insert (StructInst::create (getSILDebugLocation (Loc), Ty, Elements,
1226
+ getModule (), hasOwnership));
1201
1227
}
1202
1228
1203
1229
TupleInst *createTuple (SILLocation Loc, SILType Ty,
1204
1230
ArrayRef<SILValue> Elements) {
1205
1231
assert (Ty.isLoadableOrOpaque (getModule ()));
1206
- return insert (
1207
- TupleInst::create (getSILDebugLocation (Loc), Ty, Elements,
1208
- getModule ()));
1232
+ return insert (TupleInst::create (getSILDebugLocation (Loc), Ty, Elements,
1233
+ getModule (), hasOwnership));
1209
1234
}
1210
1235
1211
1236
TupleInst *createTuple (SILLocation loc, ArrayRef<SILValue> elts);
@@ -1286,7 +1311,7 @@ class SILBuilder {
1286
1311
assert (Ty.isLoadableOrOpaque (getModule ()));
1287
1312
return insert (SelectEnumInst::create (
1288
1313
getSILDebugLocation (Loc), Operand, Ty, DefaultValue, CaseValues,
1289
- getFunction (), CaseCounts, DefaultCount));
1314
+ getModule (), CaseCounts, DefaultCount, hasOwnership ));
1290
1315
}
1291
1316
1292
1317
SelectEnumAddrInst *createSelectEnumAddr (
@@ -1296,15 +1321,15 @@ class SILBuilder {
1296
1321
ProfileCounter DefaultCount = ProfileCounter()) {
1297
1322
return insert (SelectEnumAddrInst::create (
1298
1323
getSILDebugLocation (Loc), Operand, Ty, DefaultValue, CaseValues,
1299
- getFunction (), CaseCounts, DefaultCount));
1324
+ getModule (), CaseCounts, DefaultCount));
1300
1325
}
1301
1326
1302
1327
SelectValueInst *createSelectValue (
1303
1328
SILLocation Loc, SILValue Operand, SILType Ty, SILValue DefaultResult,
1304
1329
ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResults) {
1305
1330
return insert (SelectValueInst::create (getSILDebugLocation (Loc), Operand, Ty,
1306
1331
DefaultResult, CaseValuesAndResults,
1307
- getFunction () ));
1332
+ getModule (), hasOwnership ));
1308
1333
}
1309
1334
1310
1335
TupleExtractInst *createTupleExtract (SILLocation Loc, SILValue Operand,
@@ -1491,7 +1516,7 @@ class SILBuilder {
1491
1516
OpenExistentialRefInst *
1492
1517
createOpenExistentialRef (SILLocation Loc, SILValue Operand, SILType Ty) {
1493
1518
auto *I = insert (new (getModule ()) OpenExistentialRefInst (
1494
- getSILDebugLocation (Loc), Operand, Ty));
1519
+ getSILDebugLocation (Loc), Operand, Ty, hasOwnership ));
1495
1520
if (C.OpenedArchetypesTracker )
1496
1521
C.OpenedArchetypesTracker ->registerOpenedArchetypes (I);
1497
1522
return I;
0 commit comments