@@ -1107,7 +1107,107 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
1107
1107
<< " Live at beginning of block! No dead args!\n " );
1108
1108
}
1109
1109
1110
- assert ((isLiveOut ||
1111
- prevCount < boundary.getNumLastUsersAndDeadDefs (bitNo)) &&
1112
- " findBoundariesInBlock must be called on a live block" );
1110
+ assert (
1111
+ (isLiveOut || prevCount < boundary.getNumLastUsersAndDeadDefs (bitNo)) &&
1112
+ " findBoundariesInBlock must be called on a live block" );
1113
+ }
1114
+
1115
+ bool FieldSensitiveMultiDefPrunedLiveRange::findEarlierConsumingUse (
1116
+ SILInstruction *inst, unsigned index,
1117
+ llvm::function_ref<bool (SILInstruction *)> callback) const {
1118
+ PRUNED_LIVENESS_LOG (
1119
+ llvm::dbgs ()
1120
+ << " Performing single block search for consuming use for bit: " << index
1121
+ << " !\n " );
1122
+
1123
+ // Walk our block back from inst looking for defs or a consuming use. If we
1124
+ // see a def, return true. If we see a use, we keep processing if the callback
1125
+ // returns true... and return false early if the callback returns false.
1126
+ for (auto ii = std::next (inst->getReverseIterator ()),
1127
+ ie = inst->getParent ()->rend ();
1128
+ ii != ie; ++ii) {
1129
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << *ii);
1130
+ // If we have a def, then we are automatically done.
1131
+ if (isDef (&*ii, index)) {
1132
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Def! Returning true!\n " );
1133
+ return true ;
1134
+ }
1135
+
1136
+ // If we have a consuming use, emit the error.
1137
+ if (isInterestingUser (&*ii, index) ==
1138
+ IsInterestingUser::LifetimeEndingUse) {
1139
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Lifetime Ending Use!\n " );
1140
+ if (!callback (&*ii)) {
1141
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1142
+ << " Callback returned false... exiting!\n " );
1143
+ return false ;
1144
+ }
1145
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1146
+ << " Callback returned true... continuing!\n " );
1147
+ }
1148
+
1149
+ // Otherwise, keep going.
1150
+ }
1151
+
1152
+ // Then check our argument defs.
1153
+ for (auto *arg : inst->getParent ()->getArguments ()) {
1154
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting arg: " << *arg);
1155
+ if (isDef (arg, index)) {
1156
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found def. Returning true!\n " );
1157
+ return true ;
1158
+ }
1159
+ }
1160
+
1161
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Finished single block. Didn't find "
1162
+ " anything... Performing interprocedural" );
1163
+
1164
+ // Ok, we now know that we need to look further back.
1165
+ BasicBlockWorklist worklist (inst->getFunction ());
1166
+ for (auto *predBlock : inst->getParent ()->getPredecessorBlocks ()) {
1167
+ worklist.pushIfNotVisited (predBlock);
1168
+ }
1169
+
1170
+ while (auto *next = worklist.pop ()) {
1171
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1172
+ << " Checking block bb" << next->getDebugID () << ' \n ' );
1173
+ for (auto ii = next->rbegin (), ie = next->rend (); ii != ie; ++ii) {
1174
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << *ii);
1175
+ // If we have a def, then we are automatically done.
1176
+ if (isDef (&*ii, index)) {
1177
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Def! Returning true!\n " );
1178
+ return true ;
1179
+ }
1180
+
1181
+ // If we have a consuming use, emit the error.
1182
+ if (isInterestingUser (&*ii, index) ==
1183
+ IsInterestingUser::LifetimeEndingUse) {
1184
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Lifetime Ending Use!\n " );
1185
+ if (!callback (&*ii)) {
1186
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1187
+ << " Callback returned false... exiting!\n " );
1188
+ return false ;
1189
+ }
1190
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1191
+ << " Callback returned true... continuing!\n " );
1192
+ }
1193
+
1194
+ // Otherwise, keep going.
1195
+ }
1196
+
1197
+ for (auto *arg : next->getArguments ()) {
1198
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting arg: " << *arg);
1199
+ if (isDef (arg, index)) {
1200
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found def. Returning true!\n " );
1201
+ return true ;
1202
+ }
1203
+ }
1204
+
1205
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1206
+ << " Didn't find anything... visiting predecessors!\n " );
1207
+ for (auto *predBlock : next->getPredecessorBlocks ()) {
1208
+ worklist.pushIfNotVisited (predBlock);
1209
+ }
1210
+ }
1211
+
1212
+ return true ;
1113
1213
}
0 commit comments