@@ -999,7 +999,28 @@ SILCloner<ImplClass>::visitStringLiteralInst(StringLiteralInst *Inst) {
999
999
template <typename ImplClass>
1000
1000
void SILCloner<ImplClass>::visitLoadInst(LoadInst *Inst) {
1001
1001
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1002
- recordClonedInstruction (
1002
+ if (!getBuilder ().hasOwnership ()) {
1003
+ switch (Inst->getOwnershipQualifier ()) {
1004
+ case LoadOwnershipQualifier::Copy: {
1005
+ auto *li = getBuilder ().createLoad (getOpLocation (Inst->getLoc ()),
1006
+ getOpValue (Inst->getOperand ()),
1007
+ LoadOwnershipQualifier::Unqualified);
1008
+ // This will emit a retain_value/strong_retain as appropriate.
1009
+ getBuilder ().emitCopyValueOperation (getOpLocation (Inst->getLoc ()), li);
1010
+ return recordClonedInstruction (Inst, li);
1011
+ }
1012
+ case LoadOwnershipQualifier::Take:
1013
+ case LoadOwnershipQualifier::Trivial:
1014
+ case LoadOwnershipQualifier::Unqualified:
1015
+ break ;
1016
+ }
1017
+ return recordClonedInstruction (
1018
+ Inst, getBuilder ().createLoad (getOpLocation (Inst->getLoc ()),
1019
+ getOpValue (Inst->getOperand ()),
1020
+ LoadOwnershipQualifier::Unqualified));
1021
+ }
1022
+
1023
+ return recordClonedInstruction (
1003
1024
Inst, getBuilder ().createLoad (getOpLocation (Inst->getLoc ()),
1004
1025
getOpValue (Inst->getOperand ()),
1005
1026
Inst->getOwnershipQualifier ()));
@@ -1008,6 +1029,14 @@ void SILCloner<ImplClass>::visitLoadInst(LoadInst *Inst) {
1008
1029
template <typename ImplClass>
1009
1030
void SILCloner<ImplClass>::visitLoadBorrowInst(LoadBorrowInst *Inst) {
1010
1031
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1032
+ // If we are not inlining into an ownership function, just use a load.
1033
+ if (!getBuilder ().hasOwnership ()) {
1034
+ return recordClonedInstruction (
1035
+ Inst, getBuilder ().createLoad (getOpLocation (Inst->getLoc ()),
1036
+ getOpValue (Inst->getOperand ()),
1037
+ LoadOwnershipQualifier::Unqualified));
1038
+ }
1039
+
1011
1040
recordClonedInstruction (
1012
1041
Inst, getBuilder ().createLoadBorrow (getOpLocation (Inst->getLoc ()),
1013
1042
getOpValue (Inst->getOperand ())));
@@ -1016,6 +1045,10 @@ void SILCloner<ImplClass>::visitLoadBorrowInst(LoadBorrowInst *Inst) {
1016
1045
template <typename ImplClass>
1017
1046
void SILCloner<ImplClass>::visitBeginBorrowInst(BeginBorrowInst *Inst) {
1018
1047
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1048
+ if (!getBuilder ().hasOwnership ()) {
1049
+ return recordFoldedValue (Inst, getOpValue (Inst->getOperand ()));
1050
+ }
1051
+
1019
1052
recordClonedInstruction (
1020
1053
Inst, getBuilder ().createBeginBorrow (getOpLocation (Inst->getLoc ()),
1021
1054
getOpValue (Inst->getOperand ())));
@@ -1024,6 +1057,31 @@ void SILCloner<ImplClass>::visitBeginBorrowInst(BeginBorrowInst *Inst) {
1024
1057
template <typename ImplClass>
1025
1058
void SILCloner<ImplClass>::visitStoreInst(StoreInst *Inst) {
1026
1059
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1060
+ if (!getBuilder ().hasOwnership ()) {
1061
+ switch (Inst->getOwnershipQualifier ()) {
1062
+ case StoreOwnershipQualifier::Assign: {
1063
+ auto *li = getBuilder ().createLoad (getOpLocation (Inst->getLoc ()),
1064
+ getOpValue (Inst->getDest ()),
1065
+ LoadOwnershipQualifier::Unqualified);
1066
+ auto *si = getBuilder ().createStore (
1067
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getSrc ()),
1068
+ getOpValue (Inst->getDest ()), StoreOwnershipQualifier::Unqualified);
1069
+ getBuilder ().emitDestroyValueOperation (getOpLocation (Inst->getLoc ()), li);
1070
+ return recordClonedInstruction (Inst, si);
1071
+ }
1072
+ case StoreOwnershipQualifier::Init:
1073
+ case StoreOwnershipQualifier::Trivial:
1074
+ case StoreOwnershipQualifier::Unqualified:
1075
+ break ;
1076
+ }
1077
+
1078
+ return recordClonedInstruction (
1079
+ Inst, getBuilder ().createStore (getOpLocation (Inst->getLoc ()),
1080
+ getOpValue (Inst->getSrc ()),
1081
+ getOpValue (Inst->getDest ()),
1082
+ StoreOwnershipQualifier::Unqualified));
1083
+ }
1084
+
1027
1085
recordClonedInstruction (
1028
1086
Inst, getBuilder ().createStore (
1029
1087
getOpLocation (Inst->getLoc ()), getOpValue (Inst->getSrc ()),
@@ -1033,6 +1091,16 @@ void SILCloner<ImplClass>::visitStoreInst(StoreInst *Inst) {
1033
1091
template <typename ImplClass>
1034
1092
void SILCloner<ImplClass>::visitStoreBorrowInst(StoreBorrowInst *Inst) {
1035
1093
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1094
+ if (!getBuilder ().hasOwnership ()) {
1095
+ // TODO: Eliminate store_borrow result so we can use
1096
+ // recordClonedInstruction. It is not "technically" necessary, but it is
1097
+ // better from an invariant perspective.
1098
+ getBuilder ().createStore (
1099
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getSrc ()),
1100
+ getOpValue (Inst->getDest ()), StoreOwnershipQualifier::Unqualified);
1101
+ return ;
1102
+ }
1103
+
1036
1104
recordClonedInstruction (
1037
1105
Inst, getBuilder ().createStoreBorrow (getOpLocation (Inst->getLoc ()),
1038
1106
getOpValue (Inst->getSrc ()),
@@ -1042,6 +1110,11 @@ void SILCloner<ImplClass>::visitStoreBorrowInst(StoreBorrowInst *Inst) {
1042
1110
template <typename ImplClass>
1043
1111
void SILCloner<ImplClass>::visitEndBorrowInst(EndBorrowInst *Inst) {
1044
1112
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1113
+
1114
+ // Do not clone any end_borrow.
1115
+ if (!getBuilder ().hasOwnership ())
1116
+ return ;
1117
+
1045
1118
recordClonedInstruction (
1046
1119
Inst,
1047
1120
getBuilder ().createEndBorrow (getOpLocation (Inst->getLoc ()),
@@ -1546,6 +1619,12 @@ void SILCloner<ImplClass>::visitUnmanagedRetainValueInst(
1546
1619
template <typename ImplClass>
1547
1620
void SILCloner<ImplClass>::visitCopyValueInst(CopyValueInst *Inst) {
1548
1621
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1622
+ if (!getBuilder ().hasOwnership ()) {
1623
+ SILValue newValue = getBuilder ().emitCopyValueOperation (
1624
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ()));
1625
+ return recordFoldedValue (Inst, newValue);
1626
+ }
1627
+
1549
1628
recordClonedInstruction (
1550
1629
Inst, getBuilder ().createCopyValue (getOpLocation (Inst->getLoc ()),
1551
1630
getOpValue (Inst->getOperand ())));
@@ -1583,6 +1662,13 @@ void SILCloner<ImplClass>::visitUnmanagedReleaseValueInst(
1583
1662
template <typename ImplClass>
1584
1663
void SILCloner<ImplClass>::visitDestroyValueInst(DestroyValueInst *Inst) {
1585
1664
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1665
+ if (!getBuilder ().hasOwnership ()) {
1666
+ return recordClonedInstruction (
1667
+ Inst, getBuilder ().createReleaseValue (
1668
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ()),
1669
+ RefCountingInst::Atomicity::Atomic));
1670
+ }
1671
+
1586
1672
recordClonedInstruction (
1587
1673
Inst, getBuilder ().createDestroyValue (getOpLocation (Inst->getLoc ()),
1588
1674
getOpValue (Inst->getOperand ())));
@@ -1795,6 +1881,16 @@ template <typename ImplClass>
1795
1881
void SILCloner<ImplClass>::visitDestructureStructInst(
1796
1882
DestructureStructInst *Inst) {
1797
1883
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1884
+
1885
+ if (!getBuilder ().hasOwnership ()) {
1886
+ getBuilder ().emitDestructureValueOperation (
1887
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ()),
1888
+ [&](unsigned index, SILValue value) {
1889
+ recordFoldedValue (Inst->getResults ()[index], value);
1890
+ });
1891
+ return ;
1892
+ }
1893
+
1798
1894
recordClonedInstruction (
1799
1895
Inst, getBuilder ().createDestructureStruct (
1800
1896
getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ())));
@@ -1804,6 +1900,15 @@ template <typename ImplClass>
1804
1900
void SILCloner<ImplClass>::visitDestructureTupleInst(
1805
1901
DestructureTupleInst *Inst) {
1806
1902
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
1903
+ if (!getBuilder ().hasOwnership ()) {
1904
+ getBuilder ().emitDestructureValueOperation (
1905
+ getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ()),
1906
+ [&](unsigned index, SILValue value) {
1907
+ recordFoldedValue (Inst->getResults ()[index], value);
1908
+ });
1909
+ return ;
1910
+ }
1911
+
1807
1912
recordClonedInstruction (
1808
1913
Inst, getBuilder ().createDestructureTuple (
1809
1914
getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ())));
@@ -2104,6 +2209,11 @@ SILCloner<ImplClass>::visitFixLifetimeInst(FixLifetimeInst *Inst) {
2104
2209
template <typename ImplClass>
2105
2210
void SILCloner<ImplClass>::visitEndLifetimeInst(EndLifetimeInst *Inst) {
2106
2211
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2212
+
2213
+ // These are only needed in OSSA.
2214
+ if (!getBuilder ().hasOwnership ())
2215
+ return ;
2216
+
2107
2217
recordClonedInstruction (
2108
2218
Inst, getBuilder ().createEndLifetime (getOpLocation (Inst->getLoc ()),
2109
2219
getOpValue (Inst->getOperand ())));
@@ -2113,6 +2223,11 @@ template <typename ImplClass>
2113
2223
void SILCloner<ImplClass>::visitUncheckedOwnershipConversionInst(
2114
2224
UncheckedOwnershipConversionInst *Inst) {
2115
2225
getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2226
+
2227
+ if (!getBuilder ().hasOwnership ()) {
2228
+ return recordFoldedValue (Inst, getOpValue (Inst->getOperand ()));
2229
+ }
2230
+
2116
2231
ValueOwnershipKind Kind = SILValue (Inst).getOwnershipKind ();
2117
2232
if (getOpValue (Inst->getOperand ()).getOwnershipKind () ==
2118
2233
ValueOwnershipKind::Any) {
0 commit comments