@@ -257,6 +257,80 @@ struct PolymorphicBuiltinSpecializedOverloadInfo {
257
257
// / return SILValue().
258
258
SILValue getStaticOverloadForSpecializedPolymorphicBuiltin (BuiltinInst *bi);
259
259
260
+ // / An ADT for writing generic code against conversion instructions.
261
+ struct ConversionOperation {
262
+ SingleValueInstruction *inst = nullptr ;
263
+
264
+ ConversionOperation () = default ;
265
+
266
+ explicit ConversionOperation (SILInstruction *inst) {
267
+ auto *svi = dyn_cast<SingleValueInstruction>(inst);
268
+ if (!svi) {
269
+ return ;
270
+ }
271
+ if (!ConversionOperation::isa (svi)) {
272
+ return ;
273
+ }
274
+ this ->inst = svi;
275
+ }
276
+
277
+ explicit ConversionOperation (SILValue value) {
278
+ auto *inst = value->getDefiningInstruction ();
279
+ if (!inst) {
280
+ return ;
281
+ }
282
+ auto *svi = dyn_cast<SingleValueInstruction>(inst);
283
+ if (!svi) {
284
+ return ;
285
+ }
286
+ if (!ConversionOperation::isa (svi)) {
287
+ return ;
288
+ }
289
+ this ->inst = svi;
290
+ }
291
+
292
+ operator bool () const { return inst != nullptr ; }
293
+
294
+ SingleValueInstruction *operator ->() { return inst; }
295
+ SingleValueInstruction *operator ->() const { return inst; }
296
+ SingleValueInstruction *operator *() { return inst; }
297
+ SingleValueInstruction *operator *() const { return inst; }
298
+
299
+ static bool isa (SILInstruction *inst) {
300
+ switch (inst->getKind ()) {
301
+ case SILInstructionKind::ConvertFunctionInst:
302
+ case SILInstructionKind::UpcastInst:
303
+ case SILInstructionKind::AddressToPointerInst:
304
+ case SILInstructionKind::UncheckedTrivialBitCastInst:
305
+ case SILInstructionKind::UncheckedAddrCastInst:
306
+ case SILInstructionKind::UncheckedBitwiseCastInst:
307
+ case SILInstructionKind::RefToRawPointerInst:
308
+ case SILInstructionKind::RawPointerToRefInst:
309
+ case SILInstructionKind::ConvertEscapeToNoEscapeInst:
310
+ case SILInstructionKind::RefToBridgeObjectInst:
311
+ case SILInstructionKind::BridgeObjectToRefInst:
312
+ case SILInstructionKind::BridgeObjectToWordInst:
313
+ case SILInstructionKind::ThinToThickFunctionInst:
314
+ case SILInstructionKind::ThickToObjCMetatypeInst:
315
+ case SILInstructionKind::ObjCToThickMetatypeInst:
316
+ case SILInstructionKind::ObjCMetatypeToObjectInst:
317
+ case SILInstructionKind::ObjCExistentialMetatypeToObjectInst:
318
+ case SILInstructionKind::UnconditionalCheckedCastInst:
319
+ case SILInstructionKind::UncheckedRefCastInst:
320
+ case SILInstructionKind::UncheckedValueCastInst:
321
+ case SILInstructionKind::RefToUnmanagedInst:
322
+ case SILInstructionKind::RefToUnownedInst:
323
+ case SILInstructionKind::UnmanagedToRefInst:
324
+ case SILInstructionKind::UnownedToRefInst:
325
+ return true ;
326
+ default :
327
+ return false ;
328
+ }
329
+ }
330
+
331
+ SILValue getConverted () { return inst->getOperand (0 ); }
332
+ };
333
+
260
334
} // end namespace swift
261
335
262
336
#endif
0 commit comments