Skip to content

Commit 16c300c

Browse files
committed
Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
1 parent 6df7ebb commit 16c300c

20 files changed

+269
-276
lines changed

include/swift/SIL/InstructionUtils.h

+74
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,80 @@ struct PolymorphicBuiltinSpecializedOverloadInfo {
257257
/// return SILValue().
258258
SILValue getStaticOverloadForSpecializedPolymorphicBuiltin(BuiltinInst *bi);
259259

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+
260334
} // end namespace swift
261335

262336
#endif

include/swift/SIL/SILCloner.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ visitRefToBridgeObjectInst(RefToBridgeObjectInst *Inst) {
16931693
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16941694
recordClonedInstruction(
16951695
Inst, getBuilder().createRefToBridgeObject(
1696-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getConverted()),
1696+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand(0)),
16971697
getOpValue(Inst->getBitsOperand()),
16981698
getBuilder().hasOwnership()
16991699
? Inst->getForwardingOwnershipKind()
@@ -1707,7 +1707,7 @@ visitBridgeObjectToRefInst(BridgeObjectToRefInst *Inst) {
17071707
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17081708
recordClonedInstruction(
17091709
Inst, getBuilder().createBridgeObjectToRef(
1710-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getConverted()),
1710+
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
17111711
getOpType(Inst->getType()),
17121712
getBuilder().hasOwnership()
17131713
? Inst->getForwardingOwnershipKind()
@@ -1721,7 +1721,7 @@ visitBridgeObjectToWordInst(BridgeObjectToWordInst *Inst) {
17211721
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17221722
recordClonedInstruction(Inst, getBuilder().createBridgeObjectToWord(
17231723
getOpLocation(Inst->getLoc()),
1724-
getOpValue(Inst->getConverted()),
1724+
getOpValue(Inst->getOperand()),
17251725
getOpType(Inst->getType())));
17261726
}
17271727

0 commit comments

Comments
 (0)