Skip to content

Commit 5660643

Browse files
committed
Print forwardingOwnershipKind when it differs from the operand's
ownershipKind
1 parent a6f828d commit 5660643

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,13 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
14201420
}
14211421
}
14221422

1423+
void printForwardingOwnershipKind(OwnershipForwardingMixin *inst,
1424+
SILValue op) {
1425+
if (inst->getForwardingOwnershipKind() != op.getOwnershipKind()) {
1426+
*this << ", forwarding: @" << inst->getForwardingOwnershipKind();
1427+
}
1428+
}
1429+
14231430
void visitStoreInst(StoreInst *SI) {
14241431
*this << Ctx.getID(SI->getSrc()) << " to ";
14251432
printStoreOwnershipQualifier(SI->getOwnershipQualifier());
@@ -1465,8 +1472,8 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
14651472
*this << "[delegatingselfallocated] ";
14661473
break;
14671474
}
1468-
14691475
*this << getIDAndType(MU->getOperand());
1476+
printForwardingOwnershipKind(MU, MU->getOperand());
14701477
}
14711478

14721479
void visitMarkFunctionEscapeInst(MarkFunctionEscapeInst *MFE) {
@@ -1516,6 +1523,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
15161523

15171524
void visitUnconditionalCheckedCastInst(UnconditionalCheckedCastInst *CI) {
15181525
*this << getIDAndType(CI->getOperand()) << " to " << CI->getTargetFormalType();
1526+
printForwardingOwnershipKind(CI, CI->getOperand());
15191527
}
15201528

15211529
void visitCheckedCastBranchInst(CheckedCastBranchInst *CI) {
@@ -1564,6 +1572,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
15641572

15651573
void printUncheckedConversionInst(ConversionInst *CI, SILValue operand) {
15661574
*this << getIDAndType(operand) << " to " << CI->getType();
1575+
if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(CI)) {
1576+
printForwardingOwnershipKind(ofci, ofci->getOperand(0));
1577+
}
15671578
}
15681579

15691580
void visitUncheckedOwnershipConversionInst(
@@ -1578,6 +1589,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
15781589
if (CI->withoutActuallyEscaping())
15791590
*this << "[without_actually_escaping] ";
15801591
*this << CI->getType();
1592+
printForwardingOwnershipKind(CI, CI->getOperand());
15811593
}
15821594
void visitConvertEscapeToNoEscapeInst(ConvertEscapeToNoEscapeInst *CI) {
15831595
*this << (CI->isLifetimeGuaranteed() ? "" : "[not_guaranteed] ")
@@ -1661,10 +1673,12 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
16611673
void visitRefToBridgeObjectInst(RefToBridgeObjectInst *I) {
16621674
*this << getIDAndType(I->getConverted()) << ", "
16631675
<< getIDAndType(I->getBitsOperand());
1676+
printForwardingOwnershipKind(I, I->getConverted());
16641677
}
16651678

16661679
void visitBridgeObjectToRefInst(BridgeObjectToRefInst *I) {
16671680
printUncheckedConversionInst(I, I->getOperand());
1681+
printForwardingOwnershipKind(I, I->getOperand());
16681682
}
16691683
void visitBridgeObjectToWordInst(BridgeObjectToWordInst *I) {
16701684
printUncheckedConversionInst(I, I->getOperand());
@@ -1748,6 +1762,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17481762
<< SILDeclRef(UI->getElement(), SILDeclRef::Kind::EnumElement);
17491763
if (UI->hasOperand()) {
17501764
*this << ", " << getIDAndType(UI->getOperand());
1765+
printForwardingOwnershipKind(UI, UI->getOperand());
17511766
}
17521767
}
17531768

@@ -1759,6 +1774,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17591774
void visitUncheckedEnumDataInst(UncheckedEnumDataInst *UDAI) {
17601775
*this << getIDAndType(UDAI->getOperand()) << ", "
17611776
<< SILDeclRef(UDAI->getElement(), SILDeclRef::Kind::EnumElement);
1777+
printForwardingOwnershipKind(UDAI, UDAI->getOperand());
17621778
}
17631779

17641780
void visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *UDAI) {
@@ -1773,6 +1789,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17731789

17741790
void visitTupleExtractInst(TupleExtractInst *EI) {
17751791
*this << getIDAndType(EI->getOperand()) << ", " << EI->getFieldIndex();
1792+
printForwardingOwnershipKind(EI, EI->getOperand());
17761793
}
17771794

17781795
void visitTupleElementAddrInst(TupleElementAddrInst *EI) {
@@ -1782,6 +1799,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17821799
*this << getIDAndType(EI->getOperand()) << ", #";
17831800
printFullContext(EI->getField()->getDeclContext(), PrintState.OS);
17841801
*this << EI->getField()->getName().get();
1802+
printForwardingOwnershipKind(EI, EI->getOperand());
17851803
}
17861804
void visitStructElementAddrInst(StructElementAddrInst *EI) {
17871805
*this << getIDAndType(EI->getOperand()) << ", #";
@@ -1802,10 +1820,12 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18021820

18031821
void visitDestructureStructInst(DestructureStructInst *DSI) {
18041822
*this << getIDAndType(DSI->getOperand());
1823+
printForwardingOwnershipKind(DSI, DSI->getOperand());
18051824
}
18061825

18071826
void visitDestructureTupleInst(DestructureTupleInst *DTI) {
18081827
*this << getIDAndType(DTI->getOperand());
1828+
printForwardingOwnershipKind(DTI, DTI->getOperand());
18091829
}
18101830

18111831
void printMethodInst(MethodInst *I, SILValue Operand) {
@@ -1859,6 +1879,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18591879
}
18601880
void visitOpenExistentialRefInst(OpenExistentialRefInst *OI) {
18611881
*this << getIDAndType(OI->getOperand()) << " to " << OI->getType();
1882+
printForwardingOwnershipKind(OI, OI->getOperand());
18621883
}
18631884
void visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *OI) {
18641885
*this << getIDAndType(OI->getOperand()) << " to " << OI->getType();
@@ -1868,9 +1889,11 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18681889
}
18691890
void visitOpenExistentialBoxValueInst(OpenExistentialBoxValueInst *OI) {
18701891
*this << getIDAndType(OI->getOperand()) << " to " << OI->getType();
1892+
printForwardingOwnershipKind(OI, OI->getOperand());
18711893
}
18721894
void visitOpenExistentialValueInst(OpenExistentialValueInst *OI) {
18731895
*this << getIDAndType(OI->getOperand()) << " to " << OI->getType();
1896+
printForwardingOwnershipKind(OI, OI->getOperand());
18741897
}
18751898
void visitInitExistentialAddrInst(InitExistentialAddrInst *AEI) {
18761899
*this << getIDAndType(AEI->getOperand()) << ", $"
@@ -1886,6 +1909,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
18861909
*this << getIDAndType(AEI->getOperand()) << " : $"
18871910
<< AEI->getFormalConcreteType() << ", " << AEI->getType();
18881911
printConformances(AEI->getConformances());
1912+
printForwardingOwnershipKind(AEI, AEI->getOperand());
18891913
}
18901914
void visitInitExistentialMetatypeInst(InitExistentialMetatypeInst *EMI) {
18911915
*this << getIDAndType(EMI->getOperand()) << ", " << EMI->getType();
@@ -1939,6 +1963,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
19391963
void visitMarkDependenceInst(MarkDependenceInst *MDI) {
19401964
*this << getIDAndType(MDI->getValue()) << " on "
19411965
<< getIDAndType(MDI->getBase());
1966+
printForwardingOwnershipKind(MDI, MDI->getValue());
19421967
}
19431968
void visitCopyBlockInst(CopyBlockInst *RI) {
19441969
*this << getIDAndType(RI->getOperand());
@@ -2133,6 +2158,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
21332158

21342159
void visitSwitchEnumInst(SwitchEnumInst *SOI) {
21352160
printSwitchEnumInst(SOI);
2161+
printForwardingOwnershipKind(SOI, SOI->getOperand());
21362162
}
21372163
void visitSwitchEnumAddrInst(SwitchEnumAddrInst *SOI) {
21382164
printSwitchEnumInst(SOI);
@@ -2156,6 +2182,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
21562182

21572183
void visitSelectEnumInst(SelectEnumInst *SEI) {
21582184
printSelectEnumInst(SEI);
2185+
printForwardingOwnershipKind(SEI, SEI->getOperand());
21592186
}
21602187
void visitSelectEnumAddrInst(SelectEnumAddrInst *SEI) {
21612188
printSelectEnumInst(SEI);
@@ -2174,6 +2201,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
21742201
*this << ", default " << Ctx.getID(SVI->getDefaultResult());
21752202

21762203
*this << " : " << SVI->getType();
2204+
printForwardingOwnershipKind(SVI, SVI->getOperand());
21772205
}
21782206

21792207
void visitDynamicMethodBranchInst(DynamicMethodBranchInst *DMBI) {
@@ -2411,6 +2439,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
24112439
*this << " as ";
24122440
*this << dfei->getType();
24132441
}
2442+
printForwardingOwnershipKind(dfei, dfei->getOperand());
24142443
}
24152444

24162445
void visitLinearFunctionExtractInst(LinearFunctionExtractInst *lfei) {
@@ -2425,6 +2454,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
24252454
}
24262455
*this << "] ";
24272456
*this << getIDAndType(lfei->getOperand());
2457+
printForwardingOwnershipKind(lfei, lfei->getOperand());
24282458
}
24292459

24302460
void visitDifferentiabilityWitnessFunctionInst(

test/SILOptimizer/sil_combine_ossa.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4931,7 +4931,7 @@ bb2(%error : @owned $Error):
49314931
sil [ossa] @takeKlass : $@convention(thin) (@owned Optional<Klass>) -> ()
49324932

49334933
// CHECK_FORWARDING_OWNERSHIP_KIND-LABEL: sil shared [ossa] @$s8refcast24main5KlassC_Tg5 :
4934-
// CHECK_FORWARDING_OWNERSHIP_KIND: unchecked_ref_cast
4934+
// CHECK_FORWARDING_OWNERSHIP_KIND: unchecked_ref_cast %1 : $Klass to $Optional<Klass>, forwarding: @unowned
49354935
// CHECK_FORWARDING_OWNERSHIP_KIND-LABEL: } // end sil function '$s8refcast24main5KlassC_Tg5'
49364936
sil [ossa] @refcast2 : $@convention(thin) <T> (@in T, @owned Klass) -> () {
49374937
bb0(%0 : $*T, %1 : @owned $Klass):

0 commit comments

Comments
 (0)