@@ -987,35 +987,15 @@ static bool findNonEscapingPartialApplyUses(PartialApplyInst *pai,
987
987
return true ;
988
988
}
989
989
990
- void UseState::initializeLiveness (
991
- FieldSensitiveMultiDefPrunedLiveRange &liveness) {
992
- assert (liveness.getNumSubElements () == getNumSubelements ());
993
- // We begin by initializing all of our init uses.
994
- for (auto initInstAndValue : initInsts) {
995
- LLVM_DEBUG (llvm::dbgs () << " Found def: " << *initInstAndValue.first );
996
-
997
- liveness.initializeDef (initInstAndValue.first , initInstAndValue.second );
998
- }
999
-
1000
- // If we have a reinitInstAndValue that we are going to be able to convert
1001
- // into a simple init, add it as an init. We are going to consider the rest of
1002
- // our reinit uses to be liveness uses.
1003
- for (auto reinitInstAndValue : reinitInsts) {
1004
- if (isReinitToInitConvertibleInst (reinitInstAndValue.first )) {
1005
- LLVM_DEBUG (llvm::dbgs () << " Found def: " << *reinitInstAndValue.first );
1006
- liveness.initializeDef (reinitInstAndValue.first ,
1007
- reinitInstAndValue.second );
1008
- }
1009
- }
1010
-
990
+ static bool
991
+ addressBeginsInitialized (MarkUnresolvedNonCopyableValueInst *address) {
1011
992
// FIXME: Whether the initial use is an initialization ought to be entirely
1012
993
// derivable from the CheckKind of the mark instruction.
1013
994
1014
- // Then check if our markedValue is from an argument that is in,
1015
- // in_guaranteed, inout, or inout_aliasable, consider the marked address to be
1016
- // the initialization point.
1017
- bool beginsInitialized = false ;
1018
995
{
996
+ // Then check if our markedValue is from an argument that is in,
997
+ // in_guaranteed, inout, or inout_aliasable, consider the marked address to
998
+ // be the initialization point.
1019
999
SILValue operand = address->getOperand ();
1020
1000
if (auto *c = dyn_cast<CopyableToMoveOnlyWrapperAddrInst>(operand))
1021
1001
operand = c->getOperand ();
@@ -1034,7 +1014,7 @@ void UseState::initializeLiveness(
1034
1014
" an init... adding mark_unresolved_non_copyable_value as "
1035
1015
" init!\n " );
1036
1016
// We cheat here slightly and use our address's operand.
1037
- beginsInitialized = true ;
1017
+ return true ;
1038
1018
break ;
1039
1019
case swift::SILArgumentConvention::Indirect_Out:
1040
1020
llvm_unreachable (" Should never have out addresses here" );
@@ -1059,7 +1039,7 @@ void UseState::initializeLiveness(
1059
1039
LLVM_DEBUG (llvm::dbgs ()
1060
1040
<< " Found move only arg closure box use... "
1061
1041
" adding mark_unresolved_non_copyable_value as init!\n " );
1062
- beginsInitialized = true ;
1042
+ return true ;
1063
1043
break ;
1064
1044
case SILAccessKind::Init:
1065
1045
break ;
@@ -1081,14 +1061,14 @@ void UseState::initializeLiveness(
1081
1061
LLVM_DEBUG (llvm::dbgs ()
1082
1062
<< " Found move only arg closure box use... "
1083
1063
" adding mark_unresolved_non_copyable_value as init!\n " );
1084
- beginsInitialized = true ;
1064
+ return true ;
1085
1065
}
1086
1066
} else if (auto *box = dyn_cast<AllocBoxInst>(
1087
1067
lookThroughOwnershipInsts (projectBox->getOperand ()))) {
1088
1068
LLVM_DEBUG (llvm::dbgs ()
1089
1069
<< " Found move only var allocbox use... "
1090
1070
" adding mark_unresolved_non_copyable_value as init!\n " );
1091
- beginsInitialized = true ;
1071
+ return true ;
1092
1072
}
1093
1073
}
1094
1074
@@ -1099,7 +1079,7 @@ void UseState::initializeLiveness(
1099
1079
LLVM_DEBUG (llvm::dbgs ()
1100
1080
<< " Found ref_element_addr use... "
1101
1081
" adding mark_unresolved_non_copyable_value as init!\n " );
1102
- beginsInitialized = true ;
1082
+ return true ;
1103
1083
}
1104
1084
1105
1085
// Check if our address is from a global_addr. In such a case, we treat the
@@ -1109,7 +1089,7 @@ void UseState::initializeLiveness(
1109
1089
LLVM_DEBUG (llvm::dbgs ()
1110
1090
<< " Found global_addr use... "
1111
1091
" adding mark_unresolved_non_copyable_value as init!\n " );
1112
- beginsInitialized = true ;
1092
+ return true ;
1113
1093
}
1114
1094
1115
1095
if (auto *ptai = dyn_cast<PointerToAddressInst>(
@@ -1118,21 +1098,21 @@ void UseState::initializeLiveness(
1118
1098
LLVM_DEBUG (llvm::dbgs ()
1119
1099
<< " Found pointer to address use... "
1120
1100
" adding mark_unresolved_non_copyable_value as init!\n " );
1121
- beginsInitialized = true ;
1101
+ return true ;
1122
1102
}
1123
1103
1124
1104
if (auto *bai = dyn_cast_or_null<BeginApplyInst>(
1125
1105
stripAccessMarkers (address->getOperand ())->getDefiningInstruction ())) {
1126
1106
LLVM_DEBUG (llvm::dbgs ()
1127
1107
<< " Adding accessor coroutine begin_apply as init!\n " );
1128
- beginsInitialized = true ;
1108
+ return true ;
1129
1109
}
1130
1110
1131
1111
if (auto *eai = dyn_cast<UncheckedTakeEnumDataAddrInst>(
1132
1112
stripAccessMarkers (address->getOperand ()))) {
1133
1113
LLVM_DEBUG (llvm::dbgs ()
1134
1114
<< " Adding enum projection as init!\n " );
1135
- beginsInitialized = true ;
1115
+ return true ;
1136
1116
}
1137
1117
1138
1118
// Assume a strict check of a temporary or formal access is initialized
@@ -1142,30 +1122,55 @@ void UseState::initializeLiveness(
1142
1122
asi && address->isStrict ()) {
1143
1123
LLVM_DEBUG (llvm::dbgs ()
1144
1124
<< " Adding strict-marked alloc_stack as init!\n " );
1145
- beginsInitialized = true ;
1125
+ return true ;
1146
1126
}
1147
1127
1148
1128
// Assume a strict-checked value initialized before the check.
1149
1129
if (address->isStrict ()) {
1150
1130
LLVM_DEBUG (llvm::dbgs ()
1151
1131
<< " Adding strict marker as init!\n " );
1152
- beginsInitialized = true ;
1132
+ return true ;
1153
1133
}
1154
1134
1155
1135
// Assume a value whose deinit has been dropped has been initialized.
1156
1136
if (auto *ddi = dyn_cast<DropDeinitInst>(address->getOperand ())) {
1157
1137
LLVM_DEBUG (llvm::dbgs ()
1158
1138
<< " Adding copyable_to_move_only_wrapper as init!\n " );
1159
- beginsInitialized = true ;
1139
+ return true ;
1160
1140
}
1161
1141
1162
1142
// Assume a value wrapped in a MoveOnlyWrapper is initialized.
1163
1143
if (auto *m2c = dyn_cast<CopyableToMoveOnlyWrapperAddrInst>(address->getOperand ())) {
1164
1144
LLVM_DEBUG (llvm::dbgs ()
1165
1145
<< " Adding copyable_to_move_only_wrapper as init!\n " );
1166
- beginsInitialized = true ;
1146
+ return true ;
1167
1147
}
1168
-
1148
+ return false ;
1149
+ }
1150
+
1151
+ void UseState::initializeLiveness (
1152
+ FieldSensitiveMultiDefPrunedLiveRange &liveness) {
1153
+ assert (liveness.getNumSubElements () == getNumSubelements ());
1154
+ // We begin by initializing all of our init uses.
1155
+ for (auto initInstAndValue : initInsts) {
1156
+ LLVM_DEBUG (llvm::dbgs () << " Found def: " << *initInstAndValue.first );
1157
+
1158
+ liveness.initializeDef (initInstAndValue.first , initInstAndValue.second );
1159
+ }
1160
+
1161
+ // If we have a reinitInstAndValue that we are going to be able to convert
1162
+ // into a simple init, add it as an init. We are going to consider the rest of
1163
+ // our reinit uses to be liveness uses.
1164
+ for (auto reinitInstAndValue : reinitInsts) {
1165
+ if (isReinitToInitConvertibleInst (reinitInstAndValue.first )) {
1166
+ LLVM_DEBUG (llvm::dbgs () << " Found def: " << *reinitInstAndValue.first );
1167
+ liveness.initializeDef (reinitInstAndValue.first ,
1168
+ reinitInstAndValue.second );
1169
+ }
1170
+ }
1171
+
1172
+ bool beginsInitialized = addressBeginsInitialized (address);
1173
+
1169
1174
if (beginsInitialized) {
1170
1175
recordInitUse (address, address, liveness.getTopLevelSpan ());
1171
1176
liveness.initializeDef (SILValue (address), liveness.getTopLevelSpan ());
0 commit comments