@@ -1286,6 +1286,31 @@ static bool addNoRecurseAttrs(const SCCNodeSet &SCCNodes) {
1286
1286
return setDoesNotRecurse (*F);
1287
1287
}
1288
1288
1289
+ template <typename AARGetterT>
1290
+ static bool deriveAttrsInPostOrder (SCCNodeSet &SCCNodes, AARGetterT &&AARGetter,
1291
+ bool HasUnknownCall) {
1292
+ bool Changed = false ;
1293
+
1294
+ // Bail if the SCC only contains optnone functions.
1295
+ if (SCCNodes.empty ())
1296
+ return Changed;
1297
+
1298
+ Changed |= addArgumentReturnedAttrs (SCCNodes);
1299
+ Changed |= addReadAttrs (SCCNodes, AARGetter);
1300
+ Changed |= addArgumentAttrs (SCCNodes);
1301
+
1302
+ // If we have no external nodes participating in the SCC, we can deduce some
1303
+ // more precise attributes as well.
1304
+ if (!HasUnknownCall) {
1305
+ Changed |= addNoAliasAttrs (SCCNodes);
1306
+ Changed |= addNonNullAttrs (SCCNodes);
1307
+ Changed |= inferAttrsFromFunctionBodies (SCCNodes);
1308
+ Changed |= addNoRecurseAttrs (SCCNodes);
1309
+ }
1310
+
1311
+ return Changed;
1312
+ }
1313
+
1289
1314
PreservedAnalyses PostOrderFunctionAttrsPass::run (LazyCallGraph::SCC &C,
1290
1315
CGSCCAnalysisManager &AM,
1291
1316
LazyCallGraph &CG,
@@ -1328,21 +1353,10 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
1328
1353
SCCNodes.insert (&F);
1329
1354
}
1330
1355
1331
- bool Changed = false ;
1332
- Changed |= addArgumentReturnedAttrs (SCCNodes);
1333
- Changed |= addReadAttrs (SCCNodes, AARGetter);
1334
- Changed |= addArgumentAttrs (SCCNodes);
1335
-
1336
- // If we have no external nodes participating in the SCC, we can deduce some
1337
- // more precise attributes as well.
1338
- if (!HasUnknownCall) {
1339
- Changed |= addNoAliasAttrs (SCCNodes);
1340
- Changed |= addNonNullAttrs (SCCNodes);
1341
- Changed |= inferAttrsFromFunctionBodies (SCCNodes);
1342
- Changed |= addNoRecurseAttrs (SCCNodes);
1343
- }
1356
+ if (deriveAttrsInPostOrder (SCCNodes, AARGetter, HasUnknownCall))
1357
+ return PreservedAnalyses::none ();
1344
1358
1345
- return Changed ? PreservedAnalyses::none () : PreservedAnalyses::all ();
1359
+ return PreservedAnalyses::all ();
1346
1360
}
1347
1361
1348
1362
namespace {
@@ -1382,7 +1396,6 @@ Pass *llvm::createPostOrderFunctionAttrsLegacyPass() {
1382
1396
1383
1397
template <typename AARGetterT>
1384
1398
static bool runImpl (CallGraphSCC &SCC, AARGetterT AARGetter) {
1385
- bool Changed = false ;
1386
1399
1387
1400
// Fill SCCNodes with the elements of the SCC. Used for quickly looking up
1388
1401
// whether a given CallGraphNode is in this SCC. Also track whether there are
@@ -1403,24 +1416,7 @@ static bool runImpl(CallGraphSCC &SCC, AARGetterT AARGetter) {
1403
1416
SCCNodes.insert (F);
1404
1417
}
1405
1418
1406
- // Skip it if the SCC only contains optnone functions.
1407
- if (SCCNodes.empty ())
1408
- return Changed;
1409
-
1410
- Changed |= addArgumentReturnedAttrs (SCCNodes);
1411
- Changed |= addReadAttrs (SCCNodes, AARGetter);
1412
- Changed |= addArgumentAttrs (SCCNodes);
1413
-
1414
- // If we have no external nodes participating in the SCC, we can deduce some
1415
- // more precise attributes as well.
1416
- if (!ExternalNode) {
1417
- Changed |= addNoAliasAttrs (SCCNodes);
1418
- Changed |= addNonNullAttrs (SCCNodes);
1419
- Changed |= inferAttrsFromFunctionBodies (SCCNodes);
1420
- Changed |= addNoRecurseAttrs (SCCNodes);
1421
- }
1422
-
1423
- return Changed;
1419
+ return deriveAttrsInPostOrder (SCCNodes, AARGetter, ExternalNode);
1424
1420
}
1425
1421
1426
1422
bool PostOrderFunctionAttrsLegacyPass::runOnSCC (CallGraphSCC &SCC) {
0 commit comments