@@ -67,17 +67,6 @@ class SILBuilderContext {
6767 // / only by SILGen or SIL deserializers.
6868 SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr ;
6969
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-
8170public:
8271 explicit SILBuilderContext (
8372 SILModule &M, SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
@@ -130,10 +119,6 @@ class SILBuilder {
130119 // / can store the SILGlobalVariable here as well.
131120 SILFunction *F;
132121
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-
137122 // / If this is non-null, the instruction is inserted in the specified
138123 // / basic block, at the specified InsertPt. If null, created instructions
139124 // / are not auto-inserted.
@@ -143,21 +128,17 @@ class SILBuilder {
143128 Optional<SILLocation> CurDebugLocOverride = None;
144129
145130public:
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 ) {}
151133
152134 SILBuilder (SILFunction &F, SmallVectorImpl<SILInstruction *> *InsertedInstrs)
153135 : TempContext(F.getModule(), InsertedInstrs), C(TempContext), F(&F),
154- hasOwnership (F.hasOwnership()), BB(0 ) {}
136+ BB (nullptr ) {}
155137
156138 explicit SILBuilder (SILInstruction *I,
157139 SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
158140 : TempContext(I->getFunction ()->getModule(), InsertedInstrs),
159- C(TempContext), F(I->getFunction ()),
160- hasOwnership(F->hasOwnership ()) {
141+ C(TempContext), F(I->getFunction ()) {
161142 setInsertionPoint (I);
162143 }
163144
@@ -168,8 +149,7 @@ class SILBuilder {
168149 explicit SILBuilder (SILBasicBlock *BB,
169150 SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
170151 : TempContext(BB->getParent ()->getModule(), InsertedInstrs),
171- C(TempContext), F(BB->getParent ()),
172- hasOwnership(F->hasOwnership ()) {
152+ C(TempContext), F(BB->getParent ()) {
173153 setInsertionPoint (BB);
174154 }
175155
@@ -179,8 +159,7 @@ class SILBuilder {
179159 SILBuilder (SILBasicBlock *BB, SILBasicBlock::iterator InsertPt,
180160 SmallVectorImpl<SILInstruction *> *InsertedInstrs = 0 )
181161 : TempContext(BB->getParent ()->getModule(), InsertedInstrs),
182- C(TempContext), F(BB->getParent ()),
183- hasOwnership(F->hasOwnership ()) {
162+ C(TempContext), F(BB->getParent ()) {
184163 setInsertionPoint (BB, InsertPt);
185164 }
186165
@@ -189,8 +168,7 @@ class SILBuilder {
189168 // /
190169 // / SILBuilderContext must outlive this SILBuilder instance.
191170 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 ()) {
194172 assert (DS && " instruction has no debug scope" );
195173 setCurrentDebugScope (DS);
196174 setInsertionPoint (I);
@@ -201,8 +179,7 @@ class SILBuilder {
201179 // /
202180 // / SILBuilderContext must outlive this SILBuilder instance.
203181 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 ()) {
206183 assert (DS && " block has no debug scope" );
207184 setCurrentDebugScope (DS);
208185 setInsertionPoint (BB);
@@ -260,15 +237,13 @@ class SILBuilder {
260237 return SILDebugLocation (overriddenLoc, Scope);
261238 }
262239
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+ }
272247
273248 // ===--------------------------------------------------------------------===//
274249 // Insertion Point Management
@@ -683,7 +658,7 @@ class SILBuilder {
683658 LoadInst *createTrivialLoadOr (SILLocation Loc, SILValue LV,
684659 LoadOwnershipQualifier Qualifier,
685660 bool SupportUnqualifiedSIL = false ) {
686- if (SupportUnqualifiedSIL && !getFunction (). hasOwnership ()) {
661+ if (SupportUnqualifiedSIL && !hasOwnership ()) {
687662 assert (
688663 Qualifier != LoadOwnershipQualifier::Copy &&
689664 " In unqualified SIL, a copy must be done separately form the load" );
@@ -699,11 +674,9 @@ class SILBuilder {
699674 LoadInst *createLoad (SILLocation Loc, SILValue LV,
700675 LoadOwnershipQualifier Qualifier) {
701676 assert ((Qualifier != LoadOwnershipQualifier::Unqualified) ||
702- !getFunction ().hasOwnership () &&
703- " Unqualified inst in qualified function" );
677+ !hasOwnership () && " Unqualified inst in qualified function" );
704678 assert ((Qualifier == LoadOwnershipQualifier::Unqualified) ||
705- getFunction ().hasOwnership () &&
706- " Qualified inst in unqualified function" );
679+ hasOwnership () && " Qualified inst in unqualified function" );
707680 assert (LV->getType ().isLoadableOrOpaque (getModule ()));
708681 return insert (new (getModule ())
709682 LoadInst (getSILDebugLocation (Loc), LV, Qualifier));
@@ -757,7 +730,7 @@ class SILBuilder {
757730 SILValue DestAddr,
758731 StoreOwnershipQualifier Qualifier,
759732 bool SupportUnqualifiedSIL = false ) {
760- if (SupportUnqualifiedSIL && !getFunction (). hasOwnership ()) {
733+ if (SupportUnqualifiedSIL && !hasOwnership ()) {
761734 assert (
762735 Qualifier != StoreOwnershipQualifier::Assign &&
763736 " In unqualified SIL, assigns must be represented via 2 instructions" );
@@ -773,11 +746,9 @@ class SILBuilder {
773746 StoreInst *createStore (SILLocation Loc, SILValue Src, SILValue DestAddr,
774747 StoreOwnershipQualifier Qualifier) {
775748 assert ((Qualifier != StoreOwnershipQualifier::Unqualified) ||
776- !getFunction ().hasOwnership () &&
777- " Unqualified inst in qualified function" );
749+ !hasOwnership () && " Unqualified inst in qualified function" );
778750 assert ((Qualifier == StoreOwnershipQualifier::Unqualified) ||
779- getFunction ().hasOwnership () &&
780- " Qualified inst in unqualified function" );
751+ hasOwnership () && " Qualified inst in unqualified function" );
781752 return insert (new (getModule ()) StoreInst (getSILDebugLocation (Loc), Src,
782753 DestAddr, Qualifier));
783754 }
@@ -1128,22 +1099,22 @@ class SILBuilder {
11281099
11291100 RetainValueInst *createRetainValue (SILLocation Loc, SILValue operand,
11301101 Atomicity atomicity) {
1131- assert (C. isParsing || ! getFunction (). hasOwnership ());
1102+ assert (! hasOwnership ());
11321103 assert (operand->getType ().isLoadableOrOpaque (getModule ()));
11331104 return insert (new (getModule ()) RetainValueInst (getSILDebugLocation (Loc),
11341105 operand, atomicity));
11351106 }
11361107
11371108 RetainValueAddrInst *createRetainValueAddr (SILLocation Loc, SILValue operand,
11381109 Atomicity atomicity) {
1139- assert (C. isParsing || ! getFunction (). hasOwnership ());
1110+ assert (! hasOwnership ());
11401111 return insert (new (getModule ()) RetainValueAddrInst (
11411112 getSILDebugLocation (Loc), operand, atomicity));
11421113 }
11431114
11441115 ReleaseValueInst *createReleaseValue (SILLocation Loc, SILValue operand,
11451116 Atomicity atomicity) {
1146- assert (C. isParsing || ! getFunction (). hasOwnership ());
1117+ assert (! hasOwnership ());
11471118 assert (operand->getType ().isLoadableOrOpaque (getModule ()));
11481119 return insert (new (getModule ()) ReleaseValueInst (getSILDebugLocation (Loc),
11491120 operand, atomicity));
@@ -1152,15 +1123,15 @@ class SILBuilder {
11521123 ReleaseValueAddrInst *createReleaseValueAddr (SILLocation Loc,
11531124 SILValue operand,
11541125 Atomicity atomicity) {
1155- assert (C. isParsing || ! getFunction (). hasOwnership ());
1126+ assert (! hasOwnership ());
11561127 return insert (new (getModule ()) ReleaseValueAddrInst (
11571128 getSILDebugLocation (Loc), operand, atomicity));
11581129 }
11591130
11601131 UnmanagedRetainValueInst *createUnmanagedRetainValue (SILLocation Loc,
11611132 SILValue operand,
11621133 Atomicity atomicity) {
1163- assert (getFunction (). hasOwnership ());
1134+ assert (hasOwnership ());
11641135 assert (operand->getType ().isLoadableOrOpaque (getModule ()));
11651136 return insert (new (getModule ()) UnmanagedRetainValueInst (
11661137 getSILDebugLocation (Loc), operand, atomicity));
@@ -1169,7 +1140,7 @@ class SILBuilder {
11691140 UnmanagedReleaseValueInst *createUnmanagedReleaseValue (SILLocation Loc,
11701141 SILValue operand,
11711142 Atomicity atomicity) {
1172- assert (getFunction (). hasOwnership ());
1143+ assert (hasOwnership ());
11731144 assert (operand->getType ().isLoadableOrOpaque (getModule ()));
11741145 return insert (new (getModule ()) UnmanagedReleaseValueInst (
11751146 getSILDebugLocation (Loc), operand, atomicity));
@@ -1201,21 +1172,21 @@ class SILBuilder {
12011172 unsigned NumBaseElements) {
12021173 return insert (ObjectInst::create (getSILDebugLocation (Loc), Ty, Elements,
12031174 NumBaseElements, getModule (),
1204- hasOwnership));
1175+ hasOwnership () ));
12051176 }
12061177
12071178 StructInst *createStruct (SILLocation Loc, SILType Ty,
12081179 ArrayRef<SILValue> Elements) {
12091180 assert (Ty.isLoadableOrOpaque (getModule ()));
12101181 return insert (StructInst::create (getSILDebugLocation (Loc), Ty, Elements,
1211- getModule (), hasOwnership));
1182+ getModule (), hasOwnership () ));
12121183 }
12131184
12141185 TupleInst *createTuple (SILLocation Loc, SILType Ty,
12151186 ArrayRef<SILValue> Elements) {
12161187 assert (Ty.isLoadableOrOpaque (getModule ()));
12171188 return insert (TupleInst::create (getSILDebugLocation (Loc), Ty, Elements,
1218- getModule (), hasOwnership));
1189+ getModule (), hasOwnership () ));
12191190 }
12201191
12211192 TupleInst *createTuple (SILLocation loc, ArrayRef<SILValue> elts);
@@ -1296,7 +1267,7 @@ class SILBuilder {
12961267 assert (Ty.isLoadableOrOpaque (getModule ()));
12971268 return insert (SelectEnumInst::create (
12981269 getSILDebugLocation (Loc), Operand, Ty, DefaultValue, CaseValues,
1299- getModule (), CaseCounts, DefaultCount, hasOwnership));
1270+ getModule (), CaseCounts, DefaultCount, hasOwnership () ));
13001271 }
13011272
13021273 SelectEnumAddrInst *createSelectEnumAddr (
@@ -1314,7 +1285,7 @@ class SILBuilder {
13141285 ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResults) {
13151286 return insert (SelectValueInst::create (getSILDebugLocation (Loc), Operand, Ty,
13161287 DefaultResult, CaseValuesAndResults,
1317- getModule (), hasOwnership));
1288+ getModule (), hasOwnership () ));
13181289 }
13191290
13201291 TupleExtractInst *createTupleExtract (SILLocation Loc, SILValue Operand,
@@ -1501,7 +1472,7 @@ class SILBuilder {
15011472 OpenExistentialRefInst *
15021473 createOpenExistentialRef (SILLocation Loc, SILValue Operand, SILType Ty) {
15031474 auto *I = insert (new (getModule ()) OpenExistentialRefInst (
1504- getSILDebugLocation (Loc), Operand, Ty, hasOwnership));
1475+ getSILDebugLocation (Loc), Operand, Ty, hasOwnership () ));
15051476 if (C.OpenedArchetypesTracker )
15061477 C.OpenedArchetypesTracker ->registerOpenedArchetypes (I);
15071478 return I;
@@ -1637,13 +1608,13 @@ class SILBuilder {
16371608
16381609 StrongRetainInst *createStrongRetain (SILLocation Loc, SILValue Operand,
16391610 Atomicity atomicity) {
1640- assert (C. isParsing || ! getFunction (). hasOwnership ());
1611+ assert (! hasOwnership ());
16411612 return insert (new (getModule ()) StrongRetainInst (getSILDebugLocation (Loc),
16421613 Operand, atomicity));
16431614 }
16441615 StrongReleaseInst *createStrongRelease (SILLocation Loc, SILValue Operand,
16451616 Atomicity atomicity) {
1646- assert (C. isParsing || ! getFunction (). hasOwnership ());
1617+ assert (! hasOwnership ());
16471618 return insert (new (getModule ()) StrongReleaseInst (
16481619 getSILDebugLocation (Loc), Operand, atomicity));
16491620 }
0 commit comments