22
22
// /
23
23
// ===----------------------------------------------------------------------===//
24
24
25
+ #include " llvm/Support/ErrorHandling.h"
25
26
#define DEBUG_TYPE " sil-ownership-model-eliminator"
26
27
27
28
#include " swift/Basic/BlotSetVector.h"
28
29
#include " swift/SIL/Projection.h"
29
30
#include " swift/SIL/SILBuilder.h"
30
31
#include " swift/SIL/SILFunction.h"
32
+ #include " swift/SIL/SILInstruction.h"
31
33
#include " swift/SIL/SILVisitor.h"
32
34
#include " swift/SILOptimizer/Analysis/SimplifyInstruction.h"
33
35
#include " swift/SILOptimizer/PassManager/Transforms.h"
@@ -119,7 +121,16 @@ struct OwnershipModelEliminatorVisitor
119
121
eraseInstruction (i);
120
122
}
121
123
122
- bool visitSILInstruction (SILInstruction *) { return false ; }
124
+ bool visitSILInstruction (SILInstruction *inst) {
125
+ // Make sure this wasn't a forwarding instruction in case someone adds a new
126
+ // forwarding instruction but does not update this code.
127
+ if (OwnershipForwardingMixin::isa (inst)) {
128
+ llvm::errs () << " Found unhandled forwarding inst: " << *inst;
129
+ llvm_unreachable (" standard error handler" );
130
+ }
131
+ return false ;
132
+ }
133
+
123
134
bool visitLoadInst (LoadInst *li);
124
135
bool visitStoreInst (StoreInst *si);
125
136
bool visitStoreBorrowInst (StoreBorrowInst *si);
@@ -164,6 +175,37 @@ struct OwnershipModelEliminatorVisitor
164
175
165
176
void splitDestructure (SILInstruction *destructure,
166
177
SILValue destructureOperand);
178
+
179
+ #define HANDLE_FORWARDING_INST (Cls ) \
180
+ bool visit##Cls##Inst(Cls##Inst *i) { \
181
+ OwnershipForwardingMixin::get (i)->setOwnershipKind (OwnershipKind::None); \
182
+ return true ; \
183
+ }
184
+ HANDLE_FORWARDING_INST (ConvertFunction)
185
+ HANDLE_FORWARDING_INST (Upcast)
186
+ HANDLE_FORWARDING_INST (UncheckedRefCast)
187
+ HANDLE_FORWARDING_INST (RefToBridgeObject)
188
+ HANDLE_FORWARDING_INST (BridgeObjectToRef)
189
+ HANDLE_FORWARDING_INST (ThinToThickFunction)
190
+ HANDLE_FORWARDING_INST (UnconditionalCheckedCast)
191
+ HANDLE_FORWARDING_INST (Struct)
192
+ HANDLE_FORWARDING_INST (Object)
193
+ HANDLE_FORWARDING_INST (Tuple)
194
+ HANDLE_FORWARDING_INST (Enum)
195
+ HANDLE_FORWARDING_INST (UncheckedEnumData)
196
+ HANDLE_FORWARDING_INST (SelectEnum)
197
+ HANDLE_FORWARDING_INST (SelectValue)
198
+ HANDLE_FORWARDING_INST (OpenExistentialRef)
199
+ HANDLE_FORWARDING_INST (InitExistentialRef)
200
+ HANDLE_FORWARDING_INST (MarkDependence)
201
+ HANDLE_FORWARDING_INST (DifferentiableFunction)
202
+ HANDLE_FORWARDING_INST (LinearFunction)
203
+ HANDLE_FORWARDING_INST (StructExtract)
204
+ HANDLE_FORWARDING_INST (TupleExtract)
205
+ HANDLE_FORWARDING_INST (LinearFunctionExtract)
206
+ HANDLE_FORWARDING_INST (DifferentiableFunctionExtract)
207
+ HANDLE_FORWARDING_INST (MarkUninitialized)
208
+ #undef HANDLE_FORWARDING_INST
167
209
};
168
210
169
211
} // end anonymous namespace
@@ -295,6 +337,8 @@ bool OwnershipModelEliminatorVisitor::visitDestroyValueInst(
295
337
296
338
bool OwnershipModelEliminatorVisitor::visitCheckedCastBranchInst (
297
339
CheckedCastBranchInst *cbi) {
340
+ cbi->setOwnershipKind (OwnershipKind::None);
341
+
298
342
// In ownership qualified SIL, checked_cast_br must pass its argument to the
299
343
// fail case so we can clean it up. In non-ownership qualified SIL, we expect
300
344
// no argument from the checked_cast_br in the default case. The way that we
@@ -313,6 +357,8 @@ bool OwnershipModelEliminatorVisitor::visitCheckedCastBranchInst(
313
357
314
358
bool OwnershipModelEliminatorVisitor::visitSwitchEnumInst (
315
359
SwitchEnumInst *swei) {
360
+ swei->setOwnershipKind (OwnershipKind::None);
361
+
316
362
// In ownership qualified SIL, switch_enum must pass its argument to the fail
317
363
// case so we can clean it up. In non-ownership qualified SIL, we expect no
318
364
// argument from the switch_enum in the default case. The way that we handle
@@ -340,7 +386,6 @@ void OwnershipModelEliminatorVisitor::splitDestructure(
340
386
341
387
// First before we destructure anything, see if we can simplify any of our
342
388
// instruction operands.
343
-
344
389
SILModule &M = destructureInst->getModule ();
345
390
SILType opType = destructureOperand->getType ();
346
391
0 commit comments