Skip to content

Commit 03b8c49

Browse files
authored
Merge pull request #66645 from meg-gupta/mixinremovesmall
Simplify forwarding instruction definitions in SIL
2 parents 44879be + 16c300c commit 03b8c49

32 files changed

+456
-582
lines changed

include/swift/SIL/InstructionUtils.h

Lines changed: 74 additions & 0 deletions
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/OwnershipUseVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bool OwnershipUseVisitor<Impl>::visitInnerBorrowScopeEnd(Operand *borrowEnd) {
296296
// TODO: When we have ForwardingInstruction abstraction, walk the use-def
297297
// chain to ensure we have a partial_apply [on_stack] def.
298298
assert(pai && pai->isOnStack() ||
299-
OwnershipForwardingMixin::get(
299+
ForwardingInstruction::get(
300300
cast<SingleValueInstruction>(borrowEnd->get())));
301301
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
302302
}

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ForwardingOperand {
219219
}
220220

221221
bool preservesOwnership() const {
222-
auto &mixin = *OwnershipForwardingMixin::get(use->getUser());
222+
auto &mixin = *ForwardingInstruction::get(use->getUser());
223223
return mixin.preservesOwnership();
224224
}
225225

include/swift/SIL/SILCloner.h

Lines changed: 3 additions & 3 deletions
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)