@@ -1191,7 +1191,107 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
1191
1191
<< " Live at beginning of block! No dead args!\n " );
1192
1192
}
1193
1193
1194
- assert ((isLiveOut ||
1195
- prevCount < boundary.getNumLastUsersAndDeadDefs (bitNo)) &&
1196
- " findBoundariesInBlock must be called on a live block" );
1194
+ assert (
1195
+ (isLiveOut || prevCount < boundary.getNumLastUsersAndDeadDefs (bitNo)) &&
1196
+ " findBoundariesInBlock must be called on a live block" );
1197
+ }
1198
+
1199
+ bool FieldSensitiveMultiDefPrunedLiveRange::findEarlierConsumingUse (
1200
+ SILInstruction *inst, unsigned index,
1201
+ llvm::function_ref<bool (SILInstruction *)> callback) const {
1202
+ PRUNED_LIVENESS_LOG (
1203
+ llvm::dbgs ()
1204
+ << " Performing single block search for consuming use for bit: " << index
1205
+ << " !\n " );
1206
+
1207
+ // Walk our block back from inst looking for defs or a consuming use. If we
1208
+ // see a def, return true. If we see a use, we keep processing if the callback
1209
+ // returns true... and return false early if the callback returns false.
1210
+ for (auto ii = std::next (inst->getReverseIterator ()),
1211
+ ie = inst->getParent ()->rend ();
1212
+ ii != ie; ++ii) {
1213
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << *ii);
1214
+ // If we have a def, then we are automatically done.
1215
+ if (isDef (&*ii, index)) {
1216
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Def! Returning true!\n " );
1217
+ return true ;
1218
+ }
1219
+
1220
+ // If we have a consuming use, emit the error.
1221
+ if (isInterestingUser (&*ii, index) ==
1222
+ IsInterestingUser::LifetimeEndingUse) {
1223
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Lifetime Ending Use!\n " );
1224
+ if (!callback (&*ii)) {
1225
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1226
+ << " Callback returned false... exiting!\n " );
1227
+ return false ;
1228
+ }
1229
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1230
+ << " Callback returned true... continuing!\n " );
1231
+ }
1232
+
1233
+ // Otherwise, keep going.
1234
+ }
1235
+
1236
+ // Then check our argument defs.
1237
+ for (auto *arg : inst->getParent ()->getArguments ()) {
1238
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting arg: " << *arg);
1239
+ if (isDef (arg, index)) {
1240
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found def. Returning true!\n " );
1241
+ return true ;
1242
+ }
1243
+ }
1244
+
1245
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Finished single block. Didn't find "
1246
+ " anything... Performing interprocedural" );
1247
+
1248
+ // Ok, we now know that we need to look further back.
1249
+ BasicBlockWorklist worklist (inst->getFunction ());
1250
+ for (auto *predBlock : inst->getParent ()->getPredecessorBlocks ()) {
1251
+ worklist.pushIfNotVisited (predBlock);
1252
+ }
1253
+
1254
+ while (auto *next = worklist.pop ()) {
1255
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1256
+ << " Checking block bb" << next->getDebugID () << ' \n ' );
1257
+ for (auto ii = next->rbegin (), ie = next->rend (); ii != ie; ++ii) {
1258
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting: " << *ii);
1259
+ // If we have a def, then we are automatically done.
1260
+ if (isDef (&*ii, index)) {
1261
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Def! Returning true!\n " );
1262
+ return true ;
1263
+ }
1264
+
1265
+ // If we have a consuming use, emit the error.
1266
+ if (isInterestingUser (&*ii, index) ==
1267
+ IsInterestingUser::LifetimeEndingUse) {
1268
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Is Lifetime Ending Use!\n " );
1269
+ if (!callback (&*ii)) {
1270
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1271
+ << " Callback returned false... exiting!\n " );
1272
+ return false ;
1273
+ }
1274
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1275
+ << " Callback returned true... continuing!\n " );
1276
+ }
1277
+
1278
+ // Otherwise, keep going.
1279
+ }
1280
+
1281
+ for (auto *arg : next->getArguments ()) {
1282
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Visiting arg: " << *arg);
1283
+ if (isDef (arg, index)) {
1284
+ PRUNED_LIVENESS_LOG (llvm::dbgs () << " Found def. Returning true!\n " );
1285
+ return true ;
1286
+ }
1287
+ }
1288
+
1289
+ PRUNED_LIVENESS_LOG (llvm::dbgs ()
1290
+ << " Didn't find anything... visiting predecessors!\n " );
1291
+ for (auto *predBlock : next->getPredecessorBlocks ()) {
1292
+ worklist.pushIfNotVisited (predBlock);
1293
+ }
1294
+ }
1295
+
1296
+ return true ;
1197
1297
}
0 commit comments